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,
19 /* This module inserts a hook in the program main loop. This hook processes
20 all the events in the main tracefile while testing the speed and
21 functionality of the state and stats computations. */
28 #include <lttv/lttv.h>
29 #include <lttv/attribute.h>
30 #include <lttv/hook.h>
31 #include <lttv/option.h>
32 #include <lttv/module.h>
33 #include <lttv/tracecontext.h>
34 #include <lttv/state.h>
35 #include <lttv/stats.h>
36 #include <ltt/trace.h>
37 #include <ltt/event.h>
39 #include <ltt/facility.h>
41 #define __UNUSED__ __attribute__((__unused__))
43 static LttvTraceset
*traceset
;
59 static char *a_dump_tracefiles
;
61 static char *a_save_sample
;
83 static GQuark QUARK_BLOCK_START
,
86 LttEventPosition
*a_event_position
;
88 typedef struct _save_state
{
99 static void lttv_trace_option(void __UNUSED__
*hook_data
)
103 trace
= ltt_trace_open(a_trace
);
105 g_critical("cannot open trace %s", a_trace
);
107 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
111 static double get_time()
115 g_get_current_time(>
);
116 return gt
.tv_sec
+ (double)gt
.tv_usec
/ (double)1000000.0;
119 static double run_one_test(LttvTracesetState
*ts
, LttTime start
, LttTime end
)
125 //lttv_traceset_context_add_hooks(&ts->parent,
126 //before_traceset, after_traceset, NULL, before_trace, after_trace,
127 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
128 lttv_process_traceset_begin(&ts
->parent
,
135 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
136 ((LttvTraceState
*)(ts
->parent
.traces
[i
]))->save_interval
=a_save_interval
;
140 lttv_state_traceset_seek_time_closest(ts
, start
);
141 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
142 lttv_process_traceset_middle(&ts
->parent
,
148 //lttv_traceset_context_remove_hooks(&ts->parent,
149 //before_traceset, after_traceset, NULL, before_trace, after_trace,
150 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
151 lttv_process_traceset_end(&ts
->parent
,
162 gboolean
trace_event(void __UNUSED__
*hook_data
, void *call_data
)
164 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
166 guint nb_block
, offset
;
171 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
172 ltt_event_position(e
, a_event_position
);
173 ltt_event_position_get(a_event_position
, &tf
, &nb_block
, &offset
, &tsc
);
174 fprintf(stderr
,"Event %s %lu.%09lu [%u 0x%x tsc %llu]\n",
175 g_quark_to_string(ltt_eventtype_name(ltt_event_eventtype(e
))),
176 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
,
177 nb_block
, offset
, tsc
);
181 static LttTime count_previous_time
= { 0, 0 };
183 gboolean
count_event(void *hook_data
, void __UNUSED__
*call_data
)
185 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
186 LttTracefile
*tracefile
= tfs
->parent
.tf
;
187 guint nb_block
, offset
;
188 LttTracefile
*tf_pos
;
190 LttEvent
* event
= ltt_tracefile_get_event(tracefile
);
192 guint
*pcount
= (guint
*)hook_data
;
196 time
= ltt_event_time(event
);
197 ltt_event_position(event
, a_event_position
);
198 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
200 if(ltt_time_compare(time
, count_previous_time
) < 0) {
201 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
202 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
203 g_quark_to_string(ltt_tracefile_name(tracefile
)),
204 ltt_tracefile_num(tracefile
), nb_block
, offset
);
205 g_warning("last time %lu.%lu vs current %lu.%lu",
206 count_previous_time
.tv_sec
, count_previous_time
.tv_nsec
,
207 time
.tv_sec
, time
.tv_nsec
);
209 count_previous_time
= time
;
217 gboolean
save_state_copy_event(void *hook_data
, void *call_data
)
219 SaveState __UNUSED__
*save_state
= (SaveState
*)hook_data
;
221 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
223 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
225 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
231 if(ts
->nb_event
== 0 &&
232 ltt_eventtype_name(ltt_event_eventtype(e
))
233 == QUARK_BLOCK_START
) {
234 if(a_save_sample
!= NULL
) {
235 filename
= g_string_new("");
236 g_string_printf(filename
, "%s.copy.%lu.%09lu.xml", a_save_sample
,
237 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
238 fp
= fopen(filename
->str
, "w");
239 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
240 g_string_free(filename
, TRUE
);
241 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
243 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
249 gboolean
save_state_event(void *hook_data
, void *call_data
)
251 SaveState
*save_state
= (SaveState
*)hook_data
;
253 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
255 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
261 (save_state
->count
)++;
262 if(save_state
->count
% save_state
->interval
== 0 &&
263 save_state
->position
< save_state
->size
) {
264 if(a_save_sample
!= NULL
) {
265 filename
= g_string_new("");
266 g_string_printf(filename
, "%s.%u.xml.%u", a_save_sample
,
267 save_state
->position
, save_state
->version
);
268 fp
= fopen(filename
->str
, "w");
269 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
270 g_string_free(filename
, TRUE
);
271 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
273 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
275 save_state
->write_time
[save_state
->position
] = tfs
->parent
.timestamp
;
276 save_state
->position
++;
282 static void sanitize_name(gchar
*name
)
284 while(*name
!= '\0') {
285 if(*name
== '/') *name
= '_';
292 static void compute_tracefile(LttTracefile
*tracefile
, void *hook_data
)
295 guint nb_equal
, nb_block
, offset
;
298 LttTime time
, previous_time
;
299 LttEvent
*event
= ltt_tracefile_get_event(tracefile
);
300 LttFacility
*facility
;
301 LttEventType
*event_type
;
303 gchar mod_name
[PATH_MAX
];
305 /* start_count is always initialized in this function _if_ there is always
306 * a block_start before a block_end.
308 long long unsigned cycle_count
, start_count
=0, delta_cycle
;
311 filename
= g_string_new("");
312 strcpy(mod_name
, g_quark_to_string(ltt_tracefile_name(tracefile
)));
314 sanitize_name(mod_name
);
316 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile
)));
317 g_string_printf(filename
, "%s.%s.%u.trace", a_dump_tracefiles
,
318 mod_name
, ltt_tracefile_num(tracefile
));
319 fp
= fopen(filename
->str
, "w");
320 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
321 g_string_free(filename
, TRUE
);
322 err
= ltt_tracefile_seek_time(tracefile
, ltt_time_zero
);
325 previous_time
= ltt_time_zero
;
329 LttTracefile
*tf_pos
;
330 facility
= ltt_event_facility(event
);
331 event_type
= ltt_event_eventtype(event
);
332 time
= ltt_event_time(event
);
333 ltt_event_position(event
, a_event_position
);
334 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
335 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
336 fprintf(fp
, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
337 g_quark_to_string(ltt_facility_name(facility
)),
338 g_quark_to_string(ltt_eventtype_name(event_type
)),
339 tsc
, (unsigned long)time
.tv_sec
,
340 (unsigned long)time
.tv_nsec
,
342 g_quark_to_string(ltt_tracefile_name(tracefile
)));
344 if(ltt_time_compare(time
, previous_time
) < 0) {
345 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
346 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
347 g_quark_to_string(ltt_tracefile_name(tracefile
)),
348 ltt_tracefile_num(tracefile
), nb_block
, offset
);
349 g_warning("last time %lu.%lu vs current %lu.%lu",
350 previous_time
.tv_sec
, previous_time
.tv_nsec
,
351 time
.tv_sec
, time
.tv_nsec
);
355 if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_START
) {
356 start_count
= cycle_count
;
359 else if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_END
) {
360 delta_cycle
= cycle_count
- start_count
;
361 end_nsec_sec
= (long long unsigned)time
.tv_sec
* (long long unsigned)1000000000;
362 end_nsec_nsec
= time
.tv_nsec
;
363 end_nsec
= end_nsec_sec
+ end_nsec_nsec
;
364 start_nsec
= (long long unsigned)start_time
.tv_sec
* (long long unsigned)1000000000 + (long long unsigned)start_time
.tv_nsec
;
365 delta_nsec
= end_nsec
- start_nsec
;
366 cycle_per_nsec
= (double)delta_cycle
/ (double)delta_nsec
;
367 nsec_per_cycle
= (double)delta_nsec
/ (double)delta_cycle
;
368 added_nsec
= (double)delta_cycle
* nsec_per_cycle
;
369 interpolated_nsec
= start_nsec
+ added_nsec
;
370 added_nsec2
= (double)delta_cycle
/ cycle_per_nsec
;
371 interpolated_nsec2
= start_nsec
+ added_nsec2
;
373 fprintf(fp
,"Time: start_count %llu, end_count %llu, delta_cycle %llu, start_nsec %llu, end_nsec_sec %llu, end_nsec_nsec %llu, end_nsec %llu, delta_nsec %llu, cycle_per_nsec %.25f, nsec_per_cycle %.25f, added_nsec %llu, added_nsec2 %llu, interpolated_nsec %llu, interpolated_nsec2 %llu\n", start_count
, cycle_count
, delta_cycle
, start_nsec
, end_nsec_sec
, end_nsec_nsec
, end_nsec
, delta_nsec
, cycle_per_nsec
, nsec_per_cycle
, added_nsec
, added_nsec2
, interpolated_nsec
, interpolated_nsec2
);
377 if(ltt_time_compare(time
, previous_time
) == 0) nb_equal
++;
378 else if(nb_equal
> 0) {
379 g_warning("Consecutive %d events with time %lu.%09lu",
380 nb_equal
+ 1, previous_time
.tv_sec
, previous_time
.tv_nsec
);
383 previous_time
= time
;
385 } while((!ltt_tracefile_read(tracefile
)));
391 static gboolean
process_traceset(void __UNUSED__
*hook_data
,
392 void __UNUSED__
*call_data
)
395 LttvTracesetStats
*tscs
;
397 LttvTracesetState
*ts
;
399 LttvTracesetContext
*tc
;
405 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
406 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
411 long long unsigned start_nsec
, end_nsec
, delta_nsec
, added_nsec
, added_nsec2
;
413 double cycle_per_nsec
, nsec_per_cycle
;
415 long long interpolated_nsec
, interpolated_nsec2
, end_nsec_sec
, end_nsec_nsec
;
419 LttTime max_time
= { G_MAXULONG
, G_MAXULONG
};
421 a_event_position
= ltt_event_position_new();
423 GData
**tracefiles_groups
;
425 struct compute_tracefile_group_args args
;
427 args
.func
= compute_tracefile
;
428 args
.func_args
= NULL
;
430 if(a_dump_tracefiles
!= NULL
) {
431 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
432 trace
= lttv_trace(lttv_traceset_get(traceset
, i
));
433 tracefiles_groups
= ltt_trace_get_tracefiles_groups(trace
);
435 g_datalist_foreach(tracefiles_groups
,
436 (GDataForeachFunc
)compute_tracefile_group
,
442 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
444 tc
= &tscs
->parent
.parent
;
446 lttv_context_init(tc
, traceset
);
448 /* For each case compute and print the elapsed time.
449 The first case is simply to run through all events with a
452 if(a_test1
|| a_test_all
) {
454 lttv_hooks_add(event_hook
, count_event
, &count
, LTTV_PRIO_DEFAULT
);
455 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
456 lttv_hooks_remove_data(event_hook
, count_event
, &count
);
458 "Processing trace while counting events (%u events in %g seconds)",
462 /* Run through all events computing the state. */
464 if(a_test2
|| a_test_all
) {
465 lttv_state_add_event_hooks(ts
);
466 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
467 lttv_state_remove_event_hooks(ts
);
468 g_message("Processing trace while updating state (%g seconds)", t
);
471 /* Run through all events computing the state and writing it out
474 SaveState save_state
;
476 save_state
.interval
= a_sample_interval
;
477 save_state
.size
= a_sample_number
;
478 save_state
.fp
= stderr
;
479 save_state
.write_time
= g_new(LttTime
, a_sample_number
);
482 if(a_test3
|| a_test_all
) {
483 for(i
= 0 ; i
< 2 ; i
++) {
484 save_state
.count
= 0;
485 save_state
.position
= 0;
486 save_state
.version
= i
;
487 lttv_state_add_event_hooks(ts
);
488 lttv_hooks_add(event_hook
, save_state_event
, &save_state
,
490 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
491 lttv_state_remove_event_hooks(ts
);
492 lttv_hooks_remove_data(event_hook
, save_state_event
, &save_state
);
493 g_warning("Processing while updating/writing state (%g seconds)", t
);
497 /* Run through all events computing the stats. */
499 if(a_test4
|| a_test_all
) {
500 if(lttv_profile_memory
) {
501 g_message("Memory summary before computing stats");
505 lttv_stats_add_event_hooks(tscs
);
506 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
507 lttv_stats_remove_event_hooks(tscs
);
508 g_message("Processing trace while counting stats (%g seconds)", t
);
510 if(lttv_profile_memory
) {
511 g_message("Memory summary after computing stats");
515 lttv_stats_sum_traceset(tscs
);
517 if(lttv_profile_memory
) {
518 g_message("Memory summary after summing stats");
522 lttv_context_fini(tc
);
523 lttv_context_init(tc
, traceset
);
525 if(lttv_profile_memory
) {
526 g_message("Memory summary after cleaning up the stats");
531 /* Run through all events computing the state and stats. */
533 if(a_test5
|| a_test_all
) {
534 if(lttv_profile_memory
) {
535 g_message("Memory summary before computing state and stats");
539 lttv_state_add_event_hooks(ts
);
540 lttv_stats_add_event_hooks(tscs
);
541 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
542 lttv_state_remove_event_hooks(ts
);
543 lttv_stats_remove_event_hooks(tscs
);
545 "Processing trace while counting state and stats (%g seconds)", t
);
547 if(lttv_profile_memory
) {
548 g_message("Memory summary after computing and state and stats");
552 lttv_context_fini(tc
);
553 lttv_context_init(tc
, traceset
);
555 if(lttv_profile_memory
) {
556 g_message("Memory summary after cleaning up the stats");
561 /* Run through all events computing and saving the state. */
563 if(a_trace_event
) lttv_hooks_add(event_hook
, trace_event
, NULL
,
566 if(a_test6
|| a_test_all
) {
567 if(lttv_profile_memory
) {
568 g_message("Memory summary before computing and saving state");
572 lttv_state_add_event_hooks(ts
);
573 lttv_state_save_add_event_hooks(ts
);
574 if(a_save_state_copy
)
575 lttv_hooks_add(event_hook
, save_state_copy_event
, &save_state
,
577 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
578 lttv_state_remove_event_hooks(ts
);
579 lttv_state_save_remove_event_hooks(ts
);
580 if(a_save_state_copy
)
581 lttv_hooks_remove_data(event_hook
,save_state_copy_event
, &save_state
);
583 g_message("Processing trace while updating/saving state (%g seconds)", t
);
585 if(lttv_profile_memory
) {
586 g_message("Memory summary after computing/saving state");
591 /* Seek a few times to each saved position */
593 if((a_test7
&& a_test3
) || a_test_all
) {
594 g_assert(a_seek_number
>= 0);
595 for(i
= 0 ; i
< (guint
)a_seek_number
; i
++) {
596 gint reverse_j
; /* just to make sure j is unsigned */
597 for(reverse_j
= save_state
.position
- 1 ; reverse_j
>= 0 ; reverse_j
--) {
598 j
= (guint
)reverse_j
;
599 lttv_state_add_event_hooks(ts
);
600 t
= run_one_test(ts
, save_state
.write_time
[j
],
601 save_state
.write_time
[j
]);
602 lttv_state_remove_event_hooks(ts
);
603 g_message("Seeking to %lu.%lu (%g seconds)",
604 save_state
.write_time
[j
].tv_sec
, save_state
.write_time
[j
].tv_nsec
,
607 if(a_save_sample
!= NULL
) {
608 filename
= g_string_new("");
609 g_string_printf(filename
, "%s.%d.xml.bak%d", a_save_sample
, j
, i
);
610 fp
= fopen(filename
->str
, "w");
611 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
612 g_string_free(filename
, TRUE
);
613 lttv_state_write((LttvTraceState
*)tc
->traces
[0],
614 save_state
.write_time
[j
], fp
);
617 //else lttv_state_write((LttvTraceState *)tc->traces[0],
618 // save_state.write_time[j], save_state.fp);
623 /* Seek at specified interval, using states computed in 6, making
624 * sure that there is no more than the number of events between
625 * state save interval to read before getting there.
628 if((a_test8
&& a_test6
) || a_test_all
) {
629 g_message("Running test 8 : check save interval");
630 LttTime time
= tc
->time_span
.start_time
;
633 interval
.tv_nsec
= 175674987;
636 while(ltt_time_compare(time
, tc
->time_span
.end_time
) < 0) {
637 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
638 lttv_process_traceset_seek_time(&ts
->parent
, ltt_time_zero
);
639 lttv_state_traceset_seek_time_closest(ts
, time
);
640 /* We add no hook to the traceset, not necessary */
641 count
= lttv_process_traceset_middle(&ts
->parent
,
642 time
, G_MAXUINT
, NULL
);
643 g_info("Number of events to jump over : %u", count
);
645 if(count
> LTTV_STATE_SAVE_INTERVAL
)
646 g_warning("Oops! Save interval is %u and it took %u events to seek to a time %lu.%lu supposed to be closer from the last saved state.",
647 LTTV_STATE_SAVE_INTERVAL
, count
, time
.tv_sec
, time
.tv_nsec
);
648 time
= ltt_time_add(time
, interval
);
653 if(a_test9
|| a_test_all
) {
654 /* Run seek_forward and seek_backward test */
655 LttvTracesetContextPosition
*saved_pos
=
656 lttv_traceset_context_position_new();
658 LttvTracesetContext
*tsc
= &ts
->parent
;
659 g_message("Running test 9 : seek_forward and seek_backward");
660 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
662 count
= lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
663 g_assert(count
== 500);
664 lttv_traceset_context_position_save(tsc
, saved_pos
);
665 count
= lttv_process_traceset_seek_n_forward(tsc
, 150000, NULL
);
666 g_assert(count
== 150000);
667 count
= lttv_process_traceset_seek_n_backward(tsc
, 150000,
668 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
669 g_assert(count
== 150000);
670 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
671 g_warning("Problem with seek_n ! Positions differ. (1)");
674 lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
675 lttv_traceset_context_position_save(tsc
, saved_pos
);
676 lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
677 lttv_process_traceset_seek_n_backward(tsc
, 15005,
678 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
679 lttv_process_traceset_seek_n_forward(tsc
, 5, NULL
);
680 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
681 g_warning("Problem with seek_n ! Positions differ. (2)");
684 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
686 count
= lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
688 g_warning("Problem with seek_n ! Forward at end of traceset.");
690 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
692 lttv_traceset_context_position_save(tsc
, saved_pos
);
693 lttv_process_traceset_seek_n_backward(tsc
, 300,
694 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
695 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
696 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
698 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
699 g_warning("Problem with seek_n ! Positions differ. (4)");
702 /* try a volountary error */
703 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
705 lttv_traceset_context_position_save(tsc
, saved_pos
);
706 lttv_process_traceset_seek_n_backward(tsc
, 301,
707 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
708 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
709 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
711 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) == 0) {
712 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
715 /* Try a seek by closest time : Hint : try this one with and without states
717 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
718 count
= lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
);
719 lttv_traceset_context_position_save(tsc
, saved_pos
);
720 lttv_process_traceset_seek_n_backward(tsc
, 100301,
721 //seek_back_default_offset, lttv_state_traceset_seek_time_closest, NULL);
722 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
723 count
= lttv_process_traceset_seek_n_forward(tsc
, 100301, NULL
);
725 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
726 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
729 lttv_traceset_context_position_destroy(saved_pos
);
731 if(a_trace_event
) lttv_hooks_remove_data(event_hook
, trace_event
, NULL
);
733 g_free(save_state
.write_time
);
734 g_free(a_event_position
);
735 lttv_context_fini(tc
);
736 g_object_unref(tscs
);
738 if(lttv_profile_memory
) {
739 g_message("Memory summary at the end of batchtest");
743 g_info("BatchTest end process traceset");
750 LttvAttributeValue value
;
752 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
754 g_info("Init batchtest.c");
757 QUARK_BLOCK_START
= g_quark_from_string("block_start");
758 QUARK_BLOCK_END
= g_quark_from_string("block_end");
761 lttv_option_add("trace", 't',
762 "add a trace to the trace set to analyse",
763 "pathname of the directory containing the trace",
764 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
766 a_trace_event
= FALSE
;
768 a_dump_tracefiles
= NULL
;
769 lttv_option_add("dump-tracefiles", 'D',
770 "Write event by event the content of tracefiles",
771 "basename for the files where to dump events",
772 LTTV_OPT_STRING
, &a_dump_tracefiles
, NULL
, NULL
);
774 a_save_sample
= NULL
;
775 lttv_option_add("save-sample", 's',
776 "Save state samples to multiple files",
777 "basename for the files containing the state samples",
778 LTTV_OPT_STRING
, &a_save_sample
, NULL
, NULL
);
780 a_save_state_copy
= FALSE
;
781 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
782 "", LTTV_OPT_NONE
, &a_save_state_copy
, NULL
, NULL
);
784 a_save_interval
= 100000;
785 lttv_option_add("save-interval", 'i',
786 "Interval between saving state",
787 "number of events before a block start triggers saving state",
788 LTTV_OPT_INT
, &a_save_interval
, NULL
, NULL
);
790 a_sample_interval
= 100000;
791 lttv_option_add("sample-interval", 'S',
792 "Interval between sampling state",
793 "number of events before sampling and writing state",
794 LTTV_OPT_INT
, &a_sample_interval
, NULL
, NULL
);
796 a_sample_number
= 20;
797 lttv_option_add("sample-number", 'N',
798 "Number of state samples",
800 LTTV_OPT_INT
, &a_sample_number
, NULL
, NULL
);
803 lttv_option_add("seek-number", 'K',
806 LTTV_OPT_INT
, &a_seek_number
, NULL
, NULL
);
809 lttv_option_add("test1", '1', "Test just counting events", "",
810 LTTV_OPT_NONE
, &a_test1
, NULL
, NULL
);
813 lttv_option_add("test2", '2', "Test computing the state", "",
814 LTTV_OPT_NONE
, &a_test2
, NULL
, NULL
);
817 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
818 "", LTTV_OPT_NONE
, &a_test3
, NULL
, NULL
);
821 lttv_option_add("test4", '4', "Test computing the stats", "",
822 LTTV_OPT_NONE
, &a_test4
, NULL
, NULL
);
825 lttv_option_add("test5", '5', "Test computing the state and stats", "",
826 LTTV_OPT_NONE
, &a_test5
, NULL
, NULL
);
829 lttv_option_add("test6", '6', "Test computing and saving the state", "",
830 LTTV_OPT_NONE
, &a_test6
, NULL
, NULL
);
833 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
834 "", LTTV_OPT_NONE
, &a_test7
, NULL
, NULL
);
837 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
838 "", LTTV_OPT_NONE
, &a_test8
, NULL
, NULL
);
841 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
842 "", LTTV_OPT_NONE
, &a_test9
, NULL
, NULL
);
846 lttv_option_add("testall", 'a', "Run all tests ", "",
847 LTTV_OPT_NONE
, &a_test_all
, NULL
, NULL
);
849 traceset
= lttv_traceset_new();
851 before_traceset
= lttv_hooks_new();
852 after_traceset
= lttv_hooks_new();
853 before_trace
= lttv_hooks_new();
854 after_trace
= lttv_hooks_new();
855 before_tracefile
= lttv_hooks_new();
856 after_tracefile
= lttv_hooks_new();
857 //before_event = lttv_hooks_new();
858 //after_event = lttv_hooks_new();
859 event_hook
= lttv_hooks_new();
862 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
863 LTTV_POINTER
, &value
));
864 *(value
.v_pointer
) = before_traceset
;
865 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
866 LTTV_POINTER
, &value
));
867 *(value
.v_pointer
) = after_traceset
;
868 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
869 LTTV_POINTER
, &value
));
870 *(value
.v_pointer
) = before_trace
;
871 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
872 LTTV_POINTER
, &value
));
873 *(value
.v_pointer
) = after_trace
;
874 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
875 LTTV_POINTER
, &value
));
876 *(value
.v_pointer
) = before_tracefile
;
877 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
878 LTTV_POINTER
, &value
));
879 *(value
.v_pointer
) = after_tracefile
;
880 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
881 // LTTV_POINTER, &value));
882 //*(value.v_pointer) = before_event;
883 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
884 // LTTV_POINTER, &value));
885 //*(value.v_pointer) = after_event;
886 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
887 LTTV_POINTER
, &value
));
888 *(value
.v_pointer
) = event_hook
;
889 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
890 LTTV_POINTER
, &value
));
891 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
892 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
896 static void destroy()
902 g_info("Destroy batchAnalysis.c");
904 lttv_option_remove("trace");
905 lttv_option_remove("dump-tracefiles");
906 lttv_option_remove("save-sample");
907 lttv_option_remove("save-state-copy");
908 lttv_option_remove("sample-interval");
909 lttv_option_remove("sample-number");
910 lttv_option_remove("seek-number");
911 lttv_option_remove("save-interval");
912 lttv_option_remove("test1");
913 lttv_option_remove("test2");
914 lttv_option_remove("test3");
915 lttv_option_remove("test4");
916 lttv_option_remove("test5");
917 lttv_option_remove("test6");
918 lttv_option_remove("test7");
919 lttv_option_remove("test8");
920 lttv_option_remove("test9");
921 lttv_option_remove("testall");
923 lttv_hooks_destroy(before_traceset
);
924 lttv_hooks_destroy(after_traceset
);
925 lttv_hooks_destroy(before_trace
);
926 lttv_hooks_destroy(after_trace
);
927 lttv_hooks_destroy(before_tracefile
);
928 lttv_hooks_destroy(after_tracefile
);
929 //lttv_hooks_destroy(before_event);
930 //lttv_hooks_destroy(after_event);
931 lttv_hooks_destroy(event_hook
);
932 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
934 nb
= lttv_traceset_number(traceset
);
935 for(i
= 0 ; i
< nb
; i
++) {
936 trace
= lttv_traceset_get(traceset
, i
);
937 lttv_traceset_remove(traceset
,i
);
938 ltt_trace_close(lttv_trace(trace
));
939 lttv_trace_destroy(trace
);
942 lttv_traceset_destroy(traceset
);
946 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
947 "Run through a trace calling all the registered hooks for tests", \
948 init
, destroy
, "state", "stats", "option" )