1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
25 #include <lttv/lttv.h>
26 #include <lttv/module.h>
27 #include <lttv/state.h>
28 #include <ltt/trace.h>
29 #include <ltt/event.h>
31 #include <ltt/marker-desc.h>
34 #include <ltt/ltt-private.h>
39 * usertrace is there only to be able to update the current CPU of the
40 * usertraces when there is a schedchange. it is a way to link the ProcessState
41 * to the associated usertrace. Link only created upon thread creation.
43 * The cpu id is necessary : it gives us back the current ProcessState when we
44 * are considering data from the usertrace.
47 #define PREALLOCATED_EXECUTION_STACK 10
53 LTT_CHANNEL_GLOBAL_STATE
,
54 LTT_CHANNEL_IRQ_STATE
,
55 LTT_CHANNEL_MODULE_STATE
,
56 LTT_CHANNEL_NETIF_STATE
,
57 LTT_CHANNEL_SOFTIRQ_STATE
,
58 LTT_CHANNEL_SWAP_STATE
,
59 LTT_CHANNEL_SYSCALL_STATE
,
60 LTT_CHANNEL_TASK_STATE
,
62 LTT_CHANNEL_KPROBE_STATE
,
66 LTT_CHANNEL_USERSPACE
,
72 LTT_EVENT_SYSCALL_ENTRY
,
73 LTT_EVENT_SYSCALL_EXIT
,
74 LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
,
75 LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
,
76 LTT_EVENT_PAGE_FAULT_ENTRY
,
77 LTT_EVENT_PAGE_FAULT_EXIT
,
82 LTT_EVENT_SOFT_IRQ_RAISE
,
83 LTT_EVENT_SOFT_IRQ_ENTRY
,
84 LTT_EVENT_SOFT_IRQ_EXIT
,
85 LTT_EVENT_SCHED_SCHEDULE
,
86 LTT_EVENT_SCHED_TRY_WAKEUP
,
87 LTT_EVENT_PROCESS_FORK
,
88 LTT_EVENT_KTHREAD_CREATE
,
89 LTT_EVENT_PROCESS_EXIT
,
90 LTT_EVENT_PROCESS_FREE
,
92 LTT_EVENT_PROCESS_STATE
,
93 LTT_EVENT_STATEDUMP_END
,
94 LTT_EVENT_FUNCTION_ENTRY
,
95 LTT_EVENT_FUNCTION_EXIT
,
96 LTT_EVENT_THREAD_BRAND
,
97 LTT_EVENT_REQUEST_ISSUE
,
98 LTT_EVENT_REQUEST_COMPLETE
,
99 LTT_EVENT_LIST_INTERRUPT
,
100 LTT_EVENT_SYS_CALL_TABLE
,
101 LTT_EVENT_SOFTIRQ_VEC
,
102 LTT_EVENT_KPROBE_TABLE
,
106 LTT_EVENT_POLL_EVENT
;
111 LTT_FIELD_SYSCALL_ID
,
114 LTT_FIELD_SOFT_IRQ_ID
,
117 LTT_FIELD_PREV_STATE
,
118 LTT_FIELD_PARENT_PID
,
122 LTT_FIELD_CHILD_TGID
,
144 LTTV_STATE_MODE_UNKNOWN
,
145 LTTV_STATE_USER_MODE
,
146 LTTV_STATE_MAYBE_USER_MODE
,
148 LTTV_STATE_MAYBE_SYSCALL
,
150 LTTV_STATE_MAYBE_TRAP
,
155 LTTV_STATE_SUBMODE_UNKNOWN
,
156 LTTV_STATE_SUBMODE_NONE
;
160 LTTV_STATE_WAIT_FORK
,
169 LTTV_STATE_UNBRANDED
;
172 LTTV_STATE_USER_THREAD
,
173 LTTV_STATE_KERNEL_THREAD
;
191 LTTV_BDEV_BUSY_READING
,
192 LTTV_BDEV_BUSY_WRITING
;
195 LTTV_STATE_TRACEFILES
,
196 LTTV_STATE_PROCESSES
,
198 LTTV_STATE_RUNNING_PROCESS
,
200 LTTV_STATE_SAVED_STATES
,
201 LTTV_STATE_SAVED_STATES_TIME
,
204 LTTV_STATE_NAME_TABLES
,
205 LTTV_STATE_TRACE_STATE_USE_COUNT
,
206 LTTV_STATE_RESOURCE_CPUS
,
207 LTTV_STATE_RESOURCE_CPUS_COUNT
,
208 LTTV_STATE_RESOURCE_IRQS
,
209 LTTV_STATE_RESOURCE_SOFT_IRQS
,
210 LTTV_STATE_RESOURCE_TRAPS
,
211 LTTV_STATE_RESOURCE_BLKDEVS
;
213 static void create_max_time(LttvTraceState
*tcs
);
215 static void get_max_time(LttvTraceState
*tcs
);
217 static void free_max_time(LttvTraceState
*tcs
);
219 static void create_name_tables(LttvTraceState
*tcs
);
221 static void get_name_tables(LttvTraceState
*tcs
);
223 static void free_name_tables(LttvTraceState
*tcs
);
225 static void free_saved_state(LttvTraceState
*tcs
);
227 static void lttv_state_free_process_table(GHashTable
*processes
);
229 static void lttv_trace_states_read_raw(LttvTraceState
*tcs
, FILE *fp
,
230 GPtrArray
*quarktable
);
232 /* Resource function prototypes */
233 static LttvBdevState
*get_hashed_bdevstate(LttvTraceState
*ts
, guint32 devcode
);
234 static LttvBdevState
*bdevstate_new(void);
235 static void bdevstate_free(LttvBdevState
*);
236 static void bdevstate_free_cb(gpointer key
, gpointer value
, gpointer user_data
);
237 static LttvBdevState
*bdevstate_copy(LttvBdevState
*bds
);
240 #if (__WORDSIZE == 32)
241 guint
guint64_hash(gconstpointer key
)
243 guint64 ukey
= *(const guint64
*)key
;
245 return (guint
)ukey
^ (guint
)(ukey
>> 32);
248 gboolean
guint64_equal(gconstpointer a
, gconstpointer b
)
250 guint64 ua
= *(const guint64
*)a
;
251 guint64 ub
= *(const guint64
*)b
;
257 void lttv_state_save(LttvTraceState
*self
, LttvAttribute
*container
)
259 LTTV_TRACE_STATE_GET_CLASS(self
)->state_save(self
, container
);
263 void lttv_state_restore(LttvTraceState
*self
, LttvAttribute
*container
)
265 LTTV_TRACE_STATE_GET_CLASS(self
)->state_restore(self
, container
);
269 void lttv_state_state_saved_free(LttvTraceState
*self
,
270 LttvAttribute
*container
)
272 LTTV_TRACE_STATE_GET_CLASS(self
)->state_saved_free(self
, container
);
276 guint
process_hash(gconstpointer key
)
278 guint pid
= ((const LttvProcessState
*)key
)->pid
;
279 return (pid
>>8 ^ pid
>>4 ^ pid
>>2 ^ pid
) ;
283 /* If the hash table hash function is well distributed,
284 * the process_equal should compare different pid */
285 gboolean
process_equal(gconstpointer a
, gconstpointer b
)
287 const LttvProcessState
*process_a
, *process_b
;
290 process_a
= (const LttvProcessState
*)a
;
291 process_b
= (const LttvProcessState
*)b
;
293 if(likely(process_a
->pid
!= process_b
->pid
)) ret
= FALSE
;
294 else if(likely(process_a
->pid
== 0 &&
295 process_a
->cpu
!= process_b
->cpu
)) ret
= FALSE
;
300 static void delete_usertrace(gpointer key
, gpointer value
, gpointer user_data
)
302 g_tree_destroy((GTree
*)value
);
305 static void lttv_state_free_usertraces(GHashTable
*usertraces
)
307 g_hash_table_foreach(usertraces
, delete_usertrace
, NULL
);
308 g_hash_table_destroy(usertraces
);
311 gboolean
rettrue(gpointer key
, gpointer value
, gpointer user_data
)
316 static guint
check_expand(nb
, id
)
321 return max(id
+ 1, nb
* 2);
324 static void expand_name_table(LttvTraceState
*ts
, GQuark
**table
,
325 guint nb
, guint new_nb
)
327 /* Expand an incomplete table */
328 GQuark
*old_table
= *table
;
329 *table
= g_new(GQuark
, new_nb
);
330 memcpy(*table
, old_table
, nb
* sizeof(GQuark
));
334 static void fill_name_table(LttvTraceState
*ts
, GQuark
*table
, guint nb
,
335 guint new_nb
, const char *def_string
)
338 GString
*fe_name
= g_string_new("");
339 for(i
= nb
; i
< new_nb
; i
++) {
340 g_string_printf(fe_name
, "%s %d", def_string
, i
);
341 table
[i
] = g_quark_from_string(fe_name
->str
);
343 g_string_free(fe_name
, TRUE
);
346 static void expand_syscall_table(LttvTraceState
*ts
, int id
)
348 LttvNameTables
*nt
= ts
->name_tables
;
351 new_nb
= check_expand(nt
->nb_syscalls
, id
);
352 if(likely(new_nb
== nt
->nb_syscalls
))
354 expand_name_table(ts
, &nt
->syscall_names
, nt
->nb_syscalls
, new_nb
);
355 fill_name_table(ts
, nt
->syscall_names
, nt
->nb_syscalls
, new_nb
, "syscall");
356 /* Update the table size */
357 nt
->nb_syscalls
= new_nb
;
360 static void expand_kprobe_table(LttvTraceState
*ts
, guint64 ip
, char *symbol
)
362 LttvNameTables
*nt
= ts
->name_tables
;
363 #if (__WORDSIZE == 32)
364 guint64
*ip_ptr
= g_new(guint64
, 1);
365 g_hash_table_insert(nt
->kprobe_hash
, ip_ptr
,
366 (gpointer
)(glong
)g_quark_from_string(symbol
));
368 g_hash_table_insert(nt
->kprobe_hash
, (gpointer
)ip
,
369 (gpointer
)(glong
)g_quark_from_string(symbol
));
373 static void expand_trap_table(LttvTraceState
*ts
, int id
)
375 LttvNameTables
*nt
= ts
->name_tables
;
376 LttvTrapState
*old_table
;
379 new_nb
= check_expand(nt
->nb_traps
, id
);
380 if(likely(new_nb
== nt
->nb_traps
))
383 expand_name_table(ts
, &nt
->trap_names
, nt
->nb_traps
, new_nb
);
384 fill_name_table(ts
, nt
->trap_names
, nt
->nb_traps
, new_nb
, "trap");
386 old_table
= ts
->trap_states
;
387 ts
->trap_states
= g_new(LttvTrapState
, new_nb
);
388 memcpy(ts
->trap_states
, old_table
, nt
->nb_traps
* sizeof(LttvTrapState
));
390 for(i
= nt
->nb_traps
; i
< new_nb
; i
++)
391 ts
->trap_states
[i
].running
= 0;
393 /* Update the table size */
394 nt
->nb_traps
= new_nb
;
397 static void expand_irq_table(LttvTraceState
*ts
, int id
)
399 LttvNameTables
*nt
= ts
->name_tables
;
400 LttvIRQState
*old_table
;
403 new_nb
= check_expand(nt
->nb_irqs
, id
);
404 if(likely(new_nb
== nt
->nb_irqs
))
407 expand_name_table(ts
, &nt
->irq_names
, nt
->nb_irqs
, new_nb
);
408 fill_name_table(ts
, nt
->irq_names
, nt
->nb_irqs
, new_nb
, "irq");
410 old_table
= ts
->irq_states
;
411 ts
->irq_states
= g_new(LttvIRQState
, new_nb
);
412 memcpy(ts
->irq_states
, old_table
, nt
->nb_irqs
* sizeof(LttvIRQState
));
414 for(i
= nt
->nb_irqs
; i
< new_nb
; i
++)
415 ts
->irq_states
[i
].mode_stack
=
416 g_array_new(FALSE
, FALSE
, sizeof(LttvIRQMode
));
418 /* Update the table size */
419 nt
->nb_irqs
= new_nb
;
422 static void expand_soft_irq_table(LttvTraceState
*ts
, int id
)
424 LttvNameTables
*nt
= ts
->name_tables
;
425 LttvSoftIRQState
*old_table
;
428 new_nb
= check_expand(nt
->nb_soft_irqs
, id
);
429 if(likely(new_nb
== nt
->nb_soft_irqs
))
432 expand_name_table(ts
, &nt
->soft_irq_names
, nt
->nb_soft_irqs
, new_nb
);
433 fill_name_table(ts
, nt
->soft_irq_names
, nt
->nb_soft_irqs
, new_nb
, "softirq");
435 old_table
= ts
->soft_irq_states
;
436 ts
->soft_irq_states
= g_new(LttvSoftIRQState
, new_nb
);
437 memcpy(ts
->soft_irq_states
, old_table
,
438 nt
->nb_soft_irqs
* sizeof(LttvSoftIRQState
));
440 for(i
= nt
->nb_soft_irqs
; i
< new_nb
; i
++)
441 ts
->soft_irq_states
[i
].running
= 0;
443 /* Update the table size */
444 nt
->nb_soft_irqs
= new_nb
;
447 static void restore_init_state(LttvTraceState
*self
)
449 guint i
, nb_cpus
, nb_irqs
, nb_soft_irqs
, nb_traps
;
451 //LttvTracefileState *tfcs;
453 LttTime start_time
, end_time
;
455 /* Free the process tables */
456 if(self
->processes
!= NULL
) lttv_state_free_process_table(self
->processes
);
457 if(self
->usertraces
!= NULL
) lttv_state_free_usertraces(self
->usertraces
);
458 self
->processes
= g_hash_table_new(process_hash
, process_equal
);
459 self
->usertraces
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
462 /* Seek time to beginning */
463 // Mathieu : fix : don't seek traceset here : causes inconsistency in seek
464 // closest. It's the tracecontext job to seek the trace to the beginning
465 // anyway : the init state might be used at the middle of the trace as well...
466 //g_tree_destroy(self->parent.ts_context->pqueue);
467 //self->parent.ts_context->pqueue = g_tree_new(compare_tracefile);
469 ltt_trace_time_span_get(self
->parent
.t
, &start_time
, &end_time
);
471 //lttv_process_trace_seek_time(&self->parent, ltt_time_zero);
473 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
474 nb_irqs
= self
->name_tables
->nb_irqs
;
475 nb_soft_irqs
= self
->name_tables
->nb_soft_irqs
;
476 nb_traps
= self
->name_tables
->nb_traps
;
478 /* Put the per cpu running_process to beginning state : process 0. */
479 for(i
=0; i
< nb_cpus
; i
++) {
480 LttvExecutionState
*es
;
481 self
->running_process
[i
] = lttv_state_create_process(self
, NULL
, i
, 0, 0,
482 LTTV_STATE_UNNAMED
, &start_time
);
483 /* We are not sure is it's a kernel thread or normal thread, put the
484 * bottom stack state to unknown */
485 self
->running_process
[i
]->execution_stack
=
486 g_array_set_size(self
->running_process
[i
]->execution_stack
, 1);
487 es
= self
->running_process
[i
]->state
=
488 &g_array_index(self
->running_process
[i
]->execution_stack
,
489 LttvExecutionState
, 0);
490 es
->t
= LTTV_STATE_MODE_UNKNOWN
;
491 es
->s
= LTTV_STATE_UNNAMED
;
493 //self->running_process[i]->state->s = LTTV_STATE_RUN;
494 self
->running_process
[i
]->cpu
= i
;
496 /* reset cpu states */
497 if(self
->cpu_states
[i
].mode_stack
->len
> 0) {
498 g_array_remove_range(self
->cpu_states
[i
].mode_stack
, 0,
499 self
->cpu_states
[i
].mode_stack
->len
);
500 if(self
->cpu_states
[i
].irq_stack
->len
)
501 g_array_remove_range(self
->cpu_states
[i
].irq_stack
, 0,
502 self
->cpu_states
[i
].irq_stack
->len
);
503 if(self
->cpu_states
[i
].softirq_stack
->len
)
504 g_array_remove_range(self
->cpu_states
[i
].softirq_stack
, 0,
505 self
->cpu_states
[i
].softirq_stack
->len
);
506 if(self
->cpu_states
[i
].trap_stack
->len
)
507 g_array_remove_range(self
->cpu_states
[i
].trap_stack
, 0,
508 self
->cpu_states
[i
].trap_stack
->len
);
512 /* reset irq states */
513 for(i
=0; i
<nb_irqs
; i
++) {
514 if(self
->irq_states
[i
].mode_stack
->len
> 0)
515 g_array_remove_range(self
->irq_states
[i
].mode_stack
, 0,
516 self
->irq_states
[i
].mode_stack
->len
);
519 /* reset softirq states */
520 for(i
=0; i
<nb_soft_irqs
; i
++) {
521 self
->soft_irq_states
[i
].pending
= 0;
522 self
->soft_irq_states
[i
].running
= 0;
525 /* reset trap states */
526 for(i
=0; i
<nb_traps
; i
++) {
527 self
->trap_states
[i
].running
= 0;
530 /* reset bdev states */
531 g_hash_table_foreach(self
->bdev_states
, bdevstate_free_cb
, NULL
);
532 //g_hash_table_steal_all(self->bdev_states);
533 g_hash_table_foreach_steal(self
->bdev_states
, rettrue
, NULL
);
536 nb_tracefile
= self
->parent
.tracefiles
->len
;
538 for(i
= 0 ; i
< nb_tracefile
; i
++) {
540 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
541 LttvTracefileContext
*, i
));
542 ltt_trace_time_span_get(self
->parent
.t
, &tfcs
->parent
.timestamp
, NULL
);
543 // tfcs->saved_position = 0;
544 tfcs
->process
= lttv_state_create_process(tfcs
, NULL
,0);
545 tfcs
->process
->state
->s
= LTTV_STATE_RUN
;
546 tfcs
->process
->last_cpu
= tfcs
->cpu_name
;
547 tfcs
->process
->last_cpu_index
= ltt_tracefile_num(((LttvTracefileContext
*)tfcs
)->tf
);
552 //static LttTime time_zero = {0,0};
554 static gint
compare_usertraces(gconstpointer a
, gconstpointer b
,
557 const LttTime
*t1
= (const LttTime
*)a
;
558 const LttTime
*t2
= (const LttTime
*)b
;
560 return ltt_time_compare(*t1
, *t2
);
563 static void free_usertrace_key(gpointer data
)
568 #define MAX_STRING_LEN 4096
570 static void state_load_saved_states(LttvTraceState
*tcs
)
573 GPtrArray
*quarktable
;
574 const char *trace_path
;
578 tcs
->has_precomputed_states
= FALSE
;
582 gchar buf
[MAX_STRING_LEN
];
586 trace_path
= g_quark_to_string(ltt_trace_name(tcs
->parent
.t
));
587 strncpy(path
, trace_path
, PATH_MAX
-1);
588 count
= strnlen(trace_path
, PATH_MAX
-1);
589 // quarktable : open, test
590 strncat(path
, "/precomputed/quarktable", PATH_MAX
-count
-1);
591 fp
= fopen(path
, "r");
593 quarktable
= g_ptr_array_sized_new(4096);
595 /* Index 0 is null */
597 if(hdr
== EOF
) return;
598 g_assert(hdr
== HDR_QUARKS
);
602 if(hdr
== EOF
) break;
603 g_assert(hdr
== HDR_QUARK
);
604 g_ptr_array_set_size(quarktable
, q
+1);
607 res
= fread(&buf
[i
], sizeof(gchar
), 1, fp
);
609 if(buf
[i
] == '\0' || feof(fp
)) break;
612 len
= strnlen(buf
, MAX_STRING_LEN
-1);
613 g_ptr_array_index (quarktable
, q
) = g_new(gchar
, len
+1);
614 strncpy(g_ptr_array_index (quarktable
, q
), buf
, len
+1);
620 // saved_states : open, test
621 strncpy(path
, trace_path
, PATH_MAX
-1);
622 count
= strnlen(trace_path
, PATH_MAX
-1);
623 strncat(path
, "/precomputed/states", PATH_MAX
-count
-1);
624 fp
= fopen(path
, "r");
628 if(hdr
!= HDR_TRACE
) goto end
;
630 lttv_trace_states_read_raw(tcs
, fp
, quarktable
);
632 tcs
->has_precomputed_states
= TRUE
;
637 /* Free the quarktable */
638 for(i
=0; i
<quarktable
->len
; i
++) {
639 string
= g_ptr_array_index (quarktable
, i
);
642 g_ptr_array_free(quarktable
, TRUE
);
646 static void init(LttvTracesetState
*self
, LttvTraceset
*ts
)
648 guint i
, j
, nb_trace
, nb_tracefile
, nb_cpu
;
651 LttvTraceContext
*tc
;
655 LttvTracefileState
*tfcs
;
657 LttvAttributeValue v
;
659 LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
660 init((LttvTracesetContext
*)self
, ts
);
662 nb_trace
= lttv_traceset_number(ts
);
663 for(i
= 0 ; i
< nb_trace
; i
++) {
664 tc
= self
->parent
.traces
[i
];
665 tcs
= LTTV_TRACE_STATE(tc
);
666 tcs
->save_interval
= LTTV_STATE_SAVE_INTERVAL
;
667 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_TRACE_STATE_USE_COUNT
,
671 if(*(v
.v_uint
) == 1) {
672 create_name_tables(tcs
);
673 create_max_time(tcs
);
675 get_name_tables(tcs
);
678 nb_tracefile
= tc
->tracefiles
->len
;
679 nb_cpu
= ltt_trace_get_num_cpu(tc
->t
);
680 nb_irq
= tcs
->name_tables
->nb_irqs
;
681 tcs
->processes
= NULL
;
682 tcs
->usertraces
= NULL
;
683 tcs
->running_process
= g_new(LttvProcessState
*, nb_cpu
);
685 /* init cpu resource stuff */
686 tcs
->cpu_states
= g_new(LttvCPUState
, nb_cpu
);
687 for(j
= 0; j
<nb_cpu
; j
++) {
688 tcs
->cpu_states
[j
].mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(LttvCPUMode
));
689 tcs
->cpu_states
[j
].irq_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
690 tcs
->cpu_states
[j
].softirq_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
691 tcs
->cpu_states
[j
].trap_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
692 g_assert(tcs
->cpu_states
[j
].mode_stack
!= NULL
);
695 /* init irq resource stuff */
696 tcs
->irq_states
= g_new(LttvIRQState
, nb_irq
);
697 for(j
= 0; j
<nb_irq
; j
++) {
698 tcs
->irq_states
[j
].mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(LttvIRQMode
));
699 g_assert(tcs
->irq_states
[j
].mode_stack
!= NULL
);
702 /* init soft irq stuff */
703 /* the kernel has a statically fixed max of 32 softirqs */
704 tcs
->soft_irq_states
= g_new(LttvSoftIRQState
, tcs
->name_tables
->nb_soft_irqs
);
706 /* init trap stuff */
707 tcs
->trap_states
= g_new(LttvTrapState
, tcs
->name_tables
->nb_traps
);
709 /* init bdev resource stuff */
710 tcs
->bdev_states
= g_hash_table_new(g_int_hash
, g_int_equal
);
712 restore_init_state(tcs
);
713 for(j
= 0 ; j
< nb_tracefile
; j
++) {
715 LTTV_TRACEFILE_STATE(g_array_index(tc
->tracefiles
,
716 LttvTracefileContext
*, j
));
717 tfcs
->tracefile_name
= ltt_tracefile_name(tfcs
->parent
.tf
);
718 tfcs
->cpu
= ltt_tracefile_cpu(tfcs
->parent
.tf
);
719 tfcs
->cpu_state
= &(tcs
->cpu_states
[tfcs
->cpu
]);
720 if(ltt_tracefile_tid(tfcs
->parent
.tf
) != 0) {
721 /* It's a Usertrace */
722 guint tid
= ltt_tracefile_tid(tfcs
->parent
.tf
);
723 GTree
*usertrace_tree
= (GTree
*)g_hash_table_lookup(tcs
->usertraces
,
724 GUINT_TO_POINTER(tid
));
725 if(!usertrace_tree
) {
726 usertrace_tree
= g_tree_new_full(compare_usertraces
,
727 NULL
, free_usertrace_key
, NULL
);
728 g_hash_table_insert(tcs
->usertraces
,
729 GUINT_TO_POINTER(tid
), usertrace_tree
);
731 LttTime
*timestamp
= g_new(LttTime
, 1);
732 *timestamp
= ltt_interpolate_time_from_tsc(tfcs
->parent
.tf
,
733 ltt_tracefile_creation(tfcs
->parent
.tf
));
734 g_tree_insert(usertrace_tree
, timestamp
, tfcs
);
738 /* See if the trace has saved states */
739 state_load_saved_states(tcs
);
743 static void fini(LttvTracesetState
*self
)
749 //LttvTracefileState *tfcs;
751 LttvAttributeValue v
;
753 nb_trace
= lttv_traceset_number(LTTV_TRACESET_CONTEXT(self
)->ts
);
754 for(i
= 0 ; i
< nb_trace
; i
++) {
755 tcs
= (LttvTraceState
*)(LTTV_TRACESET_CONTEXT(self
)->traces
[i
]);
756 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_TRACE_STATE_USE_COUNT
,
759 g_assert(*(v
.v_uint
) != 0);
762 if(*(v
.v_uint
) == 0) {
763 free_name_tables(tcs
);
765 free_saved_state(tcs
);
767 g_free(tcs
->running_process
);
768 tcs
->running_process
= NULL
;
769 lttv_state_free_process_table(tcs
->processes
);
770 lttv_state_free_usertraces(tcs
->usertraces
);
771 tcs
->processes
= NULL
;
772 tcs
->usertraces
= NULL
;
774 LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
775 fini((LttvTracesetContext
*)self
);
779 static LttvTracesetContext
*new_traceset_context(LttvTracesetContext
*self
)
781 return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE
, NULL
));
785 static LttvTraceContext
*new_trace_context(LttvTracesetContext
*self
)
787 return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE
, NULL
));
791 static LttvTracefileContext
*new_tracefile_context(LttvTracesetContext
*self
)
793 return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE
, NULL
));
797 /* Write the process state of the trace */
799 static void write_process_state(gpointer key
, gpointer value
,
802 LttvProcessState
*process
;
804 LttvExecutionState
*es
;
806 FILE *fp
= (FILE *)user_data
;
811 process
= (LttvProcessState
*)value
;
812 fprintf(fp
," <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\" FREE_EVENTS=\"%u\">\n",
813 process
, process
->pid
, process
->tgid
, process
->ppid
,
814 g_quark_to_string(process
->type
),
815 process
->creation_time
.tv_sec
,
816 process
->creation_time
.tv_nsec
,
817 process
->insertion_time
.tv_sec
,
818 process
->insertion_time
.tv_nsec
,
819 g_quark_to_string(process
->name
),
820 g_quark_to_string(process
->brand
),
821 process
->cpu
, process
->free_events
);
823 for(i
= 0 ; i
< process
->execution_stack
->len
; i
++) {
824 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, i
);
825 fprintf(fp
, " <ES MODE=\"%s\" SUBMODE=\"%s\" ENTRY_S=%lu ENTRY_NS=%lu",
826 g_quark_to_string(es
->t
), g_quark_to_string(es
->n
),
827 es
->entry
.tv_sec
, es
->entry
.tv_nsec
);
828 fprintf(fp
, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n",
829 es
->change
.tv_sec
, es
->change
.tv_nsec
, g_quark_to_string(es
->s
));
832 for(i
= 0 ; i
< process
->user_stack
->len
; i
++) {
833 address
= g_array_index(process
->user_stack
, guint64
, i
);
834 fprintf(fp
, " <USER_STACK ADDRESS=\"%" PRIu64
"\"/>\n", address
);
837 if(process
->usertrace
) {
838 fprintf(fp
, " <USERTRACE NAME=\"%s\" CPU=%u\n/>",
839 g_quark_to_string(process
->usertrace
->tracefile_name
),
840 process
->usertrace
->cpu
);
844 fprintf(fp
, " </PROCESS>\n");
848 void lttv_state_write(LttvTraceState
*self
, LttTime t
, FILE *fp
)
850 guint i
, nb_tracefile
, nb_block
, offset
;
853 LttvTracefileState
*tfcs
;
857 LttEventPosition
*ep
;
861 ep
= ltt_event_position_new();
863 fprintf(fp
,"<PROCESS_STATE TIME_S=%lu TIME_NS=%lu>\n", t
.tv_sec
, t
.tv_nsec
);
865 g_hash_table_foreach(self
->processes
, write_process_state
, fp
);
867 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
868 for(i
=0;i
<nb_cpus
;i
++) {
869 fprintf(fp
," <CPU NUM=%u RUNNING_PROCESS=%u>\n",
870 i
, self
->running_process
[i
]->pid
);
873 nb_tracefile
= self
->parent
.tracefiles
->len
;
875 for(i
= 0 ; i
< nb_tracefile
; i
++) {
877 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
878 LttvTracefileContext
*, i
));
879 fprintf(fp
, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu",
880 tfcs
->parent
.timestamp
.tv_sec
,
881 tfcs
->parent
.timestamp
.tv_nsec
);
882 LttEvent
*e
= ltt_tracefile_get_event(tfcs
->parent
.tf
);
883 if(e
== NULL
) fprintf(fp
,"/>\n");
885 ltt_event_position(e
, ep
);
886 ltt_event_position_get(ep
, &tf
, &nb_block
, &offset
, &tsc
);
887 fprintf(fp
, " BLOCK=%u OFFSET=%u TSC=%" PRIu64
"/>\n", nb_block
, offset
,
892 fprintf(fp
,"</PROCESS_STATE>\n");
896 static void write_process_state_raw(gpointer key
, gpointer value
,
899 LttvProcessState
*process
;
901 LttvExecutionState
*es
;
903 FILE *fp
= (FILE *)user_data
;
908 process
= (LttvProcessState
*)value
;
909 fputc(HDR_PROCESS
, fp
);
910 //fwrite(&header, sizeof(header), 1, fp);
911 //fprintf(fp, "%s", g_quark_to_string(process->type));
913 fwrite(&process
->type
, sizeof(process
->type
), 1, fp
);
914 //fprintf(fp, "%s", g_quark_to_string(process->name));
916 fwrite(&process
->name
, sizeof(process
->name
), 1, fp
);
917 //fprintf(fp, "%s", g_quark_to_string(process->brand));
919 fwrite(&process
->brand
, sizeof(process
->brand
), 1, fp
);
920 fwrite(&process
->pid
, sizeof(process
->pid
), 1, fp
);
921 fwrite(&process
->free_events
, sizeof(process
->free_events
), 1, fp
);
922 fwrite(&process
->tgid
, sizeof(process
->tgid
), 1, fp
);
923 fwrite(&process
->ppid
, sizeof(process
->ppid
), 1, fp
);
924 fwrite(&process
->cpu
, sizeof(process
->cpu
), 1, fp
);
925 fwrite(&process
->creation_time
, sizeof(process
->creation_time
), 1, fp
);
926 fwrite(&process
->insertion_time
, sizeof(process
->insertion_time
), 1, fp
);
929 fprintf(fp
," <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",
930 process
, process
->pid
, process
->tgid
, process
->ppid
,
931 g_quark_to_string(process
->type
),
932 process
->creation_time
.tv_sec
,
933 process
->creation_time
.tv_nsec
,
934 process
->insertion_time
.tv_sec
,
935 process
->insertion_time
.tv_nsec
,
936 g_quark_to_string(process
->name
),
937 g_quark_to_string(process
->brand
),
941 for(i
= 0 ; i
< process
->execution_stack
->len
; i
++) {
942 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, i
);
945 //fprintf(fp, "%s", g_quark_to_string(es->t));
947 fwrite(&es
->t
, sizeof(es
->t
), 1, fp
);
948 //fprintf(fp, "%s", g_quark_to_string(es->n));
950 fwrite(&es
->n
, sizeof(es
->n
), 1, fp
);
951 //fprintf(fp, "%s", g_quark_to_string(es->s));
953 fwrite(&es
->s
, sizeof(es
->s
), 1, fp
);
954 fwrite(&es
->entry
, sizeof(es
->entry
), 1, fp
);
955 fwrite(&es
->change
, sizeof(es
->change
), 1, fp
);
956 fwrite(&es
->cum_cpu_time
, sizeof(es
->cum_cpu_time
), 1, fp
);
958 fprintf(fp
, " <ES MODE=\"%s\" SUBMODE=\"%s\" ENTRY_S=%lu ENTRY_NS=%lu",
959 g_quark_to_string(es
->t
), g_quark_to_string(es
->n
),
960 es
->entry
.tv_sec
, es
->entry
.tv_nsec
);
961 fprintf(fp
, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n",
962 es
->change
.tv_sec
, es
->change
.tv_nsec
, g_quark_to_string(es
->s
));
966 for(i
= 0 ; i
< process
->user_stack
->len
; i
++) {
967 address
= g_array_index(process
->user_stack
, guint64
, i
);
968 fputc(HDR_USER_STACK
, fp
);
969 fwrite(&address
, sizeof(address
), 1, fp
);
971 fprintf(fp
, " <USER_STACK ADDRESS=\"%llu\"/>\n", address
);
975 if(process
->usertrace
) {
976 fputc(HDR_USERTRACE
, fp
);
977 //fprintf(fp, "%s", g_quark_to_string(process->usertrace->tracefile_name));
979 fwrite(&process
->usertrace
->tracefile_name
,
980 sizeof(process
->usertrace
->tracefile_name
), 1, fp
);
981 fwrite(&process
->usertrace
->cpu
, sizeof(process
->usertrace
->cpu
), 1, fp
);
983 fprintf(fp
, " <USERTRACE NAME=\"%s\" CPU=%u\n/>",
984 g_quark_to_string(process
->usertrace
->tracefile_name
),
985 process
->usertrace
->cpu
);
992 void lttv_state_write_raw(LttvTraceState
*self
, LttTime t
, FILE *fp
)
994 guint i
, nb_tracefile
, nb_block
, offset
;
997 LttvTracefileState
*tfcs
;
1001 LttEventPosition
*ep
;
1005 ep
= ltt_event_position_new();
1007 //fprintf(fp,"<PROCESS_STATE TIME_S=%lu TIME_NS=%lu>\n", t.tv_sec, t.tv_nsec);
1008 fputc(HDR_PROCESS_STATE
, fp
);
1009 fwrite(&t
, sizeof(t
), 1, fp
);
1011 g_hash_table_foreach(self
->processes
, write_process_state_raw
, fp
);
1013 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
1014 for(i
=0;i
<nb_cpus
;i
++) {
1016 fwrite(&i
, sizeof(i
), 1, fp
); /* cpu number */
1017 fwrite(&self
->running_process
[i
]->pid
,
1018 sizeof(self
->running_process
[i
]->pid
), 1, fp
);
1019 //fprintf(fp," <CPU NUM=%u RUNNING_PROCESS=%u>\n",
1020 // i, self->running_process[i]->pid);
1023 nb_tracefile
= self
->parent
.tracefiles
->len
;
1025 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1027 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
1028 LttvTracefileContext
*, i
));
1029 // fprintf(fp, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu",
1030 // tfcs->parent.timestamp.tv_sec,
1031 // tfcs->parent.timestamp.tv_nsec);
1032 fputc(HDR_TRACEFILE
, fp
);
1033 fwrite(&tfcs
->parent
.timestamp
, sizeof(tfcs
->parent
.timestamp
), 1, fp
);
1034 /* Note : if timestamp if LTT_TIME_INFINITE, there will be no
1035 * position following : end of trace */
1036 LttEvent
*e
= ltt_tracefile_get_event(tfcs
->parent
.tf
);
1038 ltt_event_position(e
, ep
);
1039 ltt_event_position_get(ep
, &tf
, &nb_block
, &offset
, &tsc
);
1040 //fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset,
1042 fwrite(&nb_block
, sizeof(nb_block
), 1, fp
);
1043 fwrite(&offset
, sizeof(offset
), 1, fp
);
1044 fwrite(&tsc
, sizeof(tsc
), 1, fp
);
1051 /* Read process state from a file */
1053 /* Called because a HDR_PROCESS was found */
1054 static void read_process_state_raw(LttvTraceState
*self
, FILE *fp
,
1055 GPtrArray
*quarktable
)
1057 LttvExecutionState
*es
;
1058 LttvProcessState
*process
, *parent_process
;
1059 LttvProcessState tmp
;
1065 res
= fread(&tmp
.type
, sizeof(tmp
.type
), 1, fp
);
1066 res
+= fread(&tmp
.name
, sizeof(tmp
.name
), 1, fp
);
1067 res
+= fread(&tmp
.brand
, sizeof(tmp
.brand
), 1, fp
);
1068 res
+= fread(&tmp
.pid
, sizeof(tmp
.pid
), 1, fp
);
1069 res
+= fread(&tmp
.free_events
, sizeof(tmp
.free_events
), 1, fp
);
1070 res
+= fread(&tmp
.tgid
, sizeof(tmp
.tgid
), 1, fp
);
1071 res
+= fread(&tmp
.ppid
, sizeof(tmp
.ppid
), 1, fp
);
1072 res
+= fread(&tmp
.cpu
, sizeof(tmp
.cpu
), 1, fp
);
1073 res
+= fread(&tmp
.creation_time
, sizeof(tmp
.creation_time
), 1, fp
);
1074 res
+= fread(&tmp
.insertion_time
, sizeof(tmp
.insertion_time
), 1, fp
);
1075 g_assert(res
== 10);
1078 process
= lttv_state_find_process(self
, tmp
.cpu
, tmp
.pid
);
1080 /* We must link to the parent */
1081 parent_process
= lttv_state_find_process_or_create(self
, ANY_CPU
, tmp
.ppid
,
1083 process
= lttv_state_find_process(self
, ANY_CPU
, tmp
.pid
);
1084 if(process
== NULL
) {
1085 process
= lttv_state_create_process(self
, parent_process
, tmp
.cpu
,
1087 g_quark_from_string((gchar
*)g_ptr_array_index(quarktable
, tmp
.name
)),
1088 &tmp
.creation_time
);
1091 process
->insertion_time
= tmp
.insertion_time
;
1092 process
->creation_time
= tmp
.creation_time
;
1093 process
->type
= g_quark_from_string(
1094 (gchar
*)g_ptr_array_index(quarktable
, tmp
.type
));
1095 process
->tgid
= tmp
.tgid
;
1096 process
->ppid
= tmp
.ppid
;
1097 process
->brand
= g_quark_from_string(
1098 (gchar
*)g_ptr_array_index(quarktable
, tmp
.brand
));
1100 g_quark_from_string((gchar
*)g_ptr_array_index(quarktable
, tmp
.name
));
1101 process
->free_events
= tmp
.free_events
;
1104 if(feof(fp
) || ferror(fp
)) goto end_loop
;
1106 gint hdr
= fgetc(fp
);
1107 if(hdr
== EOF
) goto end_loop
;
1111 process
->execution_stack
=
1112 g_array_set_size(process
->execution_stack
,
1113 process
->execution_stack
->len
+ 1);
1114 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
,
1115 process
->execution_stack
->len
-1);
1116 process
->state
= es
;
1118 res
= fread(&es
->t
, sizeof(es
->t
), 1, fp
);
1120 es
->t
= g_quark_from_string(
1121 (gchar
*)g_ptr_array_index(quarktable
, es
->t
));
1122 res
= fread(&es
->n
, sizeof(es
->n
), 1, fp
);
1124 es
->n
= g_quark_from_string(
1125 (gchar
*)g_ptr_array_index(quarktable
, es
->n
));
1126 res
= fread(&es
->s
, sizeof(es
->s
), 1, fp
);
1128 es
->s
= g_quark_from_string(
1129 (gchar
*)g_ptr_array_index(quarktable
, es
->s
));
1130 res
= fread(&es
->entry
, sizeof(es
->entry
), 1, fp
);
1131 res
+= fread(&es
->change
, sizeof(es
->change
), 1, fp
);
1132 res
+= fread(&es
->cum_cpu_time
, sizeof(es
->cum_cpu_time
), 1, fp
);
1136 case HDR_USER_STACK
:
1137 process
->user_stack
= g_array_set_size(process
->user_stack
,
1138 process
->user_stack
->len
+ 1);
1139 address
= &g_array_index(process
->user_stack
, guint64
,
1140 process
->user_stack
->len
-1);
1141 res
= fread(address
, sizeof(address
), 1, fp
);
1143 process
->current_function
= *address
;
1147 res
= fread(&tmpq
, sizeof(tmpq
), 1, fp
);
1148 res
+= fread(&process
->usertrace
->cpu
,
1149 sizeof(process
->usertrace
->cpu
), 1, fp
);
1163 /* Called because a HDR_PROCESS_STATE was found */
1164 /* Append a saved state to the trace states */
1165 void lttv_state_read_raw(LttvTraceState
*self
, FILE *fp
, GPtrArray
*quarktable
)
1167 guint i
, nb_tracefile
, nb_block
, offset
;
1169 LttvTracefileState
*tfcs
;
1171 LttEventPosition
*ep
;
1180 LttvAttribute
*saved_states_tree
, *saved_state_tree
;
1182 LttvAttributeValue value
;
1183 GTree
*pqueue
= self
->parent
.ts_context
->pqueue
;
1184 ep
= ltt_event_position_new();
1186 restore_init_state(self
);
1188 res
= fread(&t
, sizeof(t
), 1, fp
);
1192 if(feof(fp
) || ferror(fp
)) goto end_loop
;
1194 if(hdr
== EOF
) goto end_loop
;
1198 /* Call read_process_state_raw */
1199 read_process_state_raw(self
, fp
, quarktable
);
1207 case HDR_USER_STACK
:
1209 case HDR_PROCESS_STATE
:
1215 g_error("Error while parsing saved state file : unknown data header %d",
1221 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
1222 for(i
=0;i
<nb_cpus
;i
++) {
1225 g_assert(hdr
== HDR_CPU
);
1226 res
= fread(&cpu_num
, sizeof(cpu_num
), 1, fp
); /* cpu number */
1228 g_assert(i
== cpu_num
);
1229 res
= fread(&self
->running_process
[i
]->pid
,
1230 sizeof(self
->running_process
[i
]->pid
), 1, fp
);
1234 nb_tracefile
= self
->parent
.tracefiles
->len
;
1236 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1238 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
1239 LttvTracefileContext
*, i
));
1240 // fprintf(fp, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu",
1241 // tfcs->parent.timestamp.tv_sec,
1242 // tfcs->parent.timestamp.tv_nsec);
1243 g_tree_remove(pqueue
, &tfcs
->parent
);
1245 g_assert(hdr
== HDR_TRACEFILE
);
1246 res
= fread(&tfcs
->parent
.timestamp
, sizeof(tfcs
->parent
.timestamp
), 1, fp
);
1248 /* Note : if timestamp if LTT_TIME_INFINITE, there will be no
1249 * position following : end of trace */
1250 if(ltt_time_compare(tfcs
->parent
.timestamp
, ltt_time_infinite
) != 0) {
1251 res
= fread(&nb_block
, sizeof(nb_block
), 1, fp
);
1252 res
+= fread(&offset
, sizeof(offset
), 1, fp
);
1253 res
+= fread(&tsc
, sizeof(tsc
), 1, fp
);
1255 ltt_event_position_set(ep
, tfcs
->parent
.tf
, nb_block
, offset
, tsc
);
1256 gint ret
= ltt_tracefile_seek_position(tfcs
->parent
.tf
, ep
);
1258 g_tree_insert(pqueue
, &tfcs
->parent
, &tfcs
->parent
);
1263 saved_states_tree
= lttv_attribute_find_subdir(self
->parent
.t_a
,
1264 LTTV_STATE_SAVED_STATES
);
1265 saved_state_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
1266 value
= lttv_attribute_add(saved_states_tree
,
1267 lttv_attribute_get_number(saved_states_tree
), LTTV_GOBJECT
);
1268 *(value
.v_gobject
) = (GObject
*)saved_state_tree
;
1269 value
= lttv_attribute_add(saved_state_tree
, LTTV_STATE_TIME
, LTTV_TIME
);
1270 *(value
.v_time
) = t
;
1271 lttv_state_save(self
, saved_state_tree
);
1272 g_debug("Saving state at time %lu.%lu", t
.tv_sec
,
1275 *(self
->max_time_state_recomputed_in_seek
) = t
;
1279 /* Called when a HDR_TRACE is found */
1280 void lttv_trace_states_read_raw(LttvTraceState
*tcs
, FILE *fp
,
1281 GPtrArray
*quarktable
)
1286 if(feof(fp
) || ferror(fp
)) goto end_loop
;
1288 if(hdr
== EOF
) goto end_loop
;
1291 case HDR_PROCESS_STATE
:
1292 /* Call read_process_state_raw */
1293 lttv_state_read_raw(tcs
, fp
, quarktable
);
1301 case HDR_USER_STACK
:
1305 g_error("Error while parsing saved state file :"
1306 " unexpected data header %d",
1310 g_error("Error while parsing saved state file : unknown data header %d",
1315 *(tcs
->max_time_state_recomputed_in_seek
) = tcs
->parent
.time_span
.end_time
;
1316 restore_init_state(tcs
);
1317 lttv_process_trace_seek_time(&tcs
->parent
, ltt_time_zero
);
1323 /* Copy each process from an existing hash table to a new one */
1325 static void copy_process_state(gpointer key
, gpointer value
,gpointer user_data
)
1327 LttvProcessState
*process
, *new_process
;
1329 GHashTable
*new_processes
= (GHashTable
*)user_data
;
1333 process
= (LttvProcessState
*)value
;
1334 new_process
= g_new(LttvProcessState
, 1);
1335 *new_process
= *process
;
1336 new_process
->execution_stack
= g_array_sized_new(FALSE
, FALSE
,
1337 sizeof(LttvExecutionState
), PREALLOCATED_EXECUTION_STACK
);
1338 new_process
->execution_stack
=
1339 g_array_set_size(new_process
->execution_stack
,
1340 process
->execution_stack
->len
);
1341 for(i
= 0 ; i
< process
->execution_stack
->len
; i
++) {
1342 g_array_index(new_process
->execution_stack
, LttvExecutionState
, i
) =
1343 g_array_index(process
->execution_stack
, LttvExecutionState
, i
);
1345 new_process
->state
= &g_array_index(new_process
->execution_stack
,
1346 LttvExecutionState
, new_process
->execution_stack
->len
- 1);
1347 new_process
->user_stack
= g_array_sized_new(FALSE
, FALSE
,
1348 sizeof(guint64
), 0);
1349 new_process
->user_stack
= g_array_set_size(new_process
->user_stack
,
1350 process
->user_stack
->len
);
1351 for(i
= 0 ; i
< process
->user_stack
->len
; i
++) {
1352 g_array_index(new_process
->user_stack
, guint64
, i
) =
1353 g_array_index(process
->user_stack
, guint64
, i
);
1355 new_process
->current_function
= process
->current_function
;
1357 /* fd hash table stuff */
1363 /* copy every item in the hash table */
1364 new_process
->fds
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
1366 g_hash_table_iter_init(&it
, process
->fds
);
1367 while (g_hash_table_iter_next (&it
, (void *)&key
, (void *)&value
)) {
1368 g_hash_table_insert(new_process
->fds
, key
, value
);
1372 /* When done creating the new process state, insert it in the
1374 g_hash_table_insert(new_processes
, new_process
, new_process
);
1378 static GHashTable
*lttv_state_copy_process_table(GHashTable
*processes
)
1380 GHashTable
*new_processes
= g_hash_table_new(process_hash
, process_equal
);
1382 g_hash_table_foreach(processes
, copy_process_state
, new_processes
);
1383 return new_processes
;
1386 static LttvCPUState
*lttv_state_copy_cpu_states(LttvCPUState
*states
, guint n
)
1389 LttvCPUState
*retval
;
1391 retval
= g_new(LttvCPUState
, n
);
1393 for(i
=0; i
<n
; i
++) {
1394 retval
[i
].irq_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
1395 g_array_set_size(retval
[i
].irq_stack
, states
[i
].irq_stack
->len
);
1396 for(j
=0; j
<states
[i
].irq_stack
->len
; j
++) {
1397 g_array_index(retval
[i
].irq_stack
, gint
, j
) =
1398 g_array_index(states
[i
].irq_stack
, gint
, j
);
1401 retval
[i
].softirq_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
1402 g_array_set_size(retval
[i
].softirq_stack
, states
[i
].softirq_stack
->len
);
1403 for(j
=0; j
<states
[i
].softirq_stack
->len
; j
++) {
1404 g_array_index(retval
[i
].softirq_stack
, gint
, j
) =
1405 g_array_index(states
[i
].softirq_stack
, gint
, j
);
1408 retval
[i
].trap_stack
= g_array_new(FALSE
, FALSE
, sizeof(gint
));
1409 g_array_set_size(retval
[i
].trap_stack
, states
[i
].trap_stack
->len
);
1410 for(j
=0; j
<states
[i
].trap_stack
->len
; j
++) {
1411 g_array_index(retval
[i
].trap_stack
, gint
, j
) =
1412 g_array_index(states
[i
].trap_stack
, gint
, j
);
1415 retval
[i
].mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(LttvCPUMode
));
1416 g_array_set_size(retval
[i
].mode_stack
, states
[i
].mode_stack
->len
);
1417 for(j
=0; j
<states
[i
].mode_stack
->len
; j
++) {
1418 g_array_index(retval
[i
].mode_stack
, GQuark
, j
) =
1419 g_array_index(states
[i
].mode_stack
, GQuark
, j
);
1426 static void lttv_state_free_cpu_states(LttvCPUState
*states
, guint n
)
1430 for(i
=0; i
<n
; i
++) {
1431 g_array_free(states
[i
].mode_stack
, TRUE
);
1432 g_array_free(states
[i
].irq_stack
, TRUE
);
1433 g_array_free(states
[i
].softirq_stack
, TRUE
);
1434 g_array_free(states
[i
].trap_stack
, TRUE
);
1440 static LttvIRQState
*lttv_state_copy_irq_states(LttvIRQState
*states
, guint n
)
1443 LttvIRQState
*retval
;
1445 retval
= g_new(LttvIRQState
, n
);
1447 for(i
=0; i
<n
; i
++) {
1448 retval
[i
].mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(LttvIRQMode
));
1449 g_array_set_size(retval
[i
].mode_stack
, states
[i
].mode_stack
->len
);
1450 for(j
=0; j
<states
[i
].mode_stack
->len
; j
++) {
1451 g_array_index(retval
[i
].mode_stack
, GQuark
, j
) =
1452 g_array_index(states
[i
].mode_stack
, GQuark
, j
);
1459 static void lttv_state_free_irq_states(LttvIRQState
*states
, guint n
)
1463 for(i
=0; i
<n
; i
++) {
1464 g_array_free(states
[i
].mode_stack
, TRUE
);
1470 static LttvSoftIRQState
*
1471 lttv_state_copy_soft_irq_states(LttvSoftIRQState
*states
, guint n
)
1474 LttvSoftIRQState
*retval
;
1476 retval
= g_new(LttvSoftIRQState
, n
);
1478 for(i
=0; i
<n
; i
++) {
1479 retval
[i
].pending
= states
[i
].pending
;
1480 retval
[i
].running
= states
[i
].running
;
1486 static void lttv_state_free_soft_irq_states(LttvSoftIRQState
*states
, guint n
)
1491 static LttvTrapState
*
1492 lttv_state_copy_trap_states(LttvTrapState
*states
, guint n
)
1495 LttvTrapState
*retval
;
1497 retval
= g_new(LttvTrapState
, n
);
1499 for(i
=0; i
<n
; i
++) {
1500 retval
[i
].running
= states
[i
].running
;
1506 static void lttv_state_free_trap_states(LttvTrapState
*states
, guint n
)
1511 /* bdevstate stuff */
1513 static LttvBdevState
*get_hashed_bdevstate(LttvTraceState
*ts
, guint32 devcode
)
1515 gint devcode_gint
= devcode
;
1516 gpointer bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1518 LttvBdevState
*bdevstate
= g_new(LttvBdevState
, 1);
1519 bdevstate
->mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(GQuark
));
1521 gint
* key
= g_new(gint
, 1);
1523 g_hash_table_insert(ts
->bdev_states
, key
, bdevstate
);
1531 static LttvBdevState
*bdevstate_new(void)
1533 LttvBdevState
*retval
;
1534 retval
= g_new(LttvBdevState
, 1);
1535 retval
->mode_stack
= g_array_new(FALSE
, FALSE
, sizeof(GQuark
));
1540 static void bdevstate_free(LttvBdevState
*bds
)
1542 g_array_free(bds
->mode_stack
, TRUE
);
1546 static void bdevstate_free_cb(gpointer key
, gpointer value
, gpointer user_data
)
1548 LttvBdevState
*bds
= (LttvBdevState
*) value
;
1550 bdevstate_free(bds
);
1553 static LttvBdevState
*bdevstate_copy(LttvBdevState
*bds
)
1555 LttvBdevState
*retval
;
1557 retval
= bdevstate_new();
1558 g_array_insert_vals(retval
->mode_stack
, 0, bds
->mode_stack
->data
,
1559 bds
->mode_stack
->len
);
1564 static void insert_and_copy_bdev_state(gpointer k
, gpointer v
, gpointer u
)
1566 //GHashTable *ht = (GHashTable *)u;
1567 LttvBdevState
*bds
= (LttvBdevState
*)v
;
1568 LttvBdevState
*newbds
;
1570 newbds
= bdevstate_copy(bds
);
1572 g_hash_table_insert(u
, k
, newbds
);
1575 static GHashTable
*lttv_state_copy_blkdev_hashtable(GHashTable
*ht
)
1579 retval
= g_hash_table_new(g_int_hash
, g_int_equal
);
1581 g_hash_table_foreach(ht
, insert_and_copy_bdev_state
, retval
);
1586 /* Free a hashtable and the LttvBdevState structures its values
1589 static void lttv_state_free_blkdev_hashtable(GHashTable
*ht
)
1591 g_hash_table_foreach(ht
, bdevstate_free_cb
, NULL
);
1592 g_hash_table_destroy(ht
);
1595 /* The saved state for each trace contains a member "processes", which
1596 stores a copy of the process table, and a member "tracefiles" with
1597 one entry per tracefile. Each tracefile has a "process" member pointing
1598 to the current process and a "position" member storing the tracefile
1599 position (needed to seek to the current "next" event. */
1601 static void state_save(LttvTraceState
*self
, LttvAttribute
*container
)
1603 guint i
, nb_tracefile
, nb_cpus
, nb_irqs
, nb_soft_irqs
, nb_traps
;
1605 LttvTracefileState
*tfcs
;
1607 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
1609 guint
*running_process
;
1611 LttvAttributeValue value
;
1613 LttEventPosition
*ep
;
1615 tracefiles_tree
= lttv_attribute_find_subdir(container
,
1616 LTTV_STATE_TRACEFILES
);
1618 value
= lttv_attribute_add(container
, LTTV_STATE_PROCESSES
,
1620 *(value
.v_pointer
) = lttv_state_copy_process_table(self
->processes
);
1622 /* Add the currently running processes array */
1623 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
1624 running_process
= g_new(guint
, nb_cpus
);
1625 for(i
=0;i
<nb_cpus
;i
++) {
1626 running_process
[i
] = self
->running_process
[i
]->pid
;
1628 value
= lttv_attribute_add(container
, LTTV_STATE_RUNNING_PROCESS
,
1630 *(value
.v_pointer
) = running_process
;
1632 g_info("State save");
1634 nb_tracefile
= self
->parent
.tracefiles
->len
;
1636 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1638 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
1639 LttvTracefileContext
*, i
));
1640 tracefile_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
1641 value
= lttv_attribute_add(tracefiles_tree
, i
,
1643 *(value
.v_gobject
) = (GObject
*)tracefile_tree
;
1645 value
= lttv_attribute_add(tracefile_tree
, LTTV_STATE_PROCESS
,
1647 *(value
.v_uint
) = tfcs
->process
->pid
;
1649 value
= lttv_attribute_add(tracefile_tree
, LTTV_STATE_EVENT
,
1651 /* Only save the position if the tfs has not infinite time. */
1652 //if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent)
1653 // && current_tfcs != tfcs) {
1654 if(ltt_time_compare(tfcs
->parent
.timestamp
, ltt_time_infinite
) == 0) {
1655 *(value
.v_pointer
) = NULL
;
1657 LttEvent
*e
= ltt_tracefile_get_event(tfcs
->parent
.tf
);
1658 ep
= ltt_event_position_new();
1659 ltt_event_position(e
, ep
);
1660 *(value
.v_pointer
) = ep
;
1662 guint nb_block
, offset
;
1665 ltt_event_position_get(ep
, &tf
, &nb_block
, &offset
, &tsc
);
1666 g_info("Block %u offset %u tsc %" PRIu64
" time %lu.%lu", nb_block
,
1667 offset
, tsc
, tfcs
->parent
.timestamp
.tv_sec
,
1668 tfcs
->parent
.timestamp
.tv_nsec
);
1672 /* save the cpu state */
1674 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_CPUS_COUNT
,
1676 *(value
.v_uint
) = nb_cpus
;
1678 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_CPUS
,
1680 *(value
.v_pointer
) = lttv_state_copy_cpu_states(self
->cpu_states
, nb_cpus
);
1683 /* save the irq state */
1684 nb_irqs
= self
->name_tables
->nb_irqs
;
1686 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_IRQS
,
1688 *(value
.v_pointer
) = lttv_state_copy_irq_states(self
->irq_states
, nb_irqs
);
1691 /* save the soft irq state */
1692 nb_soft_irqs
= self
->name_tables
->nb_soft_irqs
;
1694 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_SOFT_IRQS
,
1696 *(value
.v_pointer
) = lttv_state_copy_soft_irq_states(self
->soft_irq_states
, nb_soft_irqs
);
1699 /* save the trap state */
1700 nb_traps
= self
->name_tables
->nb_traps
;
1702 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_TRAPS
,
1704 *(value
.v_pointer
) = lttv_state_copy_trap_states(self
->trap_states
, nb_traps
);
1707 /* save the blkdev states */
1708 value
= lttv_attribute_add(container
, LTTV_STATE_RESOURCE_BLKDEVS
,
1710 *(value
.v_pointer
) = lttv_state_copy_blkdev_hashtable(self
->bdev_states
);
1714 static void state_restore(LttvTraceState
*self
, LttvAttribute
*container
)
1716 guint i
, nb_tracefile
, pid
, nb_cpus
, nb_irqs
, nb_soft_irqs
, nb_traps
;
1718 LttvTracefileState
*tfcs
;
1720 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
1722 guint
*running_process
;
1724 LttvAttributeType type
;
1726 LttvAttributeValue value
;
1728 LttvAttributeName name
;
1732 LttEventPosition
*ep
;
1734 LttvTracesetContext
*tsc
= self
->parent
.ts_context
;
1737 tracefiles_tree
= lttv_attribute_find_subdir(container
,
1738 LTTV_STATE_TRACEFILES
);
1740 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_PROCESSES
,
1742 g_assert(type
== LTTV_POINTER
);
1743 lttv_state_free_process_table(self
->processes
);
1744 self
->processes
= lttv_state_copy_process_table(*(value
.v_pointer
));
1746 /* Add the currently running processes array */
1747 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
1748 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RUNNING_PROCESS
,
1750 g_assert(type
== LTTV_POINTER
);
1751 running_process
= *(value
.v_pointer
);
1752 for(i
=0;i
<nb_cpus
;i
++) {
1753 pid
= running_process
[i
];
1754 self
->running_process
[i
] = lttv_state_find_process(self
, i
, pid
);
1755 g_assert(self
->running_process
[i
] != NULL
);
1758 nb_tracefile
= self
->parent
.tracefiles
->len
;
1760 //g_tree_destroy(tsc->pqueue);
1761 //tsc->pqueue = g_tree_new(compare_tracefile);
1763 /* restore cpu resource states */
1764 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_CPUS
, &value
);
1765 g_assert(type
== LTTV_POINTER
);
1766 lttv_state_free_cpu_states(self
->cpu_states
, nb_cpus
);
1767 self
->cpu_states
= lttv_state_copy_cpu_states(*(value
.v_pointer
), nb_cpus
);
1769 /* restore irq resource states */
1770 nb_irqs
= self
->name_tables
->nb_irqs
;
1771 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_IRQS
, &value
);
1772 g_assert(type
== LTTV_POINTER
);
1773 lttv_state_free_irq_states(self
->irq_states
, nb_irqs
);
1774 self
->irq_states
= lttv_state_copy_irq_states(*(value
.v_pointer
), nb_irqs
);
1776 /* restore soft irq resource states */
1777 nb_soft_irqs
= self
->name_tables
->nb_soft_irqs
;
1778 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_SOFT_IRQS
, &value
);
1779 g_assert(type
== LTTV_POINTER
);
1780 lttv_state_free_soft_irq_states(self
->soft_irq_states
, nb_soft_irqs
);
1781 self
->soft_irq_states
= lttv_state_copy_soft_irq_states(*(value
.v_pointer
), nb_soft_irqs
);
1783 /* restore trap resource states */
1784 nb_traps
= self
->name_tables
->nb_traps
;
1785 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_TRAPS
, &value
);
1786 g_assert(type
== LTTV_POINTER
);
1787 lttv_state_free_trap_states(self
->trap_states
, nb_traps
);
1788 self
->trap_states
= lttv_state_copy_trap_states(*(value
.v_pointer
), nb_traps
);
1790 /* restore the blkdev states */
1791 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_BLKDEVS
, &value
);
1792 g_assert(type
== LTTV_POINTER
);
1793 lttv_state_free_blkdev_hashtable(self
->bdev_states
);
1794 self
->bdev_states
= lttv_state_copy_blkdev_hashtable(*(value
.v_pointer
));
1796 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1798 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
1799 LttvTracefileContext
*, i
));
1800 type
= lttv_attribute_get(tracefiles_tree
, i
, &name
, &value
, &is_named
);
1801 g_assert(type
== LTTV_GOBJECT
);
1802 tracefile_tree
= *((LttvAttribute
**)(value
.v_gobject
));
1804 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_PROCESS
,
1806 g_assert(type
== LTTV_UINT
);
1807 pid
= *(value
.v_uint
);
1808 tfcs
->process
= lttv_state_find_process_or_create(tfcs
, pid
);
1810 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_EVENT
,
1812 g_assert(type
== LTTV_POINTER
);
1813 //g_assert(*(value.v_pointer) != NULL);
1814 ep
= *(value
.v_pointer
);
1815 g_assert(tfcs
->parent
.t_context
!= NULL
);
1817 tfcs
->cpu_state
= &self
->cpu_states
[tfcs
->cpu
];
1819 LttvTracefileContext
*tfc
= LTTV_TRACEFILE_CONTEXT(tfcs
);
1820 g_tree_remove(tsc
->pqueue
, tfc
);
1823 retval
= ltt_tracefile_seek_position(tfc
->tf
, ep
);
1824 g_assert_cmpint(retval
, ==, 0);
1825 tfc
->timestamp
= ltt_event_time(ltt_tracefile_get_event(tfc
->tf
));
1826 g_assert_cmpint(ltt_time_compare(tfc
->timestamp
, ltt_time_infinite
),
1828 g_tree_insert(tsc
->pqueue
, tfc
, tfc
);
1829 g_info("Restoring state for a tf at time %lu.%lu",
1830 tfc
->timestamp
.tv_sec
, tfc
->timestamp
.tv_nsec
);
1832 tfc
->timestamp
= ltt_time_infinite
;
1838 static void state_saved_free(LttvTraceState
*self
, LttvAttribute
*container
)
1840 guint i
, nb_tracefile
, nb_cpus
, nb_irqs
, nb_soft_irqs
;
1842 LttvTracefileState
*tfcs
;
1844 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
1846 guint
*running_process
;
1848 LttvAttributeType type
;
1850 LttvAttributeValue value
;
1852 LttvAttributeName name
;
1856 tracefiles_tree
= lttv_attribute_find_subdir(container
,
1857 LTTV_STATE_TRACEFILES
);
1858 g_object_ref(G_OBJECT(tracefiles_tree
));
1859 lttv_attribute_remove_by_name(container
, LTTV_STATE_TRACEFILES
);
1861 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_PROCESSES
,
1863 g_assert(type
== LTTV_POINTER
);
1864 lttv_state_free_process_table(*(value
.v_pointer
));
1865 *(value
.v_pointer
) = NULL
;
1866 lttv_attribute_remove_by_name(container
, LTTV_STATE_PROCESSES
);
1868 /* Free running processes array */
1869 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RUNNING_PROCESS
,
1871 g_assert(type
== LTTV_POINTER
);
1872 running_process
= *(value
.v_pointer
);
1873 g_free(running_process
);
1875 /* free cpu resource states */
1876 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_CPUS_COUNT
, &value
);
1877 g_assert(type
== LTTV_UINT
);
1878 nb_cpus
= *value
.v_uint
;
1879 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_CPUS
, &value
);
1880 g_assert(type
== LTTV_POINTER
);
1881 lttv_state_free_cpu_states(*(value
.v_pointer
), nb_cpus
);
1883 /* free irq resource states */
1884 nb_irqs
= self
->name_tables
->nb_irqs
;
1885 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_IRQS
, &value
);
1886 g_assert(type
== LTTV_POINTER
);
1887 lttv_state_free_irq_states(*(value
.v_pointer
), nb_irqs
);
1889 /* free softirq resource states */
1890 nb_soft_irqs
= self
->name_tables
->nb_soft_irqs
;
1891 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_SOFT_IRQS
, &value
);
1892 g_assert(type
== LTTV_POINTER
);
1893 lttv_state_free_soft_irq_states(*(value
.v_pointer
), nb_soft_irqs
);
1895 /* free the blkdev states */
1896 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RESOURCE_BLKDEVS
, &value
);
1897 g_assert(type
== LTTV_POINTER
);
1898 lttv_state_free_blkdev_hashtable(*(value
.v_pointer
));
1900 nb_tracefile
= self
->parent
.tracefiles
->len
;
1902 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1904 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
1905 LttvTracefileContext
*, i
));
1906 type
= lttv_attribute_get(tracefiles_tree
, i
, &name
, &value
, &is_named
);
1907 g_assert(type
== LTTV_GOBJECT
);
1908 tracefile_tree
= *((LttvAttribute
**)(value
.v_gobject
));
1910 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_EVENT
,
1912 g_assert(type
== LTTV_POINTER
);
1913 if(*(value
.v_pointer
) != NULL
) g_free(*(value
.v_pointer
));
1915 g_object_unref(G_OBJECT(tracefiles_tree
));
1919 static void free_saved_state(LttvTraceState
*self
)
1923 LttvAttributeType type
;
1925 LttvAttributeValue value
;
1927 LttvAttributeName name
;
1931 LttvAttribute
*saved_states
;
1933 saved_states
= lttv_attribute_find_subdir(self
->parent
.t_a
,
1934 LTTV_STATE_SAVED_STATES
);
1936 nb
= lttv_attribute_get_number(saved_states
);
1937 for(i
= 0 ; i
< nb
; i
++) {
1938 type
= lttv_attribute_get(saved_states
, i
, &name
, &value
, &is_named
);
1939 g_assert(type
== LTTV_GOBJECT
);
1940 state_saved_free(self
, *((LttvAttribute
**)value
.v_gobject
));
1943 lttv_attribute_remove_by_name(self
->parent
.t_a
, LTTV_STATE_SAVED_STATES
);
1947 static void create_max_time(LttvTraceState
*tcs
)
1949 LttvAttributeValue v
;
1951 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
1953 g_assert(*(v
.v_pointer
) == NULL
);
1954 *(v
.v_pointer
) = g_new(LttTime
,1);
1955 *((LttTime
*)*(v
.v_pointer
)) = ltt_time_zero
;
1959 static void get_max_time(LttvTraceState
*tcs
)
1961 LttvAttributeValue v
;
1963 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
1965 g_assert(*(v
.v_pointer
) != NULL
);
1966 tcs
->max_time_state_recomputed_in_seek
= (LttTime
*)*(v
.v_pointer
);
1970 static void free_max_time(LttvTraceState
*tcs
)
1972 LttvAttributeValue v
;
1974 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
1976 g_free(*(v
.v_pointer
));
1977 *(v
.v_pointer
) = NULL
;
1980 static void create_name_tables(LttvTraceState
*tcs
)
1984 GString
*fe_name
= g_string_new("");
1986 LttvNameTables
*name_tables
= g_new(LttvNameTables
, 1);
1988 LttvAttributeValue v
;
1992 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
1994 g_assert(*(v
.v_pointer
) == NULL
);
1995 *(v
.v_pointer
) = name_tables
;
1997 hooks
= g_array_sized_new(FALSE
, FALSE
, sizeof(LttvTraceHook
), 1);
1999 if(!lttv_trace_find_hook(tcs
->parent
.t
,
2001 LTT_EVENT_SYSCALL_ENTRY
,
2002 FIELD_ARRAY(LTT_FIELD_SYSCALL_ID
),
2003 NULL
, NULL
, &hooks
)) {
2005 // th = lttv_trace_hook_get_first(&th);
2007 // t = ltt_field_type(lttv_trace_get_hook_field(th, 0));
2008 // nb = ltt_type_element_number(t);
2010 // name_tables->syscall_names = g_new(GQuark, nb);
2011 // name_tables->nb_syscalls = nb;
2013 // for(i = 0 ; i < nb ; i++) {
2014 // name_tables->syscall_names[i] = ltt_enum_string_get(t, i);
2015 // if(!name_tables->syscall_names[i]) {
2016 // GString *string = g_string_new("");
2017 // g_string_printf(string, "syscall %u", i);
2018 // name_tables->syscall_names[i] = g_quark_from_string(string->str);
2019 // g_string_free(string, TRUE);
2023 name_tables
->nb_syscalls
= PREALLOC_NB_SYSCALLS
;
2024 name_tables
->syscall_names
= g_new(GQuark
, name_tables
->nb_syscalls
);
2025 for(i
= 0 ; i
< name_tables
->nb_syscalls
; i
++) {
2026 g_string_printf(fe_name
, "syscall %d", i
);
2027 name_tables
->syscall_names
[i
] = g_quark_from_string(fe_name
->str
);
2030 name_tables
->syscall_names
= NULL
;
2031 name_tables
->nb_syscalls
= 0;
2033 lttv_trace_hook_remove_all(&hooks
);
2035 if(!lttv_trace_find_hook(tcs
->parent
.t
,
2037 LTT_EVENT_TRAP_ENTRY
,
2038 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
2039 NULL
, NULL
, &hooks
) ||
2040 !lttv_trace_find_hook(tcs
->parent
.t
,
2042 LTT_EVENT_PAGE_FAULT_ENTRY
,
2043 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
2044 NULL
, NULL
, &hooks
)) {
2046 // th = lttv_trace_hook_get_first(&th);
2048 // t = ltt_field_type(lttv_trace_get_hook_field(th, 0));
2049 // //nb = ltt_type_element_number(t);
2051 // name_tables->trap_names = g_new(GQuark, nb);
2052 // for(i = 0 ; i < nb ; i++) {
2053 // name_tables->trap_names[i] = g_quark_from_string(
2054 // ltt_enum_string_get(t, i));
2057 name_tables
->nb_traps
= PREALLOC_NB_TRAPS
;
2058 name_tables
->trap_names
= g_new(GQuark
, name_tables
->nb_traps
);
2059 for(i
= 0 ; i
< name_tables
->nb_traps
; i
++) {
2060 g_string_printf(fe_name
, "trap %d", i
);
2061 name_tables
->trap_names
[i
] = g_quark_from_string(fe_name
->str
);
2064 name_tables
->trap_names
= NULL
;
2065 name_tables
->nb_traps
= 0;
2067 lttv_trace_hook_remove_all(&hooks
);
2069 if(!lttv_trace_find_hook(tcs
->parent
.t
,
2071 LTT_EVENT_IRQ_ENTRY
,
2072 FIELD_ARRAY(LTT_FIELD_IRQ_ID
),
2073 NULL
, NULL
, &hooks
)) {
2076 name_tables->irq_names = g_new(GQuark, nb);
2077 for(i = 0 ; i < nb ; i++) {
2078 name_tables->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i));
2081 /* FIXME: LttvIRQState *irq_states should become a g_array */
2083 name_tables
->nb_irqs
= PREALLOC_NB_IRQS
;
2084 name_tables
->irq_names
= g_new(GQuark
, name_tables
->nb_irqs
);
2085 for(i
= 0 ; i
< name_tables
->nb_irqs
; i
++) {
2086 g_string_printf(fe_name
, "irq %d", i
);
2087 name_tables
->irq_names
[i
] = g_quark_from_string(fe_name
->str
);
2090 name_tables
->nb_irqs
= 0;
2091 name_tables
->irq_names
= NULL
;
2093 lttv_trace_hook_remove_all(&hooks
);
2095 name_tables->soft_irq_names = g_new(GQuark, nb);
2096 for(i = 0 ; i < nb ; i++) {
2097 name_tables->soft_irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i));
2101 name_tables
->nb_soft_irqs
= PREALLOC_NB_SOFT_IRQS
;
2102 name_tables
->soft_irq_names
= g_new(GQuark
, name_tables
->nb_soft_irqs
);
2103 for(i
= 0 ; i
< name_tables
->nb_soft_irqs
; i
++) {
2104 g_string_printf(fe_name
, "softirq %d", i
);
2105 name_tables
->soft_irq_names
[i
] = g_quark_from_string(fe_name
->str
);
2107 g_array_free(hooks
, TRUE
);
2109 g_string_free(fe_name
, TRUE
);
2111 #if (__WORDSIZE == 32)
2112 name_tables
->kprobe_hash
= g_hash_table_new_full(guint64_hash
, guint64_equal
,
2115 name_tables
->kprobe_hash
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2120 static void get_name_tables(LttvTraceState
*tcs
)
2122 LttvAttributeValue v
;
2124 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
2126 g_assert(*(v
.v_pointer
) != NULL
);
2127 tcs
->name_tables
= (LttvNameTables
*)*(v
.v_pointer
);
2131 static void free_name_tables(LttvTraceState
*tcs
)
2133 LttvNameTables
*name_tables
;
2135 LttvAttributeValue v
;
2137 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
2139 name_tables
= (LttvNameTables
*)*(v
.v_pointer
);
2140 *(v
.v_pointer
) = NULL
;
2142 // g_free(name_tables->eventtype_names);
2143 if(name_tables
->syscall_names
) g_free(name_tables
->syscall_names
);
2144 if(name_tables
->trap_names
) g_free(name_tables
->trap_names
);
2145 if(name_tables
->irq_names
) g_free(name_tables
->irq_names
);
2146 if(name_tables
->soft_irq_names
) g_free(name_tables
->soft_irq_names
);
2147 g_hash_table_destroy(name_tables
->kprobe_hash
);
2148 g_free(name_tables
);
2151 #ifdef HASH_TABLE_DEBUG
2153 static void test_process(gpointer key
, gpointer value
, gpointer user_data
)
2155 LttvProcessState
*process
= (LttvProcessState
*)value
;
2157 /* Test for process corruption */
2158 guint stack_len
= process
->execution_stack
->len
;
2161 static void hash_table_check(GHashTable
*table
)
2163 g_hash_table_foreach(table
, test_process
, NULL
);
2169 /* clears the stack and sets the state passed as argument */
2170 static void cpu_set_base_mode(LttvCPUState
*cpust
, LttvCPUMode state
)
2172 g_array_set_size(cpust
->mode_stack
, 1);
2173 ((GQuark
*)cpust
->mode_stack
->data
)[0] = state
;
2176 static void cpu_push_mode(LttvCPUState
*cpust
, LttvCPUMode state
)
2178 g_array_set_size(cpust
->mode_stack
, cpust
->mode_stack
->len
+ 1);
2179 ((GQuark
*)cpust
->mode_stack
->data
)[cpust
->mode_stack
->len
- 1] = state
;
2182 static void cpu_pop_mode(LttvCPUState
*cpust
)
2184 if(cpust
->mode_stack
->len
<= 1)
2185 cpu_set_base_mode(cpust
, LTTV_CPU_UNKNOWN
);
2187 g_array_set_size(cpust
->mode_stack
, cpust
->mode_stack
->len
- 1);
2190 /* clears the stack and sets the state passed as argument */
2191 static void bdev_set_base_mode(LttvBdevState
*bdevst
, LttvBdevMode state
)
2193 g_array_set_size(bdevst
->mode_stack
, 1);
2194 ((GQuark
*)bdevst
->mode_stack
->data
)[0] = state
;
2197 static void bdev_push_mode(LttvBdevState
*bdevst
, LttvBdevMode state
)
2199 g_array_set_size(bdevst
->mode_stack
, bdevst
->mode_stack
->len
+ 1);
2200 ((GQuark
*)bdevst
->mode_stack
->data
)[bdevst
->mode_stack
->len
- 1] = state
;
2203 static void bdev_pop_mode(LttvBdevState
*bdevst
)
2205 if(bdevst
->mode_stack
->len
<= 1)
2206 bdev_set_base_mode(bdevst
, LTTV_BDEV_UNKNOWN
);
2208 g_array_set_size(bdevst
->mode_stack
, bdevst
->mode_stack
->len
- 1);
2211 static void irq_set_base_mode(LttvIRQState
*irqst
, LttvIRQMode state
)
2213 g_array_set_size(irqst
->mode_stack
, 1);
2214 ((GQuark
*)irqst
->mode_stack
->data
)[0] = state
;
2217 static void irq_push_mode(LttvIRQState
*irqst
, LttvIRQMode state
)
2219 g_array_set_size(irqst
->mode_stack
, irqst
->mode_stack
->len
+ 1);
2220 ((GQuark
*)irqst
->mode_stack
->data
)[irqst
->mode_stack
->len
- 1] = state
;
2223 static void irq_pop_mode(LttvIRQState
*irqst
)
2225 if(irqst
->mode_stack
->len
<= 1)
2226 irq_set_base_mode(irqst
, LTTV_IRQ_UNKNOWN
);
2228 g_array_set_size(irqst
->mode_stack
, irqst
->mode_stack
->len
- 1);
2231 static void push_state(LttvTracefileState
*tfs
, LttvExecutionMode t
,
2234 LttvExecutionState
*es
;
2236 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
2237 guint cpu
= tfs
->cpu
;
2239 #ifdef HASH_TABLE_DEBUG
2240 hash_table_check(ts
->processes
);
2242 LttvProcessState
*process
= ts
->running_process
[cpu
];
2244 guint depth
= process
->execution_stack
->len
;
2246 process
->execution_stack
=
2247 g_array_set_size(process
->execution_stack
, depth
+ 1);
2250 &g_array_index(process
->execution_stack
, LttvExecutionState
, depth
- 1);
2252 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, depth
);
2255 es
->entry
= es
->change
= tfs
->parent
.timestamp
;
2256 es
->cum_cpu_time
= ltt_time_zero
;
2257 es
->s
= process
->state
->s
;
2258 process
->state
= es
;
2262 * return 1 when empty, else 0 */
2264 lttv_state_pop_state_cleanup(LttvProcessState
*process
, LttvTracefileState
*tfs
)
2266 guint depth
= process
->execution_stack
->len
;
2272 process
->execution_stack
=
2273 g_array_set_size(process
->execution_stack
, depth
- 1);
2274 process
->state
= &g_array_index(process
->execution_stack
, LttvExecutionState
,
2276 process
->state
->change
= tfs
->parent
.timestamp
;
2281 static void pop_state(LttvTracefileState
*tfs
, LttvExecutionMode t
)
2283 guint cpu
= tfs
->cpu
;
2284 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
2285 LttvProcessState
*process
= ts
->running_process
[cpu
];
2287 guint depth
= process
->execution_stack
->len
;
2289 if(process
->state
->t
!= t
){
2290 g_info("Different execution mode type (%lu.%09lu): ignore it\n",
2291 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
2292 g_info("process state has %s when pop_int is %s\n",
2293 g_quark_to_string(process
->state
->t
),
2294 g_quark_to_string(t
));
2295 g_info("{ %u, %u, %s, %s, %s }\n",
2298 g_quark_to_string(process
->name
),
2299 g_quark_to_string(process
->brand
),
2300 g_quark_to_string(process
->state
->s
));
2305 g_info("Trying to pop last state on stack (%lu.%09lu): ignore it\n",
2306 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
2310 process
->execution_stack
=
2311 g_array_set_size(process
->execution_stack
, depth
- 1);
2312 process
->state
= &g_array_index(process
->execution_stack
, LttvExecutionState
,
2314 process
->state
->change
= tfs
->parent
.timestamp
;
2317 struct search_result
{
2318 const LttTime
*time
; /* Requested time */
2319 LttTime
*best
; /* Best result */
2322 static gint
search_usertrace(gconstpointer a
, gconstpointer b
)
2324 const LttTime
*elem_time
= (const LttTime
*)a
;
2325 /* Explicit non const cast */
2326 struct search_result
*res
= (struct search_result
*)b
;
2328 if(ltt_time_compare(*elem_time
, *(res
->time
)) < 0) {
2329 /* The usertrace was created before the schedchange */
2330 /* Get larger keys */
2332 } else if(ltt_time_compare(*elem_time
, *(res
->time
)) >= 0) {
2333 /* The usertrace was created after the schedchange time */
2334 /* Get smaller keys */
2336 if(ltt_time_compare(*elem_time
, *res
->best
) < 0) {
2337 res
->best
= (LttTime
*)elem_time
;
2340 res
->best
= (LttTime
*)elem_time
;
2347 static LttvTracefileState
*ltt_state_usertrace_find(LttvTraceState
*tcs
,
2348 guint pid
, const LttTime
*timestamp
)
2350 LttvTracefileState
*tfs
= NULL
;
2351 struct search_result res
;
2352 /* Find the usertrace associated with a pid and time interval.
2353 * Search in the usertraces by PID (within a hash) and then, for each
2354 * corresponding element of the array, find the first one with creation
2355 * timestamp the lowest, but higher or equal to "timestamp". */
2356 res
.time
= timestamp
;
2358 GTree
*usertrace_tree
= g_hash_table_lookup(tcs
->usertraces
,
2359 GUINT_TO_POINTER(pid
));
2360 if(usertrace_tree
) {
2361 g_tree_search(usertrace_tree
, search_usertrace
, &res
);
2363 tfs
= g_tree_lookup(usertrace_tree
, res
.best
);
2369 /* Return a new and initialized LttvProcessState structure */
2371 LttvProcessState
*lttv_state_create_process(LttvTraceState
*tcs
,
2372 LttvProcessState
*parent
, guint cpu
, guint pid
,
2373 guint tgid
, GQuark name
, const LttTime
*timestamp
)
2375 LttvProcessState
*process
= g_new(LttvProcessState
, 1);
2377 LttvExecutionState
*es
;
2382 process
->tgid
= tgid
;
2384 process
->name
= name
;
2385 process
->brand
= LTTV_STATE_UNBRANDED
;
2386 //process->last_cpu = tfs->cpu_name;
2387 //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
2388 process
->type
= LTTV_STATE_USER_THREAD
;
2389 process
->usertrace
= ltt_state_usertrace_find(tcs
, pid
, timestamp
);
2390 process
->current_function
= 0; //function 0x0 by default.
2392 g_info("Process %u, core %p", process
->pid
, process
);
2393 g_hash_table_insert(tcs
->processes
, process
, process
);
2396 process
->ppid
= parent
->pid
;
2397 process
->creation_time
= *timestamp
;
2400 /* No parent. This process exists but we are missing all information about
2401 its creation. The birth time is set to zero but we remember the time of
2406 process
->creation_time
= ltt_time_zero
;
2409 process
->insertion_time
= *timestamp
;
2410 sprintf(buffer
,"%d-%lu.%lu",pid
, process
->creation_time
.tv_sec
,
2411 process
->creation_time
.tv_nsec
);
2412 process
->pid_time
= g_quark_from_string(buffer
);
2414 process
->free_events
= 0;
2415 //process->last_cpu = tfs->cpu_name;
2416 //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
2417 process
->execution_stack
= g_array_sized_new(FALSE
, FALSE
,
2418 sizeof(LttvExecutionState
), PREALLOCATED_EXECUTION_STACK
);
2419 process
->execution_stack
= g_array_set_size(process
->execution_stack
, 2);
2420 es
= process
->state
= &g_array_index(process
->execution_stack
,
2421 LttvExecutionState
, 0);
2422 es
->t
= LTTV_STATE_USER_MODE
;
2423 es
->n
= LTTV_STATE_SUBMODE_NONE
;
2424 es
->entry
= *timestamp
;
2425 //g_assert(timestamp->tv_sec != 0);
2426 es
->change
= *timestamp
;
2427 es
->cum_cpu_time
= ltt_time_zero
;
2428 es
->s
= LTTV_STATE_RUN
;
2430 es
= process
->state
= &g_array_index(process
->execution_stack
,
2431 LttvExecutionState
, 1);
2432 es
->t
= LTTV_STATE_SYSCALL
;
2433 es
->n
= LTTV_STATE_SUBMODE_NONE
;
2434 es
->entry
= *timestamp
;
2435 //g_assert(timestamp->tv_sec != 0);
2436 es
->change
= *timestamp
;
2437 es
->cum_cpu_time
= ltt_time_zero
;
2438 es
->s
= LTTV_STATE_WAIT_FORK
;
2440 /* Allocate an empty function call stack. If it's empty, use 0x0. */
2441 process
->user_stack
= g_array_sized_new(FALSE
, FALSE
,
2442 sizeof(guint64
), 0);
2444 process
->fds
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2450 lttv_state_find_process(LttvTraceState
*ts
, guint cpu
, guint pid
)
2452 LttvProcessState key
;
2453 LttvProcessState
*process
;
2457 process
= g_hash_table_lookup(ts
->processes
, &key
);
2461 LttvProcessState
*lttv_state_find_process_or_create(LttvTraceState
*ts
,
2462 guint cpu
, guint pid
, const LttTime
*timestamp
)
2464 LttvProcessState
*process
= lttv_state_find_process(ts
, cpu
, pid
);
2465 LttvExecutionState
*es
;
2467 /* Put ltt_time_zero creation time for unexisting processes */
2468 if(unlikely(process
== NULL
)) {
2469 process
= lttv_state_create_process(ts
,
2470 NULL
, cpu
, pid
, 0, LTTV_STATE_UNNAMED
, timestamp
);
2471 /* We are not sure is it's a kernel thread or normal thread, put the
2472 * bottom stack state to unknown */
2473 process
->execution_stack
=
2474 g_array_set_size(process
->execution_stack
, 1);
2475 process
->state
= es
=
2476 &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
2477 es
->t
= LTTV_STATE_MODE_UNKNOWN
;
2478 es
->s
= LTTV_STATE_UNNAMED
;
2483 /* FIXME : this function should be called when we receive an event telling that
2484 * release_task has been called in the kernel. In happens generally when
2485 * the parent waits for its child termination, but may also happens in special
2486 * cases in the child's exit : when the parent ignores its children SIGCCHLD or
2487 * has the flag SA_NOCLDWAIT. It can also happen when the child is part
2488 * of a killed thread group, but isn't the leader.
2490 static int exit_process(LttvTracefileState
*tfs
, LttvProcessState
*process
)
2492 LttvTraceState
*ts
= LTTV_TRACE_STATE(tfs
->parent
.t_context
);
2493 LttvProcessState key
;
2495 /* Wait for both schedule with exit dead and process free to happen.
2496 * They can happen in any order. */
2497 if (++(process
->free_events
) < 2)
2500 key
.pid
= process
->pid
;
2501 key
.cpu
= process
->cpu
;
2502 g_hash_table_remove(ts
->processes
, &key
);
2503 g_array_free(process
->execution_stack
, TRUE
);
2504 g_array_free(process
->user_stack
, TRUE
);
2506 /* the following also clears the content */
2507 g_hash_table_destroy(process
->fds
);
2514 static void free_process_state(gpointer key
, gpointer value
,gpointer user_data
)
2516 g_array_free(((LttvProcessState
*)value
)->execution_stack
, TRUE
);
2517 g_array_free(((LttvProcessState
*)value
)->user_stack
, TRUE
);
2519 /* the following also clears the content */
2520 g_hash_table_destroy(((LttvProcessState
*)value
)->fds
);
2526 static void lttv_state_free_process_table(GHashTable
*processes
)
2528 g_hash_table_foreach(processes
, free_process_state
, NULL
);
2529 g_hash_table_destroy(processes
);
2533 static gboolean
syscall_entry(void *hook_data
, void *call_data
)
2535 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2537 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2538 LttvProcessState
*process
= ts
->running_process
[cpu
];
2539 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2540 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2541 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2542 LttvExecutionSubmode submode
;
2543 LttvNameTables
*nt
= ((LttvTraceState
*)(s
->parent
.t_context
))->name_tables
;
2545 guint syscall
= ltt_event_get_unsigned(e
, f
);
2546 expand_syscall_table(ts
, syscall
);
2547 submode
= nt
->syscall_names
[syscall
];
2548 /* There can be no system call from PID 0 : unknown state */
2549 if(process
->pid
!= 0)
2550 push_state(s
, LTTV_STATE_SYSCALL
, submode
);
2555 static gboolean
syscall_exit(void *hook_data
, void *call_data
)
2557 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2559 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2560 LttvProcessState
*process
= ts
->running_process
[cpu
];
2562 /* There can be no system call from PID 0 : unknown state */
2563 if(process
->pid
!= 0)
2564 pop_state(s
, LTTV_STATE_SYSCALL
);
2569 static gboolean
trap_entry(void *hook_data
, void *call_data
)
2571 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2572 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2573 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2574 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2575 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2576 LttvNameTables
*nt
= ((LttvTraceState
*)(s
->parent
.t_context
))->name_tables
;
2578 LttvExecutionSubmode submode
;
2580 guint64 trap
= ltt_event_get_long_unsigned(e
, f
);
2582 expand_trap_table(ts
, trap
);
2584 submode
= nt
->trap_names
[trap
];
2586 push_state(s
, LTTV_STATE_TRAP
, submode
);
2588 /* update cpu status */
2589 cpu_push_mode(s
->cpu_state
, LTTV_CPU_TRAP
);
2591 /* update trap status */
2592 g_array_append_val(s
->cpu_state
->trap_stack
, trap
);
2593 ts
->trap_states
[trap
].running
++;
2598 static gboolean
trap_exit(void *hook_data
, void *call_data
)
2600 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2601 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2603 pop_state(s
, LTTV_STATE_TRAP
);
2605 /* update cpu status */
2606 cpu_pop_mode(s
->cpu_state
);
2608 /* update trap status */
2609 if (s
->cpu_state
->trap_stack
->len
> 0) {
2610 gint last
= g_array_index(s
->cpu_state
->trap_stack
, gint
,
2611 s
->cpu_state
->trap_stack
->len
-1);
2612 if(ts
->trap_states
[last
].running
)
2613 ts
->trap_states
[last
].running
--;
2614 g_array_remove_index(s
->cpu_state
->trap_stack
,
2615 s
->cpu_state
->trap_stack
->len
-1);
2620 static gboolean
irq_entry(void *hook_data
, void *call_data
)
2622 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2623 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2624 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2625 //guint8 ev_id = ltt_event_eventtype_id(e);
2626 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2627 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2628 LttvNameTables
*nt
= ((LttvTraceState
*)(s
->parent
.t_context
))->name_tables
;
2630 LttvExecutionSubmode submode
;
2631 guint64 irq
= ltt_event_get_long_unsigned(e
, f
);
2633 expand_irq_table(ts
, irq
);
2635 submode
= nt
->irq_names
[irq
];
2637 /* Do something with the info about being in user or system mode when int? */
2638 push_state(s
, LTTV_STATE_IRQ
, submode
);
2640 /* update cpu status */
2641 cpu_push_mode(s
->cpu_state
, LTTV_CPU_IRQ
);
2643 /* update irq status */
2644 g_array_append_val(s
->cpu_state
->irq_stack
, irq
);
2645 irq_push_mode(&ts
->irq_states
[irq
], LTTV_IRQ_BUSY
);
2650 static gboolean
soft_irq_exit(void *hook_data
, void *call_data
)
2652 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2653 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2655 pop_state(s
, LTTV_STATE_SOFT_IRQ
);
2657 /* update cpu status */
2658 cpu_pop_mode(s
->cpu_state
);
2660 /* update softirq status */
2661 if (s
->cpu_state
->softirq_stack
->len
> 0) {
2662 gint last
= g_array_index(s
->cpu_state
->softirq_stack
, gint
, s
->cpu_state
->softirq_stack
->len
-1);
2663 if(ts
->soft_irq_states
[last
].running
)
2664 ts
->soft_irq_states
[last
].running
--;
2665 g_array_remove_index(s
->cpu_state
->softirq_stack
, s
->cpu_state
->softirq_stack
->len
-1);
2670 static gboolean
irq_exit(void *hook_data
, void *call_data
)
2672 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2673 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2675 pop_state(s
, LTTV_STATE_IRQ
);
2677 /* update cpu status */
2678 cpu_pop_mode(s
->cpu_state
);
2680 /* update irq status */
2681 if (s
->cpu_state
->irq_stack
->len
> 0) {
2682 gint last
= g_array_index(s
->cpu_state
->irq_stack
, gint
, s
->cpu_state
->irq_stack
->len
-1);
2683 g_array_remove_index(s
->cpu_state
->irq_stack
, s
->cpu_state
->irq_stack
->len
-1);
2684 irq_pop_mode(&ts
->irq_states
[last
]);
2690 static gboolean
soft_irq_raise(void *hook_data
, void *call_data
)
2692 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2693 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2694 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2695 //guint8 ev_id = ltt_event_eventtype_id(e);
2696 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2697 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2698 LttvNameTables
*nt
= ((LttvTraceState
*)(s
->parent
.t_context
))->name_tables
;
2699 LttvExecutionSubmode submode
;
2700 guint64 softirq
= ltt_event_get_long_unsigned(e
, f
);
2702 expand_soft_irq_table(ts
, softirq
);
2704 submode
= nt
->soft_irq_names
[softirq
];
2706 /* update softirq status */
2707 /* a soft irq raises are not cumulative */
2708 ts
->soft_irq_states
[softirq
].pending
=1;
2713 static gboolean
soft_irq_entry(void *hook_data
, void *call_data
)
2715 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2716 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2717 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2718 //guint8 ev_id = ltt_event_eventtype_id(e);
2719 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2720 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2721 LttvExecutionSubmode submode
;
2722 guint64 softirq
= ltt_event_get_long_unsigned(e
, f
);
2723 expand_soft_irq_table(ts
, softirq
);
2724 LttvNameTables
*nt
= ((LttvTraceState
*)(s
->parent
.t_context
))->name_tables
;
2725 submode
= nt
->soft_irq_names
[softirq
];
2727 /* Do something with the info about being in user or system mode when int? */
2728 push_state(s
, LTTV_STATE_SOFT_IRQ
, submode
);
2730 /* update cpu status */
2731 cpu_push_mode(s
->cpu_state
, LTTV_CPU_SOFT_IRQ
);
2733 /* update softirq status */
2734 g_array_append_val(s
->cpu_state
->softirq_stack
, softirq
);
2735 if(ts
->soft_irq_states
[softirq
].pending
)
2736 ts
->soft_irq_states
[softirq
].pending
--;
2737 ts
->soft_irq_states
[softirq
].running
++;
2742 static gboolean
enum_interrupt(void *hook_data
, void *call_data
)
2744 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2745 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2746 LttvNameTables
*nt
= ts
->name_tables
;
2747 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2748 //guint8 ev_id = ltt_event_eventtype_id(e);
2749 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2751 GQuark action
= g_quark_from_string(ltt_event_get_string(e
,
2752 lttv_trace_get_hook_field(th
, 0)));
2753 guint irq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
2755 expand_irq_table(ts
, irq
);
2756 nt
->irq_names
[irq
] = action
;
2762 static gboolean
bdev_request_issue(void *hook_data
, void *call_data
)
2764 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2765 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2766 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2767 //guint8 ev_id = ltt_event_eventtype_id(e);
2768 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2770 guint major
= ltt_event_get_long_unsigned(e
,
2771 lttv_trace_get_hook_field(th
, 0));
2772 guint minor
= ltt_event_get_long_unsigned(e
,
2773 lttv_trace_get_hook_field(th
, 1));
2774 guint oper
= ltt_event_get_long_unsigned(e
,
2775 lttv_trace_get_hook_field(th
, 2));
2776 guint32 devcode
= MKDEV(major
,minor
);
2778 /* have we seen this block device before? */
2779 gpointer bdev
= get_hashed_bdevstate(ts
, devcode
);
2782 bdev_push_mode(bdev
, LTTV_BDEV_BUSY_READING
);
2784 bdev_push_mode(bdev
, LTTV_BDEV_BUSY_WRITING
);
2789 static gboolean
bdev_request_complete(void *hook_data
, void *call_data
)
2791 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2792 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2793 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2794 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2796 guint major
= ltt_event_get_long_unsigned(e
,
2797 lttv_trace_get_hook_field(th
, 0));
2798 guint minor
= ltt_event_get_long_unsigned(e
,
2799 lttv_trace_get_hook_field(th
, 1));
2800 //guint oper = ltt_event_get_long_unsigned(e,
2801 // lttv_trace_get_hook_field(th, 2));
2802 guint32 devcode
= MKDEV(major
,minor
);
2804 /* have we seen this block device before? */
2805 gpointer bdev
= get_hashed_bdevstate(ts
, devcode
);
2807 /* update block device */
2808 bdev_pop_mode(bdev
);
2813 static void push_function(LttvTracefileState
*tfs
, guint64 funcptr
)
2817 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
2818 guint cpu
= tfs
->cpu
;
2819 LttvProcessState
*process
= ts
->running_process
[cpu
];
2821 guint depth
= process
->user_stack
->len
;
2823 process
->user_stack
=
2824 g_array_set_size(process
->user_stack
, depth
+ 1);
2826 new_func
= &g_array_index(process
->user_stack
, guint64
, depth
);
2827 *new_func
= funcptr
;
2828 process
->current_function
= funcptr
;
2831 static void pop_function(LttvTracefileState
*tfs
, guint64 funcptr
)
2833 guint cpu
= tfs
->cpu
;
2834 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
2835 LttvProcessState
*process
= ts
->running_process
[cpu
];
2837 if(process
->current_function
!= funcptr
){
2838 g_info("Different functions (%lu.%09lu): ignore it\n",
2839 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
2840 g_info("process state has %" PRIu64
" when pop_function is %" PRIu64
"\n",
2841 process
->current_function
, funcptr
);
2842 g_info("{ %u, %u, %s, %s, %s }\n",
2845 g_quark_to_string(process
->name
),
2846 g_quark_to_string(process
->brand
),
2847 g_quark_to_string(process
->state
->s
));
2850 guint depth
= process
->user_stack
->len
;
2853 g_info("Trying to pop last function on stack (%lu.%09lu): ignore it\n",
2854 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
2858 process
->user_stack
=
2859 g_array_set_size(process
->user_stack
, depth
- 1);
2860 process
->current_function
=
2861 g_array_index(process
->user_stack
, guint64
, depth
- 2);
2865 static gboolean
function_entry(void *hook_data
, void *call_data
)
2867 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2868 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2869 //guint8 ev_id = ltt_event_eventtype_id(e);
2870 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2871 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2872 guint64 funcptr
= ltt_event_get_long_unsigned(e
, f
);
2874 push_function(s
, funcptr
);
2878 static gboolean
function_exit(void *hook_data
, void *call_data
)
2880 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2881 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2882 //guint8 ev_id = ltt_event_eventtype_id(e);
2883 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2884 struct marker_field
*f
= lttv_trace_get_hook_field(th
, 0);
2885 guint64 funcptr
= ltt_event_get_long_unsigned(e
, f
);
2887 pop_function(s
, funcptr
);
2891 static gboolean
dump_syscall(void *hook_data
, void *call_data
)
2893 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2894 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2895 LttvNameTables
*nt
= ts
->name_tables
;
2896 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2897 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2902 id
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
2903 address
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
2904 symbol
= ltt_event_get_string(e
, lttv_trace_get_hook_field(th
, 2));
2906 expand_syscall_table(ts
, id
);
2907 nt
->syscall_names
[id
] = g_quark_from_string(symbol
);
2912 static gboolean
dump_kprobe(void *hook_data
, void *call_data
)
2914 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2915 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2916 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2917 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2921 ip
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
2922 symbol
= ltt_event_get_string(e
, lttv_trace_get_hook_field(th
, 1));
2924 expand_kprobe_table(ts
, ip
, symbol
);
2929 static gboolean
dump_softirq(void *hook_data
, void *call_data
)
2931 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2932 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2933 LttvNameTables
*nt
= ts
->name_tables
;
2934 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2935 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2940 id
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
2941 address
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
2942 symbol
= ltt_event_get_string(e
, lttv_trace_get_hook_field(th
, 2));
2944 expand_soft_irq_table(ts
, id
);
2945 nt
->soft_irq_names
[id
] = g_quark_from_string(symbol
);
2950 static gboolean
sched_try_wakeup(void *hook_data
, void *call_data
)
2952 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2953 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2954 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2955 LttvProcessState
*process
;
2959 woken_pid
= ltt_event_get_int(e
, lttv_trace_get_hook_field(th
, 0));
2960 woken_cpu
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
2962 process
= lttv_state_find_process_or_create(
2963 (LttvTraceState
*)s
->parent
.t_context
,
2964 woken_cpu
, woken_pid
,
2965 &s
->parent
.timestamp
);
2967 if (process
->state
->s
== LTTV_STATE_WAIT
|| process
->state
->s
== LTTV_STATE_WAIT_FORK
)
2969 process
->state
->s
= LTTV_STATE_WAIT_CPU
;
2970 process
->state
->change
= s
->parent
.timestamp
;
2973 g_debug("Wakeup: process %d on CPU %u\n", woken_pid
, woken_cpu
);
2978 static gboolean
schedchange(void *hook_data
, void *call_data
)
2980 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
2982 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
2983 LttvProcessState
*process
= ts
->running_process
[cpu
];
2984 //LttvProcessState *old_process = ts->running_process[cpu];
2986 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
2987 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
2988 guint pid_in
, pid_out
;
2991 pid_out
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
2992 pid_in
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
2993 state_out
= ltt_event_get_long_int(e
, lttv_trace_get_hook_field(th
, 2));
2995 if(likely(process
!= NULL
)) {
2997 /* We could not know but it was not the idle process executing.
2998 This should only happen at the beginning, before the first schedule
2999 event, and when the initial information (current process for each CPU)
3000 is missing. It is not obvious how we could, after the fact, compensate
3001 the wrongly attributed statistics. */
3003 //This test only makes sense once the state is known and if there is no
3004 //missing events. We need to silently ignore schedchange coming after a
3005 //process_free, or it causes glitches. (FIXME)
3006 //if(unlikely(process->pid != pid_out)) {
3007 // g_assert(process->pid == 0);
3009 if(process
->pid
== 0
3010 && process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
) {
3013 * Scheduling out of pid 0 at beginning of the trace.
3014 * We are typically in system call mode at this point although
3015 * (FIXME) we might be in a trap handler.
3017 g_assert(process
->execution_stack
->len
== 1);
3018 process
->state
->t
= LTTV_STATE_SYSCALL
;
3019 process
->state
->s
= LTTV_STATE_WAIT
;
3020 process
->state
->change
= s
->parent
.timestamp
;
3021 process
->state
->entry
= s
->parent
.timestamp
;
3024 if(unlikely(process
->state
->s
== LTTV_STATE_EXIT
)) {
3025 process
->state
->s
= LTTV_STATE_ZOMBIE
;
3026 process
->state
->change
= s
->parent
.timestamp
;
3028 if(unlikely(state_out
== 0)) process
->state
->s
= LTTV_STATE_WAIT_CPU
;
3029 else process
->state
->s
= LTTV_STATE_WAIT
;
3030 process
->state
->change
= s
->parent
.timestamp
;
3033 if(state_out
== 32 || state_out
== 64) { /* EXIT_DEAD || TASK_DEAD */
3034 /* see sched.h for states */
3035 if (!exit_process(s
, process
)) {
3036 process
->state
->s
= LTTV_STATE_DEAD
;
3037 process
->state
->change
= s
->parent
.timestamp
;
3042 process
= ts
->running_process
[cpu
] = lttv_state_find_process_or_create(
3043 (LttvTraceState
*)s
->parent
.t_context
,
3045 &s
->parent
.timestamp
);
3046 process
->state
->s
= LTTV_STATE_RUN
;
3048 if(process
->usertrace
)
3049 process
->usertrace
->cpu
= cpu
;
3050 // process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
3051 process
->state
->change
= s
->parent
.timestamp
;
3053 /* update cpu status */
3055 /* going to idle task */
3056 cpu_set_base_mode(s
->cpu_state
, LTTV_CPU_IDLE
);
3058 /* scheduling a real task.
3059 * we must be careful here:
3060 * if we just schedule()'ed to a process that is
3061 * in a trap, we must put the cpu in trap mode
3063 cpu_set_base_mode(s
->cpu_state
, LTTV_CPU_BUSY
);
3064 if(process
->state
->t
== LTTV_STATE_TRAP
)
3065 cpu_push_mode(s
->cpu_state
, LTTV_CPU_TRAP
);
3071 static gboolean
process_fork(void *hook_data
, void *call_data
)
3073 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3074 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3075 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3077 guint child_pid
; /* In the Linux Kernel, there is one PID per thread. */
3078 guint child_tgid
; /* tgid in the Linux kernel is the "real" POSIX PID. */
3079 //LttvProcessState *zombie_process;
3081 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3082 LttvProcessState
*process
= ts
->running_process
[cpu
];
3083 LttvProcessState
*child_process
;
3084 struct marker_field
*f
;
3087 parent_pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
3090 child_pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
3091 s
->parent
.target_pid
= child_pid
;
3094 f
= lttv_trace_get_hook_field(th
, 2);
3096 child_tgid
= ltt_event_get_unsigned(e
, f
);
3100 /* Mathieu : it seems like the process might have been scheduled in before the
3101 * fork, and, in a rare case, might be the current process. This might happen
3102 * in a SMP case where we don't have enough precision on the clocks.
3104 * Test reenabled after precision fixes on time. (Mathieu) */
3106 zombie_process
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
3108 if(unlikely(zombie_process
!= NULL
)) {
3109 /* Reutilisation of PID. Only now we are sure that the old PID
3110 * has been released. FIXME : should know when release_task happens instead.
3112 guint num_cpus
= ltt_trace_get_num_cpu(ts
->parent
.t
);
3114 for(i
=0; i
< num_cpus
; i
++) {
3115 g_assert(zombie_process
!= ts
->running_process
[i
]);
3118 exit_process(s
, zombie_process
);
3121 g_assert(process
->pid
!= child_pid
);
3122 // FIXME : Add this test in the "known state" section
3123 // g_assert(process->pid == parent_pid);
3124 child_process
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
3125 if(child_process
== NULL
) {
3126 child_process
= lttv_state_create_process(ts
, process
, cpu
,
3127 child_pid
, child_tgid
,
3128 LTTV_STATE_UNNAMED
, &s
->parent
.timestamp
);
3130 /* The process has already been created : due to time imprecision between
3131 * multiple CPUs : it has been scheduled in before creation. Note that we
3132 * shouldn't have this kind of imprecision.
3134 * Simply put a correct parent.
3136 g_error("Process %u has been created at [%lu.%09lu] "
3137 "and inserted at [%lu.%09lu] before \n"
3138 "fork on cpu %u[%lu.%09lu].\n"
3139 "Probably an unsynchronized TSC problem on the traced machine.",
3141 child_process
->creation_time
.tv_sec
,
3142 child_process
->creation_time
.tv_nsec
,
3143 child_process
->insertion_time
.tv_sec
,
3144 child_process
->insertion_time
.tv_nsec
,
3145 cpu
, ltt_event_time(e
).tv_sec
, ltt_event_time(e
).tv_nsec
);
3146 //g_assert(0); /* This is a problematic case : the process has been created
3147 // before the fork event */
3148 child_process
->ppid
= process
->pid
;
3149 child_process
->tgid
= child_tgid
;
3151 g_assert(child_process
->name
== LTTV_STATE_UNNAMED
);
3152 child_process
->name
= process
->name
;
3153 child_process
->brand
= process
->brand
;
3158 /* We stamp a newly created process as kernel_thread.
3159 * The thread should not be running yet. */
3160 static gboolean
process_kernel_thread(void *hook_data
, void *call_data
)
3162 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3163 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3164 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3166 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3167 LttvProcessState
*process
;
3168 LttvExecutionState
*es
;
3171 pid
= (guint
)ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
3172 s
->parent
.target_pid
= pid
;
3174 process
= lttv_state_find_process_or_create(ts
, ANY_CPU
, pid
,
3176 if (process
->state
->s
!= LTTV_STATE_DEAD
) {
3177 process
->execution_stack
=
3178 g_array_set_size(process
->execution_stack
, 1);
3179 es
= process
->state
=
3180 &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
3181 es
->t
= LTTV_STATE_SYSCALL
;
3183 process
->type
= LTTV_STATE_KERNEL_THREAD
;
3188 static gboolean
process_exit(void *hook_data
, void *call_data
)
3190 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3191 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3192 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3194 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3195 LttvProcessState
*process
; // = ts->running_process[cpu];
3197 pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
3198 s
->parent
.target_pid
= pid
;
3200 // FIXME : Add this test in the "known state" section
3201 // g_assert(process->pid == pid);
3203 process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
3204 if(likely(process
!= NULL
)) {
3205 process
->state
->s
= LTTV_STATE_EXIT
;
3210 static gboolean
process_free(void *hook_data
, void *call_data
)
3212 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3213 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3214 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3215 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3217 LttvProcessState
*process
;
3219 /* PID of the process to release */
3220 release_pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
3221 s
->parent
.target_pid
= release_pid
;
3223 g_assert(release_pid
!= 0);
3225 process
= lttv_state_find_process(ts
, ANY_CPU
, release_pid
);
3226 if(likely(process
!= NULL
))
3227 exit_process(s
, process
);
3230 if(likely(process
!= NULL
)) {
3231 /* release_task is happening at kernel level : we can now safely release
3232 * the data structure of the process */
3233 //This test is fun, though, as it may happen that
3234 //at time t : CPU 0 : process_free
3235 //at time t+150ns : CPU 1 : schedule out
3236 //Clearly due to time imprecision, we disable it. (Mathieu)
3237 //If this weird case happen, we have no choice but to put the
3238 //Currently running process on the cpu to 0.
3239 //I re-enable it following time precision fixes. (Mathieu)
3240 //Well, in the case where an process is freed by a process on another CPU
3241 //and still scheduled, it happens that this is the schedchange that will
3242 //drop the last reference count. Do not free it here!
3243 guint num_cpus
= ltt_trace_get_num_cpu(ts
->parent
.t
);
3245 for(i
=0; i
< num_cpus
; i
++) {
3246 //g_assert(process != ts->running_process[i]);
3247 if(process
== ts
->running_process
[i
]) {
3248 //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
3252 if(i
== num_cpus
) /* process is not scheduled */
3253 exit_process(s
, process
);
3260 static gboolean
process_exec(void *hook_data
, void *call_data
)
3262 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3263 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3264 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3265 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3268 LttvProcessState
*process
= ts
->running_process
[cpu
];
3270 #if 0//how to use a sequence that must be transformed in a string
3271 /* PID of the process to release */
3272 guint64 name_len
= ltt_event_field_element_number(e
,
3273 lttv_trace_get_hook_field(th
, 0));
3274 //name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0));
3275 LttField
*child
= ltt_event_field_element_select(e
,
3276 lttv_trace_get_hook_field(th
, 0), 0);
3278 (gchar
*)(ltt_event_data(e
)+ltt_event_field_offset(e
, child
));
3279 gchar
*null_term_name
= g_new(gchar
, name_len
+1);
3280 memcpy(null_term_name
, name_begin
, name_len
);
3281 null_term_name
[name_len
] = '\0';
3282 process
->name
= g_quark_from_string(null_term_name
);
3285 process
->name
= g_quark_from_string(ltt_event_get_string(e
,
3286 lttv_trace_get_hook_field(th
, 0)));
3287 process
->brand
= LTTV_STATE_UNBRANDED
;
3288 //g_free(null_term_name);
3292 static gboolean
thread_brand(void *hook_data
, void *call_data
)
3294 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3295 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3296 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3297 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3300 LttvProcessState
*process
= ts
->running_process
[cpu
];
3302 name
= ltt_event_get_string(e
, lttv_trace_get_hook_field(th
, 0));
3303 process
->brand
= g_quark_from_string(name
);
3308 static gboolean
fs_open(void *hook_data
, void *call_data
)
3310 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3311 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3312 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3313 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3314 struct marker_field
*f
;
3318 LttvProcessState
*process
= ts
->running_process
[cpu
];
3320 f
= lttv_trace_get_hook_field(th
, 0);
3321 fd
= ltt_event_get_int(e
, f
);
3323 f
= lttv_trace_get_hook_field(th
, 1);
3324 filename
= ltt_event_get_string(e
, f
);
3326 g_hash_table_insert(process
->fds
, (gpointer
)(long)fd
,
3327 (gpointer
)(unsigned long)g_quark_from_string(filename
));
3332 static void print_stack(LttvProcessState
*process
)
3334 LttvExecutionState
*es
;
3337 g_debug("Execution stack for process %u %s:\n",
3338 process
->pid
, g_quark_to_string(process
->name
));
3340 for (i
= 0; i
< process
->execution_stack
->len
; i
++) {
3341 es
= &g_array_index(process
->execution_stack
,
3342 LttvExecutionState
, i
);
3343 g_debug("Depth %d mode %s submode %s status %s\n",
3344 i
, g_quark_to_string(es
->t
),
3345 g_quark_to_string(es
->n
),
3346 g_quark_to_string(es
->s
));
3351 static void fix_process(gpointer key
, gpointer value
, gpointer user_data
)
3353 LttvProcessState
*process
;
3354 LttvExecutionState
*es
;
3355 process
= (LttvProcessState
*)value
;
3356 LttTime
*timestamp
= (LttTime
*)user_data
;
3358 print_stack(process
);
3360 if(process
->type
== LTTV_STATE_KERNEL_THREAD
) {
3361 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
3362 if(es
->t
== LTTV_STATE_MAYBE_SYSCALL
) {
3363 es
->t
= LTTV_STATE_SYSCALL
;
3364 es
->n
= LTTV_STATE_SUBMODE_NONE
;
3365 es
->entry
= *timestamp
;
3366 es
->change
= *timestamp
;
3367 es
->cum_cpu_time
= ltt_time_zero
;
3368 if(es
->s
== LTTV_STATE_UNNAMED
)
3369 es
->s
= LTTV_STATE_WAIT
;
3372 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
3373 if(es
->t
== LTTV_STATE_MAYBE_USER_MODE
) {
3374 es
->t
= LTTV_STATE_USER_MODE
;
3375 es
->n
= LTTV_STATE_SUBMODE_NONE
;
3376 es
->entry
= *timestamp
;
3377 //g_assert(timestamp->tv_sec != 0);
3378 es
->change
= *timestamp
;
3379 es
->cum_cpu_time
= ltt_time_zero
;
3380 if(es
->s
== LTTV_STATE_UNNAMED
)
3381 es
->s
= LTTV_STATE_RUN
;
3383 if(process
->execution_stack
->len
== 1) {
3384 /* Still in bottom unknown mode, means we either:
3385 * - never did a system call
3386 * - are scheduled out from user mode.
3387 * May be either in user mode, syscall mode, running or waiting.*/
3388 /* CHECK : we may be tagging syscall mode when being user mode
3389 * (should be fixed now) */
3390 if (es
->s
== LTTV_STATE_WAIT_CPU
) {
3391 /* nothing to do: scheduled out from userspace */
3393 process
->execution_stack
=
3394 g_array_set_size(process
->execution_stack
, 2);
3395 es
= process
->state
= &g_array_index(process
->execution_stack
,
3396 LttvExecutionState
, 1);
3397 es
->t
= LTTV_STATE_SYSCALL
;
3398 es
->n
= LTTV_STATE_SUBMODE_NONE
;
3399 es
->entry
= *timestamp
;
3400 //g_assert(timestamp->tv_sec != 0);
3401 es
->change
= *timestamp
;
3402 es
->cum_cpu_time
= ltt_time_zero
;
3403 if(es
->s
== LTTV_STATE_WAIT_FORK
)
3404 es
->s
= LTTV_STATE_WAIT
;
3411 static gboolean
statedump_end(void *hook_data
, void *call_data
)
3413 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3414 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3415 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
3416 //LttEvent *e = ltt_tracefile_get_event(s->parent.tf);
3417 //LttvTraceHook *th = (LttvTraceHook *)hook_data;
3419 /* For all processes */
3420 /* if kernel thread, if stack[0] is unknown, set to syscall mode, wait */
3421 /* else, if stack[0] is unknown, set to user mode, running */
3423 g_hash_table_foreach(ts
->processes
, fix_process
, &tfc
->timestamp
);
3428 static gboolean
enum_process_state(void *hook_data
, void *call_data
)
3430 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
3431 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
3432 //It's slow : optimise later by doing this before reading trace.
3433 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
3439 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
3440 LttvProcessState
*process
= ts
->running_process
[cpu
];
3441 LttvProcessState
*parent_process
;
3442 struct marker_field
*f
;
3443 GQuark type
, mode
, submode
, status
;
3444 LttvExecutionState
*es
;
3448 pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
3449 s
->parent
.target_pid
= pid
;
3452 parent_pid
= ltt_event_get_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
3455 command
= ltt_event_get_string(e
, lttv_trace_get_hook_field(th
, 2));
3458 f
= lttv_trace_get_hook_field(th
, 3);
3459 type
= ltt_enum_string_get(f
, ltt_event_get_unsigned(e
, f
));
3461 //FIXME: type is rarely used, enum must match possible types.
3464 f
= lttv_trace_get_hook_field(th
, 4);
3465 mode
= ltt_enum_string_get(f
,ltt_event_get_unsigned(e
, f
));
3468 f
= lttv_trace_get_hook_field(th
, 5);
3469 submode
= ltt_enum_string_get(f
, ltt_event_get_unsigned(e
, f
));
3472 f
= lttv_trace_get_hook_field(th
, 6);
3473 status
= ltt_enum_string_get(f
, ltt_event_get_unsigned(e
, f
));
3476 f
= lttv_trace_get_hook_field(th
, 7);
3478 tgid
= ltt_event_get_unsigned(e
, f
);
3483 nb_cpus
= ltt_trace_get_num_cpu(ts
->parent
.t
);
3484 for(i
=0; i
<nb_cpus
; i
++) {
3485 process
= lttv_state_find_process(ts
, i
, pid
);
3486 g_assert(process
!= NULL
);
3488 process
->ppid
= parent_pid
;
3489 process
->tgid
= tgid
;
3490 process
->name
= g_quark_from_string(command
);
3491 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
3492 process
->type
= LTTV_STATE_KERNEL_THREAD
;
3496 /* The process might exist if a process was forked while performing the
3498 process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
3499 if(process
== NULL
) {
3500 parent_process
= lttv_state_find_process(ts
, ANY_CPU
, parent_pid
);
3501 process
= lttv_state_create_process(ts
, parent_process
, cpu
,
3502 pid
, tgid
, g_quark_from_string(command
),
3503 &s
->parent
.timestamp
);
3505 /* Keep the stack bottom : a running user mode */
3506 /* Disabled because of inconsistencies in the current statedump states. */
3507 if(type
== LTTV_STATE_KERNEL_THREAD
) {
3508 /* Only keep the bottom
3509 * FIXME Kernel thread : can be in syscall or interrupt or trap. */
3510 /* Will cause expected trap when in fact being syscall (even after end of
3512 * Will cause expected interrupt when being syscall. (only before end of
3513 * statedump event) */
3514 // This will cause a "popping last state on stack, ignoring it."
3515 process
->execution_stack
= g_array_set_size(process
->execution_stack
, 1);
3516 es
= process
->state
= &g_array_index(process
->execution_stack
,
3517 LttvExecutionState
, 0);
3518 process
->type
= LTTV_STATE_KERNEL_THREAD
;
3519 es
->t
= LTTV_STATE_MAYBE_SYSCALL
;
3520 es
->s
= LTTV_STATE_UNNAMED
;
3521 es
->n
= LTTV_STATE_SUBMODE_UNKNOWN
;
3525 /* User space process :
3526 * bottom : user mode
3527 * either currently running or scheduled out.
3528 * can be scheduled out because interrupted in (user mode or in syscall)
3529 * or because of an explicit call to the scheduler in syscall. Note that
3530 * the scheduler call comes after the irq_exit, so never in interrupt
3532 // temp workaround : set size to 1 : only have user mode bottom of stack.
3533 // will cause g_info message of expected syscall mode when in fact being
3534 // in user mode. Can also cause expected trap when in fact being user
3535 // mode in the event of a page fault reenabling interrupts in the handler.
3536 // Expected syscall and trap can also happen after the end of statedump
3537 // This will cause a "popping last state on stack, ignoring it."
3538 process
->execution_stack
= g_array_set_size(process
->execution_stack
, 1);
3539 es
= process
->state
= &g_array_index(process
->execution_stack
,
3540 LttvExecutionState
, 0);
3541 es
->t
= LTTV_STATE_MAYBE_USER_MODE
;
3542 es
->s
= LTTV_STATE_UNNAMED
;
3543 es
->n
= LTTV_STATE_SUBMODE_UNKNOWN
;
3550 es
= process
->state
= &g_array_index(process
->execution_stack
,
3551 LttvExecutionState
, 1);
3552 es
->t
= LTTV_STATE_MODE_UNKNOWN
;
3553 es
->s
= LTTV_STATE_UNNAMED
;
3554 es
->n
= LTTV_STATE_SUBMODE_UNKNOWN
;
3558 /* The process has already been created :
3559 * Probably was forked while dumping the process state or
3560 * was simply scheduled in prior to get the state dump event.
3562 process
->ppid
= parent_pid
;
3563 process
->tgid
= tgid
;
3564 process
->name
= g_quark_from_string(command
);
3565 process
->type
= type
;
3566 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, 0);
3568 if(es
->t
== LTTV_STATE_MODE_UNKNOWN
) {
3569 if(type
== LTTV_STATE_KERNEL_THREAD
)
3570 es
->t
= LTTV_STATE_SYSCALL
;
3572 es
->t
= LTTV_STATE_USER_MODE
;
3575 /* Don't mess around with the stack, it will eventually become
3576 * ok after the end of state dump. */
3583 gint
lttv_state_hook_add_event_hooks(void *hook_data
, void *call_data
)
3585 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
3587 lttv_state_add_event_hooks(tss
);
3592 void lttv_state_add_event_hooks(LttvTracesetState
*self
)
3594 LttvTraceset
*traceset
= self
->parent
.ts
;
3596 guint i
, j
, k
, nb_trace
, nb_tracefile
;
3600 LttvTracefileState
*tfs
;
3606 LttvAttributeValue val
;
3608 nb_trace
= lttv_traceset_number(traceset
);
3609 for(i
= 0 ; i
< nb_trace
; i
++) {
3610 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
3612 /* Find the eventtype id for the following events and register the
3613 associated by id hooks. */
3615 hooks
= g_array_sized_new(FALSE
, FALSE
, sizeof(LttvTraceHook
), 20);
3616 //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks.
3619 lttv_trace_find_hook(ts
->parent
.t
,
3621 LTT_EVENT_SYSCALL_ENTRY
,
3622 FIELD_ARRAY(LTT_FIELD_SYSCALL_ID
),
3623 syscall_entry
, NULL
, &hooks
);
3625 lttv_trace_find_hook(ts
->parent
.t
,
3627 LTT_EVENT_SYSCALL_EXIT
,
3629 syscall_exit
, NULL
, &hooks
);
3631 lttv_trace_find_hook(ts
->parent
.t
,
3633 LTT_EVENT_TRAP_ENTRY
,
3634 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
3635 trap_entry
, NULL
, &hooks
);
3637 lttv_trace_find_hook(ts
->parent
.t
,
3639 LTT_EVENT_TRAP_EXIT
,
3641 trap_exit
, NULL
, &hooks
);
3643 lttv_trace_find_hook(ts
->parent
.t
,
3645 LTT_EVENT_PAGE_FAULT_ENTRY
,
3646 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
3647 trap_entry
, NULL
, &hooks
);
3649 lttv_trace_find_hook(ts
->parent
.t
,
3651 LTT_EVENT_PAGE_FAULT_EXIT
,
3653 trap_exit
, NULL
, &hooks
);
3655 lttv_trace_find_hook(ts
->parent
.t
,
3657 LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
,
3658 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
3659 trap_entry
, NULL
, &hooks
);
3661 lttv_trace_find_hook(ts
->parent
.t
,
3663 LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
,
3665 trap_exit
, NULL
, &hooks
);
3667 lttv_trace_find_hook(ts
->parent
.t
,
3669 LTT_EVENT_IRQ_ENTRY
,
3670 FIELD_ARRAY(LTT_FIELD_IRQ_ID
),
3671 irq_entry
, NULL
, &hooks
);
3673 lttv_trace_find_hook(ts
->parent
.t
,
3677 irq_exit
, NULL
, &hooks
);
3679 lttv_trace_find_hook(ts
->parent
.t
,
3681 LTT_EVENT_SOFT_IRQ_RAISE
,
3682 FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID
),
3683 soft_irq_raise
, NULL
, &hooks
);
3685 lttv_trace_find_hook(ts
->parent
.t
,
3687 LTT_EVENT_SOFT_IRQ_ENTRY
,
3688 FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID
),
3689 soft_irq_entry
, NULL
, &hooks
);
3691 lttv_trace_find_hook(ts
->parent
.t
,
3693 LTT_EVENT_SOFT_IRQ_EXIT
,
3695 soft_irq_exit
, NULL
, &hooks
);
3697 lttv_trace_find_hook(ts
->parent
.t
,
3699 LTT_EVENT_SCHED_SCHEDULE
,
3700 FIELD_ARRAY(LTT_FIELD_PREV_PID
, LTT_FIELD_NEXT_PID
,
3701 LTT_FIELD_PREV_STATE
),
3702 schedchange
, NULL
, &hooks
);
3704 lttv_trace_find_hook(ts
->parent
.t
,
3706 LTT_EVENT_SCHED_TRY_WAKEUP
,
3707 FIELD_ARRAY(LTT_FIELD_PID
, LTT_FIELD_CPU_ID
, LTT_FIELD_STATE
),
3708 sched_try_wakeup
, NULL
, &hooks
);
3710 lttv_trace_find_hook(ts
->parent
.t
,
3712 LTT_EVENT_PROCESS_FORK
,
3713 FIELD_ARRAY(LTT_FIELD_PARENT_PID
, LTT_FIELD_CHILD_PID
,
3714 LTT_FIELD_CHILD_TGID
),
3715 process_fork
, NULL
, &hooks
);
3717 lttv_trace_find_hook(ts
->parent
.t
,
3719 LTT_EVENT_KTHREAD_CREATE
,
3720 FIELD_ARRAY(LTT_FIELD_PID
),
3721 process_kernel_thread
, NULL
, &hooks
);
3723 lttv_trace_find_hook(ts
->parent
.t
,
3725 LTT_EVENT_PROCESS_EXIT
,
3726 FIELD_ARRAY(LTT_FIELD_PID
),
3727 process_exit
, NULL
, &hooks
);
3729 lttv_trace_find_hook(ts
->parent
.t
,
3731 LTT_EVENT_PROCESS_FREE
,
3732 FIELD_ARRAY(LTT_FIELD_PID
),
3733 process_free
, NULL
, &hooks
);
3735 lttv_trace_find_hook(ts
->parent
.t
,
3738 FIELD_ARRAY(LTT_FIELD_FILENAME
),
3739 process_exec
, NULL
, &hooks
);
3741 lttv_trace_find_hook(ts
->parent
.t
,
3742 LTT_CHANNEL_USERSPACE
,
3743 LTT_EVENT_THREAD_BRAND
,
3744 FIELD_ARRAY(LTT_FIELD_NAME
),
3745 thread_brand
, NULL
, &hooks
);
3747 /* statedump-related hooks */
3748 lttv_trace_find_hook(ts
->parent
.t
,
3749 LTT_CHANNEL_TASK_STATE
,
3750 LTT_EVENT_PROCESS_STATE
,
3751 FIELD_ARRAY(LTT_FIELD_PID
, LTT_FIELD_PARENT_PID
, LTT_FIELD_NAME
,
3752 LTT_FIELD_TYPE
, LTT_FIELD_MODE
, LTT_FIELD_SUBMODE
,
3753 LTT_FIELD_STATUS
, LTT_FIELD_TGID
),
3754 enum_process_state
, NULL
, &hooks
);
3756 lttv_trace_find_hook(ts
->parent
.t
,
3757 LTT_CHANNEL_GLOBAL_STATE
,
3758 LTT_EVENT_STATEDUMP_END
,
3760 statedump_end
, NULL
, &hooks
);
3762 lttv_trace_find_hook(ts
->parent
.t
,
3763 LTT_CHANNEL_IRQ_STATE
,
3764 LTT_EVENT_LIST_INTERRUPT
,
3765 FIELD_ARRAY(LTT_FIELD_ACTION
, LTT_FIELD_IRQ_ID
),
3766 enum_interrupt
, NULL
, &hooks
);
3768 lttv_trace_find_hook(ts
->parent
.t
,
3770 LTT_EVENT_REQUEST_ISSUE
,
3771 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
3772 bdev_request_issue
, NULL
, &hooks
);
3774 lttv_trace_find_hook(ts
->parent
.t
,
3776 LTT_EVENT_REQUEST_COMPLETE
,
3777 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
3778 bdev_request_complete
, NULL
, &hooks
);
3780 lttv_trace_find_hook(ts
->parent
.t
,
3781 LTT_CHANNEL_USERSPACE
,
3782 LTT_EVENT_FUNCTION_ENTRY
,
3783 FIELD_ARRAY(LTT_FIELD_THIS_FN
, LTT_FIELD_CALL_SITE
),
3784 function_entry
, NULL
, &hooks
);
3786 lttv_trace_find_hook(ts
->parent
.t
,
3787 LTT_CHANNEL_USERSPACE
,
3788 LTT_EVENT_FUNCTION_EXIT
,
3789 FIELD_ARRAY(LTT_FIELD_THIS_FN
, LTT_FIELD_CALL_SITE
),
3790 function_exit
, NULL
, &hooks
);
3792 lttv_trace_find_hook(ts
->parent
.t
,
3793 LTT_CHANNEL_SYSCALL_STATE
,
3794 LTT_EVENT_SYS_CALL_TABLE
,
3795 FIELD_ARRAY(LTT_FIELD_ID
, LTT_FIELD_ADDRESS
, LTT_FIELD_SYMBOL
),
3796 dump_syscall
, NULL
, &hooks
);
3798 lttv_trace_find_hook(ts
->parent
.t
,
3799 LTT_CHANNEL_KPROBE_STATE
,
3800 LTT_EVENT_KPROBE_TABLE
,
3801 FIELD_ARRAY(LTT_FIELD_IP
, LTT_FIELD_SYMBOL
),
3802 dump_kprobe
, NULL
, &hooks
);
3804 lttv_trace_find_hook(ts
->parent
.t
,
3805 LTT_CHANNEL_SOFTIRQ_STATE
,
3806 LTT_EVENT_SOFTIRQ_VEC
,
3807 FIELD_ARRAY(LTT_FIELD_ID
, LTT_FIELD_ADDRESS
, LTT_FIELD_SYMBOL
),
3808 dump_softirq
, NULL
, &hooks
);
3810 lttv_trace_find_hook(ts
->parent
.t
,
3813 FIELD_ARRAY(LTT_FIELD_FD
, LTT_FIELD_FILENAME
),
3814 fs_open
, NULL
, &hooks
);
3816 /* Add these hooks to each event_by_id hooks list */
3818 nb_tracefile
= ts
->parent
.tracefiles
->len
;
3820 for(j
= 0 ; j
< nb_tracefile
; j
++) {
3822 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
3823 LttvTracefileContext
*, j
));
3825 for(k
= 0 ; k
< hooks
->len
; k
++) {
3826 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
3827 if (th
->mdata
== tfs
->parent
.tf
->mdata
)
3829 lttv_hooks_by_id_find(tfs
->parent
.event_by_id
, th
->id
),
3835 lttv_attribute_find(ts
->parent
.a
, LTTV_STATE_HOOKS
, LTTV_POINTER
, &val
);
3836 *(val
.v_pointer
) = hooks
;
3840 gint
lttv_state_hook_remove_event_hooks(void *hook_data
, void *call_data
)
3842 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
3844 lttv_state_remove_event_hooks(tss
);
3849 void lttv_state_remove_event_hooks(LttvTracesetState
*self
)
3851 LttvTraceset
*traceset
= self
->parent
.ts
;
3853 guint i
, j
, k
, nb_trace
, nb_tracefile
;
3857 LttvTracefileState
*tfs
;
3863 LttvAttributeValue val
;
3865 nb_trace
= lttv_traceset_number(traceset
);
3866 for(i
= 0 ; i
< nb_trace
; i
++) {
3867 ts
= LTTV_TRACE_STATE(self
->parent
.traces
[i
]);
3869 lttv_attribute_find(ts
->parent
.a
, LTTV_STATE_HOOKS
, LTTV_POINTER
, &val
);
3870 hooks
= *(val
.v_pointer
);
3872 /* Remove these hooks from each event_by_id hooks list */
3874 nb_tracefile
= ts
->parent
.tracefiles
->len
;
3876 for(j
= 0 ; j
< nb_tracefile
; j
++) {
3878 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
3879 LttvTracefileContext
*, j
));
3881 for(k
= 0 ; k
< hooks
->len
; k
++) {
3882 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
3883 if (th
->mdata
== tfs
->parent
.tf
->mdata
)
3884 lttv_hooks_remove_data(
3885 lttv_hooks_by_id_find(tfs
->parent
.event_by_id
, th
->id
),
3890 lttv_trace_hook_remove_all(&hooks
);
3891 g_array_free(hooks
, TRUE
);
3895 static gboolean
state_save_event_hook(void *hook_data
, void *call_data
)
3897 guint
*event_count
= (guint
*)hook_data
;
3899 /* Only save at LTTV_STATE_SAVE_INTERVAL */
3900 if(likely((*event_count
)++ < LTTV_STATE_SAVE_INTERVAL
))
3905 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
3907 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
3909 LttvAttribute
*saved_states_tree
, *saved_state_tree
;
3911 LttvAttributeValue value
;
3913 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
3914 LTTV_STATE_SAVED_STATES
);
3915 saved_state_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
3916 value
= lttv_attribute_add(saved_states_tree
,
3917 lttv_attribute_get_number(saved_states_tree
), LTTV_GOBJECT
);
3918 *(value
.v_gobject
) = (GObject
*)saved_state_tree
;
3919 value
= lttv_attribute_add(saved_state_tree
, LTTV_STATE_TIME
, LTTV_TIME
);
3920 *(value
.v_time
) = self
->parent
.timestamp
;
3921 lttv_state_save(tcs
, saved_state_tree
);
3922 g_debug("Saving state at time %lu.%lu", self
->parent
.timestamp
.tv_sec
,
3923 self
->parent
.timestamp
.tv_nsec
);
3925 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
3930 static gboolean
state_save_after_trace_hook(void *hook_data
, void *call_data
)
3932 LttvTraceState
*tcs
= (LttvTraceState
*)(call_data
);
3934 *(tcs
->max_time_state_recomputed_in_seek
) = tcs
->parent
.time_span
.end_time
;
3939 guint
lttv_state_current_cpu(LttvTracefileState
*tfs
)
3947 static gboolean
block_start(void *hook_data
, void *call_data
)
3949 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
3951 LttvTracefileState
*tfcs
;
3953 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
3955 LttEventPosition
*ep
;
3957 guint i
, nb_block
, nb_event
, nb_tracefile
;
3961 LttvAttribute
*saved_states_tree
, *saved_state_tree
;
3963 LttvAttributeValue value
;
3965 ep
= ltt_event_position_new();
3967 nb_tracefile
= tcs
->parent
.tracefiles
->len
;
3969 /* Count the number of events added since the last block end in any
3972 for(i
= 0 ; i
< nb_tracefile
; i
++) {
3974 LTTV_TRACEFILE_STATE(&g_array_index(tcs
->parent
.tracefiles
,
3975 LttvTracefileContext
, i
));
3976 ltt_event_position(tfcs
->parent
.e
, ep
);
3977 ltt_event_position_get(ep
, &nb_block
, &nb_event
, &tf
);
3978 tcs
->nb_event
+= nb_event
- tfcs
->saved_position
;
3979 tfcs
->saved_position
= nb_event
;
3983 if(tcs
->nb_event
>= tcs
->save_interval
) {
3984 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
3985 LTTV_STATE_SAVED_STATES
);
3986 saved_state_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
3987 value
= lttv_attribute_add(saved_states_tree
,
3988 lttv_attribute_get_number(saved_states_tree
), LTTV_GOBJECT
);
3989 *(value
.v_gobject
) = (GObject
*)saved_state_tree
;
3990 value
= lttv_attribute_add(saved_state_tree
, LTTV_STATE_TIME
, LTTV_TIME
);
3991 *(value
.v_time
) = self
->parent
.timestamp
;
3992 lttv_state_save(tcs
, saved_state_tree
);
3994 g_debug("Saving state at time %lu.%lu", self
->parent
.timestamp
.tv_sec
,
3995 self
->parent
.timestamp
.tv_nsec
);
3997 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
4003 static gboolean
block_end(void *hook_data
, void *call_data
)
4005 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
4007 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
4011 LttEventPosition
*ep
;
4013 guint nb_block
, nb_event
;
4015 ep
= ltt_event_position_new();
4016 ltt_event_position(self
->parent
.e
, ep
);
4017 ltt_event_position_get(ep
, &nb_block
, &nb_event
, &tf
);
4018 tcs
->nb_event
+= nb_event
- self
->saved_position
+ 1;
4019 self
->saved_position
= 0;
4020 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
4027 void lttv_state_save_add_event_hooks(LttvTracesetState
*self
)
4029 LttvTraceset
*traceset
= self
->parent
.ts
;
4031 guint i
, j
, nb_trace
, nb_tracefile
;
4035 LttvTracefileState
*tfs
;
4037 LttvTraceHook hook_start
, hook_end
;
4039 nb_trace
= lttv_traceset_number(traceset
);
4040 for(i
= 0 ; i
< nb_trace
; i
++) {
4041 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
4043 lttv_trace_find_hook(ts
->parent
.t
, "core","block_start",NULL
,
4044 NULL
, NULL
, block_start
, &hook_start
);
4045 lttv_trace_find_hook(ts
->parent
.t
, "core","block_end",NULL
,
4046 NULL
, NULL
, block_end
, &hook_end
);
4048 nb_tracefile
= ts
->parent
.tracefiles
->len
;
4050 for(j
= 0 ; j
< nb_tracefile
; j
++) {
4052 LTTV_TRACEFILE_STATE(&g_array_index(ts
->parent
.tracefiles
,
4053 LttvTracefileContext
, j
));
4054 lttv_hooks_add(lttv_hooks_by_id_find(tfs
->parent
.event_by_id
,
4055 hook_start
.id
), hook_start
.h
, NULL
, LTTV_PRIO_STATE
);
4056 lttv_hooks_add(lttv_hooks_by_id_find(tfs
->parent
.event_by_id
,
4057 hook_end
.id
), hook_end
.h
, NULL
, LTTV_PRIO_STATE
);
4063 void lttv_state_save_add_event_hooks(LttvTracesetState
*self
)
4065 LttvTraceset
*traceset
= self
->parent
.ts
;
4067 guint i
, j
, nb_trace
, nb_tracefile
;
4071 LttvTracefileState
*tfs
;
4074 nb_trace
= lttv_traceset_number(traceset
);
4075 for(i
= 0 ; i
< nb_trace
; i
++) {
4077 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
4078 nb_tracefile
= ts
->parent
.tracefiles
->len
;
4080 if(ts
->has_precomputed_states
) continue;
4082 guint
*event_count
= g_new(guint
, 1);
4085 for(j
= 0 ; j
< nb_tracefile
; j
++) {
4087 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
4088 LttvTracefileContext
*, j
));
4089 lttv_hooks_add(tfs
->parent
.event
,
4090 state_save_event_hook
,
4097 lttv_process_traceset_begin(&self
->parent
,
4098 NULL
, NULL
, NULL
, NULL
, NULL
);
4102 gint
lttv_state_save_hook_add_event_hooks(void *hook_data
, void *call_data
)
4104 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
4106 lttv_state_save_add_event_hooks(tss
);
4113 void lttv_state_save_remove_event_hooks(LttvTracesetState
*self
)
4115 LttvTraceset
*traceset
= self
->parent
.ts
;
4117 guint i
, j
, nb_trace
, nb_tracefile
;
4121 LttvTracefileState
*tfs
;
4123 LttvTraceHook hook_start
, hook_end
;
4125 nb_trace
= lttv_traceset_number(traceset
);
4126 for(i
= 0 ; i
< nb_trace
; i
++) {
4127 ts
= LTTV_TRACE_STATE(self
->parent
.traces
[i
]);
4129 lttv_trace_find_hook(ts
->parent
.t
, "core","block_start",NULL
,
4130 NULL
, NULL
, block_start
, &hook_start
);
4132 lttv_trace_find_hook(ts
->parent
.t
, "core","block_end",NULL
,
4133 NULL
, NULL
, block_end
, &hook_end
);
4135 nb_tracefile
= ts
->parent
.tracefiles
->len
;
4137 for(j
= 0 ; j
< nb_tracefile
; j
++) {
4139 LTTV_TRACEFILE_STATE(&g_array_index(ts
->parent
.tracefiles
,
4140 LttvTracefileContext
, j
));
4141 lttv_hooks_remove_data(lttv_hooks_by_id_find(
4142 tfs
->parent
.event_by_id
, hook_start
.id
), hook_start
.h
, NULL
);
4143 lttv_hooks_remove_data(lttv_hooks_by_id_find(
4144 tfs
->parent
.event_by_id
, hook_end
.id
), hook_end
.h
, NULL
);
4150 void lttv_state_save_remove_event_hooks(LttvTracesetState
*self
)
4152 LttvTraceset
*traceset
= self
->parent
.ts
;
4154 guint i
, j
, nb_trace
, nb_tracefile
;
4158 LttvTracefileState
*tfs
;
4160 LttvHooks
*after_trace
= lttv_hooks_new();
4162 lttv_hooks_add(after_trace
,
4163 state_save_after_trace_hook
,
4168 lttv_process_traceset_end(&self
->parent
,
4169 NULL
, after_trace
, NULL
, NULL
, NULL
);
4171 lttv_hooks_destroy(after_trace
);
4173 nb_trace
= lttv_traceset_number(traceset
);
4174 for(i
= 0 ; i
< nb_trace
; i
++) {
4176 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
4177 nb_tracefile
= ts
->parent
.tracefiles
->len
;
4179 if(ts
->has_precomputed_states
) continue;
4181 guint
*event_count
= NULL
;
4183 for(j
= 0 ; j
< nb_tracefile
; j
++) {
4185 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
4186 LttvTracefileContext
*, j
));
4187 event_count
= lttv_hooks_remove(tfs
->parent
.event
,
4188 state_save_event_hook
);
4190 if(event_count
) g_free(event_count
);
4194 gint
lttv_state_save_hook_remove_event_hooks(void *hook_data
, void *call_data
)
4196 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
4198 lttv_state_save_remove_event_hooks(tss
);
4203 void lttv_state_traceset_seek_time_closest(LttvTracesetState
*self
, LttTime t
)
4205 LttvTraceset
*traceset
= self
->parent
.ts
;
4209 int min_pos
, mid_pos
, max_pos
;
4211 guint call_rest
= 0;
4213 LttvTraceState
*tcs
;
4215 LttvAttributeValue value
;
4217 LttvAttributeType type
;
4219 LttvAttributeName name
;
4223 LttvAttribute
*saved_states_tree
, *saved_state_tree
, *closest_tree
= NULL
;
4225 //g_tree_destroy(self->parent.pqueue);
4226 //self->parent.pqueue = g_tree_new(compare_tracefile);
4228 g_info("Entering seek_time_closest for time %lu.%lu", t
.tv_sec
, t
.tv_nsec
);
4230 nb_trace
= lttv_traceset_number(traceset
);
4231 for(i
= 0 ; i
< nb_trace
; i
++) {
4232 tcs
= (LttvTraceState
*)self
->parent
.traces
[i
];
4234 if(ltt_time_compare(t
, *(tcs
->max_time_state_recomputed_in_seek
)) < 0) {
4235 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
4236 LTTV_STATE_SAVED_STATES
);
4239 if(saved_states_tree
) {
4240 max_pos
= lttv_attribute_get_number(saved_states_tree
) - 1;
4241 mid_pos
= max_pos
/ 2;
4242 while(min_pos
< max_pos
) {
4243 type
= lttv_attribute_get(saved_states_tree
, mid_pos
,
4244 &name
, &value
, &is_named
);
4245 g_assert(type
== LTTV_GOBJECT
);
4246 saved_state_tree
= *((LttvAttribute
**)(value
.v_gobject
));
4247 type
= lttv_attribute_get_by_name(saved_state_tree
,
4248 LTTV_STATE_TIME
, &value
);
4249 g_assert(type
== LTTV_TIME
);
4250 if(ltt_time_compare(*(value
.v_time
), t
) < 0) {
4252 closest_tree
= saved_state_tree
;
4254 else max_pos
= mid_pos
- 1;
4256 mid_pos
= (min_pos
+ max_pos
+ 1) / 2;
4260 /* restore the closest earlier saved state */
4262 lttv_state_restore(tcs
, closest_tree
);
4266 /* There is no saved state, yet we want to have it. Restart at T0 */
4268 restore_init_state(tcs
);
4269 lttv_process_trace_seek_time(&(tcs
->parent
), ltt_time_zero
);
4272 /* We want to seek quickly without restoring/updating the state */
4274 restore_init_state(tcs
);
4275 lttv_process_trace_seek_time(&(tcs
->parent
), t
);
4278 if(!call_rest
) g_info("NOT Calling restore");
4282 static void traceset_state_instance_init (GTypeInstance
*instance
, gpointer g_class
)
4287 static void traceset_state_finalize (LttvTracesetState
*self
)
4289 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
4290 finalize(G_OBJECT(self
));
4294 static void traceset_state_class_init (LttvTracesetContextClass
*klass
)
4296 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
4298 gobject_class
->finalize
= (void (*)(GObject
*self
)) traceset_state_finalize
;
4299 klass
->init
= (void (*)(LttvTracesetContext
*self
, LttvTraceset
*ts
))init
;
4300 klass
->fini
= (void (*)(LttvTracesetContext
*self
))fini
;
4301 klass
->new_traceset_context
= new_traceset_context
;
4302 klass
->new_trace_context
= new_trace_context
;
4303 klass
->new_tracefile_context
= new_tracefile_context
;
4307 GType
lttv_traceset_state_get_type(void)
4309 static GType type
= 0;
4311 static const GTypeInfo info
= {
4312 sizeof (LttvTracesetStateClass
),
4313 NULL
, /* base_init */
4314 NULL
, /* base_finalize */
4315 (GClassInitFunc
) traceset_state_class_init
, /* class_init */
4316 NULL
, /* class_finalize */
4317 NULL
, /* class_data */
4318 sizeof (LttvTracesetState
),
4319 0, /* n_preallocs */
4320 (GInstanceInitFunc
) traceset_state_instance_init
, /* instance_init */
4321 NULL
/* value handling */
4324 type
= g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE
, "LttvTracesetStateType",
4331 static void trace_state_instance_init (GTypeInstance
*instance
, gpointer g_class
)
4336 static void trace_state_finalize (LttvTraceState
*self
)
4338 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE
))->
4339 finalize(G_OBJECT(self
));
4343 static void trace_state_class_init (LttvTraceStateClass
*klass
)
4345 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
4347 gobject_class
->finalize
= (void (*)(GObject
*self
)) trace_state_finalize
;
4348 klass
->state_save
= state_save
;
4349 klass
->state_restore
= state_restore
;
4350 klass
->state_saved_free
= state_saved_free
;
4354 GType
lttv_trace_state_get_type(void)
4356 static GType type
= 0;
4358 static const GTypeInfo info
= {
4359 sizeof (LttvTraceStateClass
),
4360 NULL
, /* base_init */
4361 NULL
, /* base_finalize */
4362 (GClassInitFunc
) trace_state_class_init
, /* class_init */
4363 NULL
, /* class_finalize */
4364 NULL
, /* class_data */
4365 sizeof (LttvTraceState
),
4366 0, /* n_preallocs */
4367 (GInstanceInitFunc
) trace_state_instance_init
, /* instance_init */
4368 NULL
/* value handling */
4371 type
= g_type_register_static (LTTV_TRACE_CONTEXT_TYPE
,
4372 "LttvTraceStateType", &info
, 0);
4378 static void tracefile_state_instance_init (GTypeInstance
*instance
,
4384 static void tracefile_state_finalize (LttvTracefileState
*self
)
4386 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE
))->
4387 finalize(G_OBJECT(self
));
4391 static void tracefile_state_class_init (LttvTracefileStateClass
*klass
)
4393 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
4395 gobject_class
->finalize
= (void (*)(GObject
*self
)) tracefile_state_finalize
;
4399 GType
lttv_tracefile_state_get_type(void)
4401 static GType type
= 0;
4403 static const GTypeInfo info
= {
4404 sizeof (LttvTracefileStateClass
),
4405 NULL
, /* base_init */
4406 NULL
, /* base_finalize */
4407 (GClassInitFunc
) tracefile_state_class_init
, /* class_init */
4408 NULL
, /* class_finalize */
4409 NULL
, /* class_data */
4410 sizeof (LttvTracefileState
),
4411 0, /* n_preallocs */
4412 (GInstanceInitFunc
) tracefile_state_instance_init
, /* instance_init */
4413 NULL
/* value handling */
4416 type
= g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE
,
4417 "LttvTracefileStateType", &info
, 0);
4423 static void module_init()
4425 LTTV_STATE_UNNAMED
= g_quark_from_string("");
4426 LTTV_STATE_UNBRANDED
= g_quark_from_string("");
4427 LTTV_STATE_MODE_UNKNOWN
= g_quark_from_string("MODE_UNKNOWN");
4428 LTTV_STATE_USER_MODE
= g_quark_from_string("USER_MODE");
4429 LTTV_STATE_MAYBE_USER_MODE
= g_quark_from_string("MAYBE_USER_MODE");
4430 LTTV_STATE_SYSCALL
= g_quark_from_string("SYSCALL");
4431 LTTV_STATE_MAYBE_SYSCALL
= g_quark_from_string("MAYBE_SYSCALL");
4432 LTTV_STATE_TRAP
= g_quark_from_string("TRAP");
4433 LTTV_STATE_MAYBE_TRAP
= g_quark_from_string("MAYBE_TRAP");
4434 LTTV_STATE_IRQ
= g_quark_from_string("IRQ");
4435 LTTV_STATE_SOFT_IRQ
= g_quark_from_string("SOFTIRQ");
4436 LTTV_STATE_SUBMODE_UNKNOWN
= g_quark_from_string("UNKNOWN");
4437 LTTV_STATE_SUBMODE_NONE
= g_quark_from_string("NONE");
4438 LTTV_STATE_WAIT_FORK
= g_quark_from_string("WAIT_FORK");
4439 LTTV_STATE_WAIT_CPU
= g_quark_from_string("WAIT_CPU");
4440 LTTV_STATE_EXIT
= g_quark_from_string("EXIT");
4441 LTTV_STATE_ZOMBIE
= g_quark_from_string("ZOMBIE");
4442 LTTV_STATE_WAIT
= g_quark_from_string("WAIT");
4443 LTTV_STATE_RUN
= g_quark_from_string("RUN");
4444 LTTV_STATE_DEAD
= g_quark_from_string("DEAD");
4445 LTTV_STATE_USER_THREAD
= g_quark_from_string("USER_THREAD");
4446 LTTV_STATE_KERNEL_THREAD
= g_quark_from_string("KERNEL_THREAD");
4447 LTTV_STATE_TRACEFILES
= g_quark_from_string("tracefiles");
4448 LTTV_STATE_PROCESSES
= g_quark_from_string("processes");
4449 LTTV_STATE_PROCESS
= g_quark_from_string("process");
4450 LTTV_STATE_RUNNING_PROCESS
= g_quark_from_string("running_process");
4451 LTTV_STATE_EVENT
= g_quark_from_string("event");
4452 LTTV_STATE_SAVED_STATES
= g_quark_from_string("saved states");
4453 LTTV_STATE_SAVED_STATES_TIME
= g_quark_from_string("saved states time");
4454 LTTV_STATE_TIME
= g_quark_from_string("time");
4455 LTTV_STATE_HOOKS
= g_quark_from_string("saved state hooks");
4456 LTTV_STATE_NAME_TABLES
= g_quark_from_string("name tables");
4457 LTTV_STATE_TRACE_STATE_USE_COUNT
=
4458 g_quark_from_string("trace_state_use_count");
4459 LTTV_STATE_RESOURCE_CPUS
= g_quark_from_string("cpu resource states");
4460 LTTV_STATE_RESOURCE_CPUS
= g_quark_from_string("cpu count");
4461 LTTV_STATE_RESOURCE_IRQS
= g_quark_from_string("irq resource states");
4462 LTTV_STATE_RESOURCE_SOFT_IRQS
= g_quark_from_string("soft irq resource states");
4463 LTTV_STATE_RESOURCE_TRAPS
= g_quark_from_string("trap resource states");
4464 LTTV_STATE_RESOURCE_BLKDEVS
= g_quark_from_string("blkdevs resource states");
4466 LTT_CHANNEL_FD_STATE
= g_quark_from_string("fd_state");
4467 LTT_CHANNEL_GLOBAL_STATE
= g_quark_from_string("global_state");
4468 LTT_CHANNEL_IRQ_STATE
= g_quark_from_string("irq_state");
4469 LTT_CHANNEL_MODULE_STATE
= g_quark_from_string("module_state");
4470 LTT_CHANNEL_NETIF_STATE
= g_quark_from_string("netif_state");
4471 LTT_CHANNEL_SOFTIRQ_STATE
= g_quark_from_string("softirq_state");
4472 LTT_CHANNEL_SWAP_STATE
= g_quark_from_string("swap_state");
4473 LTT_CHANNEL_SYSCALL_STATE
= g_quark_from_string("syscall_state");
4474 LTT_CHANNEL_TASK_STATE
= g_quark_from_string("task_state");
4475 LTT_CHANNEL_VM_STATE
= g_quark_from_string("vm_state");
4476 LTT_CHANNEL_KPROBE_STATE
= g_quark_from_string("kprobe_state");
4477 LTT_CHANNEL_FS
= g_quark_from_string("fs");
4478 LTT_CHANNEL_KERNEL
= g_quark_from_string("kernel");
4479 LTT_CHANNEL_MM
= g_quark_from_string("mm");
4480 LTT_CHANNEL_USERSPACE
= g_quark_from_string("userspace");
4481 LTT_CHANNEL_BLOCK
= g_quark_from_string("block");
4483 LTT_EVENT_SYSCALL_ENTRY
= g_quark_from_string("syscall_entry");
4484 LTT_EVENT_SYSCALL_EXIT
= g_quark_from_string("syscall_exit");
4485 LTT_EVENT_TRAP_ENTRY
= g_quark_from_string("trap_entry");
4486 LTT_EVENT_TRAP_EXIT
= g_quark_from_string("trap_exit");
4487 LTT_EVENT_PAGE_FAULT_ENTRY
= g_quark_from_string("page_fault_entry");
4488 LTT_EVENT_PAGE_FAULT_EXIT
= g_quark_from_string("page_fault_exit");
4489 LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
= g_quark_from_string("page_fault_nosem_entry");
4490 LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
= g_quark_from_string("page_fault_nosem_exit");
4491 LTT_EVENT_IRQ_ENTRY
= g_quark_from_string("irq_entry");
4492 LTT_EVENT_IRQ_EXIT
= g_quark_from_string("irq_exit");
4493 LTT_EVENT_SOFT_IRQ_RAISE
= g_quark_from_string("softirq_raise");
4494 LTT_EVENT_SOFT_IRQ_ENTRY
= g_quark_from_string("softirq_entry");
4495 LTT_EVENT_SOFT_IRQ_EXIT
= g_quark_from_string("softirq_exit");
4496 LTT_EVENT_SCHED_SCHEDULE
= g_quark_from_string("sched_schedule");
4497 LTT_EVENT_SCHED_TRY_WAKEUP
= g_quark_from_string("sched_try_wakeup");
4498 LTT_EVENT_PROCESS_FORK
= g_quark_from_string("process_fork");
4499 LTT_EVENT_KTHREAD_CREATE
= g_quark_from_string("kthread_create");
4500 LTT_EVENT_PROCESS_EXIT
= g_quark_from_string("process_exit");
4501 LTT_EVENT_PROCESS_FREE
= g_quark_from_string("process_free");
4502 LTT_EVENT_EXEC
= g_quark_from_string("exec");
4503 LTT_EVENT_PROCESS_STATE
= g_quark_from_string("process_state");
4504 LTT_EVENT_STATEDUMP_END
= g_quark_from_string("statedump_end");
4505 LTT_EVENT_FUNCTION_ENTRY
= g_quark_from_string("function_entry");
4506 LTT_EVENT_FUNCTION_EXIT
= g_quark_from_string("function_exit");
4507 LTT_EVENT_THREAD_BRAND
= g_quark_from_string("thread_brand");
4508 LTT_EVENT_REQUEST_ISSUE
= g_quark_from_string("_blk_request_issue");
4509 LTT_EVENT_REQUEST_COMPLETE
= g_quark_from_string("_blk_request_complete");
4510 LTT_EVENT_LIST_INTERRUPT
= g_quark_from_string("interrupt");
4511 LTT_EVENT_SYS_CALL_TABLE
= g_quark_from_string("sys_call_table");
4512 LTT_EVENT_SOFTIRQ_VEC
= g_quark_from_string("softirq_vec");
4513 LTT_EVENT_KPROBE_TABLE
= g_quark_from_string("kprobe_table");
4514 LTT_EVENT_KPROBE
= g_quark_from_string("kprobe");
4515 LTT_EVENT_OPEN
= g_quark_from_string("open");
4516 LTT_EVENT_READ
= g_quark_from_string("read");
4517 LTT_EVENT_POLL_EVENT
= g_quark_from_string("poll_event");
4519 LTT_FIELD_SYSCALL_ID
= g_quark_from_string("syscall_id");
4520 LTT_FIELD_TRAP_ID
= g_quark_from_string("trap_id");
4521 LTT_FIELD_IRQ_ID
= g_quark_from_string("irq_id");
4522 LTT_FIELD_SOFT_IRQ_ID
= g_quark_from_string("softirq_id");
4523 LTT_FIELD_PREV_PID
= g_quark_from_string("prev_pid");
4524 LTT_FIELD_NEXT_PID
= g_quark_from_string("next_pid");
4525 LTT_FIELD_PREV_STATE
= g_quark_from_string("prev_state");
4526 LTT_FIELD_PARENT_PID
= g_quark_from_string("parent_pid");
4527 LTT_FIELD_CHILD_PID
= g_quark_from_string("child_pid");
4528 LTT_FIELD_PID
= g_quark_from_string("pid");
4529 LTT_FIELD_TGID
= g_quark_from_string("tgid");
4530 LTT_FIELD_CHILD_TGID
= g_quark_from_string("child_tgid");
4531 LTT_FIELD_FILENAME
= g_quark_from_string("filename");
4532 LTT_FIELD_NAME
= g_quark_from_string("name");
4533 LTT_FIELD_TYPE
= g_quark_from_string("type");
4534 LTT_FIELD_MODE
= g_quark_from_string("mode");
4535 LTT_FIELD_SUBMODE
= g_quark_from_string("submode");
4536 LTT_FIELD_STATUS
= g_quark_from_string("status");
4537 LTT_FIELD_THIS_FN
= g_quark_from_string("this_fn");
4538 LTT_FIELD_CALL_SITE
= g_quark_from_string("call_site");
4539 LTT_FIELD_MAJOR
= g_quark_from_string("major");
4540 LTT_FIELD_MINOR
= g_quark_from_string("minor");
4541 LTT_FIELD_OPERATION
= g_quark_from_string("direction");
4542 LTT_FIELD_ACTION
= g_quark_from_string("action");
4543 LTT_FIELD_ID
= g_quark_from_string("id");
4544 LTT_FIELD_ADDRESS
= g_quark_from_string("address");
4545 LTT_FIELD_SYMBOL
= g_quark_from_string("symbol");
4546 LTT_FIELD_IP
= g_quark_from_string("ip");
4547 LTT_FIELD_FD
= g_quark_from_string("fd");
4548 LTT_FIELD_STATE
= g_quark_from_string("state");
4549 LTT_FIELD_CPU_ID
= g_quark_from_string("cpu_id");
4551 LTTV_CPU_UNKNOWN
= g_quark_from_string("unknown");
4552 LTTV_CPU_IDLE
= g_quark_from_string("idle");
4553 LTTV_CPU_BUSY
= g_quark_from_string("busy");
4554 LTTV_CPU_IRQ
= g_quark_from_string("irq");
4555 LTTV_CPU_SOFT_IRQ
= g_quark_from_string("softirq");
4556 LTTV_CPU_TRAP
= g_quark_from_string("trap");
4558 LTTV_IRQ_UNKNOWN
= g_quark_from_string("unknown");
4559 LTTV_IRQ_IDLE
= g_quark_from_string("idle");
4560 LTTV_IRQ_BUSY
= g_quark_from_string("busy");
4562 LTTV_BDEV_UNKNOWN
= g_quark_from_string("unknown");
4563 LTTV_BDEV_IDLE
= g_quark_from_string("idle");
4564 LTTV_BDEV_BUSY_READING
= g_quark_from_string("busy_reading");
4565 LTTV_BDEV_BUSY_WRITING
= g_quark_from_string("busy_writing");
4568 static void module_destroy()
4573 LTTV_MODULE("state", "State computation", \
4574 "Update the system state, possibly saving it at intervals", \
4575 module_init
, module_destroy
)