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,
23 #include <lttv/lttv.h>
24 #include <lttv/module.h>
25 #include <lttv/state.h>
26 #include <ltt/facility.h>
27 #include <ltt/trace.h>
28 #include <ltt/event.h>
32 #define PREALLOCATED_EXECUTION_STACK 10
34 /* Facilities Quarks */
44 LTT_EVENT_SYSCALL_ENTRY
,
45 LTT_EVENT_SYSCALL_EXIT
,
50 LTT_EVENT_SCHEDCHANGE
,
71 LTTV_STATE_MODE_UNKNOWN
,
78 LTTV_STATE_SUBMODE_UNKNOWN
,
79 LTTV_STATE_SUBMODE_NONE
;
92 LTTV_STATE_TRACEFILES
,
95 LTTV_STATE_RUNNING_PROCESS
,
97 LTTV_STATE_SAVED_STATES
,
98 LTTV_STATE_SAVED_STATES_TIME
,
101 LTTV_STATE_NAME_TABLES
,
102 LTTV_STATE_TRACE_STATE_USE_COUNT
;
104 static void create_max_time(LttvTraceState
*tcs
);
106 static void get_max_time(LttvTraceState
*tcs
);
108 static void free_max_time(LttvTraceState
*tcs
);
110 static void create_name_tables(LttvTraceState
*tcs
);
112 static void get_name_tables(LttvTraceState
*tcs
);
114 static void free_name_tables(LttvTraceState
*tcs
);
116 static void free_saved_state(LttvTraceState
*tcs
);
118 static void lttv_state_free_process_table(GHashTable
*processes
);
121 void lttv_state_save(LttvTraceState
*self
, LttvAttribute
*container
)
123 LTTV_TRACE_STATE_GET_CLASS(self
)->state_save(self
, container
);
127 void lttv_state_restore(LttvTraceState
*self
, LttvAttribute
*container
)
129 LTTV_TRACE_STATE_GET_CLASS(self
)->state_restore(self
, container
);
133 void lttv_state_state_saved_free(LttvTraceState
*self
,
134 LttvAttribute
*container
)
136 LTTV_TRACE_STATE_GET_CLASS(self
)->state_saved_free(self
, container
);
140 guint
process_hash(gconstpointer key
)
142 guint pid
= ((const LttvProcessState
*)key
)->pid
;
143 return (pid
>>8 ^ pid
>>4 ^ pid
>>2 ^ pid
) ;
147 /* If the hash table hash function is well distributed,
148 * the process_equal should compare different pid */
149 gboolean
process_equal(gconstpointer a
, gconstpointer b
)
151 const LttvProcessState
*process_a
, *process_b
;
154 process_a
= (const LttvProcessState
*)a
;
155 process_b
= (const LttvProcessState
*)b
;
157 if(likely(process_a
->pid
!= process_b
->pid
)) ret
= FALSE
;
158 else if(likely(process_a
->pid
== 0 &&
159 process_a
->cpu
!= process_b
->cpu
)) ret
= FALSE
;
166 restore_init_state(LttvTraceState
*self
)
170 LttvTracefileState
*tfcs
;
172 /* Free the process tables */
173 if(self
->processes
!= NULL
) lttv_state_free_process_table(self
->processes
);
174 self
->processes
= g_hash_table_new(process_hash
, process_equal
);
177 /* Seek time to beginning */
178 // Mathieu : fix : don't seek traceset here : causes inconsistency in seek
179 // closest. It's the tracecontext job to seek the trace to the beginning
180 // anyway : the init state might be used at the middle of the trace as well...
181 //g_tree_destroy(self->parent.ts_context->pqueue);
182 //self->parent.ts_context->pqueue = g_tree_new(compare_tracefile);
185 //lttv_process_trace_seek_time(&self->parent, ltt_time_zero);
187 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
189 /* Put the per cpu running_process to beginning state : process 0. */
190 for(i
=0; i
< nb_cpus
; i
++) {
191 self
->running_process
[i
] = lttv_state_create_process(self
, NULL
, i
, 0,
193 self
->running_process
[i
]->state
->s
= LTTV_STATE_RUN
;
194 self
->running_process
[i
]->cpu
= i
;
198 nb_tracefile
= self
->parent
.tracefiles
->len
;
200 for(i
= 0 ; i
< nb_tracefile
; i
++) {
202 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
203 LttvTracefileContext
*, i
));
204 ltt_trace_time_span_get(self
->parent
.t
, &tfcs
->parent
.timestamp
, NULL
);
205 // tfcs->saved_position = 0;
206 tfcs
->process
= lttv_state_create_process(tfcs
, NULL
,0);
207 tfcs
->process
->state
->s
= LTTV_STATE_RUN
;
208 tfcs
->process
->last_cpu
= tfcs
->cpu_name
;
209 tfcs
->process
->last_cpu_index
= ltt_tracefile_num(((LttvTracefileContext
*)tfcs
)->tf
);
214 //static LttTime time_zero = {0,0};
217 init(LttvTracesetState
*self
, LttvTraceset
*ts
)
219 guint i
, j
, nb_trace
, nb_tracefile
;
221 LttvTraceContext
*tc
;
225 LttvTracefileState
*tfcs
;
227 LttvAttributeValue v
;
229 LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
230 init((LttvTracesetContext
*)self
, ts
);
232 nb_trace
= lttv_traceset_number(ts
);
233 for(i
= 0 ; i
< nb_trace
; i
++) {
234 tc
= self
->parent
.traces
[i
];
235 tcs
= LTTV_TRACE_STATE(tc
);
236 tcs
->save_interval
= LTTV_STATE_SAVE_INTERVAL
;
237 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_TRACE_STATE_USE_COUNT
,
241 if(*(v
.v_uint
) == 1) {
242 create_name_tables(tcs
);
243 create_max_time(tcs
);
245 get_name_tables(tcs
);
248 nb_tracefile
= tc
->tracefiles
->len
;
250 for(j
= 0 ; j
< nb_tracefile
; j
++) {
252 LTTV_TRACEFILE_STATE(g_array_index(tc
->tracefiles
,
253 LttvTracefileContext
*, j
));
254 tfcs
->tracefile_name
= ltt_tracefile_name(tfcs
->parent
.tf
);
257 tcs
->processes
= NULL
;
258 tcs
->running_process
= g_new(LttvProcessState
*,
259 ltt_trace_get_num_cpu(tc
->t
));
260 restore_init_state(tcs
);
266 fini(LttvTracesetState
*self
)
272 LttvTracefileState
*tfcs
;
274 LttvAttributeValue v
;
276 nb_trace
= lttv_traceset_number(LTTV_TRACESET_CONTEXT(self
)->ts
);
277 for(i
= 0 ; i
< nb_trace
; i
++) {
278 tcs
= (LttvTraceState
*)(LTTV_TRACESET_CONTEXT(self
)->traces
[i
]);
279 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_TRACE_STATE_USE_COUNT
,
282 g_assert(*(v
.v_uint
) != 0);
285 if(*(v
.v_uint
) == 0) {
286 free_name_tables(tcs
);
288 free_saved_state(tcs
);
290 g_free(tcs
->running_process
);
291 tcs
->running_process
= NULL
;
292 lttv_state_free_process_table(tcs
->processes
);
293 tcs
->processes
= NULL
;
295 LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
296 fini((LttvTracesetContext
*)self
);
300 static LttvTracesetContext
*
301 new_traceset_context(LttvTracesetContext
*self
)
303 return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE
, NULL
));
307 static LttvTraceContext
*
308 new_trace_context(LttvTracesetContext
*self
)
310 return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE
, NULL
));
314 static LttvTracefileContext
*
315 new_tracefile_context(LttvTracesetContext
*self
)
317 return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE
, NULL
));
321 /* Write the process state of the trace */
323 static void write_process_state(gpointer key
, gpointer value
,
326 LttvProcessState
*process
;
328 LttvExecutionState
*es
;
330 FILE *fp
= (FILE *)user_data
;
334 process
= (LttvProcessState
*)value
;
336 " <PROCESS CORE=%p PID=%u PPID=%u CTIME_S=%lu CTIME_NS=%lu NAME=\"%s\" CPU=\"%u\">\n",
337 process
, process
->pid
, process
->ppid
, process
->creation_time
.tv_sec
,
338 process
->creation_time
.tv_nsec
, g_quark_to_string(process
->name
),
341 for(i
= 0 ; i
< process
->execution_stack
->len
; i
++) {
342 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, i
);
343 fprintf(fp
, " <ES MODE=\"%s\" SUBMODE=\"%s\" ENTRY_S=%lu ENTRY_NS=%lu",
344 g_quark_to_string(es
->t
), g_quark_to_string(es
->n
),
345 es
->entry
.tv_sec
, es
->entry
.tv_nsec
);
346 fprintf(fp
, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n",
347 es
->change
.tv_sec
, es
->change
.tv_nsec
, g_quark_to_string(es
->s
));
349 fprintf(fp
, " </PROCESS>\n");
353 void lttv_state_write(LttvTraceState
*self
, LttTime t
, FILE *fp
)
355 guint i
, nb_tracefile
, nb_block
, offset
;
358 LttvTracefileState
*tfcs
;
362 LttEventPosition
*ep
;
366 ep
= ltt_event_position_new();
368 fprintf(fp
,"<PROCESS_STATE TIME_S=%lu TIME_NS=%lu>\n", t
.tv_sec
, t
.tv_nsec
);
370 g_hash_table_foreach(self
->processes
, write_process_state
, fp
);
372 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
373 for(i
=0;i
<nb_cpus
;i
++) {
374 fprintf(fp
,"<CPU NUM=%u RUNNING_PROCESS=%u>\n",
375 i
, self
->running_process
[i
]->pid
);
378 nb_tracefile
= self
->parent
.tracefiles
->len
;
380 for(i
= 0 ; i
< nb_tracefile
; i
++) {
382 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
383 LttvTracefileContext
*, i
));
384 fprintf(fp
, " <TRACEFILE TIMESTAMP_S=%lu TIMESTAMP_NS=%lu",
385 tfcs
->parent
.timestamp
.tv_sec
,
386 tfcs
->parent
.timestamp
.tv_nsec
);
387 LttEvent
*e
= ltt_tracefile_get_event(tfcs
->parent
.tf
);
388 if(e
== NULL
) fprintf(fp
,"/>\n");
390 ltt_event_position(e
, ep
);
391 ltt_event_position_get(ep
, &tf
, &nb_block
, &offset
, &tsc
);
392 fprintf(fp
, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block
, offset
,
397 fprintf(fp
,"</PROCESS_STATE>");
401 /* Copy each process from an existing hash table to a new one */
403 static void copy_process_state(gpointer key
, gpointer value
,gpointer user_data
)
405 LttvProcessState
*process
, *new_process
;
407 GHashTable
*new_processes
= (GHashTable
*)user_data
;
411 process
= (LttvProcessState
*)value
;
412 new_process
= g_new(LttvProcessState
, 1);
413 *new_process
= *process
;
414 new_process
->execution_stack
= g_array_sized_new(FALSE
, FALSE
,
415 sizeof(LttvExecutionState
), PREALLOCATED_EXECUTION_STACK
);
416 new_process
->execution_stack
=
417 g_array_set_size(new_process
->execution_stack
,
418 process
->execution_stack
->len
);
419 for(i
= 0 ; i
< process
->execution_stack
->len
; i
++) {
420 g_array_index(new_process
->execution_stack
, LttvExecutionState
, i
) =
421 g_array_index(process
->execution_stack
, LttvExecutionState
, i
);
423 new_process
->state
= &g_array_index(new_process
->execution_stack
,
424 LttvExecutionState
, new_process
->execution_stack
->len
- 1);
425 g_hash_table_insert(new_processes
, new_process
, new_process
);
429 static GHashTable
*lttv_state_copy_process_table(GHashTable
*processes
)
431 GHashTable
*new_processes
= g_hash_table_new(process_hash
, process_equal
);
433 g_hash_table_foreach(processes
, copy_process_state
, new_processes
);
434 return new_processes
;
438 /* The saved state for each trace contains a member "processes", which
439 stores a copy of the process table, and a member "tracefiles" with
440 one entry per tracefile. Each tracefile has a "process" member pointing
441 to the current process and a "position" member storing the tracefile
442 position (needed to seek to the current "next" event. */
444 static void state_save(LttvTraceState
*self
, LttvAttribute
*container
)
446 guint i
, nb_tracefile
, nb_cpus
;
448 LttvTracefileState
*tfcs
;
450 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
452 guint
*running_process
;
454 LttvAttributeType type
;
456 LttvAttributeValue value
;
458 LttvAttributeName name
;
460 LttEventPosition
*ep
;
462 tracefiles_tree
= lttv_attribute_find_subdir(container
,
463 LTTV_STATE_TRACEFILES
);
465 value
= lttv_attribute_add(container
, LTTV_STATE_PROCESSES
,
467 *(value
.v_pointer
) = lttv_state_copy_process_table(self
->processes
);
469 /* Add the currently running processes array */
470 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
471 running_process
= g_new(guint
, nb_cpus
);
472 for(i
=0;i
<nb_cpus
;i
++) {
473 running_process
[i
] = self
->running_process
[i
]->pid
;
475 value
= lttv_attribute_add(container
, LTTV_STATE_RUNNING_PROCESS
,
477 *(value
.v_pointer
) = running_process
;
479 g_info("State save");
481 nb_tracefile
= self
->parent
.tracefiles
->len
;
483 for(i
= 0 ; i
< nb_tracefile
; i
++) {
485 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
486 LttvTracefileContext
*, i
));
487 tracefile_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
488 value
= lttv_attribute_add(tracefiles_tree
, i
,
490 *(value
.v_gobject
) = (GObject
*)tracefile_tree
;
492 value
= lttv_attribute_add(tracefile_tree
, LTTV_STATE_PROCESS
,
494 *(value
.v_uint
) = tfcs
->process
->pid
;
496 value
= lttv_attribute_add(tracefile_tree
, LTTV_STATE_EVENT
,
498 /* Only save the position if the tfs has not infinite time. */
499 //if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent)
500 // && current_tfcs != tfcs) {
501 if(ltt_time_compare(tfcs
->parent
.timestamp
, ltt_time_infinite
) == 0) {
502 *(value
.v_pointer
) = NULL
;
504 LttEvent
*e
= ltt_tracefile_get_event(tfcs
->parent
.tf
);
505 ep
= ltt_event_position_new();
506 ltt_event_position(e
, ep
);
507 *(value
.v_pointer
) = ep
;
509 guint nb_block
, offset
;
512 ltt_event_position_get(ep
, &tf
, &nb_block
, &offset
, &tsc
);
513 g_info("Block %u offset %u tsc %llu time %lu.%lu", nb_block
, offset
,
515 tfcs
->parent
.timestamp
.tv_sec
, tfcs
->parent
.timestamp
.tv_nsec
);
521 static void state_restore(LttvTraceState
*self
, LttvAttribute
*container
)
523 guint i
, nb_tracefile
, pid
, nb_cpus
;
525 LttvTracefileState
*tfcs
;
527 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
529 guint
*running_process
;
531 LttvAttributeType type
;
533 LttvAttributeValue value
;
535 LttvAttributeName name
;
537 LttEventPosition
*ep
;
539 LttvTracesetContext
*tsc
= self
->parent
.ts_context
;
541 tracefiles_tree
= lttv_attribute_find_subdir(container
,
542 LTTV_STATE_TRACEFILES
);
544 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_PROCESSES
,
546 g_assert(type
== LTTV_POINTER
);
547 lttv_state_free_process_table(self
->processes
);
548 self
->processes
= lttv_state_copy_process_table(*(value
.v_pointer
));
550 /* Add the currently running processes array */
551 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
552 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RUNNING_PROCESS
,
554 g_assert(type
== LTTV_POINTER
);
555 running_process
= *(value
.v_pointer
);
556 for(i
=0;i
<nb_cpus
;i
++) {
557 pid
= running_process
[i
];
558 self
->running_process
[i
] = lttv_state_find_process(self
, i
, pid
);
559 g_assert(self
->running_process
[i
] != NULL
);
563 nb_tracefile
= self
->parent
.tracefiles
->len
;
565 //g_tree_destroy(tsc->pqueue);
566 //tsc->pqueue = g_tree_new(compare_tracefile);
568 for(i
= 0 ; i
< nb_tracefile
; i
++) {
570 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
571 LttvTracefileContext
*, i
));
572 type
= lttv_attribute_get(tracefiles_tree
, i
, &name
, &value
);
573 g_assert(type
== LTTV_GOBJECT
);
574 tracefile_tree
= *((LttvAttribute
**)(value
.v_gobject
));
576 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_PROCESS
,
578 g_assert(type
== LTTV_UINT
);
579 pid
= *(value
.v_uint
);
580 tfcs
->process
= lttv_state_find_process_or_create(tfcs
, pid
);
582 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_EVENT
,
584 g_assert(type
== LTTV_POINTER
);
585 //g_assert(*(value.v_pointer) != NULL);
586 ep
= *(value
.v_pointer
);
587 g_assert(tfcs
->parent
.t_context
!= NULL
);
589 LttvTracefileContext
*tfc
= LTTV_TRACEFILE_CONTEXT(tfcs
);
590 g_tree_remove(tsc
->pqueue
, tfc
);
593 g_assert(ltt_tracefile_seek_position(tfc
->tf
, ep
) == 0);
594 tfc
->timestamp
= ltt_event_time(ltt_tracefile_get_event(tfc
->tf
));
595 g_assert(ltt_time_compare(tfc
->timestamp
, ltt_time_infinite
) != 0);
596 g_tree_insert(tsc
->pqueue
, tfc
, tfc
);
597 g_info("Restoring state for a tf at time %lu.%lu", tfc
->timestamp
.tv_sec
, tfc
->timestamp
.tv_nsec
);
599 tfc
->timestamp
= ltt_time_infinite
;
605 static void state_saved_free(LttvTraceState
*self
, LttvAttribute
*container
)
607 guint i
, nb_tracefile
, nb_cpus
;
609 LttvTracefileState
*tfcs
;
611 LttvAttribute
*tracefiles_tree
, *tracefile_tree
;
613 guint
*running_process
;
615 LttvAttributeType type
;
617 LttvAttributeValue value
;
619 LttvAttributeName name
;
621 LttEventPosition
*ep
;
623 tracefiles_tree
= lttv_attribute_find_subdir(container
,
624 LTTV_STATE_TRACEFILES
);
625 g_object_ref(G_OBJECT(tracefiles_tree
));
626 lttv_attribute_remove_by_name(container
, LTTV_STATE_TRACEFILES
);
628 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_PROCESSES
,
630 g_assert(type
== LTTV_POINTER
);
631 lttv_state_free_process_table(*(value
.v_pointer
));
632 *(value
.v_pointer
) = NULL
;
633 lttv_attribute_remove_by_name(container
, LTTV_STATE_PROCESSES
);
635 /* Free running processes array */
636 nb_cpus
= ltt_trace_get_num_cpu(self
->parent
.t
);
637 type
= lttv_attribute_get_by_name(container
, LTTV_STATE_RUNNING_PROCESS
,
639 g_assert(type
== LTTV_POINTER
);
640 running_process
= *(value
.v_pointer
);
641 g_free(running_process
);
643 nb_tracefile
= self
->parent
.tracefiles
->len
;
645 for(i
= 0 ; i
< nb_tracefile
; i
++) {
647 LTTV_TRACEFILE_STATE(g_array_index(self
->parent
.tracefiles
,
648 LttvTracefileContext
*, i
));
649 type
= lttv_attribute_get(tracefiles_tree
, i
, &name
, &value
);
650 g_assert(type
== LTTV_GOBJECT
);
651 tracefile_tree
= *((LttvAttribute
**)(value
.v_gobject
));
653 type
= lttv_attribute_get_by_name(tracefile_tree
, LTTV_STATE_EVENT
,
655 g_assert(type
== LTTV_POINTER
);
656 if(*(value
.v_pointer
) != NULL
) g_free(*(value
.v_pointer
));
658 g_object_unref(G_OBJECT(tracefiles_tree
));
662 static void free_saved_state(LttvTraceState
*self
)
666 LttvAttributeType type
;
668 LttvAttributeValue value
;
670 LttvAttributeName name
;
672 LttvAttribute
*saved_states
;
674 saved_states
= lttv_attribute_find_subdir(self
->parent
.t_a
,
675 LTTV_STATE_SAVED_STATES
);
677 nb
= lttv_attribute_get_number(saved_states
);
678 for(i
= 0 ; i
< nb
; i
++) {
679 type
= lttv_attribute_get(saved_states
, i
, &name
, &value
);
680 g_assert(type
== LTTV_GOBJECT
);
681 state_saved_free(self
, *((LttvAttribute
**)value
.v_gobject
));
684 lttv_attribute_remove_by_name(self
->parent
.t_a
, LTTV_STATE_SAVED_STATES
);
689 create_max_time(LttvTraceState
*tcs
)
691 LttvAttributeValue v
;
693 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
695 g_assert(*(v
.v_pointer
) == NULL
);
696 *(v
.v_pointer
) = g_new(LttTime
,1);
697 *((LttTime
*)*(v
.v_pointer
)) = ltt_time_zero
;
702 get_max_time(LttvTraceState
*tcs
)
704 LttvAttributeValue v
;
706 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
708 g_assert(*(v
.v_pointer
) != NULL
);
709 tcs
->max_time_state_recomputed_in_seek
= (LttTime
*)*(v
.v_pointer
);
714 free_max_time(LttvTraceState
*tcs
)
716 LttvAttributeValue v
;
718 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_SAVED_STATES_TIME
,
720 g_free(*(v
.v_pointer
));
721 *(v
.v_pointer
) = NULL
;
725 typedef struct _LttvNameTables
{
726 // FIXME GQuark *eventtype_names;
727 GQuark
*syscall_names
;
734 create_name_tables(LttvTraceState
*tcs
)
738 GQuark f_name
, e_name
;
742 LttvTraceHookByFacility
*thf
;
748 GString
*fe_name
= g_string_new("");
750 LttvNameTables
*name_tables
= g_new(LttvNameTables
, 1);
752 LttvAttributeValue v
;
754 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
756 g_assert(*(v
.v_pointer
) == NULL
);
757 *(v
.v_pointer
) = name_tables
;
758 #if 0 // Use iteration over the facilities_by_name and then list all event
759 // types of each facility
760 nb
= ltt_trace_eventtype_number(tcs
->parent
.t
);
761 name_tables
->eventtype_names
= g_new(GQuark
, nb
);
762 for(i
= 0 ; i
< nb
; i
++) {
763 et
= ltt_trace_eventtype_get(tcs
->parent
.t
, i
);
764 e_name
= ltt_eventtype_name(et
);
765 f_name
= ltt_facility_name(ltt_eventtype_facility(et
));
766 g_string_printf(fe_name
, "%s.%s", f_name
, e_name
);
767 name_tables
->eventtype_names
[i
] = g_quark_from_string(fe_name
->str
);
770 if(lttv_trace_find_hook(tcs
->parent
.t
,
771 LTT_FACILITY_KERNEL
, LTT_EVENT_SYSCALL_ENTRY
,
772 LTT_FIELD_SYSCALL_ID
, 0, 0,
776 thf
= lttv_trace_hook_get_first(&h
);
778 t
= ltt_field_type(thf
->f1
);
779 nb
= ltt_type_element_number(t
);
781 lttv_trace_hook_destroy(&h
);
783 /* CHECK syscalls should be an enum but currently are not!
784 name_tables->syscall_names = g_new(GQuark, nb);
786 for(i = 0 ; i < nb ; i++) {
787 name_tables->syscall_names[i] = g_quark_from_string(
788 ltt_enum_string_get(t, i));
792 name_tables
->syscall_names
= g_new(GQuark
, 256);
793 for(i
= 0 ; i
< 256 ; i
++) {
794 g_string_printf(fe_name
, "syscall %d", i
);
795 name_tables
->syscall_names
[i
] = g_quark_from_string(fe_name
->str
);
798 if(lttv_trace_find_hook(tcs
->parent
.t
, LTT_FACILITY_KERNEL
,
799 LTT_EVENT_TRAP_ENTRY
,
800 LTT_FIELD_TRAP_ID
, 0, 0,
804 thf
= lttv_trace_hook_get_first(&h
);
806 t
= ltt_field_type(thf
->f1
);
807 nb
= ltt_type_element_number(t
);
809 lttv_trace_hook_destroy(&h
);
812 name_tables->trap_names = g_new(GQuark, nb);
813 for(i = 0 ; i < nb ; i++) {
814 name_tables->trap_names[i] = g_quark_from_string(
815 ltt_enum_string_get(t, i));
819 name_tables
->trap_names
= g_new(GQuark
, 256);
820 for(i
= 0 ; i
< 256 ; i
++) {
821 g_string_printf(fe_name
, "trap %d", i
);
822 name_tables
->trap_names
[i
] = g_quark_from_string(fe_name
->str
);
825 if(lttv_trace_find_hook(tcs
->parent
.t
,
826 LTT_FACILITY_KERNEL
, LTT_EVENT_IRQ_ENTRY
,
827 LTT_FIELD_IRQ_ID
, 0, 0,
831 thf
= lttv_trace_hook_get_first(&h
);
833 t
= ltt_field_type(thf
->f1
);
834 nb
= ltt_type_element_number(t
);
836 lttv_trace_hook_destroy(&h
);
839 name_tables->irq_names = g_new(GQuark, nb);
840 for(i = 0 ; i < nb ; i++) {
841 name_tables->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i));
845 name_tables
->irq_names
= g_new(GQuark
, 256);
846 for(i
= 0 ; i
< 256 ; i
++) {
847 g_string_printf(fe_name
, "irq %d", i
);
848 name_tables
->irq_names
[i
] = g_quark_from_string(fe_name
->str
);
851 g_string_free(fe_name
, TRUE
);
856 get_name_tables(LttvTraceState
*tcs
)
858 LttvNameTables
*name_tables
;
860 LttvAttributeValue v
;
862 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
864 g_assert(*(v
.v_pointer
) != NULL
);
865 name_tables
= (LttvNameTables
*)*(v
.v_pointer
);
866 //tcs->eventtype_names = name_tables->eventtype_names;
867 tcs
->syscall_names
= name_tables
->syscall_names
;
868 tcs
->trap_names
= name_tables
->trap_names
;
869 tcs
->irq_names
= name_tables
->irq_names
;
874 free_name_tables(LttvTraceState
*tcs
)
876 LttvNameTables
*name_tables
;
878 LttvAttributeValue v
;
880 lttv_attribute_find(tcs
->parent
.t_a
, LTTV_STATE_NAME_TABLES
,
882 name_tables
= (LttvNameTables
*)*(v
.v_pointer
);
883 *(v
.v_pointer
) = NULL
;
885 // g_free(name_tables->eventtype_names);
886 g_free(name_tables
->syscall_names
);
887 g_free(name_tables
->trap_names
);
888 g_free(name_tables
->irq_names
);
892 #ifdef HASH_TABLE_DEBUG
894 static void test_process(gpointer key
, gpointer value
, gpointer user_data
)
896 LttvProcessState
*process
= (LttvProcessState
*)value
;
898 /* Test for process corruption */
899 guint stack_len
= process
->execution_stack
->len
;
902 static void hash_table_check(GHashTable
*table
)
904 g_hash_table_foreach(table
, test_process
, NULL
);
911 static void push_state(LttvTracefileState
*tfs
, LttvExecutionMode t
,
914 LttvExecutionState
*es
;
916 guint cpu
= ltt_tracefile_num(tfs
->parent
.tf
);
917 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
919 #ifdef HASH_TABLE_DEBUG
920 hash_table_check(ts
->processes
);
922 LttvProcessState
*process
= ts
->running_process
[cpu
];
924 guint depth
= process
->execution_stack
->len
;
926 process
->execution_stack
=
927 g_array_set_size(process
->execution_stack
, depth
+ 1);
930 &g_array_index(process
->execution_stack
, LttvExecutionState
, depth
- 1);
932 es
= &g_array_index(process
->execution_stack
, LttvExecutionState
, depth
);
935 es
->entry
= es
->change
= tfs
->parent
.timestamp
;
936 es
->s
= process
->state
->s
;
941 static void pop_state(LttvTracefileState
*tfs
, LttvExecutionMode t
)
943 guint cpu
= ltt_tracefile_num(tfs
->parent
.tf
);
944 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
945 LttvProcessState
*process
= ts
->running_process
[cpu
];
947 guint depth
= process
->execution_stack
->len
;
949 if(process
->state
->t
!= t
){
950 g_info("Different execution mode type (%lu.%09lu): ignore it\n",
951 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
952 g_info("process state has %s when pop_int is %s\n",
953 g_quark_to_string(process
->state
->t
),
954 g_quark_to_string(t
));
955 g_info("{ %u, %u, %s, %s }\n",
958 g_quark_to_string(process
->name
),
959 g_quark_to_string(process
->state
->s
));
964 g_info("Trying to pop last state on stack (%lu.%09lu): ignore it\n",
965 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
969 process
->execution_stack
=
970 g_array_set_size(process
->execution_stack
, depth
- 1);
971 process
->state
= &g_array_index(process
->execution_stack
, LttvExecutionState
,
973 process
->state
->change
= tfs
->parent
.timestamp
;
978 lttv_state_create_process(LttvTraceState
*tcs
, LttvProcessState
*parent
,
979 guint cpu
, guint pid
, const LttTime
*timestamp
)
981 LttvProcessState
*process
= g_new(LttvProcessState
, 1);
983 LttvExecutionState
*es
;
985 LttvTraceContext
*tc
= (LttvTraceContext
*)tcs
;
991 //process->last_cpu = tfs->cpu_name;
992 //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
993 g_info("Process %u, core %p", process
->pid
, process
);
994 g_hash_table_insert(tcs
->processes
, process
, process
);
997 process
->ppid
= parent
->pid
;
998 process
->name
= parent
->name
;
999 process
->creation_time
= *timestamp
;
1002 /* No parent. This process exists but we are missing all information about
1003 its creation. The birth time is set to zero but we remember the time of
1008 process
->name
= LTTV_STATE_UNNAMED
;
1009 process
->creation_time
= ltt_time_zero
;
1012 process
->insertion_time
= *timestamp
;
1013 sprintf(buffer
,"%d-%lu.%lu",pid
, process
->creation_time
.tv_sec
,
1014 process
->creation_time
.tv_nsec
);
1015 process
->pid_time
= g_quark_from_string(buffer
);
1017 //process->last_cpu = tfs->cpu_name;
1018 //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
1019 process
->execution_stack
= g_array_sized_new(FALSE
, FALSE
,
1020 sizeof(LttvExecutionState
), PREALLOCATED_EXECUTION_STACK
);
1021 process
->execution_stack
= g_array_set_size(process
->execution_stack
, 2);
1022 es
= process
->state
= &g_array_index(process
->execution_stack
,
1023 LttvExecutionState
, 0);
1024 es
->t
= LTTV_STATE_USER_MODE
;
1025 es
->n
= LTTV_STATE_SUBMODE_NONE
;
1026 es
->entry
= *timestamp
;
1027 //g_assert(timestamp->tv_sec != 0);
1028 es
->change
= *timestamp
;
1029 es
->s
= LTTV_STATE_RUN
;
1031 es
= process
->state
= &g_array_index(process
->execution_stack
,
1032 LttvExecutionState
, 1);
1033 es
->t
= LTTV_STATE_SYSCALL
;
1034 es
->n
= LTTV_STATE_SUBMODE_NONE
;
1035 es
->entry
= *timestamp
;
1036 //g_assert(timestamp->tv_sec != 0);
1037 es
->change
= *timestamp
;
1038 es
->s
= LTTV_STATE_WAIT_FORK
;
1043 LttvProcessState
*lttv_state_find_process(LttvTraceState
*ts
, guint cpu
,
1046 LttvProcessState key
;
1047 LttvProcessState
*process
;
1051 process
= g_hash_table_lookup(ts
->processes
, &key
);
1056 lttv_state_find_process_or_create(LttvTraceState
*ts
, guint cpu
, guint pid
,
1059 LttvProcessState
*process
= lttv_state_find_process(ts
, cpu
, pid
);
1061 /* Put ltt_time_zero creation time for unexisting processes */
1062 if(unlikely(process
== NULL
)) process
= lttv_state_create_process(ts
,
1063 NULL
, cpu
, pid
, timestamp
);
1067 /* FIXME : this function should be called when we receive an event telling that
1068 * release_task has been called in the kernel. In happens generally when
1069 * the parent waits for its child terminaison, but may also happen in special
1070 * cases in the child's exit : when the parent ignores its children SIGCCHLD or
1071 * has the flag SA_NOCLDWAIT. It can also happen when the child is part
1072 * of a killed thread ground, but isn't the leader.
1074 static void exit_process(LttvTracefileState
*tfs
, LttvProcessState
*process
)
1076 LttvTraceState
*ts
= LTTV_TRACE_STATE(tfs
->parent
.t_context
);
1077 LttvProcessState key
;
1079 key
.pid
= process
->pid
;
1080 key
.cpu
= process
->cpu
;
1081 g_hash_table_remove(ts
->processes
, &key
);
1082 g_array_free(process
->execution_stack
, TRUE
);
1087 static void free_process_state(gpointer key
, gpointer value
,gpointer user_data
)
1089 g_array_free(((LttvProcessState
*)value
)->execution_stack
, TRUE
);
1094 static void lttv_state_free_process_table(GHashTable
*processes
)
1096 g_hash_table_foreach(processes
, free_process_state
, NULL
);
1097 g_hash_table_destroy(processes
);
1101 static gboolean
syscall_entry(void *hook_data
, void *call_data
)
1103 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1104 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1105 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1106 LttField
*f
= thf
->f1
;
1108 LttvExecutionSubmode submode
;
1110 submode
= ((LttvTraceState
*)(s
->parent
.t_context
))->syscall_names
[
1111 ltt_event_get_unsigned(e
, f
)];
1112 push_state(s
, LTTV_STATE_SYSCALL
, submode
);
1117 static gboolean
syscall_exit(void *hook_data
, void *call_data
)
1119 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1121 pop_state(s
, LTTV_STATE_SYSCALL
);
1126 static gboolean
trap_entry(void *hook_data
, void *call_data
)
1128 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1129 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1130 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1131 LttField
*f
= thf
->f1
;
1133 LttvExecutionSubmode submode
;
1135 submode
= ((LttvTraceState
*)(s
->parent
.t_context
))->trap_names
[
1136 ltt_event_get_unsigned(e
, f
)];
1137 push_state(s
, LTTV_STATE_TRAP
, submode
);
1142 static gboolean
trap_exit(void *hook_data
, void *call_data
)
1144 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1146 pop_state(s
, LTTV_STATE_TRAP
);
1151 static gboolean
irq_entry(void *hook_data
, void *call_data
)
1153 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1154 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1155 guint8 fac_id
= ltt_event_facility_id(e
);
1156 guint8 ev_id
= ltt_event_eventtype_id(e
);
1157 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1158 // g_assert(lttv_trace_hook_get_first((LttvTraceHook *)hook_data)->f1 != NULL);
1159 g_assert(thf
->f1
!= NULL
);
1160 // g_assert(thf == lttv_trace_hook_get_first((LttvTraceHook *)hook_data));
1161 LttField
*f
= thf
->f1
;
1163 LttvExecutionSubmode submode
;
1165 submode
= ((LttvTraceState
*)(s
->parent
.t_context
))->irq_names
[
1166 ltt_event_get_unsigned(e
, f
)];
1168 /* Do something with the info about being in user or system mode when int? */
1169 push_state(s
, LTTV_STATE_IRQ
, submode
);
1174 static gboolean
irq_exit(void *hook_data
, void *call_data
)
1176 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1178 pop_state(s
, LTTV_STATE_IRQ
);
1183 static gboolean
schedchange(void *hook_data
, void *call_data
)
1185 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1186 guint cpu
= ltt_tracefile_num(s
->parent
.tf
);
1187 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
1188 LttvProcessState
*process
= ts
->running_process
[cpu
];
1190 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1191 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1192 guint pid_in
, pid_out
;
1195 pid_out
= ltt_event_get_unsigned(e
, thf
->f1
);
1196 pid_in
= ltt_event_get_unsigned(e
, thf
->f2
);
1197 state_out
= ltt_event_get_int(e
, thf
->f3
);
1199 if(likely(process
!= NULL
)) {
1201 /* We could not know but it was not the idle process executing.
1202 This should only happen at the beginning, before the first schedule
1203 event, and when the initial information (current process for each CPU)
1204 is missing. It is not obvious how we could, after the fact, compensate
1205 the wrongly attributed statistics. */
1207 //This test only makes sense once the state is known and if there is no
1209 //if(unlikely(process->pid != pid_out)) {
1210 // g_assert(process->pid == 0);
1213 if(unlikely(process
->state
->s
== LTTV_STATE_EXIT
)) {
1214 process
->state
->s
= LTTV_STATE_ZOMBIE
;
1215 process
->state
->change
= s
->parent
.timestamp
;
1217 if(unlikely(state_out
== 0)) process
->state
->s
= LTTV_STATE_WAIT_CPU
;
1218 else process
->state
->s
= LTTV_STATE_WAIT
;
1219 process
->state
->change
= s
->parent
.timestamp
;
1223 exit_process(s
, process
); /* EXIT_DEAD */
1224 /* see sched.h for states */
1226 process
= ts
->running_process
[cpu
] =
1227 lttv_state_find_process_or_create(
1228 (LttvTraceState
*)s
->parent
.t_context
,
1230 &s
->parent
.timestamp
);
1231 process
->state
->s
= LTTV_STATE_RUN
;
1233 // process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
1234 process
->state
->change
= s
->parent
.timestamp
;
1238 static gboolean
process_fork(void *hook_data
, void *call_data
)
1240 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1241 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1242 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1246 LttvProcessState
*zombie_process
;
1247 guint cpu
= ltt_tracefile_num(s
->parent
.tf
);
1248 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
1249 LttvProcessState
*process
= ts
->running_process
[cpu
];
1250 LttvProcessState
*child_process
;
1254 parent_pid
= ltt_event_get_unsigned(e
, f
);
1258 child_pid
= ltt_event_get_unsigned(e
, f
);
1260 /* Mathieu : it seems like the process might have been scheduled in before the
1261 * fork, and, in a rare case, might be the current process. This might happen
1262 * in a SMP case where we don't have enough precision on the clocks.
1264 * Test reenabled after precision fixes on time. (Mathieu) */
1266 zombie_process
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1268 if(unlikely(zombie_process
!= NULL
)) {
1269 /* Reutilisation of PID. Only now we are sure that the old PID
1270 * has been released. FIXME : should know when release_task happens instead.
1272 guint num_cpus
= ltt_trace_get_num_cpu(ts
->parent
.t
);
1274 for(i
=0; i
< num_cpus
; i
++) {
1275 g_assert(zombie_process
!= ts
->running_process
[i
]);
1278 exit_process(s
, zombie_process
);
1281 g_assert(process
->pid
!= child_pid
);
1282 // FIXME : Add this test in the "known state" section
1283 // g_assert(process->pid == parent_pid);
1284 child_process
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1285 if(child_process
== NULL
) {
1286 lttv_state_create_process(ts
, process
, cpu
,
1287 child_pid
, &s
->parent
.timestamp
);
1289 /* The process has already been created : due to time imprecision between
1290 * multiple CPUs : it has been scheduled in before creation. Note that we
1291 * shouldn't have this kind of imprecision.
1293 * Simply put a correct parent.
1295 g_assert(0); /* This is a problematic case : the process has been created
1296 before the fork event */
1297 child_process
->ppid
= process
->pid
;
1304 static gboolean
process_exit(void *hook_data
, void *call_data
)
1306 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1307 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1308 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1311 guint cpu
= ltt_tracefile_num(s
->parent
.tf
);
1312 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
1313 LttvProcessState
*process
= ts
->running_process
[cpu
];
1315 pid
= ltt_event_get_unsigned(e
, thf
->f1
);
1317 // FIXME : Add this test in the "known state" section
1318 // g_assert(process->pid == pid);
1320 if(likely(process
!= NULL
)) {
1321 process
->state
->s
= LTTV_STATE_EXIT
;
1326 static gboolean
process_free(void *hook_data
, void *call_data
)
1328 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1329 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
1330 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1331 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1333 LttvProcessState
*process
;
1335 /* PID of the process to release */
1336 release_pid
= ltt_event_get_unsigned(e
, thf
->f1
);
1338 g_assert(release_pid
!= 0);
1340 process
= lttv_state_find_process(ts
, ANY_CPU
, release_pid
);
1342 if(likely(process
!= NULL
)) {
1343 /* release_task is happening at kernel level : we can now safely release
1344 * the data structure of the process */
1345 //This test is fun, though, as it may happen that
1346 //at time t : CPU 0 : process_free
1347 //at time t+150ns : CPU 1 : schedule out
1348 //Clearly due to time imprecision, we disable it. (Mathieu)
1349 //If this weird case happen, we have no choice but to put the
1350 //Currently running process on the cpu to 0.
1351 //I re-enable it following time precision fixes. (Mathieu)
1352 //Well, in the case where an process is freed by a process on another CPU
1353 //and still scheduled, it happens that this is the schedchange that will
1354 //drop the last reference count. Do not free it here!
1355 guint num_cpus
= ltt_trace_get_num_cpu(ts
->parent
.t
);
1357 for(i
=0; i
< num_cpus
; i
++) {
1358 //g_assert(process != ts->running_process[i]);
1359 if(process
== ts
->running_process
[i
]) {
1360 //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1364 if(i
== num_cpus
) /* process is not scheduled */
1365 exit_process(s
, process
);
1372 static gboolean
process_exec(void *hook_data
, void *call_data
)
1374 LttvTracefileState
*s
= (LttvTracefileState
*)call_data
;
1375 LttvTraceState
*ts
= (LttvTraceState
*)s
->parent
.t_context
;
1376 LttEvent
*e
= ltt_tracefile_get_event(s
->parent
.tf
);
1377 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1379 guint cpu
= ltt_tracefile_num(s
->parent
.tf
);
1380 LttvProcessState
*process
= ts
->running_process
[cpu
];
1382 /* PID of the process to release */
1383 name
= ltt_event_get_string(e
, thf
->f1
);
1385 process
->name
= g_quark_from_string(name
);
1393 gint
lttv_state_hook_add_event_hooks(void *hook_data
, void *call_data
)
1395 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
1397 lttv_state_add_event_hooks(tss
);
1402 void lttv_state_add_event_hooks(LttvTracesetState
*self
)
1404 LttvTraceset
*traceset
= self
->parent
.ts
;
1406 guint i
, j
, k
, l
, nb_trace
, nb_tracefile
;
1410 LttvTracefileState
*tfs
;
1414 LttvTraceHookByFacility
*thf
;
1416 LttvTraceHook
*hook
;
1418 LttvAttributeValue val
;
1422 nb_trace
= lttv_traceset_number(traceset
);
1423 for(i
= 0 ; i
< nb_trace
; i
++) {
1424 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
1426 /* Find the eventtype id for the following events and register the
1427 associated by id hooks. */
1429 hooks
= g_array_sized_new(FALSE
, FALSE
, sizeof(LttvTraceHook
), 11);
1430 hooks
= g_array_set_size(hooks
, 11);
1432 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1433 LTT_FACILITY_KERNEL
, LTT_EVENT_SYSCALL_ENTRY
,
1434 LTT_FIELD_SYSCALL_ID
, 0, 0,
1435 syscall_entry
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 0));
1438 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1439 LTT_FACILITY_KERNEL
, LTT_EVENT_SYSCALL_EXIT
,
1441 syscall_exit
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 1));
1444 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1445 LTT_FACILITY_KERNEL
, LTT_EVENT_TRAP_ENTRY
,
1446 LTT_FIELD_TRAP_ID
, 0, 0,
1447 trap_entry
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 2));
1450 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1451 LTT_FACILITY_KERNEL
, LTT_EVENT_TRAP_EXIT
,
1453 trap_exit
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 3));
1456 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1457 LTT_FACILITY_KERNEL
, LTT_EVENT_IRQ_ENTRY
,
1458 LTT_FIELD_IRQ_ID
, 0, 0,
1459 irq_entry
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 4));
1462 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1463 LTT_FACILITY_KERNEL
, LTT_EVENT_IRQ_EXIT
,
1465 irq_exit
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 5));
1468 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1469 LTT_FACILITY_PROCESS
, LTT_EVENT_SCHEDCHANGE
,
1470 LTT_FIELD_OUT
, LTT_FIELD_IN
, LTT_FIELD_OUT_STATE
,
1471 schedchange
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 6));
1474 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1475 LTT_FACILITY_PROCESS
, LTT_EVENT_FORK
,
1476 LTT_FIELD_PARENT_PID
, LTT_FIELD_CHILD_PID
, 0,
1477 process_fork
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 7));
1480 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1481 LTT_FACILITY_PROCESS
, LTT_EVENT_EXIT
,
1482 LTT_FIELD_PID
, 0, 0,
1483 process_exit
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 8));
1486 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1487 LTT_FACILITY_PROCESS
, LTT_EVENT_FREE
,
1488 LTT_FIELD_PID
, 0, 0,
1489 process_free
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 9));
1492 ret
= lttv_trace_find_hook(ts
->parent
.t
,
1493 LTT_FACILITY_FS
, LTT_EVENT_EXEC
,
1494 LTT_FIELD_FILENAME
, 0, 0,
1495 process_exec
, NULL
, &g_array_index(hooks
, LttvTraceHook
, 10));
1500 /* Add these hooks to each event_by_id hooks list */
1502 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1504 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1506 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
1507 LttvTracefileContext
*, j
));
1509 for(k
= 0 ; k
< hooks
->len
; k
++) {
1510 hook
= &g_array_index(hooks
, LttvTraceHook
, k
);
1511 for(l
=0;l
<hook
->fac_list
->len
;l
++) {
1512 thf
= g_array_index(hook
->fac_list
, LttvTraceHookByFacility
*, l
);
1514 lttv_hooks_by_id_find(tfs
->parent
.event_by_id
, thf
->id
),
1521 lttv_attribute_find(self
->parent
.a
, LTTV_STATE_HOOKS
, LTTV_POINTER
, &val
);
1522 *(val
.v_pointer
) = hooks
;
1526 gint
lttv_state_hook_remove_event_hooks(void *hook_data
, void *call_data
)
1528 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
1530 lttv_state_remove_event_hooks(tss
);
1535 void lttv_state_remove_event_hooks(LttvTracesetState
*self
)
1537 LttvTraceset
*traceset
= self
->parent
.ts
;
1539 guint i
, j
, k
, l
, nb_trace
, nb_tracefile
;
1543 LttvTracefileState
*tfs
;
1547 LttvTraceHook
*hook
;
1549 LttvTraceHookByFacility
*thf
;
1551 LttvAttributeValue val
;
1553 nb_trace
= lttv_traceset_number(traceset
);
1554 for(i
= 0 ; i
< nb_trace
; i
++) {
1555 ts
= LTTV_TRACE_STATE(self
->parent
.traces
[i
]);
1556 lttv_attribute_find(self
->parent
.a
, LTTV_STATE_HOOKS
, LTTV_POINTER
, &val
);
1557 hooks
= *(val
.v_pointer
);
1559 /* Remove these hooks from each event_by_id hooks list */
1561 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1563 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1565 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
1566 LttvTracefileContext
*, j
));
1568 for(k
= 0 ; k
< hooks
->len
; k
++) {
1569 hook
= &g_array_index(hooks
, LttvTraceHook
, k
);
1570 for(l
=0;l
<hook
->fac_list
->len
;l
++) {
1571 thf
= g_array_index(hook
->fac_list
, LttvTraceHookByFacility
*, l
);
1573 lttv_hooks_remove_data(
1574 lttv_hooks_by_id_find(tfs
->parent
.event_by_id
, thf
->id
),
1580 for(k
= 0 ; k
< hooks
->len
; k
++)
1581 lttv_trace_hook_destroy(&g_array_index(hooks
, LttvTraceHook
, k
));
1582 g_array_free(hooks
, TRUE
);
1586 static gboolean
state_save_event_hook(void *hook_data
, void *call_data
)
1588 guint
*event_count
= (guint
*)hook_data
;
1590 /* Only save at LTTV_STATE_SAVE_INTERVAL */
1591 if(likely((*event_count
)++ < LTTV_STATE_SAVE_INTERVAL
))
1596 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
1598 LttvTracefileState
*tfcs
;
1600 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
1602 LttEventPosition
*ep
;
1608 LttvAttribute
*saved_states_tree
, *saved_state_tree
;
1610 LttvAttributeValue value
;
1612 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
1613 LTTV_STATE_SAVED_STATES
);
1614 saved_state_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
1615 value
= lttv_attribute_add(saved_states_tree
,
1616 lttv_attribute_get_number(saved_states_tree
), LTTV_GOBJECT
);
1617 *(value
.v_gobject
) = (GObject
*)saved_state_tree
;
1618 value
= lttv_attribute_add(saved_state_tree
, LTTV_STATE_TIME
, LTTV_TIME
);
1619 *(value
.v_time
) = self
->parent
.timestamp
;
1620 lttv_state_save(tcs
, saved_state_tree
);
1621 g_debug("Saving state at time %lu.%lu", self
->parent
.timestamp
.tv_sec
,
1622 self
->parent
.timestamp
.tv_nsec
);
1624 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
1629 static gboolean
state_save_after_trace_hook(void *hook_data
, void *call_data
)
1631 LttvTraceState
*tcs
= (LttvTraceState
*)(call_data
);
1633 *(tcs
->max_time_state_recomputed_in_seek
) = tcs
->parent
.time_span
.end_time
;
1639 static gboolean
block_start(void *hook_data
, void *call_data
)
1641 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
1643 LttvTracefileState
*tfcs
;
1645 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
1647 LttEventPosition
*ep
;
1649 guint i
, nb_block
, nb_event
, nb_tracefile
;
1653 LttvAttribute
*saved_states_tree
, *saved_state_tree
;
1655 LttvAttributeValue value
;
1657 ep
= ltt_event_position_new();
1659 nb_tracefile
= tcs
->parent
.tracefiles
->len
;
1661 /* Count the number of events added since the last block end in any
1664 for(i
= 0 ; i
< nb_tracefile
; i
++) {
1666 LTTV_TRACEFILE_STATE(&g_array_index(tcs
->parent
.tracefiles
,
1667 LttvTracefileContext
, i
));
1668 ltt_event_position(tfcs
->parent
.e
, ep
);
1669 ltt_event_position_get(ep
, &nb_block
, &nb_event
, &tf
);
1670 tcs
->nb_event
+= nb_event
- tfcs
->saved_position
;
1671 tfcs
->saved_position
= nb_event
;
1675 if(tcs
->nb_event
>= tcs
->save_interval
) {
1676 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
1677 LTTV_STATE_SAVED_STATES
);
1678 saved_state_tree
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
1679 value
= lttv_attribute_add(saved_states_tree
,
1680 lttv_attribute_get_number(saved_states_tree
), LTTV_GOBJECT
);
1681 *(value
.v_gobject
) = (GObject
*)saved_state_tree
;
1682 value
= lttv_attribute_add(saved_state_tree
, LTTV_STATE_TIME
, LTTV_TIME
);
1683 *(value
.v_time
) = self
->parent
.timestamp
;
1684 lttv_state_save(tcs
, saved_state_tree
);
1686 g_debug("Saving state at time %lu.%lu", self
->parent
.timestamp
.tv_sec
,
1687 self
->parent
.timestamp
.tv_nsec
);
1689 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
1695 static gboolean
block_end(void *hook_data
, void *call_data
)
1697 LttvTracefileState
*self
= (LttvTracefileState
*)call_data
;
1699 LttvTraceState
*tcs
= (LttvTraceState
*)(self
->parent
.t_context
);
1703 LttEventPosition
*ep
;
1705 guint nb_block
, nb_event
;
1707 ep
= ltt_event_position_new();
1708 ltt_event_position(self
->parent
.e
, ep
);
1709 ltt_event_position_get(ep
, &nb_block
, &nb_event
, &tf
);
1710 tcs
->nb_event
+= nb_event
- self
->saved_position
+ 1;
1711 self
->saved_position
= 0;
1712 *(tcs
->max_time_state_recomputed_in_seek
) = self
->parent
.timestamp
;
1719 void lttv_state_save_add_event_hooks(LttvTracesetState
*self
)
1721 LttvTraceset
*traceset
= self
->parent
.ts
;
1723 guint i
, j
, nb_trace
, nb_tracefile
;
1727 LttvTracefileState
*tfs
;
1729 LttvTraceHook hook_start
, hook_end
;
1731 nb_trace
= lttv_traceset_number(traceset
);
1732 for(i
= 0 ; i
< nb_trace
; i
++) {
1733 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
1735 lttv_trace_find_hook(ts
->parent
.t
, "core","block_start",NULL
,
1736 NULL
, NULL
, block_start
, &hook_start
);
1737 lttv_trace_find_hook(ts
->parent
.t
, "core","block_end",NULL
,
1738 NULL
, NULL
, block_end
, &hook_end
);
1740 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1742 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1744 LTTV_TRACEFILE_STATE(&g_array_index(ts
->parent
.tracefiles
,
1745 LttvTracefileContext
, j
));
1746 lttv_hooks_add(lttv_hooks_by_id_find(tfs
->parent
.event_by_id
,
1747 hook_start
.id
), hook_start
.h
, NULL
, LTTV_PRIO_STATE
);
1748 lttv_hooks_add(lttv_hooks_by_id_find(tfs
->parent
.event_by_id
,
1749 hook_end
.id
), hook_end
.h
, NULL
, LTTV_PRIO_STATE
);
1755 void lttv_state_save_add_event_hooks(LttvTracesetState
*self
)
1757 LttvTraceset
*traceset
= self
->parent
.ts
;
1759 guint i
, j
, nb_trace
, nb_tracefile
;
1763 LttvTracefileState
*tfs
;
1766 nb_trace
= lttv_traceset_number(traceset
);
1767 for(i
= 0 ; i
< nb_trace
; i
++) {
1769 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
1770 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1772 guint
*event_count
= g_new(guint
, 1);
1775 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1777 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
1778 LttvTracefileContext
*, j
));
1779 lttv_hooks_add(tfs
->parent
.event
,
1780 state_save_event_hook
,
1787 lttv_process_traceset_begin(&self
->parent
,
1788 NULL
, NULL
, NULL
, NULL
, NULL
);
1792 gint
lttv_state_save_hook_add_event_hooks(void *hook_data
, void *call_data
)
1794 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
1796 lttv_state_save_add_event_hooks(tss
);
1803 void lttv_state_save_remove_event_hooks(LttvTracesetState
*self
)
1805 LttvTraceset
*traceset
= self
->parent
.ts
;
1807 guint i
, j
, nb_trace
, nb_tracefile
;
1811 LttvTracefileState
*tfs
;
1813 LttvTraceHook hook_start
, hook_end
;
1815 nb_trace
= lttv_traceset_number(traceset
);
1816 for(i
= 0 ; i
< nb_trace
; i
++) {
1817 ts
= LTTV_TRACE_STATE(self
->parent
.traces
[i
]);
1819 lttv_trace_find_hook(ts
->parent
.t
, "core","block_start",NULL
,
1820 NULL
, NULL
, block_start
, &hook_start
);
1822 lttv_trace_find_hook(ts
->parent
.t
, "core","block_end",NULL
,
1823 NULL
, NULL
, block_end
, &hook_end
);
1825 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1827 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1829 LTTV_TRACEFILE_STATE(&g_array_index(ts
->parent
.tracefiles
,
1830 LttvTracefileContext
, j
));
1831 lttv_hooks_remove_data(lttv_hooks_by_id_find(
1832 tfs
->parent
.event_by_id
, hook_start
.id
), hook_start
.h
, NULL
);
1833 lttv_hooks_remove_data(lttv_hooks_by_id_find(
1834 tfs
->parent
.event_by_id
, hook_end
.id
), hook_end
.h
, NULL
);
1840 void lttv_state_save_remove_event_hooks(LttvTracesetState
*self
)
1842 LttvTraceset
*traceset
= self
->parent
.ts
;
1844 guint i
, j
, nb_trace
, nb_tracefile
;
1848 LttvTracefileState
*tfs
;
1850 LttvHooks
*after_trace
= lttv_hooks_new();
1852 lttv_hooks_add(after_trace
,
1853 state_save_after_trace_hook
,
1858 lttv_process_traceset_end(&self
->parent
,
1859 NULL
, after_trace
, NULL
, NULL
, NULL
);
1861 lttv_hooks_destroy(after_trace
);
1863 nb_trace
= lttv_traceset_number(traceset
);
1864 for(i
= 0 ; i
< nb_trace
; i
++) {
1866 ts
= (LttvTraceState
*)self
->parent
.traces
[i
];
1867 nb_tracefile
= ts
->parent
.tracefiles
->len
;
1871 for(j
= 0 ; j
< nb_tracefile
; j
++) {
1873 LTTV_TRACEFILE_STATE(g_array_index(ts
->parent
.tracefiles
,
1874 LttvTracefileContext
*, j
));
1875 event_count
= lttv_hooks_remove(tfs
->parent
.event
,
1876 state_save_event_hook
);
1878 g_free(event_count
);
1882 gint
lttv_state_save_hook_remove_event_hooks(void *hook_data
, void *call_data
)
1884 LttvTracesetState
*tss
= (LttvTracesetState
*)(call_data
);
1886 lttv_state_save_remove_event_hooks(tss
);
1891 void lttv_state_traceset_seek_time_closest(LttvTracesetState
*self
, LttTime t
)
1893 LttvTraceset
*traceset
= self
->parent
.ts
;
1897 int min_pos
, mid_pos
, max_pos
;
1899 guint call_rest
= 0;
1901 LttvTraceState
*tcs
;
1903 LttvAttributeValue value
;
1905 LttvAttributeType type
;
1907 LttvAttributeName name
;
1909 LttvAttribute
*saved_states_tree
, *saved_state_tree
, *closest_tree
;
1911 //g_tree_destroy(self->parent.pqueue);
1912 //self->parent.pqueue = g_tree_new(compare_tracefile);
1914 g_info("Entering seek_time_closest for time %lu.%lu", t
.tv_sec
, t
.tv_nsec
);
1916 nb_trace
= lttv_traceset_number(traceset
);
1917 for(i
= 0 ; i
< nb_trace
; i
++) {
1918 tcs
= (LttvTraceState
*)self
->parent
.traces
[i
];
1920 if(ltt_time_compare(t
, *(tcs
->max_time_state_recomputed_in_seek
)) < 0) {
1921 saved_states_tree
= lttv_attribute_find_subdir(tcs
->parent
.t_a
,
1922 LTTV_STATE_SAVED_STATES
);
1925 if(saved_states_tree
) {
1926 max_pos
= lttv_attribute_get_number(saved_states_tree
) - 1;
1927 mid_pos
= max_pos
/ 2;
1928 while(min_pos
< max_pos
) {
1929 type
= lttv_attribute_get(saved_states_tree
, mid_pos
, &name
, &value
);
1930 g_assert(type
== LTTV_GOBJECT
);
1931 saved_state_tree
= *((LttvAttribute
**)(value
.v_gobject
));
1932 type
= lttv_attribute_get_by_name(saved_state_tree
, LTTV_STATE_TIME
,
1934 g_assert(type
== LTTV_TIME
);
1935 if(ltt_time_compare(*(value
.v_time
), t
) < 0) {
1937 closest_tree
= saved_state_tree
;
1939 else max_pos
= mid_pos
- 1;
1941 mid_pos
= (min_pos
+ max_pos
+ 1) / 2;
1945 /* restore the closest earlier saved state */
1947 lttv_state_restore(tcs
, closest_tree
);
1951 /* There is no saved state, yet we want to have it. Restart at T0 */
1953 restore_init_state(tcs
);
1954 lttv_process_trace_seek_time(&(tcs
->parent
), ltt_time_zero
);
1957 /* We want to seek quickly without restoring/updating the state */
1959 restore_init_state(tcs
);
1960 lttv_process_trace_seek_time(&(tcs
->parent
), t
);
1963 if(!call_rest
) g_info("NOT Calling restore");
1968 traceset_state_instance_init (GTypeInstance
*instance
, gpointer g_class
)
1974 traceset_state_finalize (LttvTracesetState
*self
)
1976 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE
))->
1977 finalize(G_OBJECT(self
));
1982 traceset_state_class_init (LttvTracesetContextClass
*klass
)
1984 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
1986 gobject_class
->finalize
= (void (*)(GObject
*self
)) traceset_state_finalize
;
1987 klass
->init
= (void (*)(LttvTracesetContext
*self
, LttvTraceset
*ts
))init
;
1988 klass
->fini
= (void (*)(LttvTracesetContext
*self
))fini
;
1989 klass
->new_traceset_context
= new_traceset_context
;
1990 klass
->new_trace_context
= new_trace_context
;
1991 klass
->new_tracefile_context
= new_tracefile_context
;
1996 lttv_traceset_state_get_type(void)
1998 static GType type
= 0;
2000 static const GTypeInfo info
= {
2001 sizeof (LttvTracesetStateClass
),
2002 NULL
, /* base_init */
2003 NULL
, /* base_finalize */
2004 (GClassInitFunc
) traceset_state_class_init
, /* class_init */
2005 NULL
, /* class_finalize */
2006 NULL
, /* class_data */
2007 sizeof (LttvTracesetState
),
2008 0, /* n_preallocs */
2009 (GInstanceInitFunc
) traceset_state_instance_init
, /* instance_init */
2010 NULL
/* value handling */
2013 type
= g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE
, "LttvTracesetStateType",
2021 trace_state_instance_init (GTypeInstance
*instance
, gpointer g_class
)
2027 trace_state_finalize (LttvTraceState
*self
)
2029 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE
))->
2030 finalize(G_OBJECT(self
));
2035 trace_state_class_init (LttvTraceStateClass
*klass
)
2037 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
2039 gobject_class
->finalize
= (void (*)(GObject
*self
)) trace_state_finalize
;
2040 klass
->state_save
= state_save
;
2041 klass
->state_restore
= state_restore
;
2042 klass
->state_saved_free
= state_saved_free
;
2047 lttv_trace_state_get_type(void)
2049 static GType type
= 0;
2051 static const GTypeInfo info
= {
2052 sizeof (LttvTraceStateClass
),
2053 NULL
, /* base_init */
2054 NULL
, /* base_finalize */
2055 (GClassInitFunc
) trace_state_class_init
, /* class_init */
2056 NULL
, /* class_finalize */
2057 NULL
, /* class_data */
2058 sizeof (LttvTraceState
),
2059 0, /* n_preallocs */
2060 (GInstanceInitFunc
) trace_state_instance_init
, /* instance_init */
2061 NULL
/* value handling */
2064 type
= g_type_register_static (LTTV_TRACE_CONTEXT_TYPE
,
2065 "LttvTraceStateType", &info
, 0);
2072 tracefile_state_instance_init (GTypeInstance
*instance
, gpointer g_class
)
2078 tracefile_state_finalize (LttvTracefileState
*self
)
2080 G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE
))->
2081 finalize(G_OBJECT(self
));
2086 tracefile_state_class_init (LttvTracefileStateClass
*klass
)
2088 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
2090 gobject_class
->finalize
= (void (*)(GObject
*self
)) tracefile_state_finalize
;
2095 lttv_tracefile_state_get_type(void)
2097 static GType type
= 0;
2099 static const GTypeInfo info
= {
2100 sizeof (LttvTracefileStateClass
),
2101 NULL
, /* base_init */
2102 NULL
, /* base_finalize */
2103 (GClassInitFunc
) tracefile_state_class_init
, /* class_init */
2104 NULL
, /* class_finalize */
2105 NULL
, /* class_data */
2106 sizeof (LttvTracefileState
),
2107 0, /* n_preallocs */
2108 (GInstanceInitFunc
) tracefile_state_instance_init
, /* instance_init */
2109 NULL
/* value handling */
2112 type
= g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE
,
2113 "LttvTracefileStateType", &info
, 0);
2119 static void module_init()
2121 LTTV_STATE_UNNAMED
= g_quark_from_string("unnamed");
2122 LTTV_STATE_MODE_UNKNOWN
= g_quark_from_string("unknown execution mode");
2123 LTTV_STATE_USER_MODE
= g_quark_from_string("user mode");
2124 LTTV_STATE_WAIT_FORK
= g_quark_from_string("wait fork");
2125 LTTV_STATE_SYSCALL
= g_quark_from_string("system call");
2126 LTTV_STATE_TRAP
= g_quark_from_string("trap");
2127 LTTV_STATE_IRQ
= g_quark_from_string("irq");
2128 LTTV_STATE_SUBMODE_UNKNOWN
= g_quark_from_string("unknown submode");
2129 LTTV_STATE_SUBMODE_NONE
= g_quark_from_string("(no submode)");
2130 LTTV_STATE_WAIT_CPU
= g_quark_from_string("wait for cpu");
2131 LTTV_STATE_EXIT
= g_quark_from_string("exiting");
2132 LTTV_STATE_ZOMBIE
= g_quark_from_string("zombie");
2133 LTTV_STATE_WAIT
= g_quark_from_string("wait for I/O");
2134 LTTV_STATE_RUN
= g_quark_from_string("running");
2135 LTTV_STATE_DEAD
= g_quark_from_string("dead");
2136 LTTV_STATE_TRACEFILES
= g_quark_from_string("tracefiles");
2137 LTTV_STATE_PROCESSES
= g_quark_from_string("processes");
2138 LTTV_STATE_PROCESS
= g_quark_from_string("process");
2139 LTTV_STATE_RUNNING_PROCESS
= g_quark_from_string("running_process");
2140 LTTV_STATE_EVENT
= g_quark_from_string("event");
2141 LTTV_STATE_SAVED_STATES
= g_quark_from_string("saved states");
2142 LTTV_STATE_SAVED_STATES_TIME
= g_quark_from_string("saved states time");
2143 LTTV_STATE_TIME
= g_quark_from_string("time");
2144 LTTV_STATE_HOOKS
= g_quark_from_string("saved state hooks");
2145 LTTV_STATE_NAME_TABLES
= g_quark_from_string("name tables");
2146 LTTV_STATE_TRACE_STATE_USE_COUNT
=
2147 g_quark_from_string("trace_state_use_count");
2150 LTT_FACILITY_KERNEL
= g_quark_from_string("kernel");
2151 LTT_FACILITY_PROCESS
= g_quark_from_string("process");
2152 LTT_FACILITY_FS
= g_quark_from_string("fs");
2155 LTT_EVENT_SYSCALL_ENTRY
= g_quark_from_string("syscall_entry");
2156 LTT_EVENT_SYSCALL_EXIT
= g_quark_from_string("syscall_exit");
2157 LTT_EVENT_TRAP_ENTRY
= g_quark_from_string("trap_entry");
2158 LTT_EVENT_TRAP_EXIT
= g_quark_from_string("trap_exit");
2159 LTT_EVENT_IRQ_ENTRY
= g_quark_from_string("irq_entry");
2160 LTT_EVENT_IRQ_EXIT
= g_quark_from_string("irq_exit");
2161 LTT_EVENT_SCHEDCHANGE
= g_quark_from_string("schedchange");
2162 LTT_EVENT_FORK
= g_quark_from_string("fork");
2163 LTT_EVENT_EXIT
= g_quark_from_string("exit");
2164 LTT_EVENT_FREE
= g_quark_from_string("free");
2165 LTT_EVENT_EXEC
= g_quark_from_string("exec");
2168 LTT_FIELD_SYSCALL_ID
= g_quark_from_string("syscall_id");
2169 LTT_FIELD_TRAP_ID
= g_quark_from_string("trap_id");
2170 LTT_FIELD_IRQ_ID
= g_quark_from_string("irq_id");
2171 LTT_FIELD_OUT
= g_quark_from_string("out");
2172 LTT_FIELD_IN
= g_quark_from_string("in");
2173 LTT_FIELD_OUT_STATE
= g_quark_from_string("out_state");
2174 LTT_FIELD_PARENT_PID
= g_quark_from_string("parent_pid");
2175 LTT_FIELD_CHILD_PID
= g_quark_from_string("child_pid");
2176 LTT_FIELD_PID
= g_quark_from_string("pid");
2177 LTT_FIELD_FILENAME
= g_quark_from_string("filename");
2181 static void module_destroy()
2186 LTTV_MODULE("state", "State computation", \
2187 "Update the system state, possibly saving it at intervals", \
2188 module_init
, module_destroy
)