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 | |
5e29121a |
19 | #define _GNU_SOURCE |
4e4d11b3 |
20 | #ifdef HAVE_CONFIG_H |
21 | #include <config.h> |
22 | #endif |
dc877563 |
23 | |
c7146c5c |
24 | #include <glib.h> |
08b1c66e |
25 | #include <lttv/lttv.h> |
26 | #include <lttv/module.h> |
dc877563 |
27 | #include <lttv/state.h> |
ba576a78 |
28 | #include <ltt/trace.h> |
308711e5 |
29 | #include <ltt/event.h> |
e1de4b54 |
30 | #include <ltt/ltt.h> |
7ad3837a |
31 | #include <ltt/marker-desc.h> |
f95bc830 |
32 | #include <stdio.h> |
b3fd4c02 |
33 | #include <string.h> |
dc877563 |
34 | |
7df20ca4 |
35 | /* Comment : |
36 | * Mathieu Desnoyers |
37 | * usertrace is there only to be able to update the current CPU of the |
38 | * usertraces when there is a schedchange. it is a way to link the ProcessState |
39 | * to the associated usertrace. Link only created upon thread creation. |
40 | * |
41 | * The cpu id is necessary : it gives us back the current ProcessState when we |
42 | * are considering data from the usertrace. |
43 | */ |
44 | |
e8f2280c |
45 | #define PREALLOCATED_EXECUTION_STACK 10 |
46 | |
eed2ef37 |
47 | /* Facilities Quarks */ |
48 | |
49 | GQuark |
50 | LTT_FACILITY_KERNEL, |
f5d7967f |
51 | LTT_FACILITY_KERNEL_ARCH, |
86c32a8f |
52 | LTT_FACILITY_LIST, |
b3fd4c02 |
53 | LTT_FACILITY_FS, |
27811799 |
54 | LTT_FACILITY_USER_GENERIC, |
55 | LTT_FACILITY_BLOCK; |
eed2ef37 |
56 | |
57 | /* Events Quarks */ |
58 | |
59 | GQuark |
60 | LTT_EVENT_SYSCALL_ENTRY, |
61 | LTT_EVENT_SYSCALL_EXIT, |
62 | LTT_EVENT_TRAP_ENTRY, |
63 | LTT_EVENT_TRAP_EXIT, |
64 | LTT_EVENT_IRQ_ENTRY, |
65 | LTT_EVENT_IRQ_EXIT, |
faf074a3 |
66 | LTT_EVENT_SOFT_IRQ_ENTRY, |
67 | LTT_EVENT_SOFT_IRQ_EXIT, |
86c32a8f |
68 | LTT_EVENT_SCHED_SCHEDULE, |
69 | LTT_EVENT_PROCESS_FORK, |
70 | LTT_EVENT_KTHREAD_CREATE, |
71 | LTT_EVENT_PROCESS_EXIT, |
72 | LTT_EVENT_PROCESS_FREE, |
b3fd4c02 |
73 | LTT_EVENT_EXEC, |
86c32a8f |
74 | LTT_EVENT_PROCESS_STATE, |
c3b3b60b |
75 | LTT_EVENT_STATEDUMP_END, |
80e0221b |
76 | LTT_EVENT_FUNCTION_ENTRY, |
77 | LTT_EVENT_FUNCTION_EXIT, |
27811799 |
78 | LTT_EVENT_THREAD_BRAND, |
79 | LTT_EVENT_REQUEST_ISSUE, |
38b73700 |
80 | LTT_EVENT_REQUEST_COMPLETE, |
81 | LTT_EVENT_LIST_INTERRUPT; |
eed2ef37 |
82 | |
83 | /* Fields Quarks */ |
84 | |
85 | GQuark |
86 | LTT_FIELD_SYSCALL_ID, |
87 | LTT_FIELD_TRAP_ID, |
88 | LTT_FIELD_IRQ_ID, |
faf074a3 |
89 | LTT_FIELD_SOFT_IRQ_ID, |
f63ebe51 |
90 | LTT_FIELD_PREV_PID, |
91 | LTT_FIELD_NEXT_PID, |
92 | LTT_FIELD_PREV_STATE, |
eed2ef37 |
93 | LTT_FIELD_PARENT_PID, |
94 | LTT_FIELD_CHILD_PID, |
f4b88a7d |
95 | LTT_FIELD_PID, |
fcc08e1e |
96 | LTT_FIELD_TGID, |
f63ebe51 |
97 | LTT_FIELD_CHILD_TGID, |
b3fd4c02 |
98 | LTT_FIELD_FILENAME, |
99 | LTT_FIELD_NAME, |
e62e7f3a |
100 | LTT_FIELD_TYPE, |
b3fd4c02 |
101 | LTT_FIELD_MODE, |
102 | LTT_FIELD_SUBMODE, |
302efbad |
103 | LTT_FIELD_STATUS, |
80e0221b |
104 | LTT_FIELD_THIS_FN, |
27811799 |
105 | LTT_FIELD_CALL_SITE, |
106 | LTT_FIELD_MINOR, |
107 | LTT_FIELD_MAJOR, |
38b73700 |
108 | LTT_FIELD_OPERATION, |
43fb1d98 |
109 | LTT_FIELD_ACTION; |
eed2ef37 |
110 | |
b445142a |
111 | LttvExecutionMode |
112 | LTTV_STATE_MODE_UNKNOWN, |
ffd54a90 |
113 | LTTV_STATE_USER_MODE, |
114 | LTTV_STATE_SYSCALL, |
115 | LTTV_STATE_TRAP, |
faf074a3 |
116 | LTTV_STATE_IRQ, |
117 | LTTV_STATE_SOFT_IRQ; |
ffd54a90 |
118 | |
b445142a |
119 | LttvExecutionSubmode |
120 | LTTV_STATE_SUBMODE_UNKNOWN, |
121 | LTTV_STATE_SUBMODE_NONE; |
ffd54a90 |
122 | |
123 | LttvProcessStatus |
124 | LTTV_STATE_UNNAMED, |
125 | LTTV_STATE_WAIT_FORK, |
126 | LTTV_STATE_WAIT_CPU, |
dbd243b1 |
127 | LTTV_STATE_EXIT, |
0828099d |
128 | LTTV_STATE_ZOMBIE, |
ffd54a90 |
129 | LTTV_STATE_WAIT, |
791dffa6 |
130 | LTTV_STATE_RUN, |
131 | LTTV_STATE_DEAD; |
ffd54a90 |
132 | |
c4a72569 |
133 | GQuark |
134 | LTTV_STATE_UNBRANDED; |
135 | |
e62e7f3a |
136 | LttvProcessType |
137 | LTTV_STATE_USER_THREAD, |
80e0221b |
138 | LTTV_STATE_KERNEL_THREAD; |
e62e7f3a |
139 | |
44ffb95f |
140 | LttvCPUMode |
141 | LTTV_CPU_UNKNOWN, |
142 | LTTV_CPU_IDLE, |
598026ba |
143 | LTTV_CPU_BUSY, |
d3d99fde |
144 | LTTV_CPU_IRQ, |
145 | LTTV_CPU_TRAP; |
44ffb95f |
146 | |
5e563da0 |
147 | LttvIRQMode |
148 | LTTV_IRQ_UNKNOWN, |
149 | LTTV_IRQ_IDLE, |
150 | LTTV_IRQ_BUSY; |
151 | |
27811799 |
152 | LttvBdevMode |
153 | LTTV_BDEV_UNKNOWN, |
154 | LTTV_BDEV_IDLE, |
155 | LTTV_BDEV_BUSY_READING, |
156 | LTTV_BDEV_BUSY_WRITING; |
157 | |
ba576a78 |
158 | static GQuark |
308711e5 |
159 | LTTV_STATE_TRACEFILES, |
160 | LTTV_STATE_PROCESSES, |
161 | LTTV_STATE_PROCESS, |
348c6ba8 |
162 | LTTV_STATE_RUNNING_PROCESS, |
308711e5 |
163 | LTTV_STATE_EVENT, |
164 | LTTV_STATE_SAVED_STATES, |
dbb7bb09 |
165 | LTTV_STATE_SAVED_STATES_TIME, |
308711e5 |
166 | LTTV_STATE_TIME, |
f95bc830 |
167 | LTTV_STATE_HOOKS, |
168 | LTTV_STATE_NAME_TABLES, |
fbfbd4db |
169 | LTTV_STATE_TRACE_STATE_USE_COUNT, |
fc6a87b2 |
170 | LTTV_STATE_RESOURCE_CPUS, |
98d7814f |
171 | LTTV_STATE_RESOURCE_IRQS, |
172 | LTTV_STATE_RESOURCE_BLKDEVS; |
ba576a78 |
173 | |
f95bc830 |
174 | static void create_max_time(LttvTraceState *tcs); |
175 | |
176 | static void get_max_time(LttvTraceState *tcs); |
177 | |
178 | static void free_max_time(LttvTraceState *tcs); |
179 | |
180 | static void create_name_tables(LttvTraceState *tcs); |
181 | |
182 | static void get_name_tables(LttvTraceState *tcs); |
b445142a |
183 | |
184 | static void free_name_tables(LttvTraceState *tcs); |
185 | |
f95bc830 |
186 | static void free_saved_state(LttvTraceState *tcs); |
187 | |
308711e5 |
188 | static void lttv_state_free_process_table(GHashTable *processes); |
ba576a78 |
189 | |
7df20ca4 |
190 | static void lttv_trace_states_read_raw(LttvTraceState *tcs, FILE *fp, |
191 | GPtrArray *quarktable); |
dc877563 |
192 | |
44c0619e |
193 | /* Resource function prototypes */ |
98d7814f |
194 | static LttvBdevState *get_hashed_bdevstate(LttvTraceState *ts, guint16 devcode); |
195 | static LttvBdevState *bdevstate_new(void); |
196 | static void bdevstate_free(LttvBdevState *); |
197 | static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data); |
198 | static LttvBdevState *bdevstate_copy(LttvBdevState *bds); |
44c0619e |
199 | |
200 | |
308711e5 |
201 | void lttv_state_save(LttvTraceState *self, LttvAttribute *container) |
202 | { |
203 | LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container); |
204 | } |
205 | |
206 | |
207 | void lttv_state_restore(LttvTraceState *self, LttvAttribute *container) |
208 | { |
209 | LTTV_TRACE_STATE_GET_CLASS(self)->state_restore(self, container); |
210 | } |
211 | |
212 | |
2d262115 |
213 | void lttv_state_state_saved_free(LttvTraceState *self, |
308711e5 |
214 | LttvAttribute *container) |
215 | { |
f95bc830 |
216 | LTTV_TRACE_STATE_GET_CLASS(self)->state_saved_free(self, container); |
308711e5 |
217 | } |
218 | |
219 | |
2a2fa4f0 |
220 | guint process_hash(gconstpointer key) |
221 | { |
7893f726 |
222 | guint pid = ((const LttvProcessState *)key)->pid; |
223 | return (pid>>8 ^ pid>>4 ^ pid>>2 ^ pid) ; |
2a2fa4f0 |
224 | } |
225 | |
226 | |
1d1df11d |
227 | /* If the hash table hash function is well distributed, |
228 | * the process_equal should compare different pid */ |
2a2fa4f0 |
229 | gboolean process_equal(gconstpointer a, gconstpointer b) |
230 | { |
00e74b69 |
231 | const LttvProcessState *process_a, *process_b; |
1d1df11d |
232 | gboolean ret = TRUE; |
233 | |
00e74b69 |
234 | process_a = (const LttvProcessState *)a; |
235 | process_b = (const LttvProcessState *)b; |
1d1df11d |
236 | |
237 | if(likely(process_a->pid != process_b->pid)) ret = FALSE; |
238 | else if(likely(process_a->pid == 0 && |
348c6ba8 |
239 | process_a->cpu != process_b->cpu)) ret = FALSE; |
2a2fa4f0 |
240 | |
1d1df11d |
241 | return ret; |
2a2fa4f0 |
242 | } |
243 | |
6806b3c6 |
244 | static void delete_usertrace(gpointer key, gpointer value, gpointer user_data) |
245 | { |
80e0221b |
246 | g_tree_destroy((GTree*)value); |
6806b3c6 |
247 | } |
248 | |
249 | static void lttv_state_free_usertraces(GHashTable *usertraces) |
250 | { |
80e0221b |
251 | g_hash_table_foreach(usertraces, delete_usertrace, NULL); |
252 | g_hash_table_destroy(usertraces); |
6806b3c6 |
253 | } |
254 | |
255 | |
2a2fa4f0 |
256 | |
308711e5 |
257 | static void |
258 | restore_init_state(LttvTraceState *self) |
259 | { |
311b8e39 |
260 | guint i, nb_cpus, nb_irqs; |
308711e5 |
261 | |
9ec91d57 |
262 | //LttvTracefileState *tfcs; |
954417fa |
263 | |
264 | LttTime start_time, end_time; |
308711e5 |
265 | |
348c6ba8 |
266 | /* Free the process tables */ |
308711e5 |
267 | if(self->processes != NULL) lttv_state_free_process_table(self->processes); |
80e0221b |
268 | if(self->usertraces != NULL) lttv_state_free_usertraces(self->usertraces); |
2a2fa4f0 |
269 | self->processes = g_hash_table_new(process_hash, process_equal); |
80e0221b |
270 | self->usertraces = g_hash_table_new(g_direct_hash, g_direct_equal); |
308711e5 |
271 | self->nb_event = 0; |
272 | |
348c6ba8 |
273 | /* Seek time to beginning */ |
9ba3aaaf |
274 | // Mathieu : fix : don't seek traceset here : causes inconsistency in seek |
275 | // closest. It's the tracecontext job to seek the trace to the beginning |
276 | // anyway : the init state might be used at the middle of the trace as well... |
277 | //g_tree_destroy(self->parent.ts_context->pqueue); |
278 | //self->parent.ts_context->pqueue = g_tree_new(compare_tracefile); |
348c6ba8 |
279 | |
954417fa |
280 | ltt_trace_time_span_get(self->parent.t, &start_time, &end_time); |
9ba3aaaf |
281 | |
282 | //lttv_process_trace_seek_time(&self->parent, ltt_time_zero); |
348c6ba8 |
283 | |
284 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
311b8e39 |
285 | nb_irqs = self->nb_irqs; |
348c6ba8 |
286 | |
287 | /* Put the per cpu running_process to beginning state : process 0. */ |
288 | for(i=0; i< nb_cpus; i++) { |
1e304fa1 |
289 | LttvExecutionState *es; |
fcc08e1e |
290 | self->running_process[i] = lttv_state_create_process(self, NULL, i, 0, 0, |
954417fa |
291 | LTTV_STATE_UNNAMED, &start_time); |
1e304fa1 |
292 | /* We are not sure is it's a kernel thread or normal thread, put the |
293 | * bottom stack state to unknown */ |
294 | self->running_process[i]->execution_stack = |
295 | g_array_set_size(self->running_process[i]->execution_stack, 1); |
296 | es = self->running_process[i]->state = |
297 | &g_array_index(self->running_process[i]->execution_stack, |
298 | LttvExecutionState, 0); |
299 | es->t = LTTV_STATE_MODE_UNKNOWN; |
c4a72569 |
300 | es->s = LTTV_STATE_UNNAMED; |
1e304fa1 |
301 | |
c4a72569 |
302 | //self->running_process[i]->state->s = LTTV_STATE_RUN; |
348c6ba8 |
303 | self->running_process[i]->cpu = i; |
311b8e39 |
304 | |
305 | /* reset cpu states */ |
306 | if(self->cpu_states[i].mode_stack->len > 0) |
307 | g_array_remove_range(self->cpu_states[i].mode_stack, 0, self->cpu_states[i].mode_stack->len); |
308 | } |
309 | |
98d7814f |
310 | /* reset irq states */ |
311b8e39 |
311 | for(i=0; i<nb_irqs; i++) { |
312 | if(self->irq_states[i].mode_stack->len > 0) |
313 | g_array_remove_range(self->irq_states[i].mode_stack, 0, self->irq_states[i].mode_stack->len); |
348c6ba8 |
314 | } |
44c0619e |
315 | |
98d7814f |
316 | /* reset bdev states */ |
317 | g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); |
44c0619e |
318 | g_hash_table_steal_all(self->bdev_states); |
348c6ba8 |
319 | |
320 | #if 0 |
eed2ef37 |
321 | nb_tracefile = self->parent.tracefiles->len; |
308711e5 |
322 | |
dbb7bb09 |
323 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
324 | tfcs = |
cb03932a |
325 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
326 | LttvTracefileContext*, i)); |
d3e01c7a |
327 | ltt_trace_time_span_get(self->parent.t, &tfcs->parent.timestamp, NULL); |
eed2ef37 |
328 | // tfcs->saved_position = 0; |
2a2fa4f0 |
329 | tfcs->process = lttv_state_create_process(tfcs, NULL,0); |
330 | tfcs->process->state->s = LTTV_STATE_RUN; |
331 | tfcs->process->last_cpu = tfcs->cpu_name; |
2c82c4dc |
332 | tfcs->process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfcs)->tf); |
308711e5 |
333 | } |
348c6ba8 |
334 | #endif //0 |
308711e5 |
335 | } |
336 | |
348c6ba8 |
337 | //static LttTime time_zero = {0,0}; |
308711e5 |
338 | |
6806b3c6 |
339 | static gint compare_usertraces(gconstpointer a, gconstpointer b, |
80e0221b |
340 | gpointer user_data) |
6806b3c6 |
341 | { |
80e0221b |
342 | const LttTime *t1 = (const LttTime *)a; |
343 | const LttTime *t2 = (const LttTime *)b; |
6806b3c6 |
344 | |
80e0221b |
345 | return ltt_time_compare(*t1, *t2); |
6806b3c6 |
346 | } |
347 | |
348 | static void free_usertrace_key(gpointer data) |
349 | { |
80e0221b |
350 | g_free(data); |
6806b3c6 |
351 | } |
352 | |
7df20ca4 |
353 | #define MAX_STRING_LEN 4096 |
354 | |
355 | static void |
356 | state_load_saved_states(LttvTraceState *tcs) |
357 | { |
358 | FILE *fp; |
359 | GPtrArray *quarktable; |
5e29121a |
360 | const char *trace_path; |
7df20ca4 |
361 | char path[PATH_MAX]; |
362 | guint count; |
363 | guint i; |
364 | tcs->has_precomputed_states = FALSE; |
365 | GQuark q; |
366 | gchar *string; |
367 | gint hdr; |
368 | gchar buf[MAX_STRING_LEN]; |
369 | guint len; |
370 | |
371 | trace_path = g_quark_to_string(ltt_trace_name(tcs->parent.t)); |
372 | strncpy(path, trace_path, PATH_MAX-1); |
373 | count = strnlen(trace_path, PATH_MAX-1); |
374 | // quarktable : open, test |
375 | strncat(path, "/precomputed/quarktable", PATH_MAX-count-1); |
376 | fp = fopen(path, "r"); |
377 | if(!fp) return; |
378 | quarktable = g_ptr_array_sized_new(4096); |
379 | |
380 | /* Index 0 is null */ |
381 | hdr = fgetc(fp); |
382 | if(hdr == EOF) return; |
383 | g_assert(hdr == HDR_QUARKS); |
384 | q = 1; |
385 | do { |
386 | hdr = fgetc(fp); |
387 | if(hdr == EOF) break; |
388 | g_assert(hdr == HDR_QUARK); |
389 | g_ptr_array_set_size(quarktable, q+1); |
390 | i=0; |
391 | while(1) { |
392 | fread(&buf[i], sizeof(gchar), 1, fp); |
393 | if(buf[i] == '\0' || feof(fp)) break; |
394 | i++; |
395 | } |
396 | len = strnlen(buf, MAX_STRING_LEN-1); |
397 | g_ptr_array_index (quarktable, q) = g_new(gchar, len+1); |
398 | strncpy(g_ptr_array_index (quarktable, q), buf, len+1); |
399 | q++; |
400 | } while(1); |
401 | |
402 | fclose(fp); |
ce05e187 |
403 | |
7df20ca4 |
404 | // saved_states : open, test |
405 | strncpy(path, trace_path, PATH_MAX-1); |
406 | count = strnlen(trace_path, PATH_MAX-1); |
407 | strncat(path, "/precomputed/states", PATH_MAX-count-1); |
408 | fp = fopen(path, "r"); |
409 | if(!fp) return; |
410 | |
411 | hdr = fgetc(fp); |
412 | if(hdr != HDR_TRACE) goto end; |
413 | |
414 | lttv_trace_states_read_raw(tcs, fp, quarktable); |
415 | |
416 | tcs->has_precomputed_states = TRUE; |
417 | |
418 | end: |
419 | fclose(fp); |
420 | |
421 | /* Free the quarktable */ |
422 | for(i=0; i<quarktable->len; i++) { |
423 | string = g_ptr_array_index (quarktable, i); |
424 | g_free(string); |
425 | } |
426 | g_ptr_array_free(quarktable, TRUE); |
427 | return; |
428 | } |
429 | |
dc877563 |
430 | static void |
431 | init(LttvTracesetState *self, LttvTraceset *ts) |
432 | { |
d3d99fde |
433 | guint i, j, nb_trace, nb_tracefile, nb_cpu; |
5e563da0 |
434 | guint64 nb_irq; |
dc877563 |
435 | |
ffd54a90 |
436 | LttvTraceContext *tc; |
dc877563 |
437 | |
ffd54a90 |
438 | LttvTraceState *tcs; |
439 | |
ffd54a90 |
440 | LttvTracefileState *tfcs; |
3d27549e |
441 | |
dbb7bb09 |
442 | LttvAttributeValue v; |
443 | |
b445142a |
444 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
445 | init((LttvTracesetContext *)self, ts); |
dc877563 |
446 | |
447 | nb_trace = lttv_traceset_number(ts); |
448 | for(i = 0 ; i < nb_trace ; i++) { |
b445142a |
449 | tc = self->parent.traces[i]; |
021eeb41 |
450 | tcs = LTTV_TRACE_STATE(tc); |
eed2ef37 |
451 | tcs->save_interval = LTTV_STATE_SAVE_INTERVAL; |
f95bc830 |
452 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, |
453 | LTTV_UINT, &v); |
454 | (*v.v_uint)++; |
dbb7bb09 |
455 | |
f95bc830 |
456 | if(*(v.v_uint) == 1) { |
457 | create_name_tables(tcs); |
458 | create_max_time(tcs); |
459 | } |
460 | get_name_tables(tcs); |
461 | get_max_time(tcs); |
dc877563 |
462 | |
eed2ef37 |
463 | nb_tracefile = tc->tracefiles->len; |
d3d99fde |
464 | nb_cpu = ltt_trace_get_num_cpu(tc->t); |
5e563da0 |
465 | nb_irq = tcs->nb_irqs; |
ae3d0f50 |
466 | tcs->processes = NULL; |
6806b3c6 |
467 | tcs->usertraces = NULL; |
d3d99fde |
468 | tcs->running_process = g_new(LttvProcessState*, nb_cpu); |
5e563da0 |
469 | |
d3d99fde |
470 | /* init cpu resource stuff */ |
471 | tcs->cpu_states = g_new(LttvCPUState, nb_cpu); |
472 | for(j = 0; j<nb_cpu; j++) { |
473 | tcs->cpu_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); |
474 | g_assert(tcs->cpu_states[j].mode_stack != NULL); |
475 | } |
476 | |
5e563da0 |
477 | /* init irq resource stuff */ |
478 | tcs->irq_states = g_new(LttvIRQState, nb_irq); |
479 | for(j = 0; j<nb_irq; j++) { |
480 | tcs->irq_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); |
481 | g_assert(tcs->irq_states[j].mode_stack != NULL); |
482 | } |
483 | |
27811799 |
484 | /* init bdev resource stuff */ |
485 | tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); |
486 | |
ae3d0f50 |
487 | restore_init_state(tcs); |
dc877563 |
488 | for(j = 0 ; j < nb_tracefile ; j++) { |
eed2ef37 |
489 | tfcs = |
cb03932a |
490 | LTTV_TRACEFILE_STATE(g_array_index(tc->tracefiles, |
491 | LttvTracefileContext*, j)); |
348c6ba8 |
492 | tfcs->tracefile_name = ltt_tracefile_name(tfcs->parent.tf); |
80e0221b |
493 | tfcs->cpu = ltt_tracefile_cpu(tfcs->parent.tf); |
44ffb95f |
494 | tfcs->cpu_state = &(tcs->cpu_states[tfcs->cpu]); |
80e0221b |
495 | if(ltt_tracefile_tid(tfcs->parent.tf) != 0) { |
496 | /* It's a Usertrace */ |
497 | guint tid = ltt_tracefile_tid(tfcs->parent.tf); |
498 | GTree *usertrace_tree = (GTree*)g_hash_table_lookup(tcs->usertraces, |
499 | (gconstpointer)tid); |
500 | if(!usertrace_tree) { |
501 | usertrace_tree = g_tree_new_full(compare_usertraces, |
502 | NULL, free_usertrace_key, NULL); |
503 | g_hash_table_insert(tcs->usertraces, |
504 | (gpointer)tid, usertrace_tree); |
505 | } |
506 | LttTime *timestamp = g_new(LttTime, 1); |
507 | *timestamp = ltt_interpolate_time_from_tsc(tfcs->parent.tf, |
508 | ltt_tracefile_creation(tfcs->parent.tf)); |
509 | g_tree_insert(usertrace_tree, timestamp, tfcs); |
510 | } |
6806b3c6 |
511 | } |
512 | |
7df20ca4 |
513 | /* See if the trace has saved states */ |
514 | state_load_saved_states(tcs); |
dc877563 |
515 | } |
516 | } |
517 | |
dc877563 |
518 | static void |
519 | fini(LttvTracesetState *self) |
520 | { |
00e74b69 |
521 | guint i, nb_trace; |
dc877563 |
522 | |
ffd54a90 |
523 | LttvTraceState *tcs; |
dc877563 |
524 | |
9ec91d57 |
525 | //LttvTracefileState *tfcs; |
dc877563 |
526 | |
f95bc830 |
527 | LttvAttributeValue v; |
528 | |
ffd54a90 |
529 | nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts); |
dc877563 |
530 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
531 | tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]); |
f95bc830 |
532 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, |
533 | LTTV_UINT, &v); |
00e74b69 |
534 | |
535 | g_assert(*(v.v_uint) != 0); |
f95bc830 |
536 | (*v.v_uint)--; |
537 | |
f95bc830 |
538 | if(*(v.v_uint) == 0) { |
539 | free_name_tables(tcs); |
540 | free_max_time(tcs); |
541 | free_saved_state(tcs); |
542 | } |
348c6ba8 |
543 | g_free(tcs->running_process); |
544 | tcs->running_process = NULL; |
308711e5 |
545 | lttv_state_free_process_table(tcs->processes); |
80e0221b |
546 | lttv_state_free_usertraces(tcs->usertraces); |
308711e5 |
547 | tcs->processes = NULL; |
6806b3c6 |
548 | tcs->usertraces = NULL; |
dc877563 |
549 | } |
b445142a |
550 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
551 | fini((LttvTracesetContext *)self); |
dc877563 |
552 | } |
553 | |
554 | |
c432246e |
555 | static LttvTracesetContext * |
dc877563 |
556 | new_traceset_context(LttvTracesetContext *self) |
557 | { |
ffd54a90 |
558 | return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL)); |
dc877563 |
559 | } |
560 | |
561 | |
c432246e |
562 | static LttvTraceContext * |
dc877563 |
563 | new_trace_context(LttvTracesetContext *self) |
564 | { |
ffd54a90 |
565 | return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL)); |
dc877563 |
566 | } |
567 | |
568 | |
c432246e |
569 | static LttvTracefileContext * |
dc877563 |
570 | new_tracefile_context(LttvTracesetContext *self) |
571 | { |
ffd54a90 |
572 | return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL)); |
573 | } |
574 | |
575 | |
dbb7bb09 |
576 | /* Write the process state of the trace */ |
577 | |
578 | static void write_process_state(gpointer key, gpointer value, |
579 | gpointer user_data) |
580 | { |
581 | LttvProcessState *process; |
582 | |
583 | LttvExecutionState *es; |
584 | |
585 | FILE *fp = (FILE *)user_data; |
586 | |
587 | guint i; |
d4dd4885 |
588 | guint64 address; |
dbb7bb09 |
589 | |
590 | process = (LttvProcessState *)value; |
591 | fprintf(fp, |
d41c66bf |
592 | " <PROCESS CORE=%p PID=%u TGID=%u PPID=%u TYPE=\"%s\" CTIME_S=%lu CTIME_NS=%lu ITIME_S=%lu ITIME_NS=%lu NAME=\"%s\" BRAND=\"%s\" CPU=\"%u\">\n", |
d4dd4885 |
593 | process, process->pid, process->tgid, process->ppid, |
594 | g_quark_to_string(process->type), |
80e0221b |
595 | process->creation_time.tv_sec, |
d4dd4885 |
596 | process->creation_time.tv_nsec, |
597 | process->insertion_time.tv_sec, |
598 | process->insertion_time.tv_nsec, |
599 | g_quark_to_string(process->name), |
7b5f6cf1 |
600 | g_quark_to_string(process->brand), |
6d0cdf22 |
601 | process->cpu); |
dbb7bb09 |
602 | |
603 | for(i = 0 ; i < process->execution_stack->len; i++) { |
604 | es = &g_array_index(process->execution_stack, LttvExecutionState, i); |
605 | fprintf(fp, " <ES MODE=\"%s\" SUBMODE=\"%s\" ENTRY_S=%lu ENTRY_NS=%lu", |
80e0221b |
606 | g_quark_to_string(es->t), g_quark_to_string(es->n), |
dbb7bb09 |
607 | es->entry.tv_sec, es->entry.tv_nsec); |
608 | fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", |
609 | es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); |
610 | } |
d4dd4885 |
611 | |
6d0cdf22 |
612 | for(i = 0 ; i < process->user_stack->len; i++) { |
5e29121a |
613 | address = g_array_index(process->user_stack, guint64, i); |
d4dd4885 |
614 | fprintf(fp, " <USER_STACK ADDRESS=\"%llu\"/>\n", |
615 | address); |
616 | } |
617 | |
618 | if(process->usertrace) { |
619 | fprintf(fp, " <USERTRACE NAME=\"%s\" CPU=%u\n/>", |
6d0cdf22 |
620 | g_quark_to_string(process->usertrace->tracefile_name), |
d4dd4885 |
621 | process->usertrace->cpu); |
622 | } |
623 | |
624 | |
dbb7bb09 |
625 | fprintf(fp, " </PROCESS>\n"); |
626 | } |
627 | |
628 | |
629 | void lttv_state_write(LttvTraceState *self, LttTime t, FILE *fp) |
630 | { |
eed2ef37 |
631 | guint i, nb_tracefile, nb_block, offset; |
632 | guint64 tsc; |
dbb7bb09 |
633 | |
634 | LttvTracefileState *tfcs; |
635 | |
636 | LttTracefile *tf; |
637 | |
638 | LttEventPosition *ep; |
639 | |
348c6ba8 |
640 | guint nb_cpus; |
641 | |
dbb7bb09 |
642 | ep = ltt_event_position_new(); |
643 | |
644 | fprintf(fp,"<PROCESS_STATE TIME_S=%lu TIME_NS=%lu>\n", t.tv_sec, t.tv_nsec); |
645 | |
646 | g_hash_table_foreach(self->processes, write_process_state, fp); |
348c6ba8 |
647 | |
648 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
649 | for(i=0;i<nb_cpus;i++) { |
6d0cdf22 |
650 | fprintf(fp," <CPU NUM=%u RUNNING_PROCESS=%u>\n", |
348c6ba8 |
651 | i, self->running_process[i]->pid); |
652 | } |
dbb7bb09 |
653 | |
eed2ef37 |
654 | nb_tracefile = self->parent.tracefiles->len; |
dbb7bb09 |
655 | |
656 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
657 | tfcs = |
cb03932a |
658 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
659 | LttvTracefileContext*, i)); |
348c6ba8 |
660 | fprintf(fp, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu", |
661 | tfcs->parent.timestamp.tv_sec, |
08b1c66e |
662 | tfcs->parent.timestamp.tv_nsec); |
eed2ef37 |
663 | LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); |
664 | if(e == NULL) fprintf(fp,"/>\n"); |
dbb7bb09 |
665 | else { |
eed2ef37 |
666 | ltt_event_position(e, ep); |
667 | ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); |
27304273 |
668 | fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset, |
eed2ef37 |
669 | tsc); |
dbb7bb09 |
670 | } |
671 | } |
672 | g_free(ep); |
6d0cdf22 |
673 | fprintf(fp,"</PROCESS_STATE>\n"); |
674 | } |
675 | |
676 | |
677 | static void write_process_state_raw(gpointer key, gpointer value, |
678 | gpointer user_data) |
679 | { |
680 | LttvProcessState *process; |
681 | |
682 | LttvExecutionState *es; |
683 | |
684 | FILE *fp = (FILE *)user_data; |
685 | |
686 | guint i; |
687 | guint64 address; |
688 | |
689 | process = (LttvProcessState *)value; |
690 | fputc(HDR_PROCESS, fp); |
691 | //fwrite(&header, sizeof(header), 1, fp); |
692 | //fprintf(fp, "%s", g_quark_to_string(process->type)); |
693 | //fputc('\0', fp); |
694 | fwrite(&process->type, sizeof(process->type), 1, fp); |
695 | //fprintf(fp, "%s", g_quark_to_string(process->name)); |
696 | //fputc('\0', fp); |
697 | fwrite(&process->name, sizeof(process->name), 1, fp); |
698 | //fprintf(fp, "%s", g_quark_to_string(process->brand)); |
699 | //fputc('\0', fp); |
700 | fwrite(&process->brand, sizeof(process->brand), 1, fp); |
701 | fwrite(&process->pid, sizeof(process->pid), 1, fp); |
702 | fwrite(&process->tgid, sizeof(process->tgid), 1, fp); |
703 | fwrite(&process->ppid, sizeof(process->ppid), 1, fp); |
704 | fwrite(&process->cpu, sizeof(process->cpu), 1, fp); |
705 | fwrite(&process->creation_time, sizeof(process->creation_time), 1, fp); |
706 | fwrite(&process->insertion_time, sizeof(process->insertion_time), 1, fp); |
707 | |
708 | #if 0 |
709 | fprintf(fp, |
710 | " <PROCESS CORE=%p PID=%u TGID=%u PPID=%u TYPE=\"%s\" CTIME_S=%lu CTIME_NS=%lu ITIME_S=%lu ITIME_NS=%lu NAME=\"%s\" BRAND=\"%s\" CPU=\"%u\" PROCESS_TYPE=%u>\n", |
711 | process, process->pid, process->tgid, process->ppid, |
712 | g_quark_to_string(process->type), |
713 | process->creation_time.tv_sec, |
714 | process->creation_time.tv_nsec, |
715 | process->insertion_time.tv_sec, |
716 | process->insertion_time.tv_nsec, |
717 | g_quark_to_string(process->name), |
718 | g_quark_to_string(process->brand), |
719 | process->cpu); |
720 | #endif //0 |
721 | |
722 | for(i = 0 ; i < process->execution_stack->len; i++) { |
723 | es = &g_array_index(process->execution_stack, LttvExecutionState, i); |
724 | |
725 | fputc(HDR_ES, fp); |
726 | //fprintf(fp, "%s", g_quark_to_string(es->t)); |
727 | //fputc('\0', fp); |
728 | fwrite(&es->t, sizeof(es->t), 1, fp); |
729 | //fprintf(fp, "%s", g_quark_to_string(es->n)); |
730 | //fputc('\0', fp); |
731 | fwrite(&es->n, sizeof(es->n), 1, fp); |
732 | //fprintf(fp, "%s", g_quark_to_string(es->s)); |
733 | //fputc('\0', fp); |
734 | fwrite(&es->s, sizeof(es->s), 1, fp); |
735 | fwrite(&es->entry, sizeof(es->entry), 1, fp); |
736 | fwrite(&es->change, sizeof(es->change), 1, fp); |
7df20ca4 |
737 | fwrite(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); |
6d0cdf22 |
738 | #if 0 |
739 | fprintf(fp, " <ES MODE=\"%s\" SUBMODE=\"%s\" ENTRY_S=%lu ENTRY_NS=%lu", |
740 | g_quark_to_string(es->t), g_quark_to_string(es->n), |
741 | es->entry.tv_sec, es->entry.tv_nsec); |
742 | fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", |
743 | es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); |
744 | #endif //0 |
745 | } |
746 | |
747 | for(i = 0 ; i < process->user_stack->len; i++) { |
5e29121a |
748 | address = g_array_index(process->user_stack, guint64, i); |
6d0cdf22 |
749 | fputc(HDR_USER_STACK, fp); |
750 | fwrite(&address, sizeof(address), 1, fp); |
751 | #if 0 |
752 | fprintf(fp, " <USER_STACK ADDRESS=\"%llu\"/>\n", |
753 | address); |
754 | #endif //0 |
755 | } |
756 | |
757 | if(process->usertrace) { |
758 | fputc(HDR_USERTRACE, fp); |
759 | //fprintf(fp, "%s", g_quark_to_string(process->usertrace->tracefile_name)); |
760 | //fputc('\0', fp); |
761 | fwrite(&process->usertrace->tracefile_name, |
762 | sizeof(process->usertrace->tracefile_name), 1, fp); |
763 | fwrite(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); |
764 | #if 0 |
765 | fprintf(fp, " <USERTRACE NAME=\"%s\" CPU=%u\n/>", |
766 | g_quark_to_string(process->usertrace->tracefile_name), |
767 | process->usertrace->cpu); |
768 | #endif //0 |
769 | } |
770 | |
dbb7bb09 |
771 | } |
772 | |
773 | |
6d0cdf22 |
774 | void lttv_state_write_raw(LttvTraceState *self, LttTime t, FILE *fp) |
775 | { |
776 | guint i, nb_tracefile, nb_block, offset; |
777 | guint64 tsc; |
778 | |
779 | LttvTracefileState *tfcs; |
780 | |
781 | LttTracefile *tf; |
782 | |
783 | LttEventPosition *ep; |
784 | |
785 | guint nb_cpus; |
786 | |
787 | ep = ltt_event_position_new(); |
788 | |
789 | //fprintf(fp,"<PROCESS_STATE TIME_S=%lu TIME_NS=%lu>\n", t.tv_sec, t.tv_nsec); |
790 | fputc(HDR_PROCESS_STATE, fp); |
791 | fwrite(&t, sizeof(t), 1, fp); |
792 | |
793 | g_hash_table_foreach(self->processes, write_process_state_raw, fp); |
794 | |
795 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
796 | for(i=0;i<nb_cpus;i++) { |
797 | fputc(HDR_CPU, fp); |
798 | fwrite(&i, sizeof(i), 1, fp); /* cpu number */ |
799 | fwrite(&self->running_process[i]->pid, |
800 | sizeof(self->running_process[i]->pid), 1, fp); |
801 | //fprintf(fp," <CPU NUM=%u RUNNING_PROCESS=%u>\n", |
802 | // i, self->running_process[i]->pid); |
803 | } |
804 | |
805 | nb_tracefile = self->parent.tracefiles->len; |
806 | |
807 | for(i = 0 ; i < nb_tracefile ; i++) { |
808 | tfcs = |
809 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
810 | LttvTracefileContext*, i)); |
811 | // fprintf(fp, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu", |
812 | // tfcs->parent.timestamp.tv_sec, |
813 | // tfcs->parent.timestamp.tv_nsec); |
814 | fputc(HDR_TRACEFILE, fp); |
815 | fwrite(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); |
816 | /* Note : if timestamp if LTT_TIME_INFINITE, there will be no |
817 | * position following : end of trace */ |
818 | LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); |
819 | if(e != NULL) { |
820 | ltt_event_position(e, ep); |
821 | ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); |
822 | //fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset, |
823 | // tsc); |
824 | fwrite(&nb_block, sizeof(nb_block), 1, fp); |
825 | fwrite(&offset, sizeof(offset), 1, fp); |
826 | fwrite(&tsc, sizeof(tsc), 1, fp); |
827 | } |
828 | } |
829 | g_free(ep); |
830 | } |
831 | |
832 | |
833 | /* Read process state from a file */ |
834 | |
835 | /* Called because a HDR_PROCESS was found */ |
7df20ca4 |
836 | static void read_process_state_raw(LttvTraceState *self, FILE *fp, |
837 | GPtrArray *quarktable) |
6d0cdf22 |
838 | { |
839 | LttvExecutionState *es; |
840 | LttvProcessState *process, *parent_process; |
841 | LttvProcessState tmp; |
7df20ca4 |
842 | GQuark tmpq; |
6d0cdf22 |
843 | |
7df20ca4 |
844 | guint64 *address; |
6d0cdf22 |
845 | |
7df20ca4 |
846 | /* TODO : check return value */ |
6d0cdf22 |
847 | fread(&tmp.type, sizeof(tmp.type), 1, fp); |
848 | fread(&tmp.name, sizeof(tmp.name), 1, fp); |
849 | fread(&tmp.brand, sizeof(tmp.brand), 1, fp); |
850 | fread(&tmp.pid, sizeof(tmp.pid), 1, fp); |
851 | fread(&tmp.tgid, sizeof(tmp.tgid), 1, fp); |
852 | fread(&tmp.ppid, sizeof(tmp.ppid), 1, fp); |
853 | fread(&tmp.cpu, sizeof(tmp.cpu), 1, fp); |
854 | fread(&tmp.creation_time, sizeof(tmp.creation_time), 1, fp); |
855 | fread(&tmp.insertion_time, sizeof(tmp.insertion_time), 1, fp); |
856 | |
857 | if(tmp.pid == 0) { |
d41c66bf |
858 | process = lttv_state_find_process(self, tmp.cpu, tmp.pid); |
6d0cdf22 |
859 | } else { |
860 | /* We must link to the parent */ |
861 | parent_process = lttv_state_find_process_or_create(self, ANY_CPU, tmp.ppid, |
d41c66bf |
862 | <t_time_zero); |
ce05e187 |
863 | process = lttv_state_find_process(self, ANY_CPU, tmp.pid); |
864 | if(process == NULL) { |
865 | process = lttv_state_create_process(self, parent_process, tmp.cpu, |
866 | tmp.pid, tmp.tgid, |
867 | g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)), |
868 | &tmp.creation_time); |
869 | } |
6d0cdf22 |
870 | } |
7df20ca4 |
871 | process->insertion_time = tmp.insertion_time; |
6d0cdf22 |
872 | process->creation_time = tmp.creation_time; |
7df20ca4 |
873 | process->type = g_quark_from_string( |
874 | (gchar*)g_ptr_array_index(quarktable, tmp.type)); |
6d0cdf22 |
875 | process->tgid = tmp.tgid; |
7df20ca4 |
876 | process->ppid = tmp.ppid; |
877 | process->brand = g_quark_from_string( |
878 | (gchar*)g_ptr_array_index(quarktable, tmp.brand)); |
879 | process->name = |
880 | g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)); |
6d0cdf22 |
881 | |
ce05e187 |
882 | |
6d0cdf22 |
883 | do { |
884 | if(feof(fp) || ferror(fp)) goto end_loop; |
885 | |
d41c66bf |
886 | gint hdr = fgetc(fp); |
7df20ca4 |
887 | if(hdr == EOF) goto end_loop; |
6d0cdf22 |
888 | |
889 | switch(hdr) { |
890 | case HDR_ES: |
7df20ca4 |
891 | process->execution_stack = |
892 | g_array_set_size(process->execution_stack, |
893 | process->execution_stack->len + 1); |
894 | es = &g_array_index(process->execution_stack, LttvExecutionState, |
895 | process->execution_stack->len-1); |
ce05e187 |
896 | process->state = es; |
7df20ca4 |
897 | |
898 | fread(&es->t, sizeof(es->t), 1, fp); |
899 | es->t = g_quark_from_string( |
900 | (gchar*)g_ptr_array_index(quarktable, es->t)); |
901 | fread(&es->n, sizeof(es->n), 1, fp); |
902 | es->n = g_quark_from_string( |
903 | (gchar*)g_ptr_array_index(quarktable, es->n)); |
904 | fread(&es->s, sizeof(es->s), 1, fp); |
905 | es->s = g_quark_from_string( |
906 | (gchar*)g_ptr_array_index(quarktable, es->s)); |
907 | fread(&es->entry, sizeof(es->entry), 1, fp); |
908 | fread(&es->change, sizeof(es->change), 1, fp); |
909 | fread(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); |
6d0cdf22 |
910 | break; |
911 | case HDR_USER_STACK: |
7df20ca4 |
912 | process->user_stack = g_array_set_size(process->user_stack, |
913 | process->user_stack->len + 1); |
914 | address = &g_array_index(process->user_stack, guint64, |
915 | process->user_stack->len-1); |
916 | fread(address, sizeof(address), 1, fp); |
917 | process->current_function = *address; |
6d0cdf22 |
918 | break; |
919 | case HDR_USERTRACE: |
7df20ca4 |
920 | fread(&tmpq, sizeof(tmpq), 1, fp); |
921 | fread(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); |
6d0cdf22 |
922 | break; |
923 | default: |
924 | ungetc(hdr, fp); |
925 | goto end_loop; |
926 | }; |
927 | } while(1); |
928 | end_loop: |
d41c66bf |
929 | return; |
6d0cdf22 |
930 | } |
931 | |
932 | |
933 | /* Called because a HDR_PROCESS_STATE was found */ |
934 | /* Append a saved state to the trace states */ |
7df20ca4 |
935 | void lttv_state_read_raw(LttvTraceState *self, FILE *fp, GPtrArray *quarktable) |
6d0cdf22 |
936 | { |
937 | guint i, nb_tracefile, nb_block, offset; |
938 | guint64 tsc; |
d41c66bf |
939 | LttvTracefileState *tfcs; |
6d0cdf22 |
940 | |
941 | LttEventPosition *ep; |
942 | |
943 | guint nb_cpus; |
944 | |
945 | int hdr; |
946 | |
947 | LttTime t; |
948 | |
949 | LttvAttribute *saved_states_tree, *saved_state_tree; |
950 | |
951 | LttvAttributeValue value; |
ce05e187 |
952 | GTree *pqueue = self->parent.ts_context->pqueue; |
6d0cdf22 |
953 | ep = ltt_event_position_new(); |
954 | |
955 | restore_init_state(self); |
956 | |
957 | fread(&t, sizeof(t), 1, fp); |
958 | |
959 | do { |
960 | if(feof(fp) || ferror(fp)) goto end_loop; |
961 | hdr = fgetc(fp); |
7df20ca4 |
962 | if(hdr == EOF) goto end_loop; |
6d0cdf22 |
963 | |
964 | switch(hdr) { |
965 | case HDR_PROCESS: |
966 | /* Call read_process_state_raw */ |
7df20ca4 |
967 | read_process_state_raw(self, fp, quarktable); |
6d0cdf22 |
968 | break; |
969 | case HDR_TRACEFILE: |
970 | case HDR_TRACESET: |
971 | case HDR_TRACE: |
972 | case HDR_QUARKS: |
973 | case HDR_QUARK: |
974 | case HDR_ES: |
975 | case HDR_USER_STACK: |
976 | case HDR_USERTRACE: |
977 | case HDR_PROCESS_STATE: |
978 | case HDR_CPU: |
7df20ca4 |
979 | ungetc(hdr, fp); |
980 | goto end_loop; |
6d0cdf22 |
981 | break; |
982 | default: |
983 | g_error("Error while parsing saved state file : unknown data header %d", |
984 | hdr); |
985 | }; |
986 | } while(1); |
987 | end_loop: |
988 | |
989 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
990 | for(i=0;i<nb_cpus;i++) { |
991 | int cpu_num; |
992 | hdr = fgetc(fp); |
993 | g_assert(hdr == HDR_CPU); |
994 | fread(&cpu_num, sizeof(cpu_num), 1, fp); /* cpu number */ |
995 | g_assert(i == cpu_num); |
996 | fread(&self->running_process[i]->pid, |
997 | sizeof(self->running_process[i]->pid), 1, fp); |
998 | } |
999 | |
1000 | nb_tracefile = self->parent.tracefiles->len; |
1001 | |
1002 | for(i = 0 ; i < nb_tracefile ; i++) { |
1003 | tfcs = |
1004 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
1005 | LttvTracefileContext*, i)); |
1006 | // fprintf(fp, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu", |
1007 | // tfcs->parent.timestamp.tv_sec, |
1008 | // tfcs->parent.timestamp.tv_nsec); |
ce05e187 |
1009 | g_tree_remove(pqueue, &tfcs->parent); |
6d0cdf22 |
1010 | hdr = fgetc(fp); |
1011 | g_assert(hdr == HDR_TRACEFILE); |
1012 | fread(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); |
1013 | /* Note : if timestamp if LTT_TIME_INFINITE, there will be no |
1014 | * position following : end of trace */ |
d41c66bf |
1015 | if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) != 0) { |
6d0cdf22 |
1016 | fread(&nb_block, sizeof(nb_block), 1, fp); |
1017 | fread(&offset, sizeof(offset), 1, fp); |
1018 | fread(&tsc, sizeof(tsc), 1, fp); |
7df20ca4 |
1019 | ltt_event_position_set(ep, tfcs->parent.tf, nb_block, offset, tsc); |
d41c66bf |
1020 | gint ret = ltt_tracefile_seek_position(tfcs->parent.tf, ep); |
1021 | g_assert(ret == 0); |
ce05e187 |
1022 | g_tree_insert(pqueue, &tfcs->parent, &tfcs->parent); |
6d0cdf22 |
1023 | } |
1024 | } |
1025 | g_free(ep); |
1026 | |
d41c66bf |
1027 | saved_states_tree = lttv_attribute_find_subdir(self->parent.t_a, |
6d0cdf22 |
1028 | LTTV_STATE_SAVED_STATES); |
1029 | saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
1030 | value = lttv_attribute_add(saved_states_tree, |
1031 | lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); |
1032 | *(value.v_gobject) = (GObject *)saved_state_tree; |
1033 | value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); |
1034 | *(value.v_time) = t; |
d41c66bf |
1035 | lttv_state_save(self, saved_state_tree); |
6d0cdf22 |
1036 | g_debug("Saving state at time %lu.%lu", t.tv_sec, |
d41c66bf |
1037 | t.tv_nsec); |
6d0cdf22 |
1038 | |
1039 | *(self->max_time_state_recomputed_in_seek) = t; |
ce05e187 |
1040 | |
6d0cdf22 |
1041 | } |
1042 | |
1043 | /* Called when a HDR_TRACE is found */ |
7df20ca4 |
1044 | void lttv_trace_states_read_raw(LttvTraceState *tcs, FILE *fp, |
1045 | GPtrArray *quarktable) |
6d0cdf22 |
1046 | { |
1047 | int hdr; |
1048 | |
1049 | do { |
1050 | if(feof(fp) || ferror(fp)) goto end_loop; |
1051 | hdr = fgetc(fp); |
7df20ca4 |
1052 | if(hdr == EOF) goto end_loop; |
6d0cdf22 |
1053 | |
1054 | switch(hdr) { |
1055 | case HDR_PROCESS_STATE: |
1056 | /* Call read_process_state_raw */ |
7df20ca4 |
1057 | lttv_state_read_raw(tcs, fp, quarktable); |
6d0cdf22 |
1058 | break; |
1059 | case HDR_TRACEFILE: |
1060 | case HDR_TRACESET: |
1061 | case HDR_TRACE: |
1062 | case HDR_QUARKS: |
1063 | case HDR_QUARK: |
1064 | case HDR_ES: |
1065 | case HDR_USER_STACK: |
1066 | case HDR_USERTRACE: |
1067 | case HDR_PROCESS: |
1068 | case HDR_CPU: |
1069 | g_error("Error while parsing saved state file :" |
1070 | " unexpected data header %d", |
1071 | hdr); |
1072 | break; |
1073 | default: |
1074 | g_error("Error while parsing saved state file : unknown data header %d", |
1075 | hdr); |
1076 | }; |
1077 | } while(1); |
1078 | end_loop: |
6d0cdf22 |
1079 | *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; |
9ec91d57 |
1080 | restore_init_state(tcs); |
1081 | lttv_process_trace_seek_time(&tcs->parent, ltt_time_zero); |
ce05e187 |
1082 | return; |
6d0cdf22 |
1083 | } |
1084 | |
1085 | |
1086 | |
dbb7bb09 |
1087 | /* Copy each process from an existing hash table to a new one */ |
1088 | |
308711e5 |
1089 | static void copy_process_state(gpointer key, gpointer value,gpointer user_data) |
ffd54a90 |
1090 | { |
308711e5 |
1091 | LttvProcessState *process, *new_process; |
ffd54a90 |
1092 | |
308711e5 |
1093 | GHashTable *new_processes = (GHashTable *)user_data; |
ffd54a90 |
1094 | |
308711e5 |
1095 | guint i; |
1096 | |
1097 | process = (LttvProcessState *)value; |
1098 | new_process = g_new(LttvProcessState, 1); |
1099 | *new_process = *process; |
e8f2280c |
1100 | new_process->execution_stack = g_array_sized_new(FALSE, FALSE, |
1101 | sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); |
e05fc742 |
1102 | new_process->execution_stack = |
1103 | g_array_set_size(new_process->execution_stack, |
1104 | process->execution_stack->len); |
308711e5 |
1105 | for(i = 0 ; i < process->execution_stack->len; i++) { |
1106 | g_array_index(new_process->execution_stack, LttvExecutionState, i) = |
1107 | g_array_index(process->execution_stack, LttvExecutionState, i); |
1108 | } |
1109 | new_process->state = &g_array_index(new_process->execution_stack, |
1110 | LttvExecutionState, new_process->execution_stack->len - 1); |
302efbad |
1111 | new_process->user_stack = g_array_sized_new(FALSE, FALSE, |
1112 | sizeof(guint64), 0); |
1113 | new_process->user_stack = |
1114 | g_array_set_size(new_process->user_stack, |
1115 | process->user_stack->len); |
1116 | for(i = 0 ; i < process->user_stack->len; i++) { |
1117 | g_array_index(new_process->user_stack, guint64, i) = |
1118 | g_array_index(process->user_stack, guint64, i); |
1119 | } |
052a984f |
1120 | new_process->current_function = process->current_function; |
2a2fa4f0 |
1121 | g_hash_table_insert(new_processes, new_process, new_process); |
ffd54a90 |
1122 | } |
1123 | |
1124 | |
308711e5 |
1125 | static GHashTable *lttv_state_copy_process_table(GHashTable *processes) |
ffd54a90 |
1126 | { |
2a2fa4f0 |
1127 | GHashTable *new_processes = g_hash_table_new(process_hash, process_equal); |
ffd54a90 |
1128 | |
308711e5 |
1129 | g_hash_table_foreach(processes, copy_process_state, new_processes); |
1130 | return new_processes; |
dc877563 |
1131 | } |
1132 | |
fbfbd4db |
1133 | static LttvCPUState *lttv_state_copy_cpu_states(LttvCPUState *states, guint n) |
1134 | { |
1135 | guint i,j; |
1136 | LttvCPUState *retval; |
1137 | |
1138 | retval = g_malloc(n*sizeof(LttvCPUState)); |
1139 | |
1140 | for(i=0; i<n; i++) { |
1141 | retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); |
1142 | retval[i].last_irq = states[i].last_irq; |
1143 | g_array_set_size(retval[i].mode_stack, states[i].mode_stack->len); |
1144 | for(j=0; j<states[i].mode_stack->len; j++) { |
1145 | g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j); |
1146 | } |
1147 | } |
1148 | |
1149 | return retval; |
1150 | } |
1151 | |
1152 | static void lttv_state_free_cpu_states(LttvCPUState *states, guint n) |
1153 | { |
1154 | guint i; |
1155 | |
1156 | for(i=0; i<n; i++) { |
1157 | g_array_free(states[i].mode_stack, FALSE); |
1158 | } |
1159 | |
1160 | g_free(states); |
1161 | } |
dc877563 |
1162 | |
fc6a87b2 |
1163 | static LttvIRQState *lttv_state_copy_irq_states(LttvIRQState *states, guint n) |
1164 | { |
1165 | guint i,j; |
1166 | LttvIRQState *retval; |
1167 | |
1168 | retval = g_malloc(n*sizeof(LttvIRQState)); |
1169 | |
1170 | for(i=0; i<n; i++) { |
1171 | retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); |
1172 | g_array_set_size(retval[i].mode_stack, states[i].mode_stack->len); |
1173 | for(j=0; j<states[i].mode_stack->len; j++) { |
1174 | g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j); |
1175 | } |
1176 | } |
1177 | |
1178 | return retval; |
1179 | } |
1180 | |
1181 | static void lttv_state_free_irq_states(LttvIRQState *states, guint n) |
1182 | { |
1183 | guint i; |
1184 | |
1185 | for(i=0; i<n; i++) { |
1186 | g_array_free(states[i].mode_stack, FALSE); |
1187 | } |
1188 | |
1189 | g_free(states); |
1190 | } |
1191 | |
98d7814f |
1192 | /* bdevstate stuff */ |
1193 | |
1194 | static LttvBdevState *get_hashed_bdevstate(LttvTraceState *ts, guint16 devcode) |
1195 | { |
1196 | gint devcode_gint = devcode; |
1197 | gpointer bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); |
1198 | if(bdev == NULL) { |
1199 | LttvBdevState *bdevstate = g_malloc(sizeof(LttvBdevState)); |
1200 | bdevstate->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); |
1201 | |
1202 | gint * key = g_malloc(sizeof(gint)); |
1203 | *key = devcode; |
1204 | g_hash_table_insert(ts->bdev_states, key, bdevstate); |
1205 | |
1206 | bdev = bdevstate; |
1207 | } |
1208 | |
1209 | return bdev; |
1210 | } |
1211 | |
1212 | static LttvBdevState *bdevstate_new(void) |
1213 | { |
1214 | LttvBdevState *retval; |
1215 | retval = g_malloc(sizeof(LttvBdevState)); |
1216 | retval->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); |
b895e4db |
1217 | |
1218 | return retval; |
98d7814f |
1219 | } |
1220 | |
1221 | static void bdevstate_free(LttvBdevState *bds) |
1222 | { |
1223 | g_array_free(bds->mode_stack, FALSE); |
1224 | g_free(bds); |
1225 | } |
1226 | |
1227 | static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data) |
1228 | { |
1229 | LttvBdevState *bds = (LttvBdevState *) value; |
1230 | |
1231 | bdevstate_free(bds); |
1232 | } |
1233 | |
1234 | static LttvBdevState *bdevstate_copy(LttvBdevState *bds) |
1235 | { |
1236 | LttvBdevState *retval; |
1237 | |
1238 | retval = bdevstate_new(); |
1239 | g_array_insert_vals(retval->mode_stack, 0, bds->mode_stack->data, bds->mode_stack->len); |
b895e4db |
1240 | |
1241 | return retval; |
98d7814f |
1242 | } |
1243 | |
1244 | static void insert_and_copy_bdev_state(gpointer k, gpointer v, gpointer u) |
1245 | { |
9ec91d57 |
1246 | //GHashTable *ht = (GHashTable *)u; |
98d7814f |
1247 | LttvBdevState *bds = (LttvBdevState *)v; |
1248 | LttvBdevState *newbds; |
1249 | |
9ec91d57 |
1250 | newbds = bdevstate_copy(bds); |
98d7814f |
1251 | |
1252 | g_hash_table_insert(u, k, newbds); |
1253 | } |
1254 | |
1255 | static GHashTable *lttv_state_copy_blkdev_hashtable(GHashTable *ht) |
1256 | { |
1257 | GHashTable *retval; |
1258 | |
1259 | retval = g_hash_table_new(g_int_hash, g_int_equal); |
1260 | |
1261 | g_hash_table_foreach(ht, insert_and_copy_bdev_state, retval); |
1262 | |
1263 | return retval; |
1264 | } |
1265 | |
1266 | /* Free a hashtable and the LttvBdevState structures its values |
1267 | * point to. */ |
1268 | |
1269 | static void lttv_state_free_blkdev_hashtable(GHashTable *ht) |
1270 | { |
1271 | g_hash_table_foreach(ht, bdevstate_free_cb, NULL); |
1272 | g_hash_table_destroy(ht); |
1273 | } |
1274 | |
308711e5 |
1275 | /* The saved state for each trace contains a member "processes", which |
1276 | stores a copy of the process table, and a member "tracefiles" with |
1277 | one entry per tracefile. Each tracefile has a "process" member pointing |
1278 | to the current process and a "position" member storing the tracefile |
1279 | position (needed to seek to the current "next" event. */ |
1280 | |
1281 | static void state_save(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
1282 | { |
fc6a87b2 |
1283 | guint i, nb_tracefile, nb_cpus, nb_irqs; |
dc877563 |
1284 | |
308711e5 |
1285 | LttvTracefileState *tfcs; |
1286 | |
1287 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
348c6ba8 |
1288 | |
1289 | guint *running_process; |
308711e5 |
1290 | |
308711e5 |
1291 | LttvAttributeValue value; |
1292 | |
308711e5 |
1293 | LttEventPosition *ep; |
1294 | |
1295 | tracefiles_tree = lttv_attribute_find_subdir(container, |
1296 | LTTV_STATE_TRACEFILES); |
1297 | |
1298 | value = lttv_attribute_add(container, LTTV_STATE_PROCESSES, |
1299 | LTTV_POINTER); |
1300 | *(value.v_pointer) = lttv_state_copy_process_table(self->processes); |
1301 | |
348c6ba8 |
1302 | /* Add the currently running processes array */ |
1303 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
1304 | running_process = g_new(guint, nb_cpus); |
1305 | for(i=0;i<nb_cpus;i++) { |
1306 | running_process[i] = self->running_process[i]->pid; |
1307 | } |
1308 | value = lttv_attribute_add(container, LTTV_STATE_RUNNING_PROCESS, |
1309 | LTTV_POINTER); |
1310 | *(value.v_pointer) = running_process; |
728d0c3e |
1311 | |
1312 | g_info("State save"); |
348c6ba8 |
1313 | |
eed2ef37 |
1314 | nb_tracefile = self->parent.tracefiles->len; |
308711e5 |
1315 | |
1316 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
1317 | tfcs = |
cb03932a |
1318 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
1319 | LttvTracefileContext*, i)); |
308711e5 |
1320 | tracefile_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
1321 | value = lttv_attribute_add(tracefiles_tree, i, |
1322 | LTTV_GOBJECT); |
1323 | *(value.v_gobject) = (GObject *)tracefile_tree; |
348c6ba8 |
1324 | #if 0 |
308711e5 |
1325 | value = lttv_attribute_add(tracefile_tree, LTTV_STATE_PROCESS, |
1326 | LTTV_UINT); |
1327 | *(value.v_uint) = tfcs->process->pid; |
348c6ba8 |
1328 | #endif //0 |
308711e5 |
1329 | value = lttv_attribute_add(tracefile_tree, LTTV_STATE_EVENT, |
1330 | LTTV_POINTER); |
3054461a |
1331 | /* Only save the position if the tfs has not infinite time. */ |
1332 | //if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent) |
1333 | // && current_tfcs != tfcs) { |
1334 | if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) == 0) { |
1986f254 |
1335 | *(value.v_pointer) = NULL; |
1336 | } else { |
1337 | LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); |
a5dcde2f |
1338 | ep = ltt_event_position_new(); |
eed2ef37 |
1339 | ltt_event_position(e, ep); |
308711e5 |
1340 | *(value.v_pointer) = ep; |
08b1c66e |
1341 | |
eed2ef37 |
1342 | guint nb_block, offset; |
1343 | guint64 tsc; |
08b1c66e |
1344 | LttTracefile *tf; |
eed2ef37 |
1345 | ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); |
728d0c3e |
1346 | g_info("Block %u offset %u tsc %llu time %lu.%lu", nb_block, offset, |
eed2ef37 |
1347 | tsc, |
08b1c66e |
1348 | tfcs->parent.timestamp.tv_sec, tfcs->parent.timestamp.tv_nsec); |
308711e5 |
1349 | } |
dc877563 |
1350 | } |
fbfbd4db |
1351 | |
fc6a87b2 |
1352 | /* save the cpu state */ |
1353 | { |
fc6a87b2 |
1354 | value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS, |
1355 | LTTV_POINTER); |
1356 | *(value.v_pointer) = lttv_state_copy_cpu_states(self->cpu_states, nb_cpus); |
1357 | } |
1358 | |
1359 | /* save the irq state */ |
1360 | nb_irqs = self->nb_irqs; |
1361 | { |
fc6a87b2 |
1362 | value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_IRQS, |
1363 | LTTV_POINTER); |
1364 | *(value.v_pointer) = lttv_state_copy_irq_states(self->irq_states, nb_irqs); |
1365 | } |
98d7814f |
1366 | |
1367 | /* save the blkdev states */ |
1368 | value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, |
1369 | LTTV_POINTER); |
1370 | *(value.v_pointer) = lttv_state_copy_blkdev_hashtable(self->bdev_states); |
dc877563 |
1371 | } |
1372 | |
1373 | |
308711e5 |
1374 | static void state_restore(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
1375 | { |
fc6a87b2 |
1376 | guint i, nb_tracefile, pid, nb_cpus, nb_irqs; |
dc877563 |
1377 | |
308711e5 |
1378 | LttvTracefileState *tfcs; |
dc877563 |
1379 | |
308711e5 |
1380 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
dc877563 |
1381 | |
348c6ba8 |
1382 | guint *running_process; |
1383 | |
308711e5 |
1384 | LttvAttributeType type; |
dc877563 |
1385 | |
308711e5 |
1386 | LttvAttributeValue value; |
dc877563 |
1387 | |
308711e5 |
1388 | LttvAttributeName name; |
dc877563 |
1389 | |
80e0221b |
1390 | gboolean is_named; |
c0cb4d12 |
1391 | |
308711e5 |
1392 | LttEventPosition *ep; |
dc877563 |
1393 | |
27304273 |
1394 | LttvTracesetContext *tsc = self->parent.ts_context; |
1395 | |
308711e5 |
1396 | tracefiles_tree = lttv_attribute_find_subdir(container, |
1397 | LTTV_STATE_TRACEFILES); |
dc877563 |
1398 | |
308711e5 |
1399 | type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, |
1400 | &value); |
1401 | g_assert(type == LTTV_POINTER); |
1402 | lttv_state_free_process_table(self->processes); |
1403 | self->processes = lttv_state_copy_process_table(*(value.v_pointer)); |
1404 | |
348c6ba8 |
1405 | /* Add the currently running processes array */ |
1406 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
1407 | type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, |
1408 | &value); |
1409 | g_assert(type == LTTV_POINTER); |
1410 | running_process = *(value.v_pointer); |
1411 | for(i=0;i<nb_cpus;i++) { |
1412 | pid = running_process[i]; |
1413 | self->running_process[i] = lttv_state_find_process(self, i, pid); |
1414 | g_assert(self->running_process[i] != NULL); |
1415 | } |
1416 | |
eed2ef37 |
1417 | nb_tracefile = self->parent.tracefiles->len; |
308711e5 |
1418 | |
d448fce2 |
1419 | //g_tree_destroy(tsc->pqueue); |
1420 | //tsc->pqueue = g_tree_new(compare_tracefile); |
fbfbd4db |
1421 | |
1422 | /* restore cpu resource states */ |
1423 | type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); |
1424 | g_assert(type == LTTV_POINTER); |
1425 | lttv_state_free_cpu_states(self->cpu_states, nb_cpus); |
1426 | self->cpu_states = lttv_state_copy_cpu_states(*(value.v_pointer), nb_cpus); |
e7f5e89d |
1427 | |
fc6a87b2 |
1428 | /* restore irq resource states */ |
1429 | nb_irqs = self->nb_irqs; |
1430 | type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); |
1431 | g_assert(type == LTTV_POINTER); |
1432 | lttv_state_free_irq_states(self->irq_states, nb_irqs); |
1433 | self->irq_states = lttv_state_copy_irq_states(*(value.v_pointer), nb_irqs); |
1434 | |
98d7814f |
1435 | /* restore the blkdev states */ |
1436 | type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); |
1437 | g_assert(type == LTTV_POINTER); |
1438 | lttv_state_free_blkdev_hashtable(self->bdev_states); |
521a0efa |
1439 | self->bdev_states = lttv_state_copy_blkdev_hashtable(*(value.v_pointer)); |
98d7814f |
1440 | |
308711e5 |
1441 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
1442 | tfcs = |
cb03932a |
1443 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
1444 | LttvTracefileContext*, i)); |
c0cb4d12 |
1445 | type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); |
308711e5 |
1446 | g_assert(type == LTTV_GOBJECT); |
1447 | tracefile_tree = *((LttvAttribute **)(value.v_gobject)); |
348c6ba8 |
1448 | #if 0 |
308711e5 |
1449 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_PROCESS, |
1450 | &value); |
1451 | g_assert(type == LTTV_UINT); |
2a2fa4f0 |
1452 | pid = *(value.v_uint); |
1453 | tfcs->process = lttv_state_find_process_or_create(tfcs, pid); |
348c6ba8 |
1454 | #endif //0 |
308711e5 |
1455 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, |
1456 | &value); |
1457 | g_assert(type == LTTV_POINTER); |
e7f5e89d |
1458 | //g_assert(*(value.v_pointer) != NULL); |
eed2ef37 |
1459 | ep = *(value.v_pointer); |
1460 | g_assert(tfcs->parent.t_context != NULL); |
fbfbd4db |
1461 | |
1462 | tfcs->cpu_state = &self->cpu_states[tfcs->cpu]; |
27304273 |
1463 | |
27304273 |
1464 | LttvTracefileContext *tfc = LTTV_TRACEFILE_CONTEXT(tfcs); |
d448fce2 |
1465 | g_tree_remove(tsc->pqueue, tfc); |
27304273 |
1466 | |
1986f254 |
1467 | if(ep != NULL) { |
1468 | g_assert(ltt_tracefile_seek_position(tfc->tf, ep) == 0); |
1469 | tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf)); |
e7f5e89d |
1470 | g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0); |
1986f254 |
1471 | g_tree_insert(tsc->pqueue, tfc, tfc); |
728d0c3e |
1472 | g_info("Restoring state for a tf at time %lu.%lu", tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec); |
1986f254 |
1473 | } else { |
1474 | tfc->timestamp = ltt_time_infinite; |
1475 | } |
dc877563 |
1476 | } |
dc877563 |
1477 | } |
1478 | |
1479 | |
308711e5 |
1480 | static void state_saved_free(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
1481 | { |
348c6ba8 |
1482 | guint i, nb_tracefile, nb_cpus; |
dc877563 |
1483 | |
308711e5 |
1484 | LttvTracefileState *tfcs; |
dc877563 |
1485 | |
308711e5 |
1486 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
dc877563 |
1487 | |
348c6ba8 |
1488 | guint *running_process; |
1489 | |
308711e5 |
1490 | LttvAttributeType type; |
dc877563 |
1491 | |
308711e5 |
1492 | LttvAttributeValue value; |
dc877563 |
1493 | |
308711e5 |
1494 | LttvAttributeName name; |
dc877563 |
1495 | |
80e0221b |
1496 | gboolean is_named; |
c0cb4d12 |
1497 | |
308711e5 |
1498 | tracefiles_tree = lttv_attribute_find_subdir(container, |
1499 | LTTV_STATE_TRACEFILES); |
c47a6dc6 |
1500 | g_object_ref(G_OBJECT(tracefiles_tree)); |
308711e5 |
1501 | lttv_attribute_remove_by_name(container, LTTV_STATE_TRACEFILES); |
dc877563 |
1502 | |
308711e5 |
1503 | type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, |
1504 | &value); |
1505 | g_assert(type == LTTV_POINTER); |
1506 | lttv_state_free_process_table(*(value.v_pointer)); |
1507 | *(value.v_pointer) = NULL; |
1508 | lttv_attribute_remove_by_name(container, LTTV_STATE_PROCESSES); |
1509 | |
348c6ba8 |
1510 | /* Free running processes array */ |
1511 | nb_cpus = ltt_trace_get_num_cpu(self->parent.t); |
728d0c3e |
1512 | type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, |
348c6ba8 |
1513 | &value); |
1514 | g_assert(type == LTTV_POINTER); |
1515 | running_process = *(value.v_pointer); |
1516 | g_free(running_process); |
1517 | |
eed2ef37 |
1518 | nb_tracefile = self->parent.tracefiles->len; |
308711e5 |
1519 | |
1520 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
1521 | tfcs = |
cb03932a |
1522 | LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, |
1523 | LttvTracefileContext*, i)); |
c0cb4d12 |
1524 | type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); |
308711e5 |
1525 | g_assert(type == LTTV_GOBJECT); |
1526 | tracefile_tree = *((LttvAttribute **)(value.v_gobject)); |
1527 | |
1528 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, |
1529 | &value); |
1530 | g_assert(type == LTTV_POINTER); |
1531 | if(*(value.v_pointer) != NULL) g_free(*(value.v_pointer)); |
dc877563 |
1532 | } |
c47a6dc6 |
1533 | g_object_unref(G_OBJECT(tracefiles_tree)); |
dc877563 |
1534 | } |
1535 | |
1536 | |
f95bc830 |
1537 | static void free_saved_state(LttvTraceState *self) |
1538 | { |
1539 | guint i, nb; |
1540 | |
1541 | LttvAttributeType type; |
1542 | |
1543 | LttvAttributeValue value; |
1544 | |
1545 | LttvAttributeName name; |
1546 | |
80e0221b |
1547 | gboolean is_named; |
c0cb4d12 |
1548 | |
f95bc830 |
1549 | LttvAttribute *saved_states; |
1550 | |
1551 | saved_states = lttv_attribute_find_subdir(self->parent.t_a, |
1552 | LTTV_STATE_SAVED_STATES); |
1553 | |
1554 | nb = lttv_attribute_get_number(saved_states); |
1555 | for(i = 0 ; i < nb ; i++) { |
c0cb4d12 |
1556 | type = lttv_attribute_get(saved_states, i, &name, &value, &is_named); |
f95bc830 |
1557 | g_assert(type == LTTV_GOBJECT); |
1558 | state_saved_free(self, *((LttvAttribute **)value.v_gobject)); |
1559 | } |
1560 | |
1561 | lttv_attribute_remove_by_name(self->parent.t_a, LTTV_STATE_SAVED_STATES); |
f95bc830 |
1562 | } |
1563 | |
1564 | |
1565 | static void |
1566 | create_max_time(LttvTraceState *tcs) |
1567 | { |
1568 | LttvAttributeValue v; |
1569 | |
1570 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, |
1571 | LTTV_POINTER, &v); |
1572 | g_assert(*(v.v_pointer) == NULL); |
1573 | *(v.v_pointer) = g_new(LttTime,1); |
348c6ba8 |
1574 | *((LttTime *)*(v.v_pointer)) = ltt_time_zero; |
f95bc830 |
1575 | } |
1576 | |
1577 | |
1578 | static void |
1579 | get_max_time(LttvTraceState *tcs) |
1580 | { |
1581 | LttvAttributeValue v; |
1582 | |
1583 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, |
1584 | LTTV_POINTER, &v); |
1585 | g_assert(*(v.v_pointer) != NULL); |
1586 | tcs->max_time_state_recomputed_in_seek = (LttTime *)*(v.v_pointer); |
1587 | } |
1588 | |
1589 | |
1590 | static void |
1591 | free_max_time(LttvTraceState *tcs) |
1592 | { |
1593 | LttvAttributeValue v; |
1594 | |
1595 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, |
1596 | LTTV_POINTER, &v); |
1597 | g_free(*(v.v_pointer)); |
1598 | *(v.v_pointer) = NULL; |
1599 | } |
1600 | |
1601 | |
1602 | typedef struct _LttvNameTables { |
eed2ef37 |
1603 | // FIXME GQuark *eventtype_names; |
f95bc830 |
1604 | GQuark *syscall_names; |
5e96e7e3 |
1605 | guint nb_syscalls; |
f95bc830 |
1606 | GQuark *trap_names; |
5e96e7e3 |
1607 | guint nb_traps; |
f95bc830 |
1608 | GQuark *irq_names; |
6214c229 |
1609 | guint nb_irqs; |
faf074a3 |
1610 | GQuark *soft_irq_names; |
6214c229 |
1611 | guint nb_softirqs; |
f95bc830 |
1612 | } LttvNameTables; |
1613 | |
1614 | |
b445142a |
1615 | static void |
f95bc830 |
1616 | create_name_tables(LttvTraceState *tcs) |
b445142a |
1617 | { |
8979f265 |
1618 | int i; |
dc877563 |
1619 | |
b445142a |
1620 | GString *fe_name = g_string_new(""); |
1621 | |
f95bc830 |
1622 | LttvNameTables *name_tables = g_new(LttvNameTables, 1); |
1623 | |
1624 | LttvAttributeValue v; |
1625 | |
6418800d |
1626 | GArray *hooks; |
1627 | |
f95bc830 |
1628 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, |
1629 | LTTV_POINTER, &v); |
1630 | g_assert(*(v.v_pointer) == NULL); |
1631 | *(v.v_pointer) = name_tables; |
e1de4b54 |
1632 | |
6418800d |
1633 | hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 1); |
1634 | |
285468d4 |
1635 | if(!lttv_trace_find_hook(tcs->parent.t, |
60c5092c |
1636 | LTT_FACILITY_KERNEL_ARCH, |
9ec91d57 |
1637 | LTT_EVENT_SYSCALL_ENTRY, |
eda0fe5f |
1638 | FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), |
6418800d |
1639 | NULL, NULL, &hooks)) { |
80e0221b |
1640 | |
8979f265 |
1641 | // th = lttv_trace_hook_get_first(&th); |
1642 | // |
d3a66443 |
1643 | // t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); |
8979f265 |
1644 | // nb = ltt_type_element_number(t); |
1645 | // |
8979f265 |
1646 | // name_tables->syscall_names = g_new(GQuark, nb); |
1647 | // name_tables->nb_syscalls = nb; |
1648 | // |
1649 | // for(i = 0 ; i < nb ; i++) { |
1650 | // name_tables->syscall_names[i] = ltt_enum_string_get(t, i); |
1651 | // if(!name_tables->syscall_names[i]) { |
1652 | // GString *string = g_string_new(""); |
1653 | // g_string_printf(string, "syscall %u", i); |
1654 | // name_tables->syscall_names[i] = g_quark_from_string(string->str); |
1655 | // g_string_free(string, TRUE); |
1656 | // } |
1657 | // } |
1658 | |
c73b5f22 |
1659 | name_tables->nb_syscalls = 256; |
8979f265 |
1660 | name_tables->syscall_names = g_new(GQuark, 256); |
1661 | for(i = 0 ; i < 256 ; i++) { |
1662 | g_string_printf(fe_name, "syscall %d", i); |
1663 | name_tables->syscall_names[i] = g_quark_from_string(fe_name->str); |
80e0221b |
1664 | } |
80e0221b |
1665 | } else { |
1666 | name_tables->syscall_names = NULL; |
1667 | name_tables->nb_syscalls = 0; |
1668 | } |
032ba5da |
1669 | lttv_trace_hook_remove_all(&hooks); |
285468d4 |
1670 | |
e1de4b54 |
1671 | if(!lttv_trace_find_hook(tcs->parent.t, |
60c5092c |
1672 | LTT_FACILITY_KERNEL_ARCH, |
eed2ef37 |
1673 | LTT_EVENT_TRAP_ENTRY, |
6418800d |
1674 | FIELD_ARRAY(LTT_FIELD_TRAP_ID), |
1675 | NULL, NULL, &hooks)) { |
eed2ef37 |
1676 | |
8979f265 |
1677 | // th = lttv_trace_hook_get_first(&th); |
1678 | // |
d3a66443 |
1679 | // t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); |
8979f265 |
1680 | // //nb = ltt_type_element_number(t); |
1681 | // |
8979f265 |
1682 | // name_tables->trap_names = g_new(GQuark, nb); |
1683 | // for(i = 0 ; i < nb ; i++) { |
1684 | // name_tables->trap_names[i] = g_quark_from_string( |
1685 | // ltt_enum_string_get(t, i)); |
1686 | // } |
80e0221b |
1687 | |
80e0221b |
1688 | name_tables->nb_traps = 256; |
1689 | name_tables->trap_names = g_new(GQuark, 256); |
1690 | for(i = 0 ; i < 256 ; i++) { |
1691 | g_string_printf(fe_name, "trap %d", i); |
1692 | name_tables->trap_names[i] = g_quark_from_string(fe_name->str); |
1693 | } |
1694 | } else { |
1695 | name_tables->trap_names = NULL; |
1696 | name_tables->nb_traps = 0; |
1697 | } |
032ba5da |
1698 | lttv_trace_hook_remove_all(&hooks); |
b445142a |
1699 | |
285468d4 |
1700 | if(!lttv_trace_find_hook(tcs->parent.t, |
60c5092c |
1701 | LTT_FACILITY_KERNEL, |
e1de4b54 |
1702 | LTT_EVENT_IRQ_ENTRY, |
6418800d |
1703 | FIELD_ARRAY(LTT_FIELD_IRQ_ID), |
1704 | NULL, NULL, &hooks)) { |
80e0221b |
1705 | |
80e0221b |
1706 | /* |
1707 | name_tables->irq_names = g_new(GQuark, nb); |
1708 | for(i = 0 ; i < nb ; i++) { |
1709 | name_tables->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); |
1710 | } |
1711 | */ |
1712 | |
6214c229 |
1713 | name_tables->nb_irqs = 256; |
80e0221b |
1714 | name_tables->irq_names = g_new(GQuark, 256); |
1715 | for(i = 0 ; i < 256 ; i++) { |
1716 | g_string_printf(fe_name, "irq %d", i); |
1717 | name_tables->irq_names[i] = g_quark_from_string(fe_name->str); |
1718 | } |
1719 | } else { |
6214c229 |
1720 | name_tables->nb_irqs = 0; |
80e0221b |
1721 | name_tables->irq_names = NULL; |
1722 | } |
032ba5da |
1723 | lttv_trace_hook_remove_all(&hooks); |
faf074a3 |
1724 | /* |
1725 | name_tables->soft_irq_names = g_new(GQuark, nb); |
1726 | for(i = 0 ; i < nb ; i++) { |
1727 | name_tables->soft_irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); |
1728 | } |
1729 | */ |
1730 | |
6214c229 |
1731 | name_tables->nb_softirqs = 256; |
faf074a3 |
1732 | name_tables->soft_irq_names = g_new(GQuark, 256); |
1733 | for(i = 0 ; i < 256 ; i++) { |
1734 | g_string_printf(fe_name, "softirq %d", i); |
1735 | name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str); |
1736 | } |
6418800d |
1737 | g_array_free(hooks, TRUE); |
faf074a3 |
1738 | |
b445142a |
1739 | g_string_free(fe_name, TRUE); |
1740 | } |
1741 | |
1742 | |
f95bc830 |
1743 | static void |
1744 | get_name_tables(LttvTraceState *tcs) |
1745 | { |
1746 | LttvNameTables *name_tables; |
1747 | |
1748 | LttvAttributeValue v; |
1749 | |
1750 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, |
1751 | LTTV_POINTER, &v); |
1752 | g_assert(*(v.v_pointer) != NULL); |
1753 | name_tables = (LttvNameTables *)*(v.v_pointer); |
eed2ef37 |
1754 | //tcs->eventtype_names = name_tables->eventtype_names; |
f95bc830 |
1755 | tcs->syscall_names = name_tables->syscall_names; |
7cd289b0 |
1756 | tcs->nb_syscalls = name_tables->nb_syscalls; |
f95bc830 |
1757 | tcs->trap_names = name_tables->trap_names; |
5e96e7e3 |
1758 | tcs->nb_traps = name_tables->nb_traps; |
f95bc830 |
1759 | tcs->irq_names = name_tables->irq_names; |
faf074a3 |
1760 | tcs->soft_irq_names = name_tables->soft_irq_names; |
6214c229 |
1761 | tcs->nb_irqs = name_tables->nb_irqs; |
1762 | tcs->nb_softirqs = name_tables->nb_softirqs; |
f95bc830 |
1763 | } |
1764 | |
1765 | |
b445142a |
1766 | static void |
1767 | free_name_tables(LttvTraceState *tcs) |
1768 | { |
f95bc830 |
1769 | LttvNameTables *name_tables; |
1770 | |
1771 | LttvAttributeValue v; |
1772 | |
1773 | lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, |
1774 | LTTV_POINTER, &v); |
1775 | name_tables = (LttvNameTables *)*(v.v_pointer); |
1776 | *(v.v_pointer) = NULL; |
1777 | |
eed2ef37 |
1778 | // g_free(name_tables->eventtype_names); |
285468d4 |
1779 | if(name_tables->syscall_names) g_free(name_tables->syscall_names); |
1780 | if(name_tables->trap_names) g_free(name_tables->trap_names); |
1781 | if(name_tables->irq_names) g_free(name_tables->irq_names); |
1782 | if(name_tables->soft_irq_names) g_free(name_tables->soft_irq_names); |
1783 | if(name_tables) g_free(name_tables); |
b445142a |
1784 | } |
dc877563 |
1785 | |
15b3d537 |
1786 | #ifdef HASH_TABLE_DEBUG |
1787 | |
1788 | static void test_process(gpointer key, gpointer value, gpointer user_data) |
1789 | { |
1790 | LttvProcessState *process = (LttvProcessState *)value; |
1791 | |
1792 | /* Test for process corruption */ |
1793 | guint stack_len = process->execution_stack->len; |
1794 | } |
1795 | |
1796 | static void hash_table_check(GHashTable *table) |
1797 | { |
1798 | g_hash_table_foreach(table, test_process, NULL); |
1799 | } |
1800 | |
1801 | |
1802 | #endif |
1803 | |
d3d99fde |
1804 | /* clears the stack and sets the state passed as argument */ |
1805 | static void cpu_set_base_mode(LttvCPUState *cpust, LttvCPUMode state) |
1806 | { |
1807 | g_array_set_size(cpust->mode_stack, 1); |
1808 | ((GQuark *)cpust->mode_stack->data)[0] = state; |
1809 | } |
1810 | |
1811 | static void cpu_push_mode(LttvCPUState *cpust, LttvCPUMode state) |
1812 | { |
1813 | g_array_set_size(cpust->mode_stack, cpust->mode_stack->len + 1); |
1814 | ((GQuark *)cpust->mode_stack->data)[cpust->mode_stack->len - 1] = state; |
1815 | } |
1816 | |
1817 | static void cpu_pop_mode(LttvCPUState *cpust) |
1818 | { |
0c0168a8 |
1819 | if(cpust->mode_stack->len <= 1) |
d3d99fde |
1820 | cpu_set_base_mode(cpust, LTTV_CPU_UNKNOWN); |
1821 | else |
1822 | g_array_set_size(cpust->mode_stack, cpust->mode_stack->len - 1); |
1823 | } |
15b3d537 |
1824 | |
5e563da0 |
1825 | /* clears the stack and sets the state passed as argument */ |
27811799 |
1826 | static void bdev_set_base_mode(LttvBdevState *bdevst, LttvBdevMode state) |
1827 | { |
1828 | g_array_set_size(bdevst->mode_stack, 1); |
1829 | ((GQuark *)bdevst->mode_stack->data)[0] = state; |
1830 | } |
1831 | |
1832 | static void bdev_push_mode(LttvBdevState *bdevst, LttvBdevMode state) |
1833 | { |
1834 | g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len + 1); |
1835 | ((GQuark *)bdevst->mode_stack->data)[bdevst->mode_stack->len - 1] = state; |
1836 | } |
1837 | |
1838 | static void bdev_pop_mode(LttvBdevState *bdevst) |
1839 | { |
0c0168a8 |
1840 | if(bdevst->mode_stack->len <= 1) |
27811799 |
1841 | bdev_set_base_mode(bdevst, LTTV_BDEV_UNKNOWN); |
1842 | else |
1843 | g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len - 1); |
1844 | } |
1845 | |
5e563da0 |
1846 | static void irq_set_base_mode(LttvIRQState *irqst, LttvIRQMode state) |
1847 | { |
1848 | g_array_set_size(irqst->mode_stack, 1); |
1849 | ((GQuark *)irqst->mode_stack->data)[0] = state; |
1850 | } |
1851 | |
1852 | static void irq_push_mode(LttvIRQState *irqst, LttvIRQMode state) |
1853 | { |
1854 | g_array_set_size(irqst->mode_stack, irqst->mode_stack->len + 1); |
1855 | ((GQuark *)irqst->mode_stack->data)[irqst->mode_stack->len - 1] = state; |
1856 | } |
1857 | |
1858 | static void irq_pop_mode(LttvIRQState *irqst) |
1859 | { |
0c0168a8 |
1860 | if(irqst->mode_stack->len <= 1) |
5e563da0 |
1861 | irq_set_base_mode(irqst, LTTV_IRQ_UNKNOWN); |
1862 | else |
1863 | g_array_set_size(irqst->mode_stack, irqst->mode_stack->len - 1); |
1864 | } |
1865 | |
b445142a |
1866 | static void push_state(LttvTracefileState *tfs, LttvExecutionMode t, |
ffd54a90 |
1867 | guint state_id) |
dc877563 |
1868 | { |
b445142a |
1869 | LttvExecutionState *es; |
348c6ba8 |
1870 | |
348c6ba8 |
1871 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
ae3d0f50 |
1872 | guint cpu = tfs->cpu; |
15b3d537 |
1873 | |
1874 | #ifdef HASH_TABLE_DEBUG |
1875 | hash_table_check(ts->processes); |
1876 | #endif |
348c6ba8 |
1877 | LttvProcessState *process = ts->running_process[cpu]; |
dc877563 |
1878 | |
b445142a |
1879 | guint depth = process->execution_stack->len; |
dc877563 |
1880 | |
e05fc742 |
1881 | process->execution_stack = |
1882 | g_array_set_size(process->execution_stack, depth + 1); |
1883 | /* Keep in sync */ |
1884 | process->state = |
1885 | &g_array_index(process->execution_stack, LttvExecutionState, depth - 1); |
1886 | |
b445142a |
1887 | es = &g_array_index(process->execution_stack, LttvExecutionState, depth); |
1888 | es->t = t; |
1889 | es->n = state_id; |
1890 | es->entry = es->change = tfs->parent.timestamp; |
80e0221b |
1891 | es->cum_cpu_time = ltt_time_zero; |
b445142a |
1892 | es->s = process->state->s; |
1893 | process->state = es; |
dc877563 |
1894 | } |
1895 | |
b49e54b4 |
1896 | /* pop state |
1897 | * return 1 when empty, else 0 */ |
1898 | int lttv_state_pop_state_cleanup(LttvProcessState *process, |
80e0221b |
1899 | LttvTracefileState *tfs) |
b49e54b4 |
1900 | { |
b49e54b4 |
1901 | guint depth = process->execution_stack->len; |
1902 | |
1903 | if(depth == 1){ |
1904 | return 1; |
1905 | } |
1906 | |
1907 | process->execution_stack = |
1908 | g_array_set_size(process->execution_stack, depth - 1); |
1909 | process->state = &g_array_index(process->execution_stack, LttvExecutionState, |
1910 | depth - 2); |
1911 | process->state->change = tfs->parent.timestamp; |
80e0221b |
1912 | |
1913 | return 0; |
b49e54b4 |
1914 | } |
dc877563 |
1915 | |
b445142a |
1916 | static void pop_state(LttvTracefileState *tfs, LttvExecutionMode t) |
dc877563 |
1917 | { |
ae3d0f50 |
1918 | guint cpu = tfs->cpu; |
348c6ba8 |
1919 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
1920 | LttvProcessState *process = ts->running_process[cpu]; |
dc877563 |
1921 | |
f95bc830 |
1922 | guint depth = process->execution_stack->len; |
dc877563 |
1923 | |
3d27549e |
1924 | if(process->state->t != t){ |
00e74b69 |
1925 | g_info("Different execution mode type (%lu.%09lu): ignore it\n", |
b445142a |
1926 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
08b1c66e |
1927 | g_info("process state has %s when pop_int is %s\n", |
80e0221b |
1928 | g_quark_to_string(process->state->t), |
1929 | g_quark_to_string(t)); |
7b5f6cf1 |
1930 | g_info("{ %u, %u, %s, %s, %s }\n", |
80e0221b |
1931 | process->pid, |
1932 | process->ppid, |
1933 | g_quark_to_string(process->name), |
1934 | g_quark_to_string(process->brand), |
1935 | g_quark_to_string(process->state->s)); |
3d27549e |
1936 | return; |
1937 | } |
b445142a |
1938 | |
f95bc830 |
1939 | if(depth == 1){ |
00e74b69 |
1940 | g_info("Trying to pop last state on stack (%lu.%09lu): ignore it\n", |
b445142a |
1941 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
1942 | return; |
1943 | } |
1944 | |
e05fc742 |
1945 | process->execution_stack = |
1946 | g_array_set_size(process->execution_stack, depth - 1); |
b445142a |
1947 | process->state = &g_array_index(process->execution_stack, LttvExecutionState, |
f95bc830 |
1948 | depth - 2); |
b445142a |
1949 | process->state->change = tfs->parent.timestamp; |
dc877563 |
1950 | } |
1951 | |
6806b3c6 |
1952 | struct search_result { |
80e0221b |
1953 | const LttTime *time; /* Requested time */ |
1954 | LttTime *best; /* Best result */ |
6806b3c6 |
1955 | }; |
1956 | |
1957 | static gint search_usertrace(gconstpointer a, gconstpointer b) |
1958 | { |
80e0221b |
1959 | const LttTime *elem_time = (const LttTime*)a; |
1960 | /* Explicit non const cast */ |
1961 | struct search_result *res = (struct search_result *)b; |
1962 | |
1963 | if(ltt_time_compare(*elem_time, *(res->time)) < 0) { |
1964 | /* The usertrace was created before the schedchange */ |
1965 | /* Get larger keys */ |
1966 | return 1; |
1967 | } else if(ltt_time_compare(*elem_time, *(res->time)) >= 0) { |
1968 | /* The usertrace was created after the schedchange time */ |
1969 | /* Get smaller keys */ |
1970 | if(res->best) { |
1971 | if(ltt_time_compare(*elem_time, *res->best) < 0) { |
e1de4b54 |
1972 | res->best = (LttTime *)elem_time; |
80e0221b |
1973 | } |
1974 | } else { |
e1de4b54 |
1975 | res->best = (LttTime *)elem_time; |
80e0221b |
1976 | } |
1977 | return -1; |
1978 | } |
1979 | return 0; |
6806b3c6 |
1980 | } |
1981 | |
1982 | static LttvTracefileState *ltt_state_usertrace_find(LttvTraceState *tcs, |
80e0221b |
1983 | guint pid, const LttTime *timestamp) |
1984 | { |
1985 | LttvTracefileState *tfs = NULL; |
1986 | struct search_result res; |
1987 | /* Find the usertrace associated with a pid and time interval. |
1988 | * Search in the usertraces by PID (within a hash) and then, for each |
1989 | * corresponding element of the array, find the first one with creation |
1990 | * timestamp the lowest, but higher or equal to "timestamp". */ |
1991 | res.time = timestamp; |
1992 | res.best = NULL; |
1993 | GTree *usertrace_tree = g_hash_table_lookup(tcs->usertraces, (gpointer)pid); |
1994 | if(usertrace_tree) { |
1995 | g_tree_search(usertrace_tree, search_usertrace, &res); |
1996 | if(res.best) |
1997 | tfs = g_tree_lookup(usertrace_tree, res.best); |
1998 | } |
6806b3c6 |
1999 | |
80e0221b |
2000 | return tfs; |
6806b3c6 |
2001 | } |
2002 | |
dc877563 |
2003 | |
2a2fa4f0 |
2004 | LttvProcessState * |
348c6ba8 |
2005 | lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent, |
fcc08e1e |
2006 | guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp) |
dc877563 |
2007 | { |
2008 | LttvProcessState *process = g_new(LttvProcessState, 1); |
2009 | |
b445142a |
2010 | LttvExecutionState *es; |
dc877563 |
2011 | |
b445142a |
2012 | char buffer[128]; |
ffd54a90 |
2013 | |
dc877563 |
2014 | process->pid = pid; |
fcc08e1e |
2015 | process->tgid = tgid; |
348c6ba8 |
2016 | process->cpu = cpu; |
b3fd4c02 |
2017 | process->name = name; |
7b5f6cf1 |
2018 | process->brand = LTTV_STATE_UNBRANDED; |
348c6ba8 |
2019 | //process->last_cpu = tfs->cpu_name; |
2020 | //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); |
80e0221b |
2021 | process->type = LTTV_STATE_USER_THREAD; |
2022 | process->usertrace = ltt_state_usertrace_find(tcs, pid, timestamp); |
2023 | process->current_function = 0; //function 0x0 by default. |
7bfd7820 |
2024 | |
cb03932a |
2025 | g_info("Process %u, core %p", process->pid, process); |
2a2fa4f0 |
2026 | g_hash_table_insert(tcs->processes, process, process); |
b445142a |
2027 | |
2028 | if(parent) { |
2029 | process->ppid = parent->pid; |
348c6ba8 |
2030 | process->creation_time = *timestamp; |
b445142a |
2031 | } |
2a2fa4f0 |
2032 | |
2033 | /* No parent. This process exists but we are missing all information about |
2034 | its creation. The birth time is set to zero but we remember the time of |
2035 | insertion */ |
2036 | |
b445142a |
2037 | else { |
2038 | process->ppid = 0; |
2a2fa4f0 |
2039 | process->creation_time = ltt_time_zero; |
b445142a |
2040 | } |
2041 | |
348c6ba8 |
2042 | process->insertion_time = *timestamp; |
b445142a |
2043 | sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec, |
80e0221b |
2044 | process->creation_time.tv_nsec); |
b445142a |
2045 | process->pid_time = g_quark_from_string(buffer); |
348c6ba8 |
2046 | process->cpu = cpu; |
2047 | //process->last_cpu = tfs->cpu_name; |
2048 | //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); |
e8f2280c |
2049 | process->execution_stack = g_array_sized_new(FALSE, FALSE, |
2050 | sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); |
c607371b |
2051 | process->execution_stack = g_array_set_size(process->execution_stack, 2); |
b445142a |
2052 | es = process->state = &g_array_index(process->execution_stack, |
2053 | LttvExecutionState, 0); |
2054 | es->t = LTTV_STATE_USER_MODE; |
2055 | es->n = LTTV_STATE_SUBMODE_NONE; |
348c6ba8 |
2056 | es->entry = *timestamp; |
2057 | //g_assert(timestamp->tv_sec != 0); |
2058 | es->change = *timestamp; |
80e0221b |
2059 | es->cum_cpu_time = ltt_time_zero; |
c607371b |
2060 | es->s = LTTV_STATE_RUN; |
2061 | |
2062 | es = process->state = &g_array_index(process->execution_stack, |
2063 | LttvExecutionState, 1); |
2064 | es->t = LTTV_STATE_SYSCALL; |
2065 | es->n = LTTV_STATE_SUBMODE_NONE; |
2066 | es->entry = *timestamp; |
2067 | //g_assert(timestamp->tv_sec != 0); |
2068 | es->change = *timestamp; |
80e0221b |
2069 | es->cum_cpu_time = ltt_time_zero; |
c3b3b60b |
2070 | es->s = LTTV_STATE_WAIT_FORK; |
80e0221b |
2071 | |
2072 | /* Allocate an empty function call stack. If it's empty, use 0x0. */ |
2073 | process->user_stack = g_array_sized_new(FALSE, FALSE, |
2074 | sizeof(guint64), 0); |
2075 | |
cbe7c836 |
2076 | return process; |
dc877563 |
2077 | } |
2078 | |
348c6ba8 |
2079 | LttvProcessState *lttv_state_find_process(LttvTraceState *ts, guint cpu, |
41c7f803 |
2080 | guint pid) |
dc877563 |
2081 | { |
2a2fa4f0 |
2082 | LttvProcessState key; |
2083 | LttvProcessState *process; |
2084 | |
2085 | key.pid = pid; |
348c6ba8 |
2086 | key.cpu = cpu; |
2a2fa4f0 |
2087 | process = g_hash_table_lookup(ts->processes, &key); |
dc877563 |
2088 | return process; |
2089 | } |
2090 | |
2a2fa4f0 |
2091 | LttvProcessState * |
348c6ba8 |
2092 | lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, |
d41c66bf |
2093 | const LttTime *timestamp) |
2a2fa4f0 |
2094 | { |
348c6ba8 |
2095 | LttvProcessState *process = lttv_state_find_process(ts, cpu, pid); |
7bfd7820 |
2096 | LttvExecutionState *es; |
348c6ba8 |
2097 | |
2098 | /* Put ltt_time_zero creation time for unexisting processes */ |
7bfd7820 |
2099 | if(unlikely(process == NULL)) { |
80e0221b |
2100 | process = lttv_state_create_process(ts, |
fcc08e1e |
2101 | NULL, cpu, pid, 0, LTTV_STATE_UNNAMED, timestamp); |
80e0221b |
2102 | /* We are not sure is it's a kernel thread or normal thread, put the |
2103 | * bottom stack state to unknown */ |
c3b3b60b |
2104 | process->execution_stack = |
2105 | g_array_set_size(process->execution_stack, 1); |
2106 | process->state = es = |
2107 | &g_array_index(process->execution_stack, LttvExecutionState, 0); |
80e0221b |
2108 | es->t = LTTV_STATE_MODE_UNKNOWN; |
c4a72569 |
2109 | es->s = LTTV_STATE_UNNAMED; |
80e0221b |
2110 | } |
2a2fa4f0 |
2111 | return process; |
2112 | } |
2113 | |
41c7f803 |
2114 | /* FIXME : this function should be called when we receive an event telling that |
2115 | * release_task has been called in the kernel. In happens generally when |
2116 | * the parent waits for its child terminaison, but may also happen in special |
2117 | * cases in the child's exit : when the parent ignores its children SIGCCHLD or |
2118 | * has the flag SA_NOCLDWAIT. It can also happen when the child is part |
2119 | * of a killed thread ground, but isn't the leader. |
41c7f803 |
2120 | */ |
b445142a |
2121 | static void exit_process(LttvTracefileState *tfs, LttvProcessState *process) |
dc877563 |
2122 | { |
ba576a78 |
2123 | LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); |
2a2fa4f0 |
2124 | LttvProcessState key; |
ba576a78 |
2125 | |
2a2fa4f0 |
2126 | key.pid = process->pid; |
348c6ba8 |
2127 | key.cpu = process->cpu; |
2a2fa4f0 |
2128 | g_hash_table_remove(ts->processes, &key); |
b445142a |
2129 | g_array_free(process->execution_stack, TRUE); |
302efbad |
2130 | g_array_free(process->user_stack, TRUE); |
dc877563 |
2131 | g_free(process); |
2132 | } |
2133 | |
2134 | |
b445142a |
2135 | static void free_process_state(gpointer key, gpointer value,gpointer user_data) |
dc877563 |
2136 | { |
b445142a |
2137 | g_array_free(((LttvProcessState *)value)->execution_stack, TRUE); |
302efbad |
2138 | g_array_free(((LttvProcessState *)value)->user_stack, TRUE); |
dc877563 |
2139 | g_free(value); |
2140 | } |
2141 | |
2142 | |
308711e5 |
2143 | static void lttv_state_free_process_table(GHashTable *processes) |
dc877563 |
2144 | { |
2145 | g_hash_table_foreach(processes, free_process_state, NULL); |
308711e5 |
2146 | g_hash_table_destroy(processes); |
dc877563 |
2147 | } |
2148 | |
2149 | |
b445142a |
2150 | static gboolean syscall_entry(void *hook_data, void *call_data) |
dc877563 |
2151 | { |
ba576a78 |
2152 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
1e304fa1 |
2153 | guint cpu = s->cpu; |
2154 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2155 | LttvProcessState *process = ts->running_process[cpu]; |
eed2ef37 |
2156 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2157 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
775c802c |
2158 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
dc877563 |
2159 | |
b445142a |
2160 | LttvExecutionSubmode submode; |
2161 | |
80e0221b |
2162 | guint nb_syscalls = ((LttvTraceState *)(s->parent.t_context))->nb_syscalls; |
2163 | guint syscall = ltt_event_get_unsigned(e, f); |
2164 | |
2165 | if(syscall < nb_syscalls) { |
2166 | submode = ((LttvTraceState *)(s->parent.t_context))->syscall_names[ |
2167 | syscall]; |
2168 | } else { |
2169 | /* Fixup an incomplete syscall table */ |
2170 | GString *string = g_string_new(""); |
7cd289b0 |
2171 | g_string_printf(string, "syscall %u", syscall); |
80e0221b |
2172 | submode = g_quark_from_string(string->str); |
2173 | g_string_free(string, TRUE); |
2174 | } |
1e304fa1 |
2175 | /* There can be no system call from PID 0 : unknown state */ |
2176 | if(process->pid != 0) |
2177 | push_state(s, LTTV_STATE_SYSCALL, submode); |
dc877563 |
2178 | return FALSE; |
2179 | } |
2180 | |
2181 | |
b445142a |
2182 | static gboolean syscall_exit(void *hook_data, void *call_data) |
dc877563 |
2183 | { |
ba576a78 |
2184 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
1e304fa1 |
2185 | guint cpu = s->cpu; |
2186 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2187 | LttvProcessState *process = ts->running_process[cpu]; |
dc877563 |
2188 | |
1e304fa1 |
2189 | /* There can be no system call from PID 0 : unknown state */ |
2190 | if(process->pid != 0) |
2191 | pop_state(s, LTTV_STATE_SYSCALL); |
dc877563 |
2192 | return FALSE; |
2193 | } |
2194 | |
2195 | |
b445142a |
2196 | static gboolean trap_entry(void *hook_data, void *call_data) |
dc877563 |
2197 | { |
ba576a78 |
2198 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
eed2ef37 |
2199 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2200 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
d3a66443 |
2201 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
dc877563 |
2202 | |
b445142a |
2203 | LttvExecutionSubmode submode; |
2204 | |
17ddd1f2 |
2205 | guint64 nb_traps = ((LttvTraceState *)(s->parent.t_context))->nb_traps; |
2206 | guint64 trap = ltt_event_get_long_unsigned(e, f); |
5e96e7e3 |
2207 | |
2208 | if(trap < nb_traps) { |
2209 | submode = ((LttvTraceState *)(s->parent.t_context))->trap_names[trap]; |
2210 | } else { |
2211 | /* Fixup an incomplete trap table */ |
2212 | GString *string = g_string_new(""); |
fcc08e1e |
2213 | g_string_printf(string, "trap %llu", trap); |
5e96e7e3 |
2214 | submode = g_quark_from_string(string->str); |
2215 | g_string_free(string, TRUE); |
2216 | } |
2217 | |
b445142a |
2218 | push_state(s, LTTV_STATE_TRAP, submode); |
d3d99fde |
2219 | |
2220 | /* update cpu status */ |
2221 | cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); |
2222 | |
dc877563 |
2223 | return FALSE; |
2224 | } |
2225 | |
b445142a |
2226 | static gboolean trap_exit(void *hook_data, void *call_data) |
dc877563 |
2227 | { |
ba576a78 |
2228 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
2229 | |
ffd54a90 |
2230 | pop_state(s, LTTV_STATE_TRAP); |
d3d99fde |
2231 | |
2232 | /* update cpu status */ |
2233 | cpu_pop_mode(s->cpu_state); |
2234 | |
dc877563 |
2235 | return FALSE; |
2236 | } |
2237 | |
b445142a |
2238 | static gboolean irq_entry(void *hook_data, void *call_data) |
dc877563 |
2239 | { |
ba576a78 |
2240 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
5e563da0 |
2241 | LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; |
eed2ef37 |
2242 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2243 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2244 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
d3a66443 |
2245 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
dc877563 |
2246 | |
b445142a |
2247 | LttvExecutionSubmode submode; |
1bb8d3a5 |
2248 | guint64 irq = ltt_event_get_long_unsigned(e, f); |
6214c229 |
2249 | guint64 nb_irqs = ((LttvTraceState *)(s->parent.t_context))->nb_irqs; |
b445142a |
2250 | |
6214c229 |
2251 | if(irq < nb_irqs) { |
2252 | submode = ((LttvTraceState *)(s->parent.t_context))->irq_names[irq]; |
2253 | } else { |
2254 | /* Fixup an incomplete irq table */ |
2255 | GString *string = g_string_new(""); |
2256 | g_string_printf(string, "irq %llu", irq); |
2257 | submode = g_quark_from_string(string->str); |
2258 | g_string_free(string, TRUE); |
2259 | } |
b445142a |
2260 | |
dc877563 |
2261 | /* Do something with the info about being in user or system mode when int? */ |
b445142a |
2262 | push_state(s, LTTV_STATE_IRQ, submode); |
598026ba |
2263 | |
2264 | /* update cpu status */ |
d3d99fde |
2265 | cpu_push_mode(s->cpu_state, LTTV_CPU_IRQ); |
598026ba |
2266 | |
5e563da0 |
2267 | /* update irq status */ |
8743690d |
2268 | s->cpu_state->last_irq = irq; |
5e563da0 |
2269 | irq_push_mode(&ts->irq_states[irq], LTTV_IRQ_BUSY); |
2270 | |
dc877563 |
2271 | return FALSE; |
2272 | } |
2273 | |
302efbad |
2274 | static gboolean soft_irq_exit(void *hook_data, void *call_data) |
2275 | { |
2276 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2277 | |
2278 | pop_state(s, LTTV_STATE_SOFT_IRQ); |
2279 | return FALSE; |
2280 | } |
2281 | |
2282 | |
dc877563 |
2283 | |
b445142a |
2284 | static gboolean irq_exit(void *hook_data, void *call_data) |
dc877563 |
2285 | { |
ba576a78 |
2286 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
8743690d |
2287 | LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; |
dc877563 |
2288 | |
ffd54a90 |
2289 | pop_state(s, LTTV_STATE_IRQ); |
598026ba |
2290 | |
2291 | /* update cpu status */ |
d3d99fde |
2292 | cpu_pop_mode(s->cpu_state); |
598026ba |
2293 | |
8743690d |
2294 | /* update irq status */ |
2295 | irq_pop_mode(&ts->irq_states[s->cpu_state->last_irq]); |
2296 | |
dc877563 |
2297 | return FALSE; |
2298 | } |
2299 | |
faf074a3 |
2300 | static gboolean soft_irq_entry(void *hook_data, void *call_data) |
2301 | { |
2302 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2303 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2304 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2305 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
d3a66443 |
2306 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
faf074a3 |
2307 | |
2308 | LttvExecutionSubmode submode; |
1bb8d3a5 |
2309 | guint64 softirq = ltt_event_get_long_unsigned(e, f); |
6214c229 |
2310 | guint64 nb_softirqs = ((LttvTraceState *)(s->parent.t_context))->nb_softirqs; |
faf074a3 |
2311 | |
6214c229 |
2312 | if(softirq < nb_softirqs) { |
2313 | submode = ((LttvTraceState *)(s->parent.t_context))->soft_irq_names[softirq]; |
2314 | } else { |
2315 | /* Fixup an incomplete irq table */ |
2316 | GString *string = g_string_new(""); |
2317 | g_string_printf(string, "softirq %llu", softirq); |
2318 | submode = g_quark_from_string(string->str); |
2319 | g_string_free(string, TRUE); |
2320 | } |
faf074a3 |
2321 | |
2322 | /* Do something with the info about being in user or system mode when int? */ |
2323 | push_state(s, LTTV_STATE_SOFT_IRQ, submode); |
2324 | return FALSE; |
2325 | } |
2326 | |
38b73700 |
2327 | static gboolean enum_interrupt(void *hook_data, void *call_data) |
2328 | { |
2329 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2330 | LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; |
2331 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2332 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2333 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
38b73700 |
2334 | |
d3a66443 |
2335 | GQuark action = g_quark_from_string(ltt_event_get_string(e, |
2336 | lttv_trace_get_hook_field(th, 0))); |
2337 | guint irq = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
38b73700 |
2338 | |
2339 | ts->irq_names[irq] = action; |
2340 | |
2341 | return FALSE; |
2342 | } |
2343 | |
2344 | |
27811799 |
2345 | static gboolean bdev_request_issue(void *hook_data, void *call_data) |
2346 | { |
2347 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2348 | LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; |
2349 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2350 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2351 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
27811799 |
2352 | |
d3a66443 |
2353 | guint major = ltt_event_get_long_unsigned(e, |
2354 | lttv_trace_get_hook_field(th, 0)); |
2355 | guint minor = ltt_event_get_long_unsigned(e, |
2356 | lttv_trace_get_hook_field(th, 1)); |
2357 | guint oper = ltt_event_get_long_unsigned(e, |
2358 | lttv_trace_get_hook_field(th, 2)); |
27811799 |
2359 | guint16 devcode = MKDEV(major,minor); |
2360 | |
2361 | /* have we seen this block device before? */ |
98d7814f |
2362 | gpointer bdev = get_hashed_bdevstate(ts, devcode); |
27811799 |
2363 | |
2364 | if(oper == 0) |
2365 | bdev_push_mode(bdev, LTTV_BDEV_BUSY_READING); |
2366 | else |
2367 | bdev_push_mode(bdev, LTTV_BDEV_BUSY_WRITING); |
2368 | |
2369 | return FALSE; |
2370 | } |
2371 | |
2372 | static gboolean bdev_request_complete(void *hook_data, void *call_data) |
2373 | { |
2374 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2375 | LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; |
2376 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2377 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
27811799 |
2378 | |
d3a66443 |
2379 | guint major = ltt_event_get_long_unsigned(e, |
2380 | lttv_trace_get_hook_field(th, 0)); |
2381 | guint minor = ltt_event_get_long_unsigned(e, |
2382 | lttv_trace_get_hook_field(th, 1)); |
2383 | //guint oper = ltt_event_get_long_unsigned(e, |
2384 | // lttv_trace_get_hook_field(th, 2)); |
27811799 |
2385 | guint16 devcode = MKDEV(major,minor); |
2386 | |
2387 | /* have we seen this block device before? */ |
98d7814f |
2388 | gpointer bdev = get_hashed_bdevstate(ts, devcode); |
27811799 |
2389 | |
2390 | /* update block device */ |
2391 | bdev_pop_mode(bdev); |
2392 | |
2393 | return FALSE; |
2394 | } |
2395 | |
302efbad |
2396 | static void push_function(LttvTracefileState *tfs, guint64 funcptr) |
2397 | { |
2398 | guint64 *new_func; |
2399 | |
2400 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
2401 | guint cpu = tfs->cpu; |
2402 | LttvProcessState *process = ts->running_process[cpu]; |
faf074a3 |
2403 | |
302efbad |
2404 | guint depth = process->user_stack->len; |
2405 | |
d3a66443 |
2406 | process->user_stack = |
302efbad |
2407 | g_array_set_size(process->user_stack, depth + 1); |
2408 | |
2409 | new_func = &g_array_index(process->user_stack, guint64, depth); |
80e0221b |
2410 | *new_func = funcptr; |
9bff13df |
2411 | process->current_function = funcptr; |
302efbad |
2412 | } |
2413 | |
2414 | static void pop_function(LttvTracefileState *tfs, guint64 funcptr) |
2415 | { |
2416 | guint cpu = tfs->cpu; |
2417 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
2418 | LttvProcessState *process = ts->running_process[cpu]; |
2419 | |
302efbad |
2420 | if(process->current_function != funcptr){ |
2421 | g_info("Different functions (%lu.%09lu): ignore it\n", |
2422 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
2423 | g_info("process state has %llu when pop_function is %llu\n", |
80e0221b |
2424 | process->current_function, funcptr); |
7b5f6cf1 |
2425 | g_info("{ %u, %u, %s, %s, %s }\n", |
80e0221b |
2426 | process->pid, |
2427 | process->ppid, |
2428 | g_quark_to_string(process->name), |
2429 | g_quark_to_string(process->brand), |
2430 | g_quark_to_string(process->state->s)); |
302efbad |
2431 | return; |
2432 | } |
9bff13df |
2433 | guint depth = process->user_stack->len; |
302efbad |
2434 | |
2435 | if(depth == 0){ |
2436 | g_info("Trying to pop last function on stack (%lu.%09lu): ignore it\n", |
2437 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
2438 | return; |
2439 | } |
2440 | |
2441 | process->user_stack = |
2442 | g_array_set_size(process->user_stack, depth - 1); |
2443 | process->current_function = |
80e0221b |
2444 | g_array_index(process->user_stack, guint64, depth - 2); |
302efbad |
2445 | } |
2446 | |
2447 | |
2448 | static gboolean function_entry(void *hook_data, void *call_data) |
faf074a3 |
2449 | { |
2450 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
302efbad |
2451 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2452 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2453 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
d3a66443 |
2454 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
80e0221b |
2455 | guint64 funcptr = ltt_event_get_long_unsigned(e, f); |
faf074a3 |
2456 | |
302efbad |
2457 | push_function(s, funcptr); |
faf074a3 |
2458 | return FALSE; |
2459 | } |
2460 | |
302efbad |
2461 | static gboolean function_exit(void *hook_data, void *call_data) |
2462 | { |
2463 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2464 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2465 | //guint8 ev_id = ltt_event_eventtype_id(e); |
2466 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
d3a66443 |
2467 | struct marker_field *f = lttv_trace_get_hook_field(th, 0); |
80e0221b |
2468 | guint64 funcptr = ltt_event_get_long_unsigned(e, f); |
302efbad |
2469 | |
302efbad |
2470 | pop_function(s, funcptr); |
2471 | return FALSE; |
2472 | } |
dc877563 |
2473 | |
b445142a |
2474 | static gboolean schedchange(void *hook_data, void *call_data) |
dc877563 |
2475 | { |
ba576a78 |
2476 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
ae3d0f50 |
2477 | guint cpu = s->cpu; |
348c6ba8 |
2478 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2479 | LttvProcessState *process = ts->running_process[cpu]; |
5fd4c7a2 |
2480 | //LttvProcessState *old_process = ts->running_process[cpu]; |
348c6ba8 |
2481 | |
eed2ef37 |
2482 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2483 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
73394fd3 |
2484 | guint pid_in, pid_out; |
7092fb86 |
2485 | gint64 state_out; |
dc877563 |
2486 | |
d3a66443 |
2487 | pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
2488 | pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
2489 | state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); |
348c6ba8 |
2490 | |
2491 | if(likely(process != NULL)) { |
b445142a |
2492 | |
f95bc830 |
2493 | /* We could not know but it was not the idle process executing. |
2494 | This should only happen at the beginning, before the first schedule |
2495 | event, and when the initial information (current process for each CPU) |
2496 | is missing. It is not obvious how we could, after the fact, compensate |
2497 | the wrongly attributed statistics. */ |
2498 | |
240f1fea |
2499 | //This test only makes sense once the state is known and if there is no |
48b002b8 |
2500 | //missing events. We need to silently ignore schedchange coming after a |
80e0221b |
2501 | //process_free, or it causes glitches. (FIXME) |
348c6ba8 |
2502 | //if(unlikely(process->pid != pid_out)) { |
2503 | // g_assert(process->pid == 0); |
240f1fea |
2504 | //} |
c4a72569 |
2505 | if(process->pid == 0 |
2506 | && process->state->t == LTTV_STATE_MODE_UNKNOWN) { |
2507 | if(pid_out == 0) { |
2508 | /* Scheduling out of pid 0 at beginning of the trace : |
2509 | * we know for sure it is in syscall mode at this point. */ |
2510 | g_assert(process->execution_stack->len == 1); |
2511 | process->state->t = LTTV_STATE_SYSCALL; |
2512 | process->state->s = LTTV_STATE_WAIT; |
2513 | process->state->change = s->parent.timestamp; |
d3670e3d |
2514 | process->state->entry = s->parent.timestamp; |
c4a72569 |
2515 | } |
dbd243b1 |
2516 | } else { |
c4a72569 |
2517 | if(unlikely(process->state->s == LTTV_STATE_EXIT)) { |
2518 | process->state->s = LTTV_STATE_ZOMBIE; |
2519 | process->state->change = s->parent.timestamp; |
2520 | } else { |
2521 | if(unlikely(state_out == 0)) process->state->s = LTTV_STATE_WAIT_CPU; |
2522 | else process->state->s = LTTV_STATE_WAIT; |
2523 | process->state->change = s->parent.timestamp; |
2524 | } |
2525 | |
5fe0b9ca |
2526 | if(state_out == 32 || state_out == 128) |
2527 | exit_process(s, process); /* EXIT_DEAD || TASK_DEAD */ |
c4a72569 |
2528 | /* see sched.h for states */ |
791dffa6 |
2529 | } |
dc877563 |
2530 | } |
348c6ba8 |
2531 | process = ts->running_process[cpu] = |
2532 | lttv_state_find_process_or_create( |
2533 | (LttvTraceState*)s->parent.t_context, |
2534 | cpu, pid_in, |
2535 | &s->parent.timestamp); |
2536 | process->state->s = LTTV_STATE_RUN; |
2537 | process->cpu = cpu; |
80e0221b |
2538 | if(process->usertrace) |
2539 | process->usertrace->cpu = cpu; |
348c6ba8 |
2540 | // process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)s)->tf); |
2541 | process->state->change = s->parent.timestamp; |
44ffb95f |
2542 | |
2543 | /* update cpu status */ |
2544 | if(pid_in == 0) |
d3d99fde |
2545 | cpu_set_base_mode(s->cpu_state, LTTV_CPU_IDLE); |
44ffb95f |
2546 | else |
d3d99fde |
2547 | cpu_set_base_mode(s->cpu_state, LTTV_CPU_BUSY); |
44ffb95f |
2548 | |
dc877563 |
2549 | return FALSE; |
2550 | } |
2551 | |
eed2ef37 |
2552 | static gboolean process_fork(void *hook_data, void *call_data) |
dc877563 |
2553 | { |
eed2ef37 |
2554 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2555 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2556 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
eed2ef37 |
2557 | guint parent_pid; |
fcc08e1e |
2558 | guint child_pid; /* In the Linux Kernel, there is one PID per thread. */ |
2559 | guint child_tgid; /* tgid in the Linux kernel is the "real" POSIX PID. */ |
0ceef9de |
2560 | //LttvProcessState *zombie_process; |
ae3d0f50 |
2561 | guint cpu = s->cpu; |
348c6ba8 |
2562 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2563 | LttvProcessState *process = ts->running_process[cpu]; |
26275aa2 |
2564 | LttvProcessState *child_process; |
d3a66443 |
2565 | struct marker_field *f; |
2cdc690b |
2566 | |
eed2ef37 |
2567 | /* Parent PID */ |
d3a66443 |
2568 | parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
eed2ef37 |
2569 | |
2cdc690b |
2570 | /* Child PID */ |
d3a66443 |
2571 | child_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
33bdc8dd |
2572 | s->parent.target_pid = child_pid; |
2cdc690b |
2573 | |
fcc08e1e |
2574 | /* Child TGID */ |
d3a66443 |
2575 | f = lttv_trace_get_hook_field(th, 2); |
2576 | if (likely(f)) |
2577 | child_tgid = ltt_event_get_unsigned(e, f); |
2578 | else |
2579 | child_tgid = 0; |
fcc08e1e |
2580 | |
15b3d537 |
2581 | /* Mathieu : it seems like the process might have been scheduled in before the |
2582 | * fork, and, in a rare case, might be the current process. This might happen |
d4942a23 |
2583 | * in a SMP case where we don't have enough precision on the clocks. |
2584 | * |
2585 | * Test reenabled after precision fixes on time. (Mathieu) */ |
791dffa6 |
2586 | #if 0 |
348c6ba8 |
2587 | zombie_process = lttv_state_find_process(ts, ANY_CPU, child_pid); |
dc877563 |
2588 | |
1d1df11d |
2589 | if(unlikely(zombie_process != NULL)) { |
4ad73431 |
2590 | /* Reutilisation of PID. Only now we are sure that the old PID |
eed2ef37 |
2591 | * has been released. FIXME : should know when release_task happens instead. |
4ad73431 |
2592 | */ |
15b3d537 |
2593 | guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); |
2594 | guint i; |
2595 | for(i=0; i< num_cpus; i++) { |
5ac05980 |
2596 | g_assert(zombie_process != ts->running_process[i]); |
15b3d537 |
2597 | } |
2598 | |
4ad73431 |
2599 | exit_process(s, zombie_process); |
2600 | } |
791dffa6 |
2601 | #endif //0 |
348c6ba8 |
2602 | g_assert(process->pid != child_pid); |
eed2ef37 |
2603 | // FIXME : Add this test in the "known state" section |
348c6ba8 |
2604 | // g_assert(process->pid == parent_pid); |
26275aa2 |
2605 | child_process = lttv_state_find_process(ts, ANY_CPU, child_pid); |
2606 | if(child_process == NULL) { |
ab893fb1 |
2607 | child_process = lttv_state_create_process(ts, process, cpu, |
fcc08e1e |
2608 | child_pid, child_tgid, |
2609 | LTTV_STATE_UNNAMED, &s->parent.timestamp); |
26275aa2 |
2610 | } else { |
2611 | /* The process has already been created : due to time imprecision between |
791dffa6 |
2612 | * multiple CPUs : it has been scheduled in before creation. Note that we |
2613 | * shouldn't have this kind of imprecision. |
26275aa2 |
2614 | * |
2615 | * Simply put a correct parent. |
2616 | */ |
6806b3c6 |
2617 | g_assert(0); /* This is a problematic case : the process has been created |
2618 | before the fork event */ |
26275aa2 |
2619 | child_process->ppid = process->pid; |
fcc08e1e |
2620 | child_process->tgid = child_tgid; |
26275aa2 |
2621 | } |
0292757b |
2622 | g_assert(child_process->name == LTTV_STATE_UNNAMED); |
2623 | child_process->name = process->name; |
2624 | child_process->brand = process->brand; |
4ad73431 |
2625 | |
dc877563 |
2626 | return FALSE; |
2627 | } |
2628 | |
89f8741a |
2629 | /* We stamp a newly created process as kernel_thread. |
2630 | * The thread should not be running yet. */ |
7bfd7820 |
2631 | static gboolean process_kernel_thread(void *hook_data, void *call_data) |
2632 | { |
2633 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2634 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2635 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
7bfd7820 |
2636 | guint pid; |
7bfd7820 |
2637 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2638 | LttvProcessState *process; |
2639 | LttvExecutionState *es; |
2640 | |
2641 | /* PID */ |
d3a66443 |
2642 | pid = (guint)ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
33bdc8dd |
2643 | s->parent.target_pid = pid; |
7bfd7820 |
2644 | |
61c8808e |
2645 | process = lttv_state_find_process_or_create(ts, ANY_CPU, pid, |
2646 | <t_time_zero); |
15f3a340 |
2647 | process->execution_stack = |
2648 | g_array_set_size(process->execution_stack, 1); |
2649 | es = process->state = |
2650 | &g_array_index(process->execution_stack, LttvExecutionState, 0); |
80e0221b |
2651 | es->t = LTTV_STATE_SYSCALL; |
2652 | process->type = LTTV_STATE_KERNEL_THREAD; |
7bfd7820 |
2653 | |
80e0221b |
2654 | return FALSE; |
7bfd7820 |
2655 | } |
dc877563 |
2656 | |
eed2ef37 |
2657 | static gboolean process_exit(void *hook_data, void *call_data) |
dc877563 |
2658 | { |
eed2ef37 |
2659 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2660 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2661 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
eed2ef37 |
2662 | guint pid; |
348c6ba8 |
2663 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
6f54e0f4 |
2664 | LttvProcessState *process; // = ts->running_process[cpu]; |
eed2ef37 |
2665 | |
d3a66443 |
2666 | pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
33bdc8dd |
2667 | s->parent.target_pid = pid; |
eed2ef37 |
2668 | |
2669 | // FIXME : Add this test in the "known state" section |
348c6ba8 |
2670 | // g_assert(process->pid == pid); |
eed2ef37 |
2671 | |
6f54e0f4 |
2672 | process = lttv_state_find_process(ts, ANY_CPU, pid); |
348c6ba8 |
2673 | if(likely(process != NULL)) { |
2674 | process->state->s = LTTV_STATE_EXIT; |
2cdc690b |
2675 | } |
2676 | return FALSE; |
2cdc690b |
2677 | } |
2678 | |
eed2ef37 |
2679 | static gboolean process_free(void *hook_data, void *call_data) |
2da61677 |
2680 | { |
eed2ef37 |
2681 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
348c6ba8 |
2682 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
eed2ef37 |
2683 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2684 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
2da61677 |
2685 | guint release_pid; |
2686 | LttvProcessState *process; |
2687 | |
2688 | /* PID of the process to release */ |
d3a66443 |
2689 | release_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
33bdc8dd |
2690 | s->parent.target_pid = release_pid; |
15b3d537 |
2691 | |
2692 | g_assert(release_pid != 0); |
2da61677 |
2693 | |
348c6ba8 |
2694 | process = lttv_state_find_process(ts, ANY_CPU, release_pid); |
2da61677 |
2695 | |
2696 | if(likely(process != NULL)) { |
2697 | /* release_task is happening at kernel level : we can now safely release |
2698 | * the data structure of the process */ |
5562ddce |
2699 | //This test is fun, though, as it may happen that |
2700 | //at time t : CPU 0 : process_free |
2701 | //at time t+150ns : CPU 1 : schedule out |
2702 | //Clearly due to time imprecision, we disable it. (Mathieu) |
2703 | //If this weird case happen, we have no choice but to put the |
2704 | //Currently running process on the cpu to 0. |
791dffa6 |
2705 | //I re-enable it following time precision fixes. (Mathieu) |
2706 | //Well, in the case where an process is freed by a process on another CPU |
2707 | //and still scheduled, it happens that this is the schedchange that will |
2708 | //drop the last reference count. Do not free it here! |
0bd2f89c |
2709 | guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); |
2710 | guint i; |
2711 | for(i=0; i< num_cpus; i++) { |
5562ddce |
2712 | //g_assert(process != ts->running_process[i]); |
2713 | if(process == ts->running_process[i]) { |
791dffa6 |
2714 | //ts->running_process[i] = lttv_state_find_process(ts, i, 0); |
2715 | break; |
5562ddce |
2716 | } |
0bd2f89c |
2717 | } |
6f54e0f4 |
2718 | if(i == num_cpus) /* process is not scheduled */ |
2719 | exit_process(s, process); |
2da61677 |
2720 | } |
2721 | |
2722 | return FALSE; |
2723 | } |
2724 | |
f4b88a7d |
2725 | |
2726 | static gboolean process_exec(void *hook_data, void *call_data) |
2727 | { |
2728 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2729 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2730 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2731 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
743e50fd |
2732 | //gchar *name; |
ae3d0f50 |
2733 | guint cpu = s->cpu; |
f4b88a7d |
2734 | LttvProcessState *process = ts->running_process[cpu]; |
2735 | |
f63ebe51 |
2736 | #if 0//how to use a sequence that must be transformed in a string |
f4b88a7d |
2737 | /* PID of the process to release */ |
d3a66443 |
2738 | guint64 name_len = ltt_event_field_element_number(e, |
2739 | lttv_trace_get_hook_field(th, 0)); |
2740 | //name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); |
2741 | LttField *child = ltt_event_field_element_select(e, |
2742 | lttv_trace_get_hook_field(th, 0), 0); |
f2923fb2 |
2743 | gchar *name_begin = |
2744 | (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e, child)); |
743e50fd |
2745 | gchar *null_term_name = g_new(gchar, name_len+1); |
2746 | memcpy(null_term_name, name_begin, name_len); |
2747 | null_term_name[name_len] = '\0'; |
743e50fd |
2748 | process->name = g_quark_from_string(null_term_name); |
f63ebe51 |
2749 | #endif //0 |
2750 | |
d3a66443 |
2751 | process->name = g_quark_from_string(ltt_event_get_string(e, |
2752 | lttv_trace_get_hook_field(th, 0))); |
0292757b |
2753 | process->brand = LTTV_STATE_UNBRANDED; |
f63ebe51 |
2754 | //g_free(null_term_name); |
f4b88a7d |
2755 | return FALSE; |
2756 | } |
2757 | |
7b5f6cf1 |
2758 | static gboolean thread_brand(void *hook_data, void *call_data) |
2759 | { |
2760 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2761 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2762 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
0ceef9de |
2763 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
7b5f6cf1 |
2764 | gchar *name; |
2765 | guint cpu = s->cpu; |
2766 | LttvProcessState *process = ts->running_process[cpu]; |
2767 | |
d3a66443 |
2768 | name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); |
7b5f6cf1 |
2769 | process->brand = g_quark_from_string(name); |
2770 | |
2771 | return FALSE; |
2772 | } |
2773 | |
c3b3b60b |
2774 | static void fix_process(gpointer key, gpointer value, |
2775 | gpointer user_data) |
2776 | { |
2777 | LttvProcessState *process; |
2778 | LttvExecutionState *es; |
2779 | process = (LttvProcessState *)value; |
c3b3b60b |
2780 | LttTime *timestamp = (LttTime*)user_data; |
2781 | |
c3b3b60b |
2782 | if(process->type == LTTV_STATE_KERNEL_THREAD) { |
2b25224d |
2783 | es = &g_array_index(process->execution_stack, LttvExecutionState, 0); |
2784 | if(es->t == LTTV_STATE_MODE_UNKNOWN) { |
2785 | es->t = LTTV_STATE_SYSCALL; |
2b25224d |
2786 | es->n = LTTV_STATE_SUBMODE_NONE; |
2787 | es->entry = *timestamp; |
2788 | es->change = *timestamp; |
2789 | es->cum_cpu_time = ltt_time_zero; |
c4a72569 |
2790 | if(es->s == LTTV_STATE_UNNAMED) |
2791 | es->s = LTTV_STATE_WAIT; |
c3b3b60b |
2792 | } |
2793 | } else { |
2b25224d |
2794 | es = &g_array_index(process->execution_stack, LttvExecutionState, 0); |
2795 | if(es->t == LTTV_STATE_MODE_UNKNOWN) { |
c3b3b60b |
2796 | es->t = LTTV_STATE_USER_MODE; |
2797 | es->n = LTTV_STATE_SUBMODE_NONE; |
2798 | es->entry = *timestamp; |
2799 | //g_assert(timestamp->tv_sec != 0); |
2800 | es->change = *timestamp; |
2801 | es->cum_cpu_time = ltt_time_zero; |
c4a72569 |
2802 | if(es->s == LTTV_STATE_UNNAMED) |
2803 | es->s = LTTV_STATE_RUN; |
c3b3b60b |
2804 | |
2b25224d |
2805 | if(process->execution_stack->len == 1) { |
89f8741a |
2806 | /* Still in bottom unknown mode, means never did a system call |
2807 | * May be either in user mode, syscall mode, running or waiting.*/ |
2808 | /* FIXME : we may be tagging syscall mode when being user mode */ |
2b25224d |
2809 | process->execution_stack = |
2810 | g_array_set_size(process->execution_stack, 2); |
2811 | es = process->state = &g_array_index(process->execution_stack, |
c3b3b60b |
2812 | LttvExecutionState, 1); |
2b25224d |
2813 | es->t = LTTV_STATE_SYSCALL; |
2814 | es->n = LTTV_STATE_SUBMODE_NONE; |
2815 | es->entry = *timestamp; |
2816 | //g_assert(timestamp->tv_sec != 0); |
2817 | es->change = *timestamp; |
2818 | es->cum_cpu_time = ltt_time_zero; |
b59b7222 |
2819 | if(es->s == LTTV_STATE_WAIT_FORK) |
2820 | es->s = LTTV_STATE_WAIT; |
2b25224d |
2821 | } |
c3b3b60b |
2822 | } |
2823 | } |
2824 | } |
2825 | |
2826 | static gboolean statedump_end(void *hook_data, void *call_data) |
2827 | { |
2828 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2829 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2830 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
0ceef9de |
2831 | //LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
2832 | //LttvTraceHook *th = (LttvTraceHook *)hook_data; |
c3b3b60b |
2833 | |
2834 | /* For all processes */ |
2835 | /* if kernel thread, if stack[0] is unknown, set to syscall mode, wait */ |
2836 | /* else, if stack[0] is unknown, set to user mode, running */ |
2837 | |
2838 | g_hash_table_foreach(ts->processes, fix_process, &tfc->timestamp); |
0ceef9de |
2839 | |
2840 | return FALSE; |
c3b3b60b |
2841 | } |
2842 | |
b3fd4c02 |
2843 | static gboolean enum_process_state(void *hook_data, void *call_data) |
2844 | { |
2845 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
2846 | LttEvent *e = ltt_tracefile_get_event(s->parent.tf); |
80e0221b |
2847 | //It's slow : optimise later by doing this before reading trace. |
0ceef9de |
2848 | LttvTraceHook *th = (LttvTraceHook *)hook_data; |
b3fd4c02 |
2849 | guint parent_pid; |
2850 | guint pid; |
fcc08e1e |
2851 | guint tgid; |
b3fd4c02 |
2852 | gchar * command; |
ae3d0f50 |
2853 | guint cpu = s->cpu; |
b3fd4c02 |
2854 | LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; |
2855 | LttvProcessState *process = ts->running_process[cpu]; |
2856 | LttvProcessState *parent_process; |
d3a66443 |
2857 | struct marker_field *f; |
80e0221b |
2858 | GQuark type, mode, submode, status; |
2859 | LttvExecutionState *es; |
c4a72569 |
2860 | guint i, nb_cpus; |
f4b88a7d |
2861 | |
b3fd4c02 |
2862 | /* PID */ |
d3a66443 |
2863 | pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
e38d9ea0 |
2864 | s->parent.target_pid = pid; |
2865 | |
b3fd4c02 |
2866 | /* Parent PID */ |
d3a66443 |
2867 | parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
b3fd4c02 |
2868 | |
2869 | /* Command name */ |
d3a66443 |
2870 | command = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); |
b3fd4c02 |
2871 | |
80e0221b |
2872 | /* type */ |
d3a66443 |
2873 | f = lttv_trace_get_hook_field(th, 3); |
deb8b4b2 |
2874 | type = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); |
b3fd4c02 |
2875 | |
b0b1c1dd |
2876 | //FIXME: type is rarely used, enum must match possible types. |
2877 | |
80e0221b |
2878 | /* mode */ |
d3a66443 |
2879 | f = lttv_trace_get_hook_field(th, 4); |
deb8b4b2 |
2880 | mode = ltt_enum_string_get(f,ltt_event_get_unsigned(e, f)); |
b3fd4c02 |
2881 | |
80e0221b |
2882 | /* submode */ |
d3a66443 |
2883 | f = lttv_trace_get_hook_field(th, 5); |
deb8b4b2 |
2884 | submode = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); |
b3fd4c02 |
2885 | |
80e0221b |
2886 | /* status */ |
d3a66443 |
2887 | f = lttv_trace_get_hook_field(th, 6); |
deb8b4b2 |
2888 | status = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); |
e62e7f3a |
2889 | |
fcc08e1e |
2890 | /* TGID */ |
d3a66443 |
2891 | f = lttv_trace_get_hook_field(th, 7); |
2892 | if(f) |
2893 | tgid = ltt_event_get_unsigned(e, f); |
2894 | else |
2895 | tgid = 0; |
c4a72569 |
2896 | |
2897 | if(pid == 0) { |
2898 | nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); |
2899 | for(i=0; i<nb_cpus; i++) { |
2900 | process = lttv_state_find_process(ts, i, pid); |
2901 | g_assert(process != NULL); |
2902 | |
2903 | process->ppid = parent_pid; |
2904 | process->tgid = tgid; |
2905 | process->name = g_quark_from_string(command); |
2906 | es = |
2907 | &g_array_index(process->execution_stack, LttvExecutionState, 0); |
c3b3b60b |
2908 | process->type = LTTV_STATE_KERNEL_THREAD; |
c4a72569 |
2909 | } |
2910 | |
2911 | } else { |
2912 | /* The process might exist if a process was forked while performing the |
2913 | * state dump. */ |
2914 | process = lttv_state_find_process(ts, ANY_CPU, pid); |
2915 | if(process == NULL) { |
2916 | parent_process = lttv_state_find_process(ts, ANY_CPU, parent_pid); |
2917 | process = lttv_state_create_process(ts, parent_process, cpu, |
2918 | pid, tgid, g_quark_from_string(command), |
2919 | &s->parent.timestamp); |
2920 | |
2921 | /* Keep the stack bottom : a running user mode */ |
2922 | /* Disabled because of inconsistencies in the current statedump states. */ |
2923 | if(type == LTTV_STATE_KERNEL_THREAD) { |
2924 | /* Only keep the bottom |
2925 | * FIXME Kernel thread : can be in syscall or interrupt or trap. */ |
2926 | /* Will cause expected trap when in fact being syscall (even after end of |
2927 | * statedump event) |
2928 | * Will cause expected interrupt when being syscall. (only before end of |
2929 | * statedump event) */ |
2930 | // This will cause a "popping last state on stack, ignoring it." |
2931 | process->execution_stack = g_array_set_size(process->execution_stack, 1); |
2932 | es = process->state = &g_array_index(process->execution_stack, |
2933 | LttvExecutionState, 0); |
2934 | process->type = LTTV_STATE_KERNEL_THREAD; |
2935 | es->t = LTTV_STATE_MODE_UNKNOWN; |
2936 | es->s = LTTV_STATE_UNNAMED; |
2937 | es->n = LTTV_STATE_SUBMODE_UNKNOWN; |
2938 | #if 0 |
2939 | es->t = LTTV_STATE_SYSCALL; |
2940 | es->s = status; |
2941 | es->n = submode; |
2942 | #endif //0 |
2943 | } else { |
2944 | /* User space process : |
2945 | * bottom : user mode |
2946 | * either currently running or scheduled out. |
2947 | * can be scheduled out because interrupted in (user mode or in syscall) |
2948 | * or because of an explicit call to the scheduler in syscall. Note that |
2949 | * the scheduler call comes after the irq_exit, so never in interrupt |
2950 | * context. */ |
2951 | // temp workaround : set size to 1 : only have user mode bottom of stack. |
2952 | // will cause g_info message of expected syscall mode when in fact being |
2953 | // in user mode. Can also cause expected trap when in fact being user |
2954 | // mode in the event of a page fault reenabling interrupts in the handler. |
2955 | // Expected syscall and trap can also happen after the end of statedump |
2956 | // This will cause a "popping last state on stack, ignoring it." |
2957 | process->execution_stack = g_array_set_size(process->execution_stack, 1); |
2958 | es = process->state = &g_array_index(process->execution_stack, |
2959 | LttvExecutionState, 0); |
2960 | es->t = LTTV_STATE_MODE_UNKNOWN; |
2961 | es->s = LTTV_STATE_UNNAMED; |
2962 | es->n = LTTV_STATE_SUBMODE_UNKNOWN; |
2963 | #if 0 |
2964 | es->t = LTTV_STATE_USER_MODE; |
2965 | es->s = status; |
2966 | es->n = submode; |
2967 | #endif //0 |
2968 | } |
2969 | #if 0 |
2970 | /* UNKNOWN STATE */ |
2971 | { |
2972 | es = process->state = &g_array_index(process->execution_stack, |
2973 | LttvExecutionState, 1); |
2974 | es->t = LTTV_STATE_MODE_UNKNOWN; |
2975 | es->s = LTTV_STATE_UNNAMED; |
2976 | es->n = LTTV_STATE_SUBMODE_UNKNOWN; |
2977 | } |
2978 | #endif //0 |
80e0221b |
2979 | } else { |
c4a72569 |
2980 | /* The process has already been created : |
2981 | * Probably was forked while dumping the process state or |
2982 | * was simply scheduled in prior to get the state dump event. |
2983 | */ |
2984 | process->ppid = parent_pid; |
2985 | process->tgid = tgid; |
2986 | process->name = g_quark_from_string(command); |
2987 | process->type = type; |
2988 | es = |
2989 | &g_array_index(process->execution_stack, LttvExecutionState, 0); |
c3b3b60b |
2990 | #if 0 |
c4a72569 |
2991 | if(es->t == LTTV_STATE_MODE_UNKNOWN) { |
2992 | if(type == LTTV_STATE_KERNEL_THREAD) |
2993 | es->t = LTTV_STATE_SYSCALL; |
2994 | else |
2995 | es->t = LTTV_STATE_USER_MODE; |
2996 | } |
cab321cf |
2997 | #endif //0 |
c4a72569 |
2998 | /* Don't mess around with the stack, it will eventually become |
2999 | * ok after the end of state dump. */ |
80e0221b |
3000 | } |
b3fd4c02 |
3001 | } |
3002 | |
3003 | return FALSE; |
3004 | } |
f4b88a7d |
3005 | |
58c88a41 |
3006 | gint lttv_state_hook_add_event_hooks(void *hook_data, void *call_data) |
3007 | { |
3008 | LttvTracesetState *tss = (LttvTracesetState*)(call_data); |
3009 | |
3010 | lttv_state_add_event_hooks(tss); |
3011 | |
3012 | return 0; |
3013 | } |
dc877563 |
3014 | |
308711e5 |
3015 | void lttv_state_add_event_hooks(LttvTracesetState *self) |
dc877563 |
3016 | { |
ba576a78 |
3017 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
3018 | |
8979f265 |
3019 | guint i, j, k, nb_trace, nb_tracefile; |
dc877563 |
3020 | |
ba576a78 |
3021 | LttvTraceState *ts; |
dc877563 |
3022 | |
ba576a78 |
3023 | LttvTracefileState *tfs; |
dc877563 |
3024 | |
dc877563 |
3025 | GArray *hooks; |
3026 | |
0ceef9de |
3027 | LttvTraceHook *th; |
eed2ef37 |
3028 | |
dc877563 |
3029 | LttvAttributeValue val; |
3030 | |
ba576a78 |
3031 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
3032 | for(i = 0 ; i < nb_trace ; i++) { |
ba576a78 |
3033 | ts = (LttvTraceState *)self->parent.traces[i]; |
dc877563 |
3034 | |
3035 | /* Find the eventtype id for the following events and register the |
3036 | associated by id hooks. */ |
3037 | |
c3b3b60b |
3038 | hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 19); |
6418800d |
3039 | //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks. |
3040 | //hn = 0; |
b445142a |
3041 | |
6418800d |
3042 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3043 | LTT_FACILITY_KERNEL_ARCH, |
0ceef9de |
3044 | LTT_EVENT_SYSCALL_ENTRY, |
6418800d |
3045 | FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), |
3046 | syscall_entry, NULL, &hooks); |
cbe7c836 |
3047 | |
6418800d |
3048 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3049 | LTT_FACILITY_KERNEL_ARCH, |
0ceef9de |
3050 | LTT_EVENT_SYSCALL_EXIT, |
032ba5da |
3051 | NULL, |
6418800d |
3052 | syscall_exit, NULL, &hooks); |
cbe7c836 |
3053 | |
6418800d |
3054 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3055 | LTT_FACILITY_KERNEL_ARCH, |
0ceef9de |
3056 | LTT_EVENT_TRAP_ENTRY, |
6418800d |
3057 | FIELD_ARRAY(LTT_FIELD_TRAP_ID), |
3058 | trap_entry, NULL, &hooks); |
cbe7c836 |
3059 | |
032ba5da |
3060 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3061 | LTT_FACILITY_KERNEL_ARCH, |
0ceef9de |
3062 | LTT_EVENT_TRAP_EXIT, |
032ba5da |
3063 | NULL, |
3064 | trap_exit, NULL, &hooks); |
cbe7c836 |
3065 | |
032ba5da |
3066 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3067 | LTT_FACILITY_KERNEL, |
0ceef9de |
3068 | LTT_EVENT_IRQ_ENTRY, |
032ba5da |
3069 | FIELD_ARRAY(LTT_FIELD_IRQ_ID), |
3070 | irq_entry, NULL, &hooks); |
cbe7c836 |
3071 | |
032ba5da |
3072 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3073 | LTT_FACILITY_KERNEL, |
0ceef9de |
3074 | LTT_EVENT_IRQ_EXIT, |
032ba5da |
3075 | NULL, |
3076 | irq_exit, NULL, &hooks); |
cbe7c836 |
3077 | |
032ba5da |
3078 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3079 | LTT_FACILITY_KERNEL, |
0ceef9de |
3080 | LTT_EVENT_SOFT_IRQ_ENTRY, |
032ba5da |
3081 | FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), |
3082 | soft_irq_entry, NULL, &hooks); |
faf074a3 |
3083 | |
032ba5da |
3084 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3085 | LTT_FACILITY_KERNEL, |
0ceef9de |
3086 | LTT_EVENT_SOFT_IRQ_EXIT, |
032ba5da |
3087 | NULL, |
3088 | soft_irq_exit, NULL, &hooks); |
faf074a3 |
3089 | |
032ba5da |
3090 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3091 | LTT_FACILITY_KERNEL, |
0ceef9de |
3092 | LTT_EVENT_SCHED_SCHEDULE, |
032ba5da |
3093 | FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, |
3094 | LTT_FIELD_PREV_STATE), |
3095 | schedchange, NULL, &hooks); |
cbe7c836 |
3096 | |
032ba5da |
3097 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3098 | LTT_FACILITY_KERNEL, |
0ceef9de |
3099 | LTT_EVENT_PROCESS_FORK, |
032ba5da |
3100 | FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, |
3101 | LTT_FIELD_CHILD_TGID), |
3102 | process_fork, NULL, &hooks); |
eed2ef37 |
3103 | |
032ba5da |
3104 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3105 | LTT_FACILITY_KERNEL_ARCH, |
0ceef9de |
3106 | LTT_EVENT_KTHREAD_CREATE, |
370231d7 |
3107 | FIELD_ARRAY(LTT_FIELD_PID), |
032ba5da |
3108 | process_kernel_thread, NULL, &hooks); |
7bfd7820 |
3109 | |
032ba5da |
3110 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3111 | LTT_FACILITY_KERNEL, |
0ceef9de |
3112 | LTT_EVENT_PROCESS_EXIT, |
032ba5da |
3113 | FIELD_ARRAY(LTT_FIELD_PID), |
3114 | process_exit, NULL, &hooks); |
eed2ef37 |
3115 | |
032ba5da |
3116 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3117 | LTT_FACILITY_KERNEL, |
0ceef9de |
3118 | LTT_EVENT_PROCESS_FREE, |
032ba5da |
3119 | FIELD_ARRAY(LTT_FIELD_PID), |
3120 | process_free, NULL, &hooks); |
2cdc690b |
3121 | |
032ba5da |
3122 | lttv_trace_find_hook(ts->parent.t, |
43fb1d98 |
3123 | LTT_FACILITY_FS, |
0ceef9de |
3124 | LTT_EVENT_EXEC, |
032ba5da |
3125 | FIELD_ARRAY(LTT_FIELD_FILENAME), |
3126 | process_exec, NULL, &hooks); |
f4b88a7d |
3127 | |
032ba5da |
3128 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3129 | LTT_FACILITY_USER_GENERIC, |
0ceef9de |
3130 | LTT_EVENT_THREAD_BRAND, |
032ba5da |
3131 | FIELD_ARRAY(LTT_FIELD_NAME), |
3132 | thread_brand, NULL, &hooks); |
7b5f6cf1 |
3133 | |
b3fd4c02 |
3134 | /* statedump-related hooks */ |
032ba5da |
3135 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3136 | LTT_FACILITY_LIST, |
0ceef9de |
3137 | LTT_EVENT_PROCESS_STATE, |
d3a66443 |
3138 | FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME, |
3139 | LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, |
3140 | LTT_FIELD_STATUS, LTT_FIELD_TGID), |
032ba5da |
3141 | enum_process_state, NULL, &hooks); |
f4b88a7d |
3142 | |
032ba5da |
3143 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3144 | LTT_FACILITY_LIST, |
0ceef9de |
3145 | LTT_EVENT_STATEDUMP_END, |
032ba5da |
3146 | NULL, |
3147 | statedump_end, NULL, &hooks); |
c3b3b60b |
3148 | |
032ba5da |
3149 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3150 | LTT_FACILITY_LIST, |
0ceef9de |
3151 | LTT_EVENT_LIST_INTERRUPT, |
43fb1d98 |
3152 | FIELD_ARRAY(LTT_FIELD_ACTION, LTT_FIELD_IRQ_ID), |
032ba5da |
3153 | enum_interrupt, NULL, &hooks); |
38b73700 |
3154 | |
032ba5da |
3155 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3156 | LTT_FACILITY_BLOCK, |
0ceef9de |
3157 | LTT_EVENT_REQUEST_ISSUE, |
032ba5da |
3158 | FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), |
3159 | bdev_request_issue, NULL, &hooks); |
27811799 |
3160 | |
032ba5da |
3161 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3162 | LTT_FACILITY_BLOCK, |
0ceef9de |
3163 | LTT_EVENT_REQUEST_COMPLETE, |
032ba5da |
3164 | FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), |
3165 | bdev_request_complete, NULL, &hooks); |
27811799 |
3166 | |
032ba5da |
3167 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3168 | LTT_FACILITY_USER_GENERIC, |
0ceef9de |
3169 | LTT_EVENT_FUNCTION_ENTRY, |
032ba5da |
3170 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), |
3171 | function_entry, NULL, &hooks); |
302efbad |
3172 | |
032ba5da |
3173 | lttv_trace_find_hook(ts->parent.t, |
60c5092c |
3174 | LTT_FACILITY_USER_GENERIC, |
0ceef9de |
3175 | LTT_EVENT_FUNCTION_EXIT, |
032ba5da |
3176 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), |
3177 | function_exit, NULL, &hooks); |
302efbad |
3178 | |
a5ba1787 |
3179 | /* Add these hooks to each event_by_id hooks list */ |
dc877563 |
3180 | |
eed2ef37 |
3181 | nb_tracefile = ts->parent.tracefiles->len; |
dbb7bb09 |
3182 | |
dc877563 |
3183 | for(j = 0 ; j < nb_tracefile ; j++) { |
eed2ef37 |
3184 | tfs = |
9d239bd9 |
3185 | LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, |
3186 | LttvTracefileContext*, j)); |
dc877563 |
3187 | |
3188 | for(k = 0 ; k < hooks->len ; k++) { |
8979f265 |
3189 | th = &g_array_index(hooks, LttvTraceHook, k); |
eed2ef37 |
3190 | lttv_hooks_add( |
5fd4c7a2 |
3191 | lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), |
3192 | th->h, |
3193 | th, |
eed2ef37 |
3194 | LTTV_PRIO_STATE); |
ffd54a90 |
3195 | } |
dc877563 |
3196 | } |
f0b795e0 |
3197 | lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
ba576a78 |
3198 | *(val.v_pointer) = hooks; |
dc877563 |
3199 | } |
3200 | } |
3201 | |
58c88a41 |
3202 | gint lttv_state_hook_remove_event_hooks(void *hook_data, void *call_data) |
3203 | { |
3204 | LttvTracesetState *tss = (LttvTracesetState*)(call_data); |
3205 | |
3206 | lttv_state_remove_event_hooks(tss); |
3207 | |
3208 | return 0; |
3209 | } |
dc877563 |
3210 | |
308711e5 |
3211 | void lttv_state_remove_event_hooks(LttvTracesetState *self) |
dc877563 |
3212 | { |
ba576a78 |
3213 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
3214 | |
8979f265 |
3215 | guint i, j, k, nb_trace, nb_tracefile; |
dc877563 |
3216 | |
ba576a78 |
3217 | LttvTraceState *ts; |
dc877563 |
3218 | |
ba576a78 |
3219 | LttvTracefileState *tfs; |
dc877563 |
3220 | |
dc877563 |
3221 | GArray *hooks; |
3222 | |
5fd4c7a2 |
3223 | LttvTraceHook *th; |
dc877563 |
3224 | |
3225 | LttvAttributeValue val; |
3226 | |
ba576a78 |
3227 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
3228 | for(i = 0 ; i < nb_trace ; i++) { |
021eeb41 |
3229 | ts = LTTV_TRACE_STATE(self->parent.traces[i]); |
7df20ca4 |
3230 | |
f0b795e0 |
3231 | lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
ba576a78 |
3232 | hooks = *(val.v_pointer); |
dc877563 |
3233 | |
a5ba1787 |
3234 | /* Remove these hooks from each event_by_id hooks list */ |
dc877563 |
3235 | |
eed2ef37 |
3236 | nb_tracefile = ts->parent.tracefiles->len; |
dbb7bb09 |
3237 | |
dc877563 |
3238 | for(j = 0 ; j < nb_tracefile ; j++) { |
eed2ef37 |
3239 | tfs = |
cb03932a |
3240 | LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, |
3241 | LttvTracefileContext*, j)); |
dc877563 |
3242 | |
3243 | for(k = 0 ; k < hooks->len ; k++) { |
8979f265 |
3244 | th = &g_array_index(hooks, LttvTraceHook, k); |
eed2ef37 |
3245 | lttv_hooks_remove_data( |
5fd4c7a2 |
3246 | lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), |
3247 | th->h, |
3248 | th); |
ffd54a90 |
3249 | } |
dc877563 |
3250 | } |
032ba5da |
3251 | lttv_trace_hook_remove_all(&hooks); |
dc877563 |
3252 | g_array_free(hooks, TRUE); |
3253 | } |
3254 | } |
3255 | |
eed2ef37 |
3256 | static gboolean state_save_event_hook(void *hook_data, void *call_data) |
3257 | { |
3258 | guint *event_count = (guint*)hook_data; |
3259 | |
3260 | /* Only save at LTTV_STATE_SAVE_INTERVAL */ |
3261 | if(likely((*event_count)++ < LTTV_STATE_SAVE_INTERVAL)) |
3262 | return FALSE; |
3263 | else |
18c87975 |
3264 | *event_count = 0; |
eed2ef37 |
3265 | |
3266 | LttvTracefileState *self = (LttvTracefileState *)call_data; |
3267 | |
eed2ef37 |
3268 | LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); |
3269 | |
eed2ef37 |
3270 | LttvAttribute *saved_states_tree, *saved_state_tree; |
3271 | |
3272 | LttvAttributeValue value; |
3273 | |
3274 | saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, |
3275 | LTTV_STATE_SAVED_STATES); |
3276 | saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
3277 | value = lttv_attribute_add(saved_states_tree, |
3278 | lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); |
3279 | *(value.v_gobject) = (GObject *)saved_state_tree; |
3280 | value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); |
3281 | *(value.v_time) = self->parent.timestamp; |
3282 | lttv_state_save(tcs, saved_state_tree); |
3283 | g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, |
3284 | self->parent.timestamp.tv_nsec); |
3285 | |
3286 | *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; |
3287 | |
3288 | return FALSE; |
3289 | } |
3290 | |
14aecf75 |
3291 | static gboolean state_save_after_trace_hook(void *hook_data, void *call_data) |
3292 | { |
3293 | LttvTraceState *tcs = (LttvTraceState *)(call_data); |
3294 | |
3295 | *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; |
3296 | |
3297 | return FALSE; |
3298 | } |
3299 | |
ae3d0f50 |
3300 | guint lttv_state_current_cpu(LttvTracefileState *tfs) |
3301 | { |
80e0221b |
3302 | return tfs->cpu; |
ae3d0f50 |
3303 | } |
3304 | |
3305 | |
3306 | |
eed2ef37 |
3307 | #if 0 |
08b1c66e |
3308 | static gboolean block_start(void *hook_data, void *call_data) |
308711e5 |
3309 | { |
dbb7bb09 |
3310 | LttvTracefileState *self = (LttvTracefileState *)call_data; |
308711e5 |
3311 | |
dbb7bb09 |
3312 | LttvTracefileState *tfcs; |
308711e5 |
3313 | |
dbb7bb09 |
3314 | LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); |
3315 | |
3316 | LttEventPosition *ep; |
308711e5 |
3317 | |
dbb7bb09 |
3318 | guint i, nb_block, nb_event, nb_tracefile; |
308711e5 |
3319 | |
3320 | LttTracefile *tf; |
3321 | |
3322 | LttvAttribute *saved_states_tree, *saved_state_tree; |
3323 | |
3324 | LttvAttributeValue value; |
3325 | |
dbb7bb09 |
3326 | ep = ltt_event_position_new(); |
eed2ef37 |
3327 | |
3328 | nb_tracefile = tcs->parent.tracefiles->len; |
dbb7bb09 |
3329 | |
3330 | /* Count the number of events added since the last block end in any |
3331 | tracefile. */ |
3332 | |
3333 | for(i = 0 ; i < nb_tracefile ; i++) { |
eed2ef37 |
3334 | tfcs = |
3335 | LTTV_TRACEFILE_STATE(&g_array_index(tcs->parent.tracefiles, |
3336 | LttvTracefileContext, i)); |
dbb7bb09 |
3337 | ltt_event_position(tfcs->parent.e, ep); |
3338 | ltt_event_position_get(ep, &nb_block, &nb_event, &tf); |
3339 | tcs->nb_event += nb_event - tfcs->saved_position; |
3340 | tfcs->saved_position = nb_event; |
3341 | } |
3342 | g_free(ep); |
308711e5 |
3343 | |
308711e5 |
3344 | if(tcs->nb_event >= tcs->save_interval) { |
3345 | saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, |
3346 | LTTV_STATE_SAVED_STATES); |
3347 | saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
3348 | value = lttv_attribute_add(saved_states_tree, |
3349 | lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); |
3350 | *(value.v_gobject) = (GObject *)saved_state_tree; |
3351 | value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); |
dbb7bb09 |
3352 | *(value.v_time) = self->parent.timestamp; |
308711e5 |
3353 | lttv_state_save(tcs, saved_state_tree); |
3354 | tcs->nb_event = 0; |
08b1c66e |
3355 | g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, |
80e0221b |
3356 | self->parent.timestamp.tv_nsec); |
308711e5 |
3357 | } |
dbb7bb09 |
3358 | *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; |
308711e5 |
3359 | return FALSE; |
3360 | } |
eed2ef37 |
3361 | #endif //0 |
308711e5 |
3362 | |
eed2ef37 |
3363 | #if 0 |
08b1c66e |
3364 | static gboolean block_end(void *hook_data, void *call_data) |
3365 | { |
3366 | LttvTracefileState *self = (LttvTracefileState *)call_data; |
3367 | |
3368 | LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); |
3369 | |
3370 | LttTracefile *tf; |
3371 | |
3372 | LttEventPosition *ep; |
3373 | |
3374 | guint nb_block, nb_event; |
3375 | |
3376 | ep = ltt_event_position_new(); |
3377 | ltt_event_position(self->parent.e, ep); |
3378 | ltt_event_position_get(ep, &nb_block, &nb_event, &tf); |
3379 | tcs->nb_event += nb_event - self->saved_position + 1; |
3380 | self->saved_position = 0; |
3381 | *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; |
3382 | g_free(ep); |
00e74b69 |
3383 | |
3384 | return FALSE; |
08b1c66e |
3385 | } |
eed2ef37 |
3386 | #endif //0 |
3387 | #if 0 |
308711e5 |
3388 | void lttv_state_save_add_event_hooks(LttvTracesetState *self) |
3389 | { |
3390 | LttvTraceset *traceset = self->parent.ts; |
3391 | |
00e74b69 |
3392 | guint i, j, nb_trace, nb_tracefile; |
308711e5 |
3393 | |
3394 | LttvTraceState *ts; |
3395 | |
3396 | LttvTracefileState *tfs; |
3397 | |
08b1c66e |
3398 | LttvTraceHook hook_start, hook_end; |
308711e5 |
3399 | |
3400 | nb_trace = lttv_traceset_number(traceset); |
3401 | for(i = 0 ; i < nb_trace ; i++) { |
3402 | ts = (LttvTraceState *)self->parent.traces[i]; |
eed2ef37 |
3403 | |
08b1c66e |
3404 | lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, |
80e0221b |
3405 | NULL, NULL, block_start, &hook_start); |
308711e5 |
3406 | lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, |
80e0221b |
3407 | NULL, NULL, block_end, &hook_end); |
308711e5 |
3408 | |
eed2ef37 |
3409 | nb_tracefile = ts->parent.tracefiles->len; |
308711e5 |
3410 | |
dbb7bb09 |
3411 | for(j = 0 ; j < nb_tracefile ; j++) { |
eed2ef37 |
3412 | tfs = |
3413 | LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, |
3414 | LttvTracefileContext, j)); |
a5ba1787 |
3415 | lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, |
80e0221b |
3416 | hook_start.id), hook_start.h, NULL, LTTV_PRIO_STATE); |
a5ba1787 |
3417 | lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, |
80e0221b |
3418 | hook_end.id), hook_end.h, NULL, LTTV_PRIO_STATE); |
eed2ef37 |
3419 | } |
3420 | } |
3421 | } |
3422 | #endif //0 |
3423 | |
3424 | void lttv_state_save_add_event_hooks(LttvTracesetState *self) |
3425 | { |
3426 | LttvTraceset *traceset = self->parent.ts; |
3427 | |
3428 | guint i, j, nb_trace, nb_tracefile; |
3429 | |
3430 | LttvTraceState *ts; |
3431 | |
3432 | LttvTracefileState *tfs; |
3433 | |
3434 | |
3435 | nb_trace = lttv_traceset_number(traceset); |
3436 | for(i = 0 ; i < nb_trace ; i++) { |
3437 | |
3438 | ts = (LttvTraceState *)self->parent.traces[i]; |
3439 | nb_tracefile = ts->parent.tracefiles->len; |
3440 | |
ce05e187 |
3441 | if(ts->has_precomputed_states) continue; |
3442 | |
3054461a |
3443 | guint *event_count = g_new(guint, 1); |
3444 | *event_count = 0; |
3445 | |
eed2ef37 |
3446 | for(j = 0 ; j < nb_tracefile ; j++) { |
3447 | tfs = |
cb03932a |
3448 | LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, |
3449 | LttvTracefileContext*, j)); |
eed2ef37 |
3450 | lttv_hooks_add(tfs->parent.event, |
3451 | state_save_event_hook, |
3452 | event_count, |
3453 | LTTV_PRIO_STATE); |
3454 | |
308711e5 |
3455 | } |
3456 | } |
14aecf75 |
3457 | |
3458 | lttv_process_traceset_begin(&self->parent, |
3459 | NULL, NULL, NULL, NULL, NULL); |
3460 | |
308711e5 |
3461 | } |
3462 | |
b56b5fec |
3463 | gint lttv_state_save_hook_add_event_hooks(void *hook_data, void *call_data) |
3464 | { |
3465 | LttvTracesetState *tss = (LttvTracesetState*)(call_data); |
3466 | |
3467 | lttv_state_save_add_event_hooks(tss); |
3468 | |
3469 | return 0; |
3470 | } |
3471 | |
308711e5 |
3472 | |
eed2ef37 |
3473 | #if 0 |
308711e5 |
3474 | void lttv_state_save_remove_event_hooks(LttvTracesetState *self) |
3475 | { |
3476 | LttvTraceset *traceset = self->parent.ts; |
3477 | |
00e74b69 |
3478 | guint i, j, nb_trace, nb_tracefile; |
308711e5 |
3479 | |
3480 | LttvTraceState *ts; |
3481 | |
3482 | LttvTracefileState *tfs; |
3483 | |
08b1c66e |
3484 | LttvTraceHook hook_start, hook_end; |
308711e5 |
3485 | |
3486 | nb_trace = lttv_traceset_number(traceset); |
3487 | for(i = 0 ; i < nb_trace ; i++) { |
3488 | ts = LTTV_TRACE_STATE(self->parent.traces[i]); |
eed2ef37 |
3489 | |
08b1c66e |
3490 | lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, |
80e0221b |
3491 | NULL, NULL, block_start, &hook_start); |
08b1c66e |
3492 | |
308711e5 |
3493 | lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, |
80e0221b |
3494 | NULL, NULL, block_end, &hook_end); |
308711e5 |
3495 | |
eed2ef37 |
3496 | nb_tracefile = ts->parent.tracefiles->len; |
308711e5 |
3497 | |
dbb7bb09 |
3498 | for(j = 0 ; j < nb_tracefile ; j++) { |
eed2ef37 |
3499 | tfs = |
3500 | LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, |
3501 | LttvTracefileContext, j)); |
308711e5 |
3502 | lttv_hooks_remove_data(lttv_hooks_by_id_find( |
a5ba1787 |
3503 | tfs->parent.event_by_id, hook_start.id), hook_start.h, NULL); |
08b1c66e |
3504 | lttv_hooks_remove_data(lttv_hooks_by_id_find( |
a5ba1787 |
3505 | tfs->parent.event_by_id, hook_end.id), hook_end.h, NULL); |
308711e5 |
3506 | } |
3507 | } |
3508 | } |
eed2ef37 |
3509 | #endif //0 |
3510 | |
3511 | void lttv_state_save_remove_event_hooks(LttvTracesetState *self) |
3512 | { |
3513 | LttvTraceset *traceset = self->parent.ts; |
3514 | |
3515 | guint i, j, nb_trace, nb_tracefile; |
3516 | |
3517 | LttvTraceState *ts; |
3518 | |
3519 | LttvTracefileState *tfs; |
3520 | |
14aecf75 |
3521 | LttvHooks *after_trace = lttv_hooks_new(); |
3522 | |
3523 | lttv_hooks_add(after_trace, |
3524 | state_save_after_trace_hook, |
3525 | NULL, |
3526 | LTTV_PRIO_STATE); |
3527 | |
3528 | |
3529 | lttv_process_traceset_end(&self->parent, |
3530 | NULL, after_trace, NULL, NULL, NULL); |
eed2ef37 |
3531 | |
14aecf75 |
3532 | lttv_hooks_destroy(after_trace); |
3533 | |
eed2ef37 |
3534 | nb_trace = lttv_traceset_number(traceset); |
3535 | for(i = 0 ; i < nb_trace ; i++) { |
3536 | |
3537 | ts = (LttvTraceState *)self->parent.traces[i]; |
3538 | nb_tracefile = ts->parent.tracefiles->len; |
3539 | |
ce05e187 |
3540 | if(ts->has_precomputed_states) continue; |
3541 | |
22b165e9 |
3542 | guint *event_count = NULL; |
eed2ef37 |
3543 | |
3544 | for(j = 0 ; j < nb_tracefile ; j++) { |
3545 | tfs = |
cb03932a |
3546 | LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, |
3547 | LttvTracefileContext*, j)); |
eed2ef37 |
3548 | event_count = lttv_hooks_remove(tfs->parent.event, |
3549 | state_save_event_hook); |
eed2ef37 |
3550 | } |
22b165e9 |
3551 | if(event_count) g_free(event_count); |
eed2ef37 |
3552 | } |
3553 | } |
308711e5 |
3554 | |
b56b5fec |
3555 | gint lttv_state_save_hook_remove_event_hooks(void *hook_data, void *call_data) |
3556 | { |
3557 | LttvTracesetState *tss = (LttvTracesetState*)(call_data); |
3558 | |
3559 | lttv_state_save_remove_event_hooks(tss); |
3560 | |
3561 | return 0; |
3562 | } |
308711e5 |
3563 | |
dd025f91 |
3564 | void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t) |
308711e5 |
3565 | { |
3566 | LttvTraceset *traceset = self->parent.ts; |
3567 | |
00e74b69 |
3568 | guint i, nb_trace; |
308711e5 |
3569 | |
3570 | int min_pos, mid_pos, max_pos; |
3571 | |
728d0c3e |
3572 | guint call_rest = 0; |
3573 | |
308711e5 |
3574 | LttvTraceState *tcs; |
3575 | |
3576 | LttvAttributeValue value; |
3577 | |
3578 | LttvAttributeType type; |
3579 | |
3580 | LttvAttributeName name; |
3581 | |
80e0221b |
3582 | gboolean is_named; |
c0cb4d12 |
3583 | |
308711e5 |
3584 | LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree; |
3585 | |
d448fce2 |
3586 | //g_tree_destroy(self->parent.pqueue); |
3587 | //self->parent.pqueue = g_tree_new(compare_tracefile); |
348c6ba8 |
3588 | |
728d0c3e |
3589 | g_info("Entering seek_time_closest for time %lu.%lu", t.tv_sec, t.tv_nsec); |
3590 | |
308711e5 |
3591 | nb_trace = lttv_traceset_number(traceset); |
3592 | for(i = 0 ; i < nb_trace ; i++) { |
3593 | tcs = (LttvTraceState *)self->parent.traces[i]; |
3594 | |
2a2fa4f0 |
3595 | if(ltt_time_compare(t, *(tcs->max_time_state_recomputed_in_seek)) < 0) { |
3596 | saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, |
3597 | LTTV_STATE_SAVED_STATES); |
3598 | min_pos = -1; |
3599 | |
3600 | if(saved_states_tree) { |
dd025f91 |
3601 | max_pos = lttv_attribute_get_number(saved_states_tree) - 1; |
3602 | mid_pos = max_pos / 2; |
3603 | while(min_pos < max_pos) { |
c0cb4d12 |
3604 | type = lttv_attribute_get(saved_states_tree, mid_pos, &name, &value, |
80e0221b |
3605 | &is_named); |
dd025f91 |
3606 | g_assert(type == LTTV_GOBJECT); |
3607 | saved_state_tree = *((LttvAttribute **)(value.v_gobject)); |
3608 | type = lttv_attribute_get_by_name(saved_state_tree, LTTV_STATE_TIME, |
3609 | &value); |
3610 | g_assert(type == LTTV_TIME); |
3611 | if(ltt_time_compare(*(value.v_time), t) < 0) { |
3612 | min_pos = mid_pos; |
3613 | closest_tree = saved_state_tree; |
3614 | } |
3615 | else max_pos = mid_pos - 1; |
3616 | |
3617 | mid_pos = (min_pos + max_pos + 1) / 2; |
3618 | } |
2a2fa4f0 |
3619 | } |
dd025f91 |
3620 | |
2a2fa4f0 |
3621 | /* restore the closest earlier saved state */ |
f95bc830 |
3622 | if(min_pos != -1) { |
3623 | lttv_state_restore(tcs, closest_tree); |
728d0c3e |
3624 | call_rest = 1; |
f95bc830 |
3625 | } |
dd025f91 |
3626 | |
2a2fa4f0 |
3627 | /* There is no saved state, yet we want to have it. Restart at T0 */ |
dd025f91 |
3628 | else { |
3629 | restore_init_state(tcs); |
3630 | lttv_process_trace_seek_time(&(tcs->parent), ltt_time_zero); |
308711e5 |
3631 | } |
9444deae |
3632 | } |
dd025f91 |
3633 | /* We want to seek quickly without restoring/updating the state */ |
3634 | else { |
308711e5 |
3635 | restore_init_state(tcs); |
dd025f91 |
3636 | lttv_process_trace_seek_time(&(tcs->parent), t); |
308711e5 |
3637 | } |
308711e5 |
3638 | } |
728d0c3e |
3639 | if(!call_rest) g_info("NOT Calling restore"); |
308711e5 |
3640 | } |
3641 | |
3642 | |
3643 | static void |
3644 | traceset_state_instance_init (GTypeInstance *instance, gpointer g_class) |
3645 | { |
3646 | } |
3647 | |
3648 | |
3649 | static void |
3650 | traceset_state_finalize (LttvTracesetState *self) |
3651 | { |
3652 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
3653 | finalize(G_OBJECT(self)); |
3654 | } |
3655 | |
3656 | |
3657 | static void |
3658 | traceset_state_class_init (LttvTracesetContextClass *klass) |
3659 | { |
3660 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
3661 | |
3662 | gobject_class->finalize = (void (*)(GObject *self)) traceset_state_finalize; |
3663 | klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; |
3664 | klass->fini = (void (*)(LttvTracesetContext *self))fini; |
3665 | klass->new_traceset_context = new_traceset_context; |
3666 | klass->new_trace_context = new_trace_context; |
3667 | klass->new_tracefile_context = new_tracefile_context; |
3668 | } |
3669 | |
3670 | |
3671 | GType |
3672 | lttv_traceset_state_get_type(void) |
3673 | { |
3674 | static GType type = 0; |
3675 | if (type == 0) { |
3676 | static const GTypeInfo info = { |
3677 | sizeof (LttvTracesetStateClass), |
3678 | NULL, /* base_init */ |
3679 | NULL, /* base_finalize */ |
3680 | (GClassInitFunc) traceset_state_class_init, /* class_init */ |
3681 | NULL, /* class_finalize */ |
3682 | NULL, /* class_data */ |
dbb7bb09 |
3683 | sizeof (LttvTracesetState), |
308711e5 |
3684 | 0, /* n_preallocs */ |
00e74b69 |
3685 | (GInstanceInitFunc) traceset_state_instance_init, /* instance_init */ |
3686 | NULL /* value handling */ |
308711e5 |
3687 | }; |
3688 | |
3689 | type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType", |
3690 | &info, 0); |
3691 | } |
3692 | return type; |
3693 | } |
3694 | |
3695 | |
3696 | static void |
3697 | trace_state_instance_init (GTypeInstance *instance, gpointer g_class) |
3698 | { |
3699 | } |
3700 | |
3701 | |
3702 | static void |
3703 | trace_state_finalize (LttvTraceState *self) |
3704 | { |
3705 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE))-> |
3706 | finalize(G_OBJECT(self)); |
3707 | } |
3708 | |
3709 | |
3710 | static void |
3711 | trace_state_class_init (LttvTraceStateClass *klass) |
3712 | { |
3713 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
3714 | |
3715 | gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize; |
3716 | klass->state_save = state_save; |
3717 | klass->state_restore = state_restore; |
3718 | klass->state_saved_free = state_saved_free; |
3719 | } |
3720 | |
3721 | |
3722 | GType |
3723 | lttv_trace_state_get_type(void) |
3724 | { |
3725 | static GType type = 0; |
3726 | if (type == 0) { |
3727 | static const GTypeInfo info = { |
3728 | sizeof (LttvTraceStateClass), |
3729 | NULL, /* base_init */ |
3730 | NULL, /* base_finalize */ |
3731 | (GClassInitFunc) trace_state_class_init, /* class_init */ |
3732 | NULL, /* class_finalize */ |
3733 | NULL, /* class_data */ |
3734 | sizeof (LttvTraceState), |
3735 | 0, /* n_preallocs */ |
00e74b69 |
3736 | (GInstanceInitFunc) trace_state_instance_init, /* instance_init */ |
3737 | NULL /* value handling */ |
308711e5 |
3738 | }; |
3739 | |
3740 | type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE, |
3741 | "LttvTraceStateType", &info, 0); |
3742 | } |
3743 | return type; |
3744 | } |
3745 | |
3746 | |
3747 | static void |
3748 | tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class) |
3749 | { |
3750 | } |
3751 | |
3752 | |
3753 | static void |
3754 | tracefile_state_finalize (LttvTracefileState *self) |
3755 | { |
3756 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE))-> |
3757 | finalize(G_OBJECT(self)); |
3758 | } |
3759 | |
3760 | |
3761 | static void |
3762 | tracefile_state_class_init (LttvTracefileStateClass *klass) |
3763 | { |
3764 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
3765 | |
3766 | gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize; |
3767 | } |
3768 | |
3769 | |
3770 | GType |
3771 | lttv_tracefile_state_get_type(void) |
3772 | { |
3773 | static GType type = 0; |
3774 | if (type == 0) { |
3775 | static const GTypeInfo info = { |
3776 | sizeof (LttvTracefileStateClass), |
3777 | NULL, /* base_init */ |
3778 | NULL, /* base_finalize */ |
3779 | (GClassInitFunc) tracefile_state_class_init, /* class_init */ |
3780 | NULL, /* class_finalize */ |
3781 | NULL, /* class_data */ |
3782 | sizeof (LttvTracefileState), |
3783 | 0, /* n_preallocs */ |
00e74b69 |
3784 | (GInstanceInitFunc) tracefile_state_instance_init, /* instance_init */ |
3785 | NULL /* value handling */ |
308711e5 |
3786 | }; |
3787 | |
3788 | type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE, |
3789 | "LttvTracefileStateType", &info, 0); |
3790 | } |
3791 | return type; |
3792 | } |
3793 | |
3794 | |
08b1c66e |
3795 | static void module_init() |
ffd54a90 |
3796 | { |
b4fa748c |
3797 | LTTV_STATE_UNNAMED = g_quark_from_string(""); |
235c78f0 |
3798 | LTTV_STATE_UNBRANDED = g_quark_from_string(""); |
b3fd4c02 |
3799 | LTTV_STATE_MODE_UNKNOWN = g_quark_from_string("MODE_UNKNOWN"); |
3800 | LTTV_STATE_USER_MODE = g_quark_from_string("USER_MODE"); |
3801 | LTTV_STATE_SYSCALL = g_quark_from_string("SYSCALL"); |
3802 | LTTV_STATE_TRAP = g_quark_from_string("TRAP"); |
3803 | LTTV_STATE_IRQ = g_quark_from_string("IRQ"); |
3804 | LTTV_STATE_SOFT_IRQ = g_quark_from_string("SOFTIRQ"); |
3805 | LTTV_STATE_SUBMODE_UNKNOWN = g_quark_from_string("UNKNOWN"); |
3806 | LTTV_STATE_SUBMODE_NONE = g_quark_from_string("NONE"); |
3807 | LTTV_STATE_WAIT_FORK = g_quark_from_string("WAIT_FORK"); |
3808 | LTTV_STATE_WAIT_CPU = g_quark_from_string("WAIT_CPU"); |
3809 | LTTV_STATE_EXIT = g_quark_from_string("EXIT"); |
3810 | LTTV_STATE_ZOMBIE = g_quark_from_string("ZOMBIE"); |
3811 | LTTV_STATE_WAIT = g_quark_from_string("WAIT"); |
3812 | LTTV_STATE_RUN = g_quark_from_string("RUN"); |
3813 | LTTV_STATE_DEAD = g_quark_from_string("DEAD"); |
80e0221b |
3814 | LTTV_STATE_USER_THREAD = g_quark_from_string("USER_THREAD"); |
3815 | LTTV_STATE_KERNEL_THREAD = g_quark_from_string("KERNEL_THREAD"); |
308711e5 |
3816 | LTTV_STATE_TRACEFILES = g_quark_from_string("tracefiles"); |
3817 | LTTV_STATE_PROCESSES = g_quark_from_string("processes"); |
3818 | LTTV_STATE_PROCESS = g_quark_from_string("process"); |
348c6ba8 |
3819 | LTTV_STATE_RUNNING_PROCESS = g_quark_from_string("running_process"); |
308711e5 |
3820 | LTTV_STATE_EVENT = g_quark_from_string("event"); |
3821 | LTTV_STATE_SAVED_STATES = g_quark_from_string("saved states"); |
dbb7bb09 |
3822 | LTTV_STATE_SAVED_STATES_TIME = g_quark_from_string("saved states time"); |
308711e5 |
3823 | LTTV_STATE_TIME = g_quark_from_string("time"); |
ffd54a90 |
3824 | LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks"); |
f95bc830 |
3825 | LTTV_STATE_NAME_TABLES = g_quark_from_string("name tables"); |
3826 | LTTV_STATE_TRACE_STATE_USE_COUNT = |
3827 | g_quark_from_string("trace_state_use_count"); |
fbfbd4db |
3828 | LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu resource states"); |
98d7814f |
3829 | LTTV_STATE_RESOURCE_IRQS = g_quark_from_string("irq resource states"); |
3830 | LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states"); |
eed2ef37 |
3831 | |
3832 | |
3833 | LTT_FACILITY_KERNEL = g_quark_from_string("kernel"); |
f5d7967f |
3834 | LTT_FACILITY_KERNEL_ARCH = g_quark_from_string("kernel_arch"); |
f4b88a7d |
3835 | LTT_FACILITY_FS = g_quark_from_string("fs"); |
86c32a8f |
3836 | LTT_FACILITY_LIST = g_quark_from_string("list"); |
302efbad |
3837 | LTT_FACILITY_USER_GENERIC = g_quark_from_string("user_generic"); |
27811799 |
3838 | LTT_FACILITY_BLOCK = g_quark_from_string("block"); |
eed2ef37 |
3839 | |
3840 | |
3841 | LTT_EVENT_SYSCALL_ENTRY = g_quark_from_string("syscall_entry"); |
3842 | LTT_EVENT_SYSCALL_EXIT = g_quark_from_string("syscall_exit"); |
3843 | LTT_EVENT_TRAP_ENTRY = g_quark_from_string("trap_entry"); |
3844 | LTT_EVENT_TRAP_EXIT = g_quark_from_string("trap_exit"); |
3845 | LTT_EVENT_IRQ_ENTRY = g_quark_from_string("irq_entry"); |
3846 | LTT_EVENT_IRQ_EXIT = g_quark_from_string("irq_exit"); |
43fb1d98 |
3847 | LTT_EVENT_SOFT_IRQ_ENTRY = g_quark_from_string("softirq_entry"); |
3848 | LTT_EVENT_SOFT_IRQ_EXIT = g_quark_from_string("softirq_exit"); |
86c32a8f |
3849 | LTT_EVENT_SCHED_SCHEDULE = g_quark_from_string("sched_schedule"); |
3850 | LTT_EVENT_PROCESS_FORK = g_quark_from_string("process_fork"); |
3851 | LTT_EVENT_KTHREAD_CREATE = g_quark_from_string("kthread_create"); |
3852 | LTT_EVENT_PROCESS_EXIT = g_quark_from_string("process_exit"); |
f63ebe51 |
3853 | LTT_EVENT_PROCESS_FREE = g_quark_from_string("process_free"); |
f4b88a7d |
3854 | LTT_EVENT_EXEC = g_quark_from_string("exec"); |
86c32a8f |
3855 | LTT_EVENT_PROCESS_STATE = g_quark_from_string("process_state"); |
c3b3b60b |
3856 | LTT_EVENT_STATEDUMP_END = g_quark_from_string("statedump_end"); |
302efbad |
3857 | LTT_EVENT_FUNCTION_ENTRY = g_quark_from_string("function_entry"); |
3858 | LTT_EVENT_FUNCTION_EXIT = g_quark_from_string("function_exit"); |
7b5f6cf1 |
3859 | LTT_EVENT_THREAD_BRAND = g_quark_from_string("thread_brand"); |
27811799 |
3860 | LTT_EVENT_REQUEST_ISSUE = g_quark_from_string("_blk_request_issue"); |
3861 | LTT_EVENT_REQUEST_COMPLETE = g_quark_from_string("_blk_request_complete"); |
38b73700 |
3862 | LTT_EVENT_LIST_INTERRUPT = g_quark_from_string("interrupt");; |
eed2ef37 |
3863 | |
3864 | |
3865 | LTT_FIELD_SYSCALL_ID = g_quark_from_string("syscall_id"); |
3866 | LTT_FIELD_TRAP_ID = g_quark_from_string("trap_id"); |
3867 | LTT_FIELD_IRQ_ID = g_quark_from_string("irq_id"); |
faf074a3 |
3868 | LTT_FIELD_SOFT_IRQ_ID = g_quark_from_string("softirq_id"); |
f63ebe51 |
3869 | LTT_FIELD_PREV_PID = g_quark_from_string("prev_pid"); |
3870 | LTT_FIELD_NEXT_PID = g_quark_from_string("next_pid"); |
3871 | LTT_FIELD_PREV_STATE = g_quark_from_string("prev_state"); |
eed2ef37 |
3872 | LTT_FIELD_PARENT_PID = g_quark_from_string("parent_pid"); |
3873 | LTT_FIELD_CHILD_PID = g_quark_from_string("child_pid"); |
3874 | LTT_FIELD_PID = g_quark_from_string("pid"); |
fcc08e1e |
3875 | LTT_FIELD_TGID = g_quark_from_string("tgid"); |
f63ebe51 |
3876 | LTT_FIELD_CHILD_TGID = g_quark_from_string("child_tgid"); |
f4b88a7d |
3877 | LTT_FIELD_FILENAME = g_quark_from_string("filename"); |
b3fd4c02 |
3878 | LTT_FIELD_NAME = g_quark_from_string("name"); |
e62e7f3a |
3879 | LTT_FIELD_TYPE = g_quark_from_string("type"); |
b3fd4c02 |
3880 | LTT_FIELD_MODE = g_quark_from_string("mode"); |
3881 | LTT_FIELD_SUBMODE = g_quark_from_string("submode"); |
3882 | LTT_FIELD_STATUS = g_quark_from_string("status"); |
302efbad |
3883 | LTT_FIELD_THIS_FN = g_quark_from_string("this_fn"); |
3884 | LTT_FIELD_CALL_SITE = g_quark_from_string("call_site"); |
27811799 |
3885 | LTT_FIELD_MAJOR = g_quark_from_string("major"); |
3886 | LTT_FIELD_MINOR = g_quark_from_string("minor"); |
3887 | LTT_FIELD_OPERATION = g_quark_from_string("direction"); |
38b73700 |
3888 | LTT_FIELD_ACTION = g_quark_from_string("action"); |
eed2ef37 |
3889 | |
44ffb95f |
3890 | LTTV_CPU_UNKNOWN = g_quark_from_string("unknown"); |
3891 | LTTV_CPU_IDLE = g_quark_from_string("idle"); |
3892 | LTTV_CPU_BUSY = g_quark_from_string("busy"); |
598026ba |
3893 | LTTV_CPU_IRQ = g_quark_from_string("irq"); |
d3d99fde |
3894 | LTTV_CPU_TRAP = g_quark_from_string("trap"); |
5e563da0 |
3895 | |
3896 | LTTV_IRQ_UNKNOWN = g_quark_from_string("unknown"); |
3897 | LTTV_IRQ_IDLE = g_quark_from_string("idle"); |
3898 | LTTV_IRQ_BUSY = g_quark_from_string("busy"); |
27811799 |
3899 | |
3900 | LTTV_BDEV_UNKNOWN = g_quark_from_string("unknown"); |
3901 | LTTV_BDEV_IDLE = g_quark_from_string("idle"); |
3902 | LTTV_BDEV_BUSY_READING = g_quark_from_string("busy_reading"); |
3903 | LTTV_BDEV_BUSY_WRITING = g_quark_from_string("busy_writing"); |
ffd54a90 |
3904 | } |
dc877563 |
3905 | |
08b1c66e |
3906 | static void module_destroy() |
ffd54a90 |
3907 | { |
3908 | } |
dc877563 |
3909 | |
3910 | |
08b1c66e |
3911 | LTTV_MODULE("state", "State computation", \ |
3912 | "Update the system state, possibly saving it at intervals", \ |
3913 | module_init, module_destroy) |
3914 | |
dc877563 |
3915 | |
3916 | |