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. */
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 #define __UNUSED__ __attribute__((__unused__))
42 static LttvTraceset
*traceset
;
58 static char *a_dump_tracefiles
;
60 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
)
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 if(lttv_traceset_add_path(traceset
, a_trace
) < 0) {
113 g_critical("cannot open trace %s", a_trace
);
117 static double get_time()
121 g_get_current_time(>
);
122 return gt
.tv_sec
+ (double)gt
.tv_usec
/ (double)1000000.0;
125 static double run_one_test(LttvTracesetState
*ts
, LttTime start
, LttTime end
)
131 //lttv_traceset_context_add_hooks(&ts->parent,
132 //before_traceset, after_traceset, NULL, before_trace, after_trace,
133 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
134 lttv_process_traceset_begin(&ts
->parent
,
141 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
142 ((LttvTraceState
*)(ts
->parent
.traces
[i
]))->save_interval
=a_save_interval
;
146 lttv_state_traceset_seek_time_closest(ts
, start
);
147 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
148 lttv_process_traceset_middle(&ts
->parent
,
154 //lttv_traceset_context_remove_hooks(&ts->parent,
155 //before_traceset, after_traceset, NULL, before_trace, after_trace,
156 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
157 lttv_process_traceset_end(&ts
->parent
,
168 gboolean
trace_event(void __UNUSED__
*hook_data
, void *call_data
)
170 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
172 guint nb_block
, offset
;
177 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
178 ltt_event_position(e
, a_event_position
);
179 ltt_event_position_get(a_event_position
, &tf
, &nb_block
, &offset
, &tsc
);
180 fprintf(stderr
, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64
"]\n",
181 g_quark_to_string(marker_get_info_from_id(tf
->mdata
,
182 ltt_event_id(e
))->name
),
183 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
,
184 nb_block
, offset
, tsc
);
188 static LttTime count_previous_time
= { 0, 0 };
190 gboolean
count_event(void *hook_data
, void __UNUSED__
*call_data
)
192 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
193 LttTracefile
*tracefile
= tfs
->parent
.tf
;
194 guint nb_block
, offset
;
195 LttTracefile
*tf_pos
;
197 LttEvent
* event
= ltt_tracefile_get_event(tracefile
);
199 guint
*pcount
= (guint
*)hook_data
;
203 time
= ltt_event_time(event
);
204 ltt_event_position(event
, a_event_position
);
205 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
207 if(ltt_time_compare(time
, count_previous_time
) < 0) {
208 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
209 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
210 g_quark_to_string(ltt_tracefile_name(tracefile
)),
211 tfs
->cpu
, nb_block
, offset
);
212 g_warning("last time %lu.%lu vs current %lu.%lu",
213 count_previous_time
.tv_sec
, count_previous_time
.tv_nsec
,
214 time
.tv_sec
, time
.tv_nsec
);
216 count_previous_time
= time
;
224 gboolean
save_state_copy_event(void *hook_data
, void *call_data
)
226 SaveState __UNUSED__
*save_state
= (SaveState
*)hook_data
;
228 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
230 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
232 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
238 if(ts
->nb_event
== 0 &&
239 marker_get_info_from_id(tfs
->parent
.tf
->mdata
, e
->event_id
)->name
240 == QUARK_BLOCK_START
) {
241 if(a_save_sample
!= NULL
) {
242 filename
= g_string_new("");
243 g_string_printf(filename
, "%s.copy.%lu.%09lu.xml", a_save_sample
,
244 tfs
->parent
.timestamp
.tv_sec
, tfs
->parent
.timestamp
.tv_nsec
);
245 fp
= fopen(filename
->str
, "w");
246 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
247 g_string_free(filename
, TRUE
);
248 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
250 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
256 gboolean
save_state_event(void *hook_data
, void *call_data
)
258 SaveState
*save_state
= (SaveState
*)hook_data
;
260 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
262 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
268 (save_state
->count
)++;
269 if(save_state
->count
% save_state
->interval
== 0 &&
270 save_state
->position
< save_state
->size
) {
271 if(a_save_sample
!= NULL
) {
272 filename
= g_string_new("");
273 g_string_printf(filename
, "%s.%u.xml.%u", a_save_sample
,
274 save_state
->position
, save_state
->version
);
275 fp
= fopen(filename
->str
, "w");
276 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
277 g_string_free(filename
, TRUE
);
278 lttv_state_write(ts
, tfs
->parent
.timestamp
, fp
);
280 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
282 save_state
->write_time
[save_state
->position
] = tfs
->parent
.timestamp
;
283 save_state
->position
++;
289 static void sanitize_name(gchar
*name
)
291 while(*name
!= '\0') {
292 if(*name
== '/') *name
= '_';
299 static void compute_tracefile(LttTracefile
*tracefile
, void *hook_data
)
302 guint nb_equal
, nb_block
, offset
;
305 LttTime time
, previous_time
;
306 LttEvent
*event
= ltt_tracefile_get_event(tracefile
);
307 //LttEventType *event_type;
308 struct marker_info
*minfo
;
310 gchar mod_name
[PATH_MAX
];
312 /* start_count is always initialized in this function _if_ there is always
313 * a block_start before a block_end.
315 //long long unsigned cycle_count, start_count=0, delta_cycle;
318 filename
= g_string_new("");
319 strcpy(mod_name
, g_quark_to_string(ltt_tracefile_name(tracefile
)));
321 sanitize_name(mod_name
);
323 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile
)));
324 g_string_printf(filename
, "%s.%s.%u.trace", a_dump_tracefiles
,
325 mod_name
, ltt_tracefile_cpu(tracefile
));
326 fp
= fopen(filename
->str
, "w");
327 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
328 g_string_free(filename
, TRUE
);
329 err
= ltt_tracefile_seek_time(tracefile
, ltt_time_zero
);
332 previous_time
= ltt_time_zero
;
336 LttTracefile
*tf_pos
;
337 //event_type = ltt_event_eventtype(event);
338 minfo
= marker_get_info_from_id(tracefile
->mdata
,
339 ltt_event_id(event
));
340 time
= ltt_event_time(event
);
341 ltt_event_position(event
, a_event_position
);
342 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
343 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
344 fprintf(fp
, "%s: %" PRIu64
" %lu.%09lu position %u/%u, tracefile %s\n",
345 g_quark_to_string(minfo
->name
),
346 tsc
, (unsigned long)time
.tv_sec
,
347 (unsigned long)time
.tv_nsec
,
349 g_quark_to_string(ltt_tracefile_name(tracefile
)));
351 if(ltt_time_compare(time
, previous_time
) < 0) {
352 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
353 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile
))),
354 g_quark_to_string(ltt_tracefile_name(tracefile
)),
355 ltt_tracefile_cpu(tracefile
), nb_block
, offset
);
356 g_warning("last time %lu.%lu vs current %lu.%lu",
357 previous_time
.tv_sec
, previous_time
.tv_nsec
,
358 time
.tv_sec
, time
.tv_nsec
);
362 if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_START
) {
363 start_count
= cycle_count
;
366 else if(ltt_eventtype_name(event_type
) == QUARK_BLOCK_END
) {
367 delta_cycle
= cycle_count
- start_count
;
368 end_nsec_sec
= (long long unsigned)time
.tv_sec
* (long long unsigned)1000000000;
369 end_nsec_nsec
= time
.tv_nsec
;
370 end_nsec
= end_nsec_sec
+ end_nsec_nsec
;
371 start_nsec
= (long long unsigned)start_time
.tv_sec
* (long long unsigned)1000000000 + (long long unsigned)start_time
.tv_nsec
;
372 delta_nsec
= end_nsec
- start_nsec
;
373 cycle_per_nsec
= (double)delta_cycle
/ (double)delta_nsec
;
374 nsec_per_cycle
= (double)delta_nsec
/ (double)delta_cycle
;
375 added_nsec
= (double)delta_cycle
* nsec_per_cycle
;
376 interpolated_nsec
= start_nsec
+ added_nsec
;
377 added_nsec2
= (double)delta_cycle
/ cycle_per_nsec
;
378 interpolated_nsec2
= start_nsec
+ added_nsec2
;
380 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
);
384 if(ltt_time_compare(time
, previous_time
) == 0)
386 else if(nb_equal
> 0) {
387 g_warning("Consecutive %d events with time %lu.%09lu",
388 nb_equal
+ 1, previous_time
.tv_sec
, previous_time
.tv_nsec
);
391 previous_time
= time
;
393 } while((!ltt_tracefile_read(tracefile
)));
399 // TODO mdenis: adapt to babeltrace
400 static gboolean
process_traceset(void __UNUSED__
*hook_data
,
401 void __UNUSED__
*call_data
)
404 LttvTracesetStats
*tscs
;
406 LttvTracesetState
*ts
;
408 LttvTracesetContext
*tc
;
414 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
415 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
418 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
, &args
);
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
);
459 g_message("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
, ltt_time_infinite
);
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
);
545 g_message("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
,
605 save_state
.write_time
[j
].tv_nsec
, t
);
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
) {
655 /* Run seek_forward and seek_backward test */
657 LttvTracesetContext
*tsc
= &ts
->parent
;
658 LttvTracesetContextPosition
*saved_pos
=
659 lttv_traceset_context_position_new(tsc
);
660 g_message("Running test 9 : seek_forward and seek_backward");
661 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
663 count
= lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
664 g_assert(count
== 500);
665 lttv_traceset_context_position_save(tsc
, saved_pos
);
667 count
= lttv_process_traceset_seek_n_forward(tsc
, 150000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
669 g_message("Seek forward 150000 events in %g seconds", t1
- t0
);
670 g_assert(count
== 150000);
672 count
= lttv_process_traceset_seek_n_backward(tsc
, 150000,
673 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
674 NULL
, NULL
, NULL
, NULL
, 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
, NULL
, NULL
, NULL
, NULL
, NULL
);
683 lttv_traceset_context_position_save(tsc
, saved_pos
);
684 lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
685 lttv_process_traceset_seek_n_backward(tsc
, 15005,
686 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
687 NULL
, NULL
, NULL
, NULL
, NULL
);
688 lttv_process_traceset_seek_n_forward(tsc
, 5, NULL
, NULL
, NULL
, NULL
, NULL
, 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
, NULL
, NULL
, NULL
, NULL
, 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
,
705 NULL
, NULL
, NULL
, NULL
, NULL
);
707 g_message("Seek backward 300 events in %g seconds", t1
- t0
);
708 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
709 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
711 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
712 g_warning("Problem with seek_n ! Positions differ. (4)");
715 lttv_traceset_context_position_save(tsc
, saved_pos
);
717 lttv_process_traceset_seek_n_backward(tsc
, 10,
718 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
719 NULL
, NULL
, NULL
, NULL
, NULL
);
721 g_message("Seek backward 10 events in %g seconds", t1
- t0
);
723 count
= lttv_process_traceset_seek_n_forward(tsc
, 10, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
725 g_message("Seek forward 10 events in %g seconds", t1
- t0
);
728 /* try a volountary error */
729 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
731 lttv_traceset_context_position_save(tsc
, saved_pos
);
732 lttv_process_traceset_seek_n_backward(tsc
, 301,
733 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
734 NULL
, NULL
, NULL
, NULL
, NULL
);
735 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
736 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
738 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) == 0) {
739 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
742 /* Try a seek by closest time : Hint : try this one with and without states
744 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
745 count
= lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
746 lttv_traceset_context_position_save(tsc
, saved_pos
);
748 lttv_process_traceset_seek_n_backward(tsc
, 100301,
749 seek_back_default_offset
,
750 (seek_time_fct
)lttv_state_traceset_seek_time_closest
, NULL
,
751 NULL
, NULL
, NULL
, NULL
, NULL
);
753 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
755 count
= lttv_process_traceset_seek_n_forward(tsc
, 100301, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
757 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
758 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
761 lttv_traceset_context_position_destroy(saved_pos
);
764 if(a_test10
|| a_test_all
) {
765 g_message("Running test 10 : check seek traceset context position");
766 LttvTracesetContext
*tsc
= &ts
->parent
;
767 LttvTracesetContextPosition
*saved_pos
=
768 lttv_traceset_context_position_new(tsc
);
770 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
771 lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
772 lttv_traceset_context_position_save(tsc
, saved_pos
);
773 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
774 g_critical("Error in seek position. (1)");
776 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
777 lttv_process_traceset_seek_n_backward(tsc
, 500,
778 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
779 NULL
, NULL
, NULL
, NULL
, NULL
);
780 lttv_traceset_context_position_save(tsc
, saved_pos
);
782 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) != 0)
783 g_critical("Error in seek position. (2)");
785 lttv_traceset_context_position_destroy(saved_pos
);
788 if(a_trace_event
) lttv_hooks_remove_data(event_hook
, trace_event
, NULL
);
790 g_free(save_state
.write_time
);
791 g_free(a_event_position
);
792 lttv_context_fini(tc
);
793 g_object_unref(tscs
);
795 if(lttv_profile_memory
) {
796 g_message("Memory summary at the end of batchtest");
800 g_info("BatchTest end process traceset");
807 LttvAttributeValue value
;
809 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
812 g_info("Init batchtest.c");
815 QUARK_BLOCK_START
= g_quark_from_string("block_start");
816 QUARK_BLOCK_END
= g_quark_from_string("block_end");
819 lttv_option_add("trace", 't',
820 "add a trace to the trace set to analyse",
821 "pathname of the directory containing the trace",
822 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
824 a_trace_event
= FALSE
;
826 a_dump_tracefiles
= NULL
;
827 lttv_option_add("dump-tracefiles", 'D',
828 "Write event by event the content of tracefiles",
829 "basename for the files where to dump events",
830 LTTV_OPT_STRING
, &a_dump_tracefiles
, NULL
, NULL
);
832 a_save_sample
= NULL
;
833 lttv_option_add("save-sample", 's',
834 "Save state samples to multiple files",
835 "basename for the files containing the state samples",
836 LTTV_OPT_STRING
, &a_save_sample
, NULL
, NULL
);
838 a_save_state_copy
= FALSE
;
839 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
840 "", LTTV_OPT_NONE
, &a_save_state_copy
, NULL
, NULL
);
842 a_save_interval
= 100000;
843 lttv_option_add("save-interval", 'i',
844 "Interval between saving state",
845 "number of events before a block start triggers saving state",
846 LTTV_OPT_INT
, &a_save_interval
, NULL
, NULL
);
848 a_sample_interval
= 100000;
849 lttv_option_add("sample-interval", 'S',
850 "Interval between sampling state",
851 "number of events before sampling and writing state",
852 LTTV_OPT_INT
, &a_sample_interval
, NULL
, NULL
);
854 a_sample_number
= 20;
855 lttv_option_add("sample-number", 'N',
856 "Number of state samples",
858 LTTV_OPT_INT
, &a_sample_number
, NULL
, NULL
);
861 lttv_option_add("seek-number", 'K',
864 LTTV_OPT_INT
, &a_seek_number
, NULL
, NULL
);
867 lttv_option_add("test1", '1', "Test just counting events", "",
868 LTTV_OPT_NONE
, &a_test1
, NULL
, NULL
);
871 lttv_option_add("test2", '2', "Test computing the state", "",
872 LTTV_OPT_NONE
, &a_test2
, NULL
, NULL
);
875 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
876 "", LTTV_OPT_NONE
, &a_test3
, NULL
, NULL
);
879 lttv_option_add("test4", '4', "Test computing the stats", "",
880 LTTV_OPT_NONE
, &a_test4
, NULL
, NULL
);
883 lttv_option_add("test5", '5', "Test computing the state and stats", "",
884 LTTV_OPT_NONE
, &a_test5
, NULL
, NULL
);
887 lttv_option_add("test6", '6', "Test computing and saving the state", "",
888 LTTV_OPT_NONE
, &a_test6
, NULL
, NULL
);
891 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
892 "", LTTV_OPT_NONE
, &a_test7
, NULL
, NULL
);
895 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
896 "", LTTV_OPT_NONE
, &a_test8
, NULL
, NULL
);
899 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
900 "", LTTV_OPT_NONE
, &a_test9
, NULL
, NULL
);
903 lttv_option_add("test10", ' ', "Test seeking traceset by position",
904 "", LTTV_OPT_NONE
, &a_test10
, NULL
, NULL
);
909 lttv_option_add("testall", 'a', "Run all tests ", "",
910 LTTV_OPT_NONE
, &a_test_all
, NULL
, NULL
);
912 traceset
= lttv_traceset_new();
914 before_traceset
= lttv_hooks_new();
915 after_traceset
= lttv_hooks_new();
916 before_trace
= lttv_hooks_new();
917 after_trace
= lttv_hooks_new();
918 before_tracefile
= lttv_hooks_new();
919 after_tracefile
= lttv_hooks_new();
920 //before_event = lttv_hooks_new();
921 //after_event = lttv_hooks_new();
922 event_hook
= lttv_hooks_new();
925 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
926 LTTV_POINTER
, &value
);
928 *(value
.v_pointer
) = before_traceset
;
929 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
930 LTTV_POINTER
, &value
);
932 *(value
.v_pointer
) = after_traceset
;
933 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
934 LTTV_POINTER
, &value
);
936 *(value
.v_pointer
) = before_trace
;
937 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
938 LTTV_POINTER
, &value
);
940 *(value
.v_pointer
) = after_trace
;
941 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
942 LTTV_POINTER
, &value
);
944 *(value
.v_pointer
) = before_tracefile
;
945 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
946 LTTV_POINTER
, &value
);
948 *(value
.v_pointer
) = after_tracefile
;
949 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/before",
950 // LTTV_POINTER, &value);
951 //*(value.v_pointer) = before_event;
952 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/after",
953 // LTTV_POINTER, &value);
954 //*(value.v_pointer) = after_event;
955 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/event",
956 LTTV_POINTER
, &value
);
958 *(value
.v_pointer
) = event_hook
;
959 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
960 LTTV_POINTER
, &value
);
962 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
963 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
967 static void destroy()
973 g_info("Destroy batchAnalysis.c");
975 lttv_option_remove("trace");
976 lttv_option_remove("dump-tracefiles");
977 lttv_option_remove("save-sample");
978 lttv_option_remove("save-state-copy");
979 lttv_option_remove("sample-interval");
980 lttv_option_remove("sample-number");
981 lttv_option_remove("seek-number");
982 lttv_option_remove("save-interval");
983 lttv_option_remove("test1");
984 lttv_option_remove("test2");
985 lttv_option_remove("test3");
986 lttv_option_remove("test4");
987 lttv_option_remove("test5");
988 lttv_option_remove("test6");
989 lttv_option_remove("test7");
990 lttv_option_remove("test8");
991 lttv_option_remove("test9");
992 lttv_option_remove("test10");
993 lttv_option_remove("testall");
995 lttv_hooks_destroy(before_traceset
);
996 lttv_hooks_destroy(after_traceset
);
997 lttv_hooks_destroy(before_trace
);
998 lttv_hooks_destroy(after_trace
);
999 lttv_hooks_destroy(before_tracefile
);
1000 lttv_hooks_destroy(after_tracefile
);
1001 //lttv_hooks_destroy(before_event);
1002 //lttv_hooks_destroy(after_event);
1003 lttv_hooks_destroy(event_hook
);
1004 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
1006 nb
= lttv_traceset_number(traceset
);
1007 for(i
= 0 ; i
< nb
; i
++) {
1008 trace
= lttv_traceset_get(traceset
, i
);
1009 lttv_traceset_remove(traceset
,i
);
1010 #ifdef BABEL_CLEANUP
1011 ltt_trace_close(lttv_trace(trace
));
1012 lttv_trace_destroy(trace
);
1016 lttv_traceset_destroy(traceset
);
1020 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
1021 "Run through a trace calling all the registered hooks for tests", \
1022 init
, destroy
, "state", "stats", "option" )