1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 * 2006 Mathieu Desnoyers
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 /* This module inserts a hook in the program main loop. This hook processes
21 all the events in the main tracefile while testing the speed and
22 functionality of the state and stats computations. */
29 #include <lttv/lttv.h>
30 #include <lttv/attribute.h>
31 #include <lttv/hook.h>
32 #include <lttv/option.h>
33 #include <lttv/module.h>
34 #include <lttv/tracecontext.h>
35 #include <lttv/state.h>
36 #include <lttv/stats.h>
37 #include <ltt/trace.h>
38 #include <ltt/event.h>
40 #include <ltt/facility.h>
42 #define __UNUSED__ __attribute__((__unused__))
44 static LttvTraceset
*traceset
;
60 static char *a_dump_tracefiles
;
62 static char *a_save_sample
;
85 static GQuark QUARK_BLOCK_START
,
88 LttEventPosition
*a_event_position
;
90 typedef struct _save_state
{
101 static void lttv_trace_option(void __UNUSED__
*hook_data
)
105 trace
= ltt_trace_open(a_trace
);
107 g_critical("cannot open trace %s", a_trace
);
109 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
113 static double get_time()
117 g_get_current_time(>
);
118 return gt
.tv_sec
+ (double)gt
.tv_usec
/ (double)1000000.0;
121 static double run_one_test(LttvTracesetState
*ts
, LttTime start
, LttTime end
)
127 //lttv_traceset_context_add_hooks(&ts->parent,
128 //before_traceset, after_traceset, NULL, before_trace, after_trace,
129 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
130 lttv_process_traceset_begin(&ts
->parent
,
137 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
138 ((LttvTraceState
*)(ts
->parent
.traces
[i
]))->save_interval
=a_save_interval
;
142 lttv_state_traceset_seek_time_closest(ts
, start
);
143 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
144 lttv_process_traceset_middle(&ts
->parent
,
150 //lttv_traceset_context_remove_hooks(&ts->parent,
151 //before_traceset, after_traceset, NULL, before_trace, after_trace,
152 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
153 lttv_process_traceset_end(&ts
->parent
,
164 gboolean
trace_event(void __UNUSED__
*hook_data
, void *call_data
)
166 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
168 guint nb_block
, offset
;
173 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
174 ltt_event_position(e
, a_event_position
);
175 ltt_event_position_get(a_event_position
, &tf
, &nb_block
, &offset
, &tsc
);
176 fprintf(stderr
,"Event %s %lu.%09lu [%u 0x%x tsc %llu]\n",
177 g_quark_to_string(ltt_eventtype_name(ltt_event_eventtype(e
))),
178 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
,
179 nb_block
, offset
, tsc
);
183 static LttTime count_previous_time
= { 0, 0 };
185 gboolean
count_event(void *hook_data
, void __UNUSED__
*call_data
)
187 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
188 LttTracefile
*tracefile
= tfs
->parent
.tf
;
189 guint nb_block
, offset
;
190 LttTracefile
*tf_pos
;
192 LttEvent
* event
= ltt_tracefile_get_event(tracefile
);
194 guint
*pcount
= (guint
*)hook_data
;
198 time
= ltt_event_time(event
);
199 ltt_event_position(event
, a_event_position
);
200 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
202 if(ltt_time_compare(time
, count_previous_time
) < 0) {
203 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
204 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
205 g_quark_to_string(ltt_tracefile_name(tracefile
)),
206 tfs
->cpu
, nb_block
, offset
);
207 g_warning("last time %lu.%lu vs current %lu.%lu",
208 count_previous_time
.tv_sec
, count_previous_time
.tv_nsec
,
209 time
.tv_sec
, time
.tv_nsec
);
211 count_previous_time
= time
;
219 gboolean
save_state_copy_event(void *hook_data
, void *call_data
)
221 SaveState __UNUSED__
*save_state
= (SaveState
*)hook_data
;
223 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
225 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
227 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
233 if(ts
->nb_event
== 0 &&
234 ltt_eventtype_name(ltt_event_eventtype(e
))
235 == QUARK_BLOCK_START
) {
236 if(a_save_sample
!= NULL
) {
237 filename
= g_string_new("");
238 g_string_printf(filename
, "%s.copy.%lu.%09lu.xml", a_save_sample
,
239 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
240 fp
= fopen(filename
->str
, "w");
241 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
242 g_string_free(filename
, TRUE
);
243 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
245 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
251 gboolean
save_state_event(void *hook_data
, void *call_data
)
253 SaveState
*save_state
= (SaveState
*)hook_data
;
255 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
257 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
263 (save_state
->count
)++;
264 if(save_state
->count
% save_state
->interval
== 0 &&
265 save_state
->position
< save_state
->size
) {
266 if(a_save_sample
!= NULL
) {
267 filename
= g_string_new("");
268 g_string_printf(filename
, "%s.%u.xml.%u", a_save_sample
,
269 save_state
->position
, save_state
->version
);
270 fp
= fopen(filename
->str
, "w");
271 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
272 g_string_free(filename
, TRUE
);
273 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
275 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
277 save_state
->write_time
[save_state
->position
] = tfs
->parent
.timestamp
;
278 save_state
->position
++;
284 static void sanitize_name(gchar
*name
)
286 while(*name
!= '\0') {
287 if(*name
== '/') *name
= '_';
294 static void compute_tracefile(LttTracefile
*tracefile
, void *hook_data
)
297 guint nb_equal
, nb_block
, offset
;
300 LttTime time
, previous_time
;
301 LttEvent
*event
= ltt_tracefile_get_event(tracefile
);
302 LttFacility
*facility
;
303 LttEventType
*event_type
;
305 gchar mod_name
[PATH_MAX
];
307 /* start_count is always initialized in this function _if_ there is always
308 * a block_start before a block_end.
310 long long unsigned cycle_count
, start_count
=0, delta_cycle
;
313 filename
= g_string_new("");
314 strcpy(mod_name
, g_quark_to_string(ltt_tracefile_name(tracefile
)));
316 sanitize_name(mod_name
);
318 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile
)));
319 g_string_printf(filename
, "%s.%s.%u.trace", a_dump_tracefiles
,
320 mod_name
, ltt_tracefile_cpu(tracefile
));
321 fp
= fopen(filename
->str
, "w");
322 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
323 g_string_free(filename
, TRUE
);
324 err
= ltt_tracefile_seek_time(tracefile
, ltt_time_zero
);
327 previous_time
= ltt_time_zero
;
331 LttTracefile
*tf_pos
;
332 facility
= ltt_event_facility(event
);
333 event_type
= ltt_event_eventtype(event
);
334 time
= ltt_event_time(event
);
335 ltt_event_position(event
, a_event_position
);
336 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
337 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
338 fprintf(fp
, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
339 g_quark_to_string(ltt_facility_name(facility
)),
340 g_quark_to_string(ltt_eventtype_name(event_type
)),
341 tsc
, (unsigned long)time
.tv_sec
,
342 (unsigned long)time
.tv_nsec
,
344 g_quark_to_string(ltt_tracefile_name(tracefile
)));
346 if(ltt_time_compare(time
, previous_time
) < 0) {
347 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
348 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
349 g_quark_to_string(ltt_tracefile_name(tracefile
)),
350 ltt_tracefile_cpu(tracefile
), nb_block
, offset
);
351 g_warning("last time %lu.%lu vs current %lu.%lu",
352 previous_time
.tv_sec
, previous_time
.tv_nsec
,
353 time
.tv_sec
, time
.tv_nsec
);
357 if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_START
) {
358 start_count
= cycle_count
;
361 else if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_END
) {
362 delta_cycle
= cycle_count
- start_count
;
363 end_nsec_sec
= (long long unsigned)time
.tv_sec
* (long long unsigned)1000000000;
364 end_nsec_nsec
= time
.tv_nsec
;
365 end_nsec
= end_nsec_sec
+ end_nsec_nsec
;
366 start_nsec
= (long long unsigned)start_time
.tv_sec
* (long long unsigned)1000000000 + (long long unsigned)start_time
.tv_nsec
;
367 delta_nsec
= end_nsec
- start_nsec
;
368 cycle_per_nsec
= (double)delta_cycle
/ (double)delta_nsec
;
369 nsec_per_cycle
= (double)delta_nsec
/ (double)delta_cycle
;
370 added_nsec
= (double)delta_cycle
* nsec_per_cycle
;
371 interpolated_nsec
= start_nsec
+ added_nsec
;
372 added_nsec2
= (double)delta_cycle
/ cycle_per_nsec
;
373 interpolated_nsec2
= start_nsec
+ added_nsec2
;
375 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
);
379 if(ltt_time_compare(time
, previous_time
) == 0) nb_equal
++;
380 else if(nb_equal
> 0) {
381 g_warning("Consecutive %d events with time %lu.%09lu",
382 nb_equal
+ 1, previous_time
.tv_sec
, previous_time
.tv_nsec
);
385 previous_time
= time
;
387 } while((!ltt_tracefile_read(tracefile
)));
393 static gboolean
process_traceset(void __UNUSED__
*hook_data
,
394 void __UNUSED__
*call_data
)
397 LttvTracesetStats
*tscs
;
399 LttvTracesetState
*ts
;
401 LttvTracesetContext
*tc
;
407 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
408 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
413 long long unsigned start_nsec
, end_nsec
, delta_nsec
, added_nsec
, added_nsec2
;
415 double cycle_per_nsec
, nsec_per_cycle
;
417 long long interpolated_nsec
, interpolated_nsec2
, end_nsec_sec
, end_nsec_nsec
;
421 LttTime max_time
= { G_MAXULONG
, G_MAXULONG
};
423 a_event_position
= ltt_event_position_new();
425 GData
**tracefiles_groups
;
427 struct compute_tracefile_group_args args
;
429 args
.func
= compute_tracefile
;
430 args
.func_args
= NULL
;
432 if(a_dump_tracefiles
!= NULL
) {
433 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
434 trace
= lttv_trace(lttv_traceset_get(traceset
, i
));
435 tracefiles_groups
= ltt_trace_get_tracefiles_groups(trace
);
437 g_datalist_foreach(tracefiles_groups
,
438 (GDataForeachFunc
)compute_tracefile_group
,
444 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
446 tc
= &tscs
->parent
.parent
;
448 lttv_context_init(tc
, traceset
);
450 /* For each case compute and print the elapsed time.
451 The first case is simply to run through all events with a
454 if(a_test1
|| a_test_all
) {
456 lttv_hooks_add(event_hook
, count_event
, &count
, LTTV_PRIO_DEFAULT
);
457 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
458 lttv_hooks_remove_data(event_hook
, count_event
, &count
);
460 "Processing trace while counting events (%u events in %g seconds)",
464 /* Run through all events computing the state. */
466 if(a_test2
|| a_test_all
) {
467 lttv_state_add_event_hooks(ts
);
468 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
469 lttv_state_remove_event_hooks(ts
);
470 g_message("Processing trace while updating state (%g seconds)", t
);
473 /* Run through all events computing the state and writing it out
476 SaveState save_state
;
478 save_state
.interval
= a_sample_interval
;
479 save_state
.size
= a_sample_number
;
480 save_state
.fp
= stderr
;
481 save_state
.write_time
= g_new(LttTime
, a_sample_number
);
484 if(a_test3
|| a_test_all
) {
485 for(i
= 0 ; i
< 2 ; i
++) {
486 save_state
.count
= 0;
487 save_state
.position
= 0;
488 save_state
.version
= i
;
489 lttv_state_add_event_hooks(ts
);
490 lttv_hooks_add(event_hook
, save_state_event
, &save_state
,
492 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
493 lttv_state_remove_event_hooks(ts
);
494 lttv_hooks_remove_data(event_hook
, save_state_event
, &save_state
);
495 g_warning("Processing while updating/writing state (%g seconds)", t
);
499 /* Run through all events computing the stats. */
501 if(a_test4
|| a_test_all
) {
502 if(lttv_profile_memory
) {
503 g_message("Memory summary before computing stats");
507 lttv_stats_add_event_hooks(tscs
);
508 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
509 lttv_stats_remove_event_hooks(tscs
);
510 g_message("Processing trace while counting stats (%g seconds)", t
);
512 if(lttv_profile_memory
) {
513 g_message("Memory summary after computing stats");
517 lttv_stats_sum_traceset(tscs
);
519 if(lttv_profile_memory
) {
520 g_message("Memory summary after summing stats");
524 lttv_context_fini(tc
);
525 lttv_context_init(tc
, traceset
);
527 if(lttv_profile_memory
) {
528 g_message("Memory summary after cleaning up the stats");
533 /* Run through all events computing the state and stats. */
535 if(a_test5
|| a_test_all
) {
536 if(lttv_profile_memory
) {
537 g_message("Memory summary before computing state and stats");
541 lttv_state_add_event_hooks(ts
);
542 lttv_stats_add_event_hooks(tscs
);
543 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
544 lttv_state_remove_event_hooks(ts
);
545 lttv_stats_remove_event_hooks(tscs
);
547 "Processing trace while counting state and stats (%g seconds)", t
);
549 if(lttv_profile_memory
) {
550 g_message("Memory summary after computing and state and stats");
554 lttv_context_fini(tc
);
555 lttv_context_init(tc
, traceset
);
557 if(lttv_profile_memory
) {
558 g_message("Memory summary after cleaning up the stats");
563 /* Run through all events computing and saving the state. */
565 if(a_trace_event
) lttv_hooks_add(event_hook
, trace_event
, NULL
,
568 if(a_test6
|| a_test_all
) {
569 if(lttv_profile_memory
) {
570 g_message("Memory summary before computing and saving state");
574 lttv_state_add_event_hooks(ts
);
575 lttv_state_save_add_event_hooks(ts
);
576 if(a_save_state_copy
)
577 lttv_hooks_add(event_hook
, save_state_copy_event
, &save_state
,
579 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
580 lttv_state_remove_event_hooks(ts
);
581 lttv_state_save_remove_event_hooks(ts
);
582 if(a_save_state_copy
)
583 lttv_hooks_remove_data(event_hook
,save_state_copy_event
, &save_state
);
585 g_message("Processing trace while updating/saving state (%g seconds)", t
);
587 if(lttv_profile_memory
) {
588 g_message("Memory summary after computing/saving state");
593 /* Seek a few times to each saved position */
595 if((a_test7
&& a_test3
) || a_test_all
) {
596 g_assert(a_seek_number
>= 0);
597 for(i
= 0 ; i
< (guint
)a_seek_number
; i
++) {
598 gint reverse_j
; /* just to make sure j is unsigned */
599 for(reverse_j
= save_state
.position
- 1 ; reverse_j
>= 0 ; reverse_j
--) {
600 j
= (guint
)reverse_j
;
601 lttv_state_add_event_hooks(ts
);
602 t
= run_one_test(ts
, save_state
.write_time
[j
],
603 save_state
.write_time
[j
]);
604 lttv_state_remove_event_hooks(ts
);
605 g_message("Seeking to %lu.%lu (%g seconds)",
606 save_state
.write_time
[j
].tv_sec
, save_state
.write_time
[j
].tv_nsec
,
609 if(a_save_sample
!= NULL
) {
610 filename
= g_string_new("");
611 g_string_printf(filename
, "%s.%d.xml.bak%d", a_save_sample
, j
, i
);
612 fp
= fopen(filename
->str
, "w");
613 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
614 g_string_free(filename
, TRUE
);
615 lttv_state_write((LttvTraceState
*)tc
->traces
[0],
616 save_state
.write_time
[j
], fp
);
619 //else lttv_state_write((LttvTraceState *)tc->traces[0],
620 // save_state.write_time[j], save_state.fp);
625 /* Seek at specified interval, using states computed in 6, making
626 * sure that there is no more than the number of events between
627 * state save interval to read before getting there.
630 if((a_test8
&& a_test6
) || a_test_all
) {
631 g_message("Running test 8 : check save interval");
632 LttTime time
= tc
->time_span
.start_time
;
635 interval
.tv_nsec
= 175674987;
638 while(ltt_time_compare(time
, tc
->time_span
.end_time
) < 0) {
639 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
640 lttv_process_traceset_seek_time(&ts
->parent
, ltt_time_zero
);
641 lttv_state_traceset_seek_time_closest(ts
, time
);
642 /* We add no hook to the traceset, not necessary */
643 count
= lttv_process_traceset_middle(&ts
->parent
,
644 time
, G_MAXUINT
, NULL
);
645 g_info("Number of events to jump over : %u", count
);
647 if(count
> LTTV_STATE_SAVE_INTERVAL
)
648 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.",
649 LTTV_STATE_SAVE_INTERVAL
, count
, time
.tv_sec
, time
.tv_nsec
);
650 time
= ltt_time_add(time
, interval
);
655 if(a_test9
|| a_test_all
) {
657 /* Run seek_forward and seek_backward test */
659 LttvTracesetContext
*tsc
= &ts
->parent
;
660 LttvTracesetContextPosition
*saved_pos
=
661 lttv_traceset_context_position_new(tsc
);
662 g_message("Running test 9 : seek_forward and seek_backward");
663 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
665 count
= lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
666 g_assert(count
== 500);
667 lttv_traceset_context_position_save(tsc
, saved_pos
);
669 count
= lttv_process_traceset_seek_n_forward(tsc
, 150000, NULL
);
671 g_message("Seek forward 150000 events in %g seconds", t1
- t0
);
672 g_assert(count
== 150000);
674 count
= lttv_process_traceset_seek_n_backward(tsc
, 150000,
675 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
677 g_message("Seek backward 150000 events in %g seconds", t1
- t0
);
678 g_assert(count
== 150000);
679 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
680 g_warning("Problem with seek_n ! Positions differ. (1)");
683 lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
684 lttv_traceset_context_position_save(tsc
, saved_pos
);
685 lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
686 lttv_process_traceset_seek_n_backward(tsc
, 15005,
687 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
688 lttv_process_traceset_seek_n_forward(tsc
, 5, NULL
);
689 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
690 g_warning("Problem with seek_n ! Positions differ. (2)");
693 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
695 count
= lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
697 g_warning("Problem with seek_n ! Forward at end of traceset.");
699 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
701 lttv_traceset_context_position_save(tsc
, saved_pos
);
703 lttv_process_traceset_seek_n_backward(tsc
, 300,
704 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
706 g_message("Seek backward 300 events in %g seconds", t1
- t0
);
707 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
708 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
710 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
711 g_warning("Problem with seek_n ! Positions differ. (4)");
714 lttv_traceset_context_position_save(tsc
, saved_pos
);
716 lttv_process_traceset_seek_n_backward(tsc
, 10,
717 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
719 g_message("Seek backward 10 events in %g seconds", t1
- t0
);
721 count
= lttv_process_traceset_seek_n_forward(tsc
, 10, NULL
);
723 g_message("Seek forward 10 events in %g seconds", t1
- t0
);
726 /* try a volountary error */
727 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
729 lttv_traceset_context_position_save(tsc
, saved_pos
);
730 lttv_process_traceset_seek_n_backward(tsc
, 301,
731 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
732 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
733 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
735 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) == 0) {
736 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
739 /* Try a seek by closest time : Hint : try this one with and without states
741 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
742 count
= lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
);
743 lttv_traceset_context_position_save(tsc
, saved_pos
);
745 lttv_process_traceset_seek_n_backward(tsc
, 100301,
746 seek_back_default_offset
,
747 (seek_time_fct
)lttv_state_traceset_seek_time_closest
, NULL
);
749 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
751 count
= lttv_process_traceset_seek_n_forward(tsc
, 100301, NULL
);
753 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
754 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
757 lttv_traceset_context_position_destroy(saved_pos
);
760 if(a_test10
|| a_test_all
) {
761 g_message("Running test 10 : check seek traceset context position");
762 LttvTracesetContext
*tsc
= &ts
->parent
;
763 LttvTracesetContextPosition
*saved_pos
=
764 lttv_traceset_context_position_new(tsc
);
766 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
767 lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
);
768 lttv_traceset_context_position_save(tsc
, saved_pos
);
769 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
770 g_critical("Error in seek position. (1)");
772 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
773 lttv_process_traceset_seek_n_backward(tsc
, 500,
774 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
775 lttv_traceset_context_position_save(tsc
, saved_pos
);
777 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
778 g_critical("Error in seek position. (2)");
780 lttv_traceset_context_position_destroy(saved_pos
);
783 if(a_trace_event
) lttv_hooks_remove_data(event_hook
, trace_event
, NULL
);
785 g_free(save_state
.write_time
);
786 g_free(a_event_position
);
787 lttv_context_fini(tc
);
788 g_object_unref(tscs
);
790 if(lttv_profile_memory
) {
791 g_message("Memory summary at the end of batchtest");
795 g_info("BatchTest end process traceset");
802 LttvAttributeValue value
;
804 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
806 g_info("Init batchtest.c");
809 QUARK_BLOCK_START
= g_quark_from_string("block_start");
810 QUARK_BLOCK_END
= g_quark_from_string("block_end");
813 lttv_option_add("trace", 't',
814 "add a trace to the trace set to analyse",
815 "pathname of the directory containing the trace",
816 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
818 a_trace_event
= FALSE
;
820 a_dump_tracefiles
= NULL
;
821 lttv_option_add("dump-tracefiles", 'D',
822 "Write event by event the content of tracefiles",
823 "basename for the files where to dump events",
824 LTTV_OPT_STRING
, &a_dump_tracefiles
, NULL
, NULL
);
826 a_save_sample
= NULL
;
827 lttv_option_add("save-sample", 's',
828 "Save state samples to multiple files",
829 "basename for the files containing the state samples",
830 LTTV_OPT_STRING
, &a_save_sample
, NULL
, NULL
);
832 a_save_state_copy
= FALSE
;
833 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
834 "", LTTV_OPT_NONE
, &a_save_state_copy
, NULL
, NULL
);
836 a_save_interval
= 100000;
837 lttv_option_add("save-interval", 'i',
838 "Interval between saving state",
839 "number of events before a block start triggers saving state",
840 LTTV_OPT_INT
, &a_save_interval
, NULL
, NULL
);
842 a_sample_interval
= 100000;
843 lttv_option_add("sample-interval", 'S',
844 "Interval between sampling state",
845 "number of events before sampling and writing state",
846 LTTV_OPT_INT
, &a_sample_interval
, NULL
, NULL
);
848 a_sample_number
= 20;
849 lttv_option_add("sample-number", 'N',
850 "Number of state samples",
852 LTTV_OPT_INT
, &a_sample_number
, NULL
, NULL
);
855 lttv_option_add("seek-number", 'K',
858 LTTV_OPT_INT
, &a_seek_number
, NULL
, NULL
);
861 lttv_option_add("test1", '1', "Test just counting events", "",
862 LTTV_OPT_NONE
, &a_test1
, NULL
, NULL
);
865 lttv_option_add("test2", '2', "Test computing the state", "",
866 LTTV_OPT_NONE
, &a_test2
, NULL
, NULL
);
869 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
870 "", LTTV_OPT_NONE
, &a_test3
, NULL
, NULL
);
873 lttv_option_add("test4", '4', "Test computing the stats", "",
874 LTTV_OPT_NONE
, &a_test4
, NULL
, NULL
);
877 lttv_option_add("test5", '5', "Test computing the state and stats", "",
878 LTTV_OPT_NONE
, &a_test5
, NULL
, NULL
);
881 lttv_option_add("test6", '6', "Test computing and saving the state", "",
882 LTTV_OPT_NONE
, &a_test6
, NULL
, NULL
);
885 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
886 "", LTTV_OPT_NONE
, &a_test7
, NULL
, NULL
);
889 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
890 "", LTTV_OPT_NONE
, &a_test8
, NULL
, NULL
);
893 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
894 "", LTTV_OPT_NONE
, &a_test9
, NULL
, NULL
);
897 lttv_option_add("test10", ' ', "Test seeking traceset by position",
898 "", LTTV_OPT_NONE
, &a_test10
, NULL
, NULL
);
903 lttv_option_add("testall", 'a', "Run all tests ", "",
904 LTTV_OPT_NONE
, &a_test_all
, NULL
, NULL
);
906 traceset
= lttv_traceset_new();
908 before_traceset
= lttv_hooks_new();
909 after_traceset
= lttv_hooks_new();
910 before_trace
= lttv_hooks_new();
911 after_trace
= lttv_hooks_new();
912 before_tracefile
= lttv_hooks_new();
913 after_tracefile
= lttv_hooks_new();
914 //before_event = lttv_hooks_new();
915 //after_event = lttv_hooks_new();
916 event_hook
= lttv_hooks_new();
919 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
920 LTTV_POINTER
, &value
));
921 *(value
.v_pointer
) = before_traceset
;
922 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
923 LTTV_POINTER
, &value
));
924 *(value
.v_pointer
) = after_traceset
;
925 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
926 LTTV_POINTER
, &value
));
927 *(value
.v_pointer
) = before_trace
;
928 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
929 LTTV_POINTER
, &value
));
930 *(value
.v_pointer
) = after_trace
;
931 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
932 LTTV_POINTER
, &value
));
933 *(value
.v_pointer
) = before_tracefile
;
934 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
935 LTTV_POINTER
, &value
));
936 *(value
.v_pointer
) = after_tracefile
;
937 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
938 // LTTV_POINTER, &value));
939 //*(value.v_pointer) = before_event;
940 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
941 // LTTV_POINTER, &value));
942 //*(value.v_pointer) = after_event;
943 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
944 LTTV_POINTER
, &value
));
945 *(value
.v_pointer
) = event_hook
;
946 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
947 LTTV_POINTER
, &value
));
948 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
949 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
953 static void destroy()
959 g_info("Destroy batchAnalysis.c");
961 lttv_option_remove("trace");
962 lttv_option_remove("dump-tracefiles");
963 lttv_option_remove("save-sample");
964 lttv_option_remove("save-state-copy");
965 lttv_option_remove("sample-interval");
966 lttv_option_remove("sample-number");
967 lttv_option_remove("seek-number");
968 lttv_option_remove("save-interval");
969 lttv_option_remove("test1");
970 lttv_option_remove("test2");
971 lttv_option_remove("test3");
972 lttv_option_remove("test4");
973 lttv_option_remove("test5");
974 lttv_option_remove("test6");
975 lttv_option_remove("test7");
976 lttv_option_remove("test8");
977 lttv_option_remove("test9");
978 lttv_option_remove("test10");
979 lttv_option_remove("testall");
981 lttv_hooks_destroy(before_traceset
);
982 lttv_hooks_destroy(after_traceset
);
983 lttv_hooks_destroy(before_trace
);
984 lttv_hooks_destroy(after_trace
);
985 lttv_hooks_destroy(before_tracefile
);
986 lttv_hooks_destroy(after_tracefile
);
987 //lttv_hooks_destroy(before_event);
988 //lttv_hooks_destroy(after_event);
989 lttv_hooks_destroy(event_hook
);
990 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
992 nb
= lttv_traceset_number(traceset
);
993 for(i
= 0 ; i
< nb
; i
++) {
994 trace
= lttv_traceset_get(traceset
, i
);
995 lttv_traceset_remove(traceset
,i
);
996 ltt_trace_close(lttv_trace(trace
));
997 lttv_trace_destroy(trace
);
1000 lttv_traceset_destroy(traceset
);
1004 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
1005 "Run through a trace calling all the registered hooks for tests", \
1006 init
, destroy
, "state", "stats", "option" )