dc877563 |
1 | #ifndef STATE_H |
2 | #define STATE_H |
3 | |
ffd54a90 |
4 | #include <glib.h> |
dc877563 |
5 | #include <lttv/processTrace.h> |
6 | |
7 | /* The operating system state kept during the trace analysis |
8 | contains a subset of the real operating system state, |
9 | sufficient for the analysis, and possibly organized quite differently. |
10 | |
ffd54a90 |
11 | The state information is added to LttvTracesetContext, LttvTraceContext |
dc877563 |
12 | and LttvTracefileContext objects, used by processTrace, through |
13 | subtyping. The context objects already reflect the multiple tracefiles |
14 | (one per cpu) per trace and multiple traces per trace set. The state |
15 | objects defined here simply add fields to the relevant context objects. */ |
16 | |
17 | |
18 | /* The LttvProcessState structure defines the current state for each process. |
19 | A process can make system calls (in some rare cases nested) and receive |
20 | interrupts/faults. For instance, a process may issue a system call, |
21 | generate a page fault while reading an argument from user space, and |
22 | get caught by an interrupt. To represent these nested states, an |
23 | interrupt stack is maintained. The stack bottom is normal user mode and |
24 | the top of stack is the current interrupt state. |
25 | |
26 | The interrupt state tells about the process status, interrupt type and |
27 | interrupt number. All these could be defined as enumerations but may |
28 | need extensions (e.g. new process state). GQuark are thus used being |
29 | as easy to manipulate as integers but having a string associated, just |
30 | like enumerations. */ |
31 | |
32 | |
ffd54a90 |
33 | typedef struct _LttvTracesetState LttvTracesetState; |
34 | typedef struct _LttvTracesetStateClass LttvTracesetStateClass; |
35 | |
36 | typedef struct _LttvTraceState LttvTraceState; |
37 | typedef struct _LttvTraceStateClass LttvTraceStateClass; |
38 | |
39 | typedef struct _LttvTracefileState LttvTracefileState; |
40 | typedef struct _LttvTracefileStateClass LttvTracefileStateClass; |
41 | |
996acd92 |
42 | gboolean lttv_state_add_event_hooks(LttvTracesetState *self); |
dc877563 |
43 | |
996acd92 |
44 | gboolean lttv_state_remove_event_hooks(LttvTracesetState *self); |
dc877563 |
45 | |
46 | |
47 | /* The interrupt type is one of "user mode", "kernel thread", "system call", |
48 | "interrupt request", "fault". */ |
49 | |
50 | typedef GQuark LttvInterruptType; |
51 | |
ffd54a90 |
52 | extern LttvInterruptType |
53 | LTTV_STATE_USER_MODE, |
54 | LTTV_STATE_SYSCALL, |
55 | LTTV_STATE_TRAP, |
56 | LTTV_STATE_IRQ; |
57 | |
dc877563 |
58 | |
59 | /* The interrupt number depends on the interrupt type. For user mode or kernel |
60 | thread, which are the normal mode (interrupt stack bottom), it is set to |
61 | "none". For interrupt requests, faults and system calls, it is set |
62 | respectively to the interrupt name (e.g. "timer"), fault name |
996acd92 |
63 | (e.g. "page fault"), and system call name (e.g. "select"). */ |
dc877563 |
64 | |
65 | typedef GQuark LttvInterruptNumber; |
66 | |
67 | |
68 | /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*" |
69 | where "*" describes the resource waited for (e.g. timer, process, |
70 | disk...). */ |
71 | |
72 | typedef GQuark LttvProcessStatus; |
73 | |
ffd54a90 |
74 | extern LttvProcessStatus |
75 | LTTV_STATE_UNNAMED, |
76 | LTTV_STATE_WAIT_FORK, |
77 | LTTV_STATE_WAIT_CPU, |
78 | LTTV_STATE_EXIT, |
79 | LTTV_STATE_WAIT, |
80 | LTTV_STATE_RUN; |
dc877563 |
81 | |
ffd54a90 |
82 | |
83 | typedef struct _LttvInterruptState { |
dc877563 |
84 | LttvInterruptType t; |
85 | LttvInterruptNumber n; |
ba576a78 |
86 | LttTime entry; |
87 | LttTime last_change; |
dc877563 |
88 | LttvProcessStatus s; |
89 | } LttvInterruptState; |
90 | |
91 | |
92 | typedef struct _LttvProcessState { |
93 | guint pid; |
ba576a78 |
94 | LttTime birth; |
dc877563 |
95 | GQuark name; |
96 | GArray *interrupt_stack; /* Array of LttvInterruptState */ |
97 | LttvInterruptState *state; /* Top of interrupt stack */ |
98 | /* opened file descriptors, address map... */ |
99 | } LttvProcessState; |
100 | |
101 | |
ffd54a90 |
102 | /* The LttvTracesetState, LttvTraceState and LttvTracefileState types |
dc877563 |
103 | inherit from the corresponding Context objects defined in processTrace. */ |
104 | |
105 | #define LTTV_TRACESET_STATE_TYPE (lttv_traceset_state_get_type ()) |
ffd54a90 |
106 | #define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTracesetState)) |
107 | #define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
dc877563 |
108 | #define LTTV_IS_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATE_TYPE)) |
109 | #define LTTV_IS_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATE_TYPE)) |
ffd54a90 |
110 | #define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
dc877563 |
111 | |
ffd54a90 |
112 | struct _LttvTracesetState { |
113 | LttvTracesetContext parent; |
dc877563 |
114 | }; |
115 | |
116 | struct _LttvTracesetStateClass { |
ffd54a90 |
117 | LttvTracesetContextClass parent; |
dc877563 |
118 | }; |
119 | |
120 | GType lttv_traceset_state_get_type (void); |
121 | |
122 | |
123 | #define LTTV_TRACE_STATE_TYPE (lttv_trace_state_get_type ()) |
124 | #define LTTV_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATE_TYPE, LttvTraceState)) |
125 | #define LTTV_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
126 | #define LTTV_IS_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATE_TYPE)) |
127 | #define LTTV_IS_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATE_TYPE)) |
128 | #define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
129 | |
dc877563 |
130 | struct _LttvTraceState { |
131 | LttvTraceContext parent; |
132 | |
133 | GHashTable *processes; /* LttvProcessState objects indexed by pid */ |
134 | /* Block/char devices, locks, memory pages... */ |
135 | }; |
136 | |
137 | struct _LttvTraceStateClass { |
138 | LttvTraceContextClass parent; |
139 | }; |
140 | |
141 | GType lttv_trace_state_get_type (void); |
142 | |
143 | |
144 | #define LTTV_TRACEFILE_STATE_TYPE (lttv_tracefile_state_get_type ()) |
145 | #define LTTV_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileState)) |
146 | #define LTTV_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
147 | #define LTTV_IS_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATE_TYPE)) |
148 | #define LTTV_IS_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATE_TYPE)) |
149 | #define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
150 | |
dc877563 |
151 | struct _LttvTracefileState { |
152 | LttvTracefileContext parent; |
153 | |
154 | LttvProcessState *process; |
155 | }; |
156 | |
157 | struct _LttvTracefileStateClass { |
158 | LttvTracefileContextClass parent; |
159 | }; |
160 | |
161 | GType lttv_tracefile_state_get_type (void); |
162 | |
163 | |
164 | #endif // PROCESSTRACE_H |