9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
dc877563 |
19 | #ifndef STATE_H |
20 | #define STATE_H |
21 | |
ffd54a90 |
22 | #include <glib.h> |
dc877563 |
23 | #include <lttv/processTrace.h> |
24 | |
dd025f91 |
25 | /* The operating system state, kept during the trace analysis, |
dc877563 |
26 | contains a subset of the real operating system state, |
27 | sufficient for the analysis, and possibly organized quite differently. |
28 | |
ffd54a90 |
29 | The state information is added to LttvTracesetContext, LttvTraceContext |
dc877563 |
30 | and LttvTracefileContext objects, used by processTrace, through |
31 | subtyping. The context objects already reflect the multiple tracefiles |
32 | (one per cpu) per trace and multiple traces per trace set. The state |
308711e5 |
33 | objects defined here simply add fields to the relevant context objects. |
34 | |
35 | There is no traceset specific state yet. It may eventually contains such |
36 | things as clock differences over time. |
37 | |
38 | The trace state currently consists in a process table. |
39 | |
40 | The tracefile level state relates to the associated cpu. It contains the |
41 | position of the current event in the tracefile (since the state depends on |
42 | which events have been processed) and a pointer to the current process, |
43 | in the process table, being run on that cpu. |
44 | |
45 | For each process in the process table, various informations such as exec |
46 | file name, pid, ppid and creation time are stored. Each process state also |
47 | contains an execution mode stack (e.g. irq within system call, called |
48 | from user mode). */ |
dc877563 |
49 | |
ffd54a90 |
50 | typedef struct _LttvTracesetState LttvTracesetState; |
51 | typedef struct _LttvTracesetStateClass LttvTracesetStateClass; |
52 | |
53 | typedef struct _LttvTraceState LttvTraceState; |
54 | typedef struct _LttvTraceStateClass LttvTraceStateClass; |
55 | |
56 | typedef struct _LttvTracefileState LttvTracefileState; |
57 | typedef struct _LttvTracefileStateClass LttvTracefileStateClass; |
58 | |
308711e5 |
59 | void lttv_state_add_event_hooks(LttvTracesetState *self); |
60 | |
61 | void lttv_state_remove_event_hooks(LttvTracesetState *self); |
62 | |
63 | void lttv_state_save_add_event_hooks(LttvTracesetState *self); |
dc877563 |
64 | |
308711e5 |
65 | void lttv_state_save_remove_event_hooks(LttvTracesetState *self); |
66 | |
dd025f91 |
67 | void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t); |
dc877563 |
68 | |
b445142a |
69 | /* The LttvProcessState structure defines the current state for each process. |
70 | A process can make system calls (in some rare cases nested) and receive |
71 | interrupts/faults. For instance, a process may issue a system call, |
72 | generate a page fault while reading an argument from user space, and |
73 | get caught by an interrupt. To represent these nested states, an |
74 | execution mode stack is maintained. The stack bottom is normal user mode |
75 | and the top of stack is the current execution mode. |
76 | |
77 | The execution mode stack tells about the process status, execution mode and |
78 | submode (interrupt, system call or IRQ number). All these could be |
79 | defined as enumerations but may need extensions (e.g. new process state). |
80 | GQuark are thus used. They are as easy to manipulate as integers but have |
81 | a string associated, just like enumerations. |
dc877563 |
82 | |
b445142a |
83 | The execution mode is one of "user mode", "kernel thread", "system call", |
dc877563 |
84 | "interrupt request", "fault". */ |
85 | |
b445142a |
86 | typedef GQuark LttvExecutionMode; |
dc877563 |
87 | |
b445142a |
88 | extern LttvExecutionMode |
ffd54a90 |
89 | LTTV_STATE_USER_MODE, |
90 | LTTV_STATE_SYSCALL, |
91 | LTTV_STATE_TRAP, |
b445142a |
92 | LTTV_STATE_IRQ, |
93 | LTTV_STATE_MODE_UNKNOWN; |
ffd54a90 |
94 | |
dc877563 |
95 | |
b445142a |
96 | /* The submode number depends on the execution mode. For user mode or kernel |
97 | thread, which are the normal mode (execution mode stack bottom), |
98 | it is set to "none". For interrupt requests, faults and system calls, |
99 | it is set respectively to the interrupt name (e.g. "timer"), fault name |
996acd92 |
100 | (e.g. "page fault"), and system call name (e.g. "select"). */ |
dc877563 |
101 | |
b445142a |
102 | typedef GQuark LttvExecutionSubmode; |
dc877563 |
103 | |
b445142a |
104 | extern LttvExecutionSubmode |
105 | LTTV_STATE_SUBMODE_NONE, |
106 | LTTV_STATE_SUBMODE_UNKNOWN; |
dc877563 |
107 | |
108 | /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*" |
109 | where "*" describes the resource waited for (e.g. timer, process, |
110 | disk...). */ |
111 | |
112 | typedef GQuark LttvProcessStatus; |
113 | |
ffd54a90 |
114 | extern LttvProcessStatus |
115 | LTTV_STATE_UNNAMED, |
116 | LTTV_STATE_WAIT_FORK, |
117 | LTTV_STATE_WAIT_CPU, |
118 | LTTV_STATE_EXIT, |
119 | LTTV_STATE_WAIT, |
120 | LTTV_STATE_RUN; |
dc877563 |
121 | |
ffd54a90 |
122 | |
b445142a |
123 | typedef struct _LttvExecutionState { |
124 | LttvExecutionMode t; |
125 | LttvExecutionSubmode n; |
ba576a78 |
126 | LttTime entry; |
b445142a |
127 | LttTime change; |
dc877563 |
128 | LttvProcessStatus s; |
b445142a |
129 | } LttvExecutionState; |
dc877563 |
130 | |
131 | |
132 | typedef struct _LttvProcessState { |
133 | guint pid; |
3e561027 |
134 | guint ppid; |
b445142a |
135 | LttTime creation_time; |
2a2fa4f0 |
136 | LttTime insertion_time; |
dc877563 |
137 | GQuark name; |
b445142a |
138 | GQuark pid_time; |
139 | GArray *execution_stack; /* Array of LttvExecutionState */ |
140 | LttvExecutionState *state; /* Top of interrupt stack */ |
2a2fa4f0 |
141 | GQuark last_cpu; /* Last CPU where process was scheduled */ |
b445142a |
142 | /* opened file descriptors, address map?... */ |
dc877563 |
143 | } LttvProcessState; |
144 | |
2a2fa4f0 |
145 | |
146 | LttvProcessState * |
147 | lttv_state_find_process(LttvTracefileState *tfs, guint pid); |
148 | |
149 | LttvProcessState * |
150 | lttv_state_find_process_from_trace(LttvTraceState *ts, GQuark cpu, guint pid); |
151 | |
152 | LttvProcessState * |
153 | lttv_state_find_process_or_create(LttvTracefileState *tfs, guint pid); |
154 | |
155 | LttvProcessState * |
156 | lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent, |
157 | guint pid); |
b445142a |
158 | |
159 | |
ffd54a90 |
160 | /* The LttvTracesetState, LttvTraceState and LttvTracefileState types |
dc877563 |
161 | inherit from the corresponding Context objects defined in processTrace. */ |
162 | |
163 | #define LTTV_TRACESET_STATE_TYPE (lttv_traceset_state_get_type ()) |
ffd54a90 |
164 | #define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTracesetState)) |
165 | #define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
dc877563 |
166 | #define LTTV_IS_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATE_TYPE)) |
167 | #define LTTV_IS_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATE_TYPE)) |
ffd54a90 |
168 | #define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
dc877563 |
169 | |
ffd54a90 |
170 | struct _LttvTracesetState { |
171 | LttvTracesetContext parent; |
dc877563 |
172 | }; |
173 | |
174 | struct _LttvTracesetStateClass { |
ffd54a90 |
175 | LttvTracesetContextClass parent; |
dc877563 |
176 | }; |
177 | |
178 | GType lttv_traceset_state_get_type (void); |
179 | |
180 | |
181 | #define LTTV_TRACE_STATE_TYPE (lttv_trace_state_get_type ()) |
182 | #define LTTV_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATE_TYPE, LttvTraceState)) |
183 | #define LTTV_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
184 | #define LTTV_IS_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATE_TYPE)) |
185 | #define LTTV_IS_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATE_TYPE)) |
186 | #define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
187 | |
dc877563 |
188 | struct _LttvTraceState { |
189 | LttvTraceContext parent; |
190 | |
191 | GHashTable *processes; /* LttvProcessState objects indexed by pid */ |
308711e5 |
192 | guint nb_event, save_interval; |
dc877563 |
193 | /* Block/char devices, locks, memory pages... */ |
b445142a |
194 | GQuark *eventtype_names; |
195 | GQuark *syscall_names; |
196 | GQuark *trap_names; |
197 | GQuark *irq_names; |
2a2fa4f0 |
198 | LttTime *max_time_state_recomputed_in_seek; |
dc877563 |
199 | }; |
200 | |
201 | struct _LttvTraceStateClass { |
202 | LttvTraceContextClass parent; |
308711e5 |
203 | |
204 | void (*state_save) (LttvTraceState *self, LttvAttribute *container); |
205 | void (*state_restore) (LttvTraceState *self, LttvAttribute *container); |
206 | void (*state_saved_free) (LttvTraceState *self, LttvAttribute *container); |
dc877563 |
207 | }; |
208 | |
209 | GType lttv_trace_state_get_type (void); |
210 | |
308711e5 |
211 | void lttv_state_save(LttvTraceState *self, LttvAttribute *container); |
212 | |
213 | void lttv_state_restore(LttvTraceState *self, LttvAttribute *container); |
214 | |
215 | void lttv_state_saved_state_free(LttvTraceState *self, |
216 | LttvAttribute *container); |
217 | |
dc877563 |
218 | |
219 | #define LTTV_TRACEFILE_STATE_TYPE (lttv_tracefile_state_get_type ()) |
220 | #define LTTV_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileState)) |
221 | #define LTTV_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
222 | #define LTTV_IS_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATE_TYPE)) |
223 | #define LTTV_IS_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATE_TYPE)) |
224 | #define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
225 | |
dc877563 |
226 | struct _LttvTracefileState { |
227 | LttvTracefileContext parent; |
228 | |
229 | LttvProcessState *process; |
b445142a |
230 | GQuark cpu_name; |
308711e5 |
231 | guint saved_position; |
dc877563 |
232 | }; |
233 | |
234 | struct _LttvTracefileStateClass { |
235 | LttvTracefileContextClass parent; |
236 | }; |
237 | |
238 | GType lttv_tracefile_state_get_type (void); |
239 | |
240 | |
b445142a |
241 | #endif // STATE_H |