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
;
84 static GQuark QUARK_BLOCK_START
,
87 LttEventPosition
*a_event_position
;
89 typedef struct _save_state
{
100 static void lttv_trace_option(void __UNUSED__
*hook_data
)
104 trace
= ltt_trace_open(a_trace
);
106 g_critical("cannot open trace %s", a_trace
);
108 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
112 static double get_time()
116 g_get_current_time(>
);
117 return gt
.tv_sec
+ (double)gt
.tv_usec
/ (double)1000000.0;
120 static double run_one_test(LttvTracesetState
*ts
, LttTime start
, LttTime end
)
126 //lttv_traceset_context_add_hooks(&ts->parent,
127 //before_traceset, after_traceset, NULL, before_trace, after_trace,
128 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
129 lttv_process_traceset_begin(&ts
->parent
,
136 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
137 ((LttvTraceState
*)(ts
->parent
.traces
[i
]))->save_interval
=a_save_interval
;
141 lttv_state_traceset_seek_time_closest(ts
, start
);
142 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
143 lttv_process_traceset_middle(&ts
->parent
,
149 //lttv_traceset_context_remove_hooks(&ts->parent,
150 //before_traceset, after_traceset, NULL, before_trace, after_trace,
151 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
152 lttv_process_traceset_end(&ts
->parent
,
163 gboolean
trace_event(void __UNUSED__
*hook_data
, void *call_data
)
165 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
167 guint nb_block
, offset
;
172 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
173 ltt_event_position(e
, a_event_position
);
174 ltt_event_position_get(a_event_position
, &tf
, &nb_block
, &offset
, &tsc
);
175 fprintf(stderr
,"Event %s %lu.%09lu [%u 0x%x tsc %llu]\n",
176 g_quark_to_string(ltt_eventtype_name(ltt_event_eventtype(e
))),
177 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
,
178 nb_block
, offset
, tsc
);
182 static LttTime count_previous_time
= { 0, 0 };
184 gboolean
count_event(void *hook_data
, void __UNUSED__
*call_data
)
186 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
187 LttTracefile
*tracefile
= tfs
->parent
.tf
;
188 guint nb_block
, offset
;
189 LttTracefile
*tf_pos
;
191 LttEvent
* event
= ltt_tracefile_get_event(tracefile
);
193 guint
*pcount
= (guint
*)hook_data
;
197 time
= ltt_event_time(event
);
198 ltt_event_position(event
, a_event_position
);
199 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
201 if(ltt_time_compare(time
, count_previous_time
) < 0) {
202 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
203 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
204 g_quark_to_string(ltt_tracefile_name(tracefile
)),
205 ltt_tracefile_num(tracefile
), nb_block
, offset
);
206 g_warning("last time %lu.%lu vs current %lu.%lu",
207 count_previous_time
.tv_sec
, count_previous_time
.tv_nsec
,
208 time
.tv_sec
, time
.tv_nsec
);
210 count_previous_time
= time
;
218 gboolean
save_state_copy_event(void *hook_data
, void *call_data
)
220 SaveState __UNUSED__
*save_state
= (SaveState
*)hook_data
;
222 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
224 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
226 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
232 if(ts
->nb_event
== 0 &&
233 ltt_eventtype_name(ltt_event_eventtype(e
))
234 == QUARK_BLOCK_START
) {
235 if(a_save_sample
!= NULL
) {
236 filename
= g_string_new("");
237 g_string_printf(filename
, "%s.copy.%lu.%09lu.xml", a_save_sample
,
238 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
239 fp
= fopen(filename
->str
, "w");
240 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
241 g_string_free(filename
, TRUE
);
242 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
244 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
250 gboolean
save_state_event(void *hook_data
, void *call_data
)
252 SaveState
*save_state
= (SaveState
*)hook_data
;
254 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
256 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
262 (save_state
->count
)++;
263 if(save_state
->count
% save_state
->interval
== 0 &&
264 save_state
->position
< save_state
->size
) {
265 if(a_save_sample
!= NULL
) {
266 filename
= g_string_new("");
267 g_string_printf(filename
, "%s.%u.xml.%u", a_save_sample
,
268 save_state
->position
, save_state
->version
);
269 fp
= fopen(filename
->str
, "w");
270 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
271 g_string_free(filename
, TRUE
);
272 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
274 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
276 save_state
->write_time
[save_state
->position
] = tfs
->parent
.timestamp
;
277 save_state
->position
++;
283 static void sanitize_name(gchar
*name
)
285 while(*name
!= '\0') {
286 if(*name
== '/') *name
= '_';
293 static void compute_tracefile(LttTracefile
*tracefile
, void *hook_data
)
296 guint nb_equal
, nb_block
, offset
;
299 LttTime time
, previous_time
;
300 LttEvent
*event
= ltt_tracefile_get_event(tracefile
);
301 LttFacility
*facility
;
302 LttEventType
*event_type
;
304 gchar mod_name
[PATH_MAX
];
306 /* start_count is always initialized in this function _if_ there is always
307 * a block_start before a block_end.
309 long long unsigned cycle_count
, start_count
=0, delta_cycle
;
312 filename
= g_string_new("");
313 strcpy(mod_name
, g_quark_to_string(ltt_tracefile_name(tracefile
)));
315 sanitize_name(mod_name
);
317 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile
)));
318 g_string_printf(filename
, "%s.%s.%u.trace", a_dump_tracefiles
,
319 mod_name
, ltt_tracefile_num(tracefile
));
320 fp
= fopen(filename
->str
, "w");
321 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
322 g_string_free(filename
, TRUE
);
323 err
= ltt_tracefile_seek_time(tracefile
, ltt_time_zero
);
326 previous_time
= ltt_time_zero
;
330 LttTracefile
*tf_pos
;
331 facility
= ltt_event_facility(event
);
332 event_type
= ltt_event_eventtype(event
);
333 time
= ltt_event_time(event
);
334 ltt_event_position(event
, a_event_position
);
335 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
336 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
337 fprintf(fp
, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
338 g_quark_to_string(ltt_facility_name(facility
)),
339 g_quark_to_string(ltt_eventtype_name(event_type
)),
340 tsc
, (unsigned long)time
.tv_sec
,
341 (unsigned long)time
.tv_nsec
,
343 g_quark_to_string(ltt_tracefile_name(tracefile
)));
345 if(ltt_time_compare(time
, previous_time
) < 0) {
346 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
347 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
348 g_quark_to_string(ltt_tracefile_name(tracefile
)),
349 ltt_tracefile_num(tracefile
), nb_block
, offset
);
350 g_warning("last time %lu.%lu vs current %lu.%lu",
351 previous_time
.tv_sec
, previous_time
.tv_nsec
,
352 time
.tv_sec
, time
.tv_nsec
);
356 if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_START
) {
357 start_count
= cycle_count
;
360 else if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_END
) {
361 delta_cycle
= cycle_count
- start_count
;
362 end_nsec_sec
= (long long unsigned)time
.tv_sec
* (long long unsigned)1000000000;
363 end_nsec_nsec
= time
.tv_nsec
;
364 end_nsec
= end_nsec_sec
+ end_nsec_nsec
;
365 start_nsec
= (long long unsigned)start_time
.tv_sec
* (long long unsigned)1000000000 + (long long unsigned)start_time
.tv_nsec
;
366 delta_nsec
= end_nsec
- start_nsec
;
367 cycle_per_nsec
= (double)delta_cycle
/ (double)delta_nsec
;
368 nsec_per_cycle
= (double)delta_nsec
/ (double)delta_cycle
;
369 added_nsec
= (double)delta_cycle
* nsec_per_cycle
;
370 interpolated_nsec
= start_nsec
+ added_nsec
;
371 added_nsec2
= (double)delta_cycle
/ cycle_per_nsec
;
372 interpolated_nsec2
= start_nsec
+ added_nsec2
;
374 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
);
378 if(ltt_time_compare(time
, previous_time
) == 0) nb_equal
++;
379 else if(nb_equal
> 0) {
380 g_warning("Consecutive %d events with time %lu.%09lu",
381 nb_equal
+ 1, previous_time
.tv_sec
, previous_time
.tv_nsec
);
384 previous_time
= time
;
386 } while((!ltt_tracefile_read(tracefile
)));
392 static gboolean
process_traceset(void __UNUSED__
*hook_data
,
393 void __UNUSED__
*call_data
)
396 LttvTracesetStats
*tscs
;
398 LttvTracesetState
*ts
;
400 LttvTracesetContext
*tc
;
406 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
407 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
412 long long unsigned start_nsec
, end_nsec
, delta_nsec
, added_nsec
, added_nsec2
;
414 double cycle_per_nsec
, nsec_per_cycle
;
416 long long interpolated_nsec
, interpolated_nsec2
, end_nsec_sec
, end_nsec_nsec
;
420 LttTime max_time
= { G_MAXULONG
, G_MAXULONG
};
422 a_event_position
= ltt_event_position_new();
424 GData
**tracefiles_groups
;
426 struct compute_tracefile_group_args args
;
428 args
.func
= compute_tracefile
;
429 args
.func_args
= NULL
;
431 if(a_dump_tracefiles
!= NULL
) {
432 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
433 trace
= lttv_trace(lttv_traceset_get(traceset
, i
));
434 tracefiles_groups
= ltt_trace_get_tracefiles_groups(trace
);
436 g_datalist_foreach(tracefiles_groups
,
437 (GDataForeachFunc
)compute_tracefile_group
,
443 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
445 tc
= &tscs
->parent
.parent
;
447 lttv_context_init(tc
, traceset
);
449 /* For each case compute and print the elapsed time.
450 The first case is simply to run through all events with a
453 if(a_test1
|| a_test_all
) {
455 lttv_hooks_add(event_hook
, count_event
, &count
, LTTV_PRIO_DEFAULT
);
456 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
457 lttv_hooks_remove_data(event_hook
, count_event
, &count
);
459 "Processing trace while counting events (%u events in %g seconds)",
463 /* Run through all events computing the state. */
465 if(a_test2
|| a_test_all
) {
466 lttv_state_add_event_hooks(ts
);
467 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
468 lttv_state_remove_event_hooks(ts
);
469 g_message("Processing trace while updating state (%g seconds)", t
);
472 /* Run through all events computing the state and writing it out
475 SaveState save_state
;
477 save_state
.interval
= a_sample_interval
;
478 save_state
.size
= a_sample_number
;
479 save_state
.fp
= stderr
;
480 save_state
.write_time
= g_new(LttTime
, a_sample_number
);
483 if(a_test3
|| a_test_all
) {
484 for(i
= 0 ; i
< 2 ; i
++) {
485 save_state
.count
= 0;
486 save_state
.position
= 0;
487 save_state
.version
= i
;
488 lttv_state_add_event_hooks(ts
);
489 lttv_hooks_add(event_hook
, save_state_event
, &save_state
,
491 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
492 lttv_state_remove_event_hooks(ts
);
493 lttv_hooks_remove_data(event_hook
, save_state_event
, &save_state
);
494 g_warning("Processing while updating/writing state (%g seconds)", t
);
498 /* Run through all events computing the stats. */
500 if(a_test4
|| a_test_all
) {
501 if(lttv_profile_memory
) {
502 g_message("Memory summary before computing stats");
506 lttv_stats_add_event_hooks(tscs
);
507 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
508 lttv_stats_remove_event_hooks(tscs
);
509 g_message("Processing trace while counting stats (%g seconds)", t
);
511 if(lttv_profile_memory
) {
512 g_message("Memory summary after computing stats");
516 lttv_stats_sum_traceset(tscs
);
518 if(lttv_profile_memory
) {
519 g_message("Memory summary after summing stats");
523 lttv_context_fini(tc
);
524 lttv_context_init(tc
, traceset
);
526 if(lttv_profile_memory
) {
527 g_message("Memory summary after cleaning up the stats");
532 /* Run through all events computing the state and stats. */
534 if(a_test5
|| a_test_all
) {
535 if(lttv_profile_memory
) {
536 g_message("Memory summary before computing state and stats");
540 lttv_state_add_event_hooks(ts
);
541 lttv_stats_add_event_hooks(tscs
);
542 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
543 lttv_state_remove_event_hooks(ts
);
544 lttv_stats_remove_event_hooks(tscs
);
546 "Processing trace while counting state and stats (%g seconds)", t
);
548 if(lttv_profile_memory
) {
549 g_message("Memory summary after computing and state and stats");
553 lttv_context_fini(tc
);
554 lttv_context_init(tc
, traceset
);
556 if(lttv_profile_memory
) {
557 g_message("Memory summary after cleaning up the stats");
562 /* Run through all events computing and saving the state. */
564 if(a_trace_event
) lttv_hooks_add(event_hook
, trace_event
, NULL
,
567 if(a_test6
|| a_test_all
) {
568 if(lttv_profile_memory
) {
569 g_message("Memory summary before computing and saving state");
573 lttv_state_add_event_hooks(ts
);
574 lttv_state_save_add_event_hooks(ts
);
575 if(a_save_state_copy
)
576 lttv_hooks_add(event_hook
, save_state_copy_event
, &save_state
,
578 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
579 lttv_state_remove_event_hooks(ts
);
580 lttv_state_save_remove_event_hooks(ts
);
581 if(a_save_state_copy
)
582 lttv_hooks_remove_data(event_hook
,save_state_copy_event
, &save_state
);
584 g_message("Processing trace while updating/saving state (%g seconds)", t
);
586 if(lttv_profile_memory
) {
587 g_message("Memory summary after computing/saving state");
592 /* Seek a few times to each saved position */
594 if((a_test7
&& a_test3
) || a_test_all
) {
595 g_assert(a_seek_number
>= 0);
596 for(i
= 0 ; i
< (guint
)a_seek_number
; i
++) {
597 gint reverse_j
; /* just to make sure j is unsigned */
598 for(reverse_j
= save_state
.position
- 1 ; reverse_j
>= 0 ; reverse_j
--) {
599 j
= (guint
)reverse_j
;
600 lttv_state_add_event_hooks(ts
);
601 t
= run_one_test(ts
, save_state
.write_time
[j
],
602 save_state
.write_time
[j
]);
603 lttv_state_remove_event_hooks(ts
);
604 g_message("Seeking to %lu.%lu (%g seconds)",
605 save_state
.write_time
[j
].tv_sec
, save_state
.write_time
[j
].tv_nsec
,
608 if(a_save_sample
!= NULL
) {
609 filename
= g_string_new("");
610 g_string_printf(filename
, "%s.%d.xml.bak%d", a_save_sample
, j
, i
);
611 fp
= fopen(filename
->str
, "w");
612 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
613 g_string_free(filename
, TRUE
);
614 lttv_state_write((LttvTraceState
*)tc
->traces
[0],
615 save_state
.write_time
[j
], fp
);
618 //else lttv_state_write((LttvTraceState *)tc->traces[0],
619 // save_state.write_time[j], save_state.fp);
624 /* Seek at specified interval, using states computed in 6, making
625 * sure that there is no more than the number of events between
626 * state save interval to read before getting there.
629 if((a_test8
&& a_test6
) || a_test_all
) {
630 g_message("Running test 8 : check save interval");
631 LttTime time
= tc
->time_span
.start_time
;
634 interval
.tv_nsec
= 175674987;
637 while(ltt_time_compare(time
, tc
->time_span
.end_time
) < 0) {
638 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
639 lttv_process_traceset_seek_time(&ts
->parent
, ltt_time_zero
);
640 lttv_state_traceset_seek_time_closest(ts
, time
);
641 /* We add no hook to the traceset, not necessary */
642 count
= lttv_process_traceset_middle(&ts
->parent
,
643 time
, G_MAXUINT
, NULL
);
644 g_info("Number of events to jump over : %u", count
);
646 if(count
> LTTV_STATE_SAVE_INTERVAL
)
647 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.",
648 LTTV_STATE_SAVE_INTERVAL
, count
, time
.tv_sec
, time
.tv_nsec
);
649 time
= ltt_time_add(time
, interval
);
654 if(a_test9
|| a_test_all
) {
656 /* Run seek_forward and seek_backward test */
658 LttvTracesetContext
*tsc
= &ts
->parent
;
659 LttvTracesetContextPosition
*saved_pos
=
660 lttv_traceset_context_position_new(tsc
);
661 g_message("Running test 9 : seek_forward and seek_backward");
662 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
664 count
= lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
665 g_assert(count
== 500);
666 lttv_traceset_context_position_save(tsc
, saved_pos
);
668 count
= lttv_process_traceset_seek_n_forward(tsc
, 150000, NULL
);
670 g_message("Seek forward 150000 events in %g seconds", t1
- t0
);
671 g_assert(count
== 150000);
673 count
= lttv_process_traceset_seek_n_backward(tsc
, 150000,
674 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
676 g_message("Seek backward 150000 events in %g seconds", t1
- t0
);
677 g_assert(count
== 150000);
678 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
679 g_warning("Problem with seek_n ! Positions differ. (1)");
682 lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
);
683 lttv_traceset_context_position_save(tsc
, saved_pos
);
684 lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
685 lttv_process_traceset_seek_n_backward(tsc
, 15005,
686 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
687 lttv_process_traceset_seek_n_forward(tsc
, 5, NULL
);
688 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
689 g_warning("Problem with seek_n ! Positions differ. (2)");
692 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
694 count
= lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
);
696 g_warning("Problem with seek_n ! Forward at end of traceset.");
698 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
700 lttv_traceset_context_position_save(tsc
, saved_pos
);
702 lttv_process_traceset_seek_n_backward(tsc
, 300,
703 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
705 g_message("Seek backward 300 events in %g seconds", t1
- t0
);
706 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
707 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
709 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
710 g_warning("Problem with seek_n ! Positions differ. (4)");
713 lttv_traceset_context_position_save(tsc
, saved_pos
);
715 lttv_process_traceset_seek_n_backward(tsc
, 10,
716 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
718 g_message("Seek backward 10 events in %g seconds", t1
- t0
);
720 count
= lttv_process_traceset_seek_n_forward(tsc
, 10, NULL
);
722 g_message("Seek forward 10 events in %g seconds", t1
- t0
);
725 /* try a volountary error */
726 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
728 lttv_traceset_context_position_save(tsc
, saved_pos
);
729 lttv_process_traceset_seek_n_backward(tsc
, 301,
730 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
731 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
);
732 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
);
734 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) == 0) {
735 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
738 /* Try a seek by closest time : Hint : try this one with and without states
740 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
741 count
= lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
);
742 lttv_traceset_context_position_save(tsc
, saved_pos
);
744 lttv_process_traceset_seek_n_backward(tsc
, 100301,
745 seek_back_default_offset
,
746 (seek_time_fct
)lttv_state_traceset_seek_time_closest
, NULL
);
748 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
750 count
= lttv_process_traceset_seek_n_forward(tsc
, 100301, NULL
);
752 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
753 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
756 lttv_traceset_context_position_destroy(saved_pos
);
759 if(a_test10
|| a_test_all
) {
760 g_message("Running test 10 : check seek traceset context position");
761 LttvTracesetContext
*tsc
= &ts
->parent
;
762 LttvTracesetContextPosition
*saved_pos
=
763 lttv_traceset_context_position_new(tsc
);
765 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
766 lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
);
767 lttv_traceset_context_position_save(tsc
, saved_pos
);
768 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
769 g_critical("Error in seek position. (1)");
771 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
772 lttv_process_traceset_seek_n_backward(tsc
, 500,
773 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
);
774 lttv_traceset_context_position_save(tsc
, saved_pos
);
776 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
777 g_critical("Error in seek position. (2)");
779 lttv_traceset_context_position_destroy(saved_pos
);
782 if(a_trace_event
) lttv_hooks_remove_data(event_hook
, trace_event
, NULL
);
784 g_free(save_state
.write_time
);
785 g_free(a_event_position
);
786 lttv_context_fini(tc
);
787 g_object_unref(tscs
);
789 if(lttv_profile_memory
) {
790 g_message("Memory summary at the end of batchtest");
794 g_info("BatchTest end process traceset");
801 LttvAttributeValue value
;
803 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
805 g_info("Init batchtest.c");
808 QUARK_BLOCK_START
= g_quark_from_string("block_start");
809 QUARK_BLOCK_END
= g_quark_from_string("block_end");
812 lttv_option_add("trace", 't',
813 "add a trace to the trace set to analyse",
814 "pathname of the directory containing the trace",
815 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
817 a_trace_event
= FALSE
;
819 a_dump_tracefiles
= NULL
;
820 lttv_option_add("dump-tracefiles", 'D',
821 "Write event by event the content of tracefiles",
822 "basename for the files where to dump events",
823 LTTV_OPT_STRING
, &a_dump_tracefiles
, NULL
, NULL
);
825 a_save_sample
= NULL
;
826 lttv_option_add("save-sample", 's',
827 "Save state samples to multiple files",
828 "basename for the files containing the state samples",
829 LTTV_OPT_STRING
, &a_save_sample
, NULL
, NULL
);
831 a_save_state_copy
= FALSE
;
832 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
833 "", LTTV_OPT_NONE
, &a_save_state_copy
, NULL
, NULL
);
835 a_save_interval
= 100000;
836 lttv_option_add("save-interval", 'i',
837 "Interval between saving state",
838 "number of events before a block start triggers saving state",
839 LTTV_OPT_INT
, &a_save_interval
, NULL
, NULL
);
841 a_sample_interval
= 100000;
842 lttv_option_add("sample-interval", 'S',
843 "Interval between sampling state",
844 "number of events before sampling and writing state",
845 LTTV_OPT_INT
, &a_sample_interval
, NULL
, NULL
);
847 a_sample_number
= 20;
848 lttv_option_add("sample-number", 'N',
849 "Number of state samples",
851 LTTV_OPT_INT
, &a_sample_number
, NULL
, NULL
);
854 lttv_option_add("seek-number", 'K',
857 LTTV_OPT_INT
, &a_seek_number
, NULL
, NULL
);
860 lttv_option_add("test1", '1', "Test just counting events", "",
861 LTTV_OPT_NONE
, &a_test1
, NULL
, NULL
);
864 lttv_option_add("test2", '2', "Test computing the state", "",
865 LTTV_OPT_NONE
, &a_test2
, NULL
, NULL
);
868 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
869 "", LTTV_OPT_NONE
, &a_test3
, NULL
, NULL
);
872 lttv_option_add("test4", '4', "Test computing the stats", "",
873 LTTV_OPT_NONE
, &a_test4
, NULL
, NULL
);
876 lttv_option_add("test5", '5', "Test computing the state and stats", "",
877 LTTV_OPT_NONE
, &a_test5
, NULL
, NULL
);
880 lttv_option_add("test6", '6', "Test computing and saving the state", "",
881 LTTV_OPT_NONE
, &a_test6
, NULL
, NULL
);
884 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
885 "", LTTV_OPT_NONE
, &a_test7
, NULL
, NULL
);
888 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
889 "", LTTV_OPT_NONE
, &a_test8
, NULL
, NULL
);
892 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
893 "", LTTV_OPT_NONE
, &a_test9
, NULL
, NULL
);
896 lttv_option_add("test10", ' ', "Test seeking traceset by position",
897 "", LTTV_OPT_NONE
, &a_test10
, NULL
, NULL
);
902 lttv_option_add("testall", 'a', "Run all tests ", "",
903 LTTV_OPT_NONE
, &a_test_all
, NULL
, NULL
);
905 traceset
= lttv_traceset_new();
907 before_traceset
= lttv_hooks_new();
908 after_traceset
= lttv_hooks_new();
909 before_trace
= lttv_hooks_new();
910 after_trace
= lttv_hooks_new();
911 before_tracefile
= lttv_hooks_new();
912 after_tracefile
= lttv_hooks_new();
913 //before_event = lttv_hooks_new();
914 //after_event = lttv_hooks_new();
915 event_hook
= lttv_hooks_new();
918 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
919 LTTV_POINTER
, &value
));
920 *(value
.v_pointer
) = before_traceset
;
921 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
922 LTTV_POINTER
, &value
));
923 *(value
.v_pointer
) = after_traceset
;
924 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
925 LTTV_POINTER
, &value
));
926 *(value
.v_pointer
) = before_trace
;
927 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
928 LTTV_POINTER
, &value
));
929 *(value
.v_pointer
) = after_trace
;
930 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
931 LTTV_POINTER
, &value
));
932 *(value
.v_pointer
) = before_tracefile
;
933 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
934 LTTV_POINTER
, &value
));
935 *(value
.v_pointer
) = after_tracefile
;
936 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
937 // LTTV_POINTER, &value));
938 //*(value.v_pointer) = before_event;
939 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
940 // LTTV_POINTER, &value));
941 //*(value.v_pointer) = after_event;
942 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
943 LTTV_POINTER
, &value
));
944 *(value
.v_pointer
) = event_hook
;
945 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
946 LTTV_POINTER
, &value
));
947 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
948 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
952 static void destroy()
958 g_info("Destroy batchAnalysis.c");
960 lttv_option_remove("trace");
961 lttv_option_remove("dump-tracefiles");
962 lttv_option_remove("save-sample");
963 lttv_option_remove("save-state-copy");
964 lttv_option_remove("sample-interval");
965 lttv_option_remove("sample-number");
966 lttv_option_remove("seek-number");
967 lttv_option_remove("save-interval");
968 lttv_option_remove("test1");
969 lttv_option_remove("test2");
970 lttv_option_remove("test3");
971 lttv_option_remove("test4");
972 lttv_option_remove("test5");
973 lttv_option_remove("test6");
974 lttv_option_remove("test7");
975 lttv_option_remove("test8");
976 lttv_option_remove("test9");
977 lttv_option_remove("test10");
978 lttv_option_remove("testall");
980 lttv_hooks_destroy(before_traceset
);
981 lttv_hooks_destroy(after_traceset
);
982 lttv_hooks_destroy(before_trace
);
983 lttv_hooks_destroy(after_trace
);
984 lttv_hooks_destroy(before_tracefile
);
985 lttv_hooks_destroy(after_tracefile
);
986 //lttv_hooks_destroy(before_event);
987 //lttv_hooks_destroy(after_event);
988 lttv_hooks_destroy(event_hook
);
989 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
991 nb
= lttv_traceset_number(traceset
);
992 for(i
= 0 ; i
< nb
; i
++) {
993 trace
= lttv_traceset_get(traceset
, i
);
994 lttv_traceset_remove(traceset
,i
);
995 ltt_trace_close(lttv_trace(trace
));
996 lttv_trace_destroy(trace
);
999 lttv_traceset_destroy(traceset
);
1003 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
1004 "Run through a trace calling all the registered hooks for tests", \
1005 init
, destroy
, "state", "stats", "option" )