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 #define __UNUSED__ __attribute__((__unused__))
41 static LttvTraceset
*traceset
;
57 static char *a_dump_tracefiles
;
59 static char *a_save_sample
;
82 static GQuark QUARK_BLOCK_START
,
85 LttEventPosition
*a_event_position
;
87 typedef struct _save_state
{
98 static void lttv_trace_option(void __UNUSED__
*hook_data
)
102 trace
= ltt_trace_open(a_trace
);
104 g_critical("cannot open trace %s", a_trace
);
106 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
110 static double get_time()
114 g_get_current_time(>
);
115 return gt
.tv_sec
+ (double)gt
.tv_usec
/ (double)1000000.0;
118 static double run_one_test(LttvTracesetState
*ts
, LttTime start
, LttTime end
)
124 //lttv_traceset_context_add_hooks(&ts->parent,
125 //before_traceset, after_traceset, NULL, before_trace, after_trace,
126 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
127 lttv_process_traceset_begin(&ts
->parent
,
134 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
135 ((LttvTraceState
*)(ts
->parent
.traces
[i
]))->save_interval
=a_save_interval
;
139 lttv_state_traceset_seek_time_closest(ts
, start
);
140 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
141 lttv_process_traceset_middle(&ts
->parent
,
147 //lttv_traceset_context_remove_hooks(&ts->parent,
148 //before_traceset, after_traceset, NULL, before_trace, after_trace,
149 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
150 lttv_process_traceset_end(&ts
->parent
,
161 gboolean
trace_event(void __UNUSED__
*hook_data
, void *call_data
)
163 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
165 guint nb_block
, offset
;
170 LttEvent
*e
= ltt_tracefile_get_event(tfs
->parent
.tf
);
171 ltt_event_position(e
, a_event_position
);
172 ltt_event_position_get(a_event_position
, &tf
, &nb_block
, &offset
, &tsc
);
173 fprintf(stderr
,"Event %s %lu.%09lu [%u 0x%x tsc %llu]\n",
174 g_quark_to_string(marker_get_info_from_id(ltt_tracefile_get_trace(tf
),
175 ltt_event_id(e
))->name
),
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 tfs
->cpu
, 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 LttTrace
*trace
= ((LttvTracefileContext
*)tfs
)->t_context
->t
;
233 if(ts
->nb_event
== 0 &&
234 marker_get_info_from_id(trace
, e
->event_id
)->name
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 //LttEventType *event_type;
303 struct marker_info
*minfo
;
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 //event_type = ltt_event_eventtype(event);
333 minfo
= marker_get_info_from_id(ltt_tracefile_get_trace(tracefile
),
334 ltt_event_id(event
));
335 time
= ltt_event_time(event
);
336 ltt_event_position(event
, a_event_position
);
337 ltt_event_position_get(a_event_position
, &tf_pos
, &nb_block
, &offset
, &tsc
);
338 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
339 fprintf(fp
, "%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
340 g_quark_to_string(minfo
->name
),
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)
381 else if(nb_equal
> 0) {
382 g_warning("Consecutive %d events with time %lu.%09lu",
383 nb_equal
+ 1, previous_time
.tv_sec
, previous_time
.tv_nsec
);
386 previous_time
= time
;
388 } while((!ltt_tracefile_read(tracefile
)));
394 static gboolean
process_traceset(void __UNUSED__
*hook_data
,
395 void __UNUSED__
*call_data
)
398 LttvTracesetStats
*tscs
;
400 LttvTracesetState
*ts
;
402 LttvTracesetContext
*tc
;
408 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
409 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
414 LttTime max_time
= { G_MAXULONG
, G_MAXULONG
};
416 a_event_position
= ltt_event_position_new();
418 GData
**tracefiles_groups
;
420 struct compute_tracefile_group_args args
;
422 args
.func
= compute_tracefile
;
423 args
.func_args
= NULL
;
425 if(a_dump_tracefiles
!= NULL
) {
426 for(i
= 0 ; i
< lttv_traceset_number(traceset
) ; i
++) {
427 trace
= lttv_trace(lttv_traceset_get(traceset
, i
));
428 tracefiles_groups
= ltt_trace_get_tracefiles_groups(trace
);
430 g_datalist_foreach(tracefiles_groups
,
431 (GDataForeachFunc
)compute_tracefile_group
,
437 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
439 tc
= &tscs
->parent
.parent
;
441 lttv_context_init(tc
, traceset
);
443 /* For each case compute and print the elapsed time.
444 The first case is simply to run through all events with a
447 if(a_test1
|| a_test_all
) {
449 lttv_hooks_add(event_hook
, count_event
, &count
, LTTV_PRIO_DEFAULT
);
450 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
451 lttv_hooks_remove_data(event_hook
, count_event
, &count
);
453 "Processing trace while counting events (%u events in %g seconds)",
457 /* Run through all events computing the state. */
459 if(a_test2
|| a_test_all
) {
460 lttv_state_add_event_hooks(ts
);
461 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
462 lttv_state_remove_event_hooks(ts
);
463 g_message("Processing trace while updating state (%g seconds)", t
);
466 /* Run through all events computing the state and writing it out
469 SaveState save_state
;
471 save_state
.interval
= a_sample_interval
;
472 save_state
.size
= a_sample_number
;
473 save_state
.fp
= stderr
;
474 save_state
.write_time
= g_new(LttTime
, a_sample_number
);
477 if(a_test3
|| a_test_all
) {
478 for(i
= 0 ; i
< 2 ; i
++) {
479 save_state
.count
= 0;
480 save_state
.position
= 0;
481 save_state
.version
= i
;
482 lttv_state_add_event_hooks(ts
);
483 lttv_hooks_add(event_hook
, save_state_event
, &save_state
,
485 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
486 lttv_state_remove_event_hooks(ts
);
487 lttv_hooks_remove_data(event_hook
, save_state_event
, &save_state
);
488 g_warning("Processing while updating/writing state (%g seconds)", t
);
492 /* Run through all events computing the stats. */
494 if(a_test4
|| a_test_all
) {
495 if(lttv_profile_memory
) {
496 g_message("Memory summary before computing stats");
500 lttv_stats_add_event_hooks(tscs
);
501 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
502 lttv_stats_remove_event_hooks(tscs
);
503 g_message("Processing trace while counting stats (%g seconds)", t
);
505 if(lttv_profile_memory
) {
506 g_message("Memory summary after computing stats");
510 lttv_stats_sum_traceset(tscs
, ltt_time_infinite
);
512 if(lttv_profile_memory
) {
513 g_message("Memory summary after summing stats");
517 lttv_context_fini(tc
);
518 lttv_context_init(tc
, traceset
);
520 if(lttv_profile_memory
) {
521 g_message("Memory summary after cleaning up the stats");
526 /* Run through all events computing the state and stats. */
528 if(a_test5
|| a_test_all
) {
529 if(lttv_profile_memory
) {
530 g_message("Memory summary before computing state and stats");
534 lttv_state_add_event_hooks(ts
);
535 lttv_stats_add_event_hooks(tscs
);
536 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
537 lttv_state_remove_event_hooks(ts
);
538 lttv_stats_remove_event_hooks(tscs
);
540 "Processing trace while counting state and stats (%g seconds)", t
);
542 if(lttv_profile_memory
) {
543 g_message("Memory summary after computing and state and stats");
547 lttv_context_fini(tc
);
548 lttv_context_init(tc
, traceset
);
550 if(lttv_profile_memory
) {
551 g_message("Memory summary after cleaning up the stats");
556 /* Run through all events computing and saving the state. */
558 if(a_trace_event
) lttv_hooks_add(event_hook
, trace_event
, NULL
,
561 if(a_test6
|| a_test_all
) {
562 if(lttv_profile_memory
) {
563 g_message("Memory summary before computing and saving state");
567 lttv_state_add_event_hooks(ts
);
568 lttv_state_save_add_event_hooks(ts
);
569 if(a_save_state_copy
)
570 lttv_hooks_add(event_hook
, save_state_copy_event
, &save_state
,
572 t
= run_one_test(ts
, ltt_time_zero
, max_time
);
573 lttv_state_remove_event_hooks(ts
);
574 lttv_state_save_remove_event_hooks(ts
);
575 if(a_save_state_copy
)
576 lttv_hooks_remove_data(event_hook
,save_state_copy_event
, &save_state
);
578 g_message("Processing trace while updating/saving state (%g seconds)", t
);
580 if(lttv_profile_memory
) {
581 g_message("Memory summary after computing/saving state");
586 /* Seek a few times to each saved position */
588 if((a_test7
&& a_test3
) || a_test_all
) {
589 g_assert(a_seek_number
>= 0);
590 for(i
= 0 ; i
< (guint
)a_seek_number
; i
++) {
591 gint reverse_j
; /* just to make sure j is unsigned */
592 for(reverse_j
= save_state
.position
- 1 ; reverse_j
>= 0 ; reverse_j
--) {
593 j
= (guint
)reverse_j
;
594 lttv_state_add_event_hooks(ts
);
595 t
= run_one_test(ts
, save_state
.write_time
[j
],
596 save_state
.write_time
[j
]);
597 lttv_state_remove_event_hooks(ts
);
598 g_message("Seeking to %lu.%lu (%g seconds)",
599 save_state
.write_time
[j
].tv_sec
, save_state
.write_time
[j
].tv_nsec
,
602 if(a_save_sample
!= NULL
) {
603 filename
= g_string_new("");
604 g_string_printf(filename
, "%s.%d.xml.bak%d", a_save_sample
, j
, i
);
605 fp
= fopen(filename
->str
, "w");
606 if(fp
== NULL
) g_error("Cannot open %s", filename
->str
);
607 g_string_free(filename
, TRUE
);
608 lttv_state_write((LttvTraceState
*)tc
->traces
[0],
609 save_state
.write_time
[j
], fp
);
612 //else lttv_state_write((LttvTraceState *)tc->traces[0],
613 // save_state.write_time[j], save_state.fp);
618 /* Seek at specified interval, using states computed in 6, making
619 * sure that there is no more than the number of events between
620 * state save interval to read before getting there.
623 if((a_test8
&& a_test6
) || a_test_all
) {
624 g_message("Running test 8 : check save interval");
625 LttTime time
= tc
->time_span
.start_time
;
628 interval
.tv_nsec
= 175674987;
631 while(ltt_time_compare(time
, tc
->time_span
.end_time
) < 0) {
632 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
633 lttv_process_traceset_seek_time(&ts
->parent
, ltt_time_zero
);
634 lttv_state_traceset_seek_time_closest(ts
, time
);
635 /* We add no hook to the traceset, not necessary */
636 count
= lttv_process_traceset_middle(&ts
->parent
,
637 time
, G_MAXUINT
, NULL
);
638 g_info("Number of events to jump over : %u", count
);
640 if(count
> LTTV_STATE_SAVE_INTERVAL
)
641 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.",
642 LTTV_STATE_SAVE_INTERVAL
, count
, time
.tv_sec
, time
.tv_nsec
);
643 time
= ltt_time_add(time
, interval
);
648 if(a_test9
|| a_test_all
) {
650 /* Run seek_forward and seek_backward test */
652 LttvTracesetContext
*tsc
= &ts
->parent
;
653 LttvTracesetContextPosition
*saved_pos
=
654 lttv_traceset_context_position_new(tsc
);
655 g_message("Running test 9 : seek_forward and seek_backward");
656 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
658 count
= lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
659 g_assert(count
== 500);
660 lttv_traceset_context_position_save(tsc
, saved_pos
);
662 count
= lttv_process_traceset_seek_n_forward(tsc
, 150000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
664 g_message("Seek forward 150000 events in %g seconds", t1
- t0
);
665 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 NULL
, NULL
, NULL
, NULL
, NULL
);
671 g_message("Seek backward 150000 events in %g seconds", t1
- t0
);
672 g_assert(count
== 150000);
673 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
674 g_warning("Problem with seek_n ! Positions differ. (1)");
677 lttv_process_traceset_seek_n_forward(tsc
, 500, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
678 lttv_traceset_context_position_save(tsc
, saved_pos
);
679 lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
680 lttv_process_traceset_seek_n_backward(tsc
, 15005,
681 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
682 NULL
, NULL
, NULL
, NULL
, NULL
);
683 lttv_process_traceset_seek_n_forward(tsc
, 5, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
684 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
685 g_warning("Problem with seek_n ! Positions differ. (2)");
688 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
690 count
= lttv_process_traceset_seek_n_forward(tsc
, 15000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
692 g_warning("Problem with seek_n ! Forward at end of traceset.");
694 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
696 lttv_traceset_context_position_save(tsc
, saved_pos
);
698 lttv_process_traceset_seek_n_backward(tsc
, 300,
699 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
700 NULL
, NULL
, NULL
, NULL
, NULL
);
702 g_message("Seek backward 300 events in %g seconds", t1
- t0
);
703 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
704 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
706 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
)) {
707 g_warning("Problem with seek_n ! Positions differ. (4)");
710 lttv_traceset_context_position_save(tsc
, saved_pos
);
712 lttv_process_traceset_seek_n_backward(tsc
, 10,
713 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
714 NULL
, NULL
, NULL
, NULL
, NULL
);
716 g_message("Seek backward 10 events in %g seconds", t1
- t0
);
718 count
= lttv_process_traceset_seek_n_forward(tsc
, 10, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
720 g_message("Seek forward 10 events in %g seconds", t1
- t0
);
723 /* try a volountary error */
724 lttv_process_traceset_seek_time(tsc
, ltt_time_infinite
);
726 lttv_traceset_context_position_save(tsc
, saved_pos
);
727 lttv_process_traceset_seek_n_backward(tsc
, 301,
728 seek_back_default_offset
, lttv_process_traceset_seek_time
, NULL
,
729 NULL
, NULL
, NULL
, NULL
, NULL
);
730 count
= lttv_process_traceset_seek_n_forward(tsc
, 299, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
731 count
= lttv_process_traceset_seek_n_forward(tsc
, 1, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
733 if(lttv_traceset_context_ctx_pos_compare(tsc
, saved_pos
) == 0) {
734 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
737 /* Try a seek by closest time : Hint : try this one with and without states
739 lttv_process_traceset_seek_time(tsc
, ltt_time_zero
);
740 count
= lttv_process_traceset_seek_n_forward(tsc
, 200000, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
741 lttv_traceset_context_position_save(tsc
, saved_pos
);
743 lttv_process_traceset_seek_n_backward(tsc
, 100301,
744 seek_back_default_offset
,
745 (seek_time_fct
)lttv_state_traceset_seek_time_closest
, NULL
,
746 NULL
, NULL
, NULL
, NULL
, 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
, NULL
, NULL
, NULL
, NULL
, 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
, NULL
, NULL
, NULL
, NULL
, 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 NULL
, NULL
, NULL
, NULL
, 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" )