Update FSF address
[lttv.git] / lttv / lttv / batchtest.c
CommitLineData
08b1c66e 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
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;
7 *
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.
12 *
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
b9ce0bad
YB
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
08b1c66e 17 */
18
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. */
08b1c66e 22
4e4d11b3 23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include <string.h>
43ed82b5 28#include <inttypes.h>
08b1c66e 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>
08b1c66e 34#include <lttv/state.h>
7a4bdb54
YB
35#include <lttv/traceset.h>
36#include <lttv/traceset-process.h>
00e74b69 37
38#define __UNUSED__ __attribute__((__unused__))
08b1c66e 39
40static LttvTraceset *traceset;
41
42static LttvHooks
90e19f82
AM
43 *before_traceset,
44 *after_traceset,
45 *before_trace,
46 *after_trace,
47 *before_tracefile,
48 *after_tracefile,
49 //*before_event,
50 //*after_event,
51 *event_hook,
52 *main_hooks;
08b1c66e 53
54static char *a_trace;
55
56static char *a_dump_tracefiles;
57
58static char *a_save_sample;
59
60static int
90e19f82
AM
61 a_sample_interval,
62 a_sample_number,
63 a_seek_number,
64 a_save_interval;
08b1c66e 65
66static gboolean
90e19f82
AM
67 a_trace_event,
68 a_save_state_copy,
69 a_test1,
70 a_test2,
71 a_test3,
72 a_test4,
73 a_test5,
74 a_test6,
75 a_test7,
76 a_test8,
77 a_test9,
78 a_test10,
79 a_test_all;
08b1c66e 80
eed2ef37 81static GQuark QUARK_BLOCK_START,
90e19f82 82 QUARK_BLOCK_END;
eed2ef37 83
f95bc830 84LttEventPosition *a_event_position;
85
08b1c66e 86typedef struct _save_state {
90e19f82
AM
87 guint count;
88 FILE *fp;
89 guint interval;
90 guint position;
91 guint size;
92 LttTime *write_time;
93 guint version;
08b1c66e 94} SaveState;
95
96
00e74b69 97static void lttv_trace_option(void __UNUSED__ *hook_data)
08b1c66e 98{
2bc1bcfb 99#ifdef BABEL_CLEANUP
90e19f82
AM
100 LttTrace *trace;
101
102 trace = ltt_trace_open(a_trace);
103 if(trace == NULL) {
104 g_critical("cannot open trace %s", a_trace);
105 } else {
106 lttv_traceset_add(traceset, lttv_trace_new(trace));
107 }
2bc1bcfb 108#endif
109
110 if(lttv_traceset_add_path(traceset, a_trace) < 0) {
111 g_critical("cannot open trace %s", a_trace);
112 }
08b1c66e 113}
114
115static double get_time()
116{
90e19f82 117 GTimeVal gt;
08b1c66e 118
90e19f82
AM
119 g_get_current_time(&gt);
120 return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0;
08b1c66e 121}
122
123static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
124{
90e19f82
AM
125 double t0, t1;
126
127 unsigned int i;
128
129 //lttv_traceset_context_add_hooks(&ts->parent,
130 //before_traceset, after_traceset, NULL, before_trace, after_trace,
131 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
132 lttv_process_traceset_begin(&ts->parent,
133 before_traceset,
134 before_trace,
135 before_tracefile,
136 event_hook,
137 NULL);
138
139 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
140 ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval;
141 }
142
143 t0 = get_time();
144 lttv_state_traceset_seek_time_closest(ts, start);
145 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
146 lttv_process_traceset_middle(&ts->parent,
147 end,
148 G_MAXULONG,
149 NULL);
150 t1 = get_time();
151
152 //lttv_traceset_context_remove_hooks(&ts->parent,
153 //before_traceset, after_traceset, NULL, before_trace, after_trace,
154 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
155 lttv_process_traceset_end(&ts->parent,
156 after_traceset,
157 after_trace,
158 after_tracefile,
159 event_hook,
160 NULL);
161
162 return t1 - t0;
08b1c66e 163}
164
165
00e74b69 166gboolean trace_event(void __UNUSED__ *hook_data, void *call_data)
f95bc830 167{
90e19f82
AM
168 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
169
170 guint nb_block, offset;
171
172 guint64 tsc;
173
174 LttTracefile *tf;
175 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
176 ltt_event_position(e, a_event_position);
177 ltt_event_position_get(a_event_position, &tf, &nb_block, &offset, &tsc);
178 fprintf(stderr, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64 "]\n",
179 g_quark_to_string(marker_get_info_from_id(tf->mdata,
180 ltt_event_id(e))->name),
181 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec,
182 nb_block, offset, tsc);
183 return FALSE;
f95bc830 184}
185
8fe3c6b6 186static LttTime count_previous_time = { 0, 0 };
f95bc830 187
00e74b69 188gboolean count_event(void *hook_data, void __UNUSED__ *call_data)
08b1c66e 189{
90e19f82
AM
190 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
191 LttTracefile *tracefile = tfs->parent.tf;
192 guint nb_block, offset;
193 LttTracefile *tf_pos;
194 guint64 tsc;
195 LttEvent * event = ltt_tracefile_get_event(tracefile);
196 LttTime time;
197 guint *pcount = (guint *)hook_data;
198
199 (*pcount)++;
200
201 time = ltt_event_time(event);
202 ltt_event_position(event, a_event_position);
203 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
204
205 if(ltt_time_compare(time, count_previous_time) < 0) {
206 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
207 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
208 g_quark_to_string(ltt_tracefile_name(tracefile)),
209 tfs->cpu, nb_block, offset);
210 g_warning("last time %lu.%lu vs current %lu.%lu",
211 count_previous_time.tv_sec, count_previous_time.tv_nsec,
212 time.tv_sec, time.tv_nsec);
213 }
214 count_previous_time = time;
215
216
217
218 return FALSE;
08b1c66e 219}
220
221
f95bc830 222gboolean save_state_copy_event(void *hook_data, void *call_data)
223{
90e19f82 224 SaveState __UNUSED__ *save_state = (SaveState *)hook_data;
f95bc830 225
90e19f82 226 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
f95bc830 227
90e19f82 228 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
f95bc830 229
90e19f82 230 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
eed2ef37 231
90e19f82 232 GString *filename;
f95bc830 233
90e19f82 234 FILE *fp;
f95bc830 235
90e19f82
AM
236 if(ts->nb_event == 0 &&
237 marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id)->name
238 == QUARK_BLOCK_START) {
239 if(a_save_sample != NULL) {
240 filename = g_string_new("");
241 g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample,
242 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
243 fp = fopen(filename->str, "w");
244 if(fp == NULL) g_error("Cannot open %s", filename->str);
245 g_string_free(filename, TRUE);
246 lttv_state_write(ts, tfs->parent.timestamp, fp);
247 fclose(fp);
248 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
249 }
250 return FALSE;
f95bc830 251}
252
253
08b1c66e 254gboolean save_state_event(void *hook_data, void *call_data)
255{
90e19f82
AM
256 SaveState *save_state = (SaveState *)hook_data;
257
258 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
259
260 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
261
262 GString *filename;
263
264 FILE *fp;
265
266 (save_state->count)++;
267 if(save_state->count % save_state->interval == 0 &&
268 save_state->position < save_state->size) {
269 if(a_save_sample != NULL) {
270 filename = g_string_new("");
271 g_string_printf(filename, "%s.%u.xml.%u", a_save_sample,
272 save_state->position, save_state->version);
273 fp = fopen(filename->str, "w");
274 if(fp == NULL) g_error("Cannot open %s", filename->str);
275 g_string_free(filename, TRUE);
276 lttv_state_write(ts, tfs->parent.timestamp, fp);
277 fclose(fp);
278 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
279
280 save_state->write_time[save_state->position] = tfs->parent.timestamp;
281 save_state->position++;
282 }
283 return FALSE;
08b1c66e 284}
285
286
d3d34f49 287static void sanitize_name(gchar *name)
288{
90e19f82
AM
289 while(*name != '\0') {
290 if(*name == '/') *name = '_';
291 name++;
292 }
293
d3d34f49 294}
295
eed2ef37 296
27304273 297static void compute_tracefile(LttTracefile *tracefile, void *hook_data)
eed2ef37 298{
90e19f82
AM
299 GString *filename;
300 guint nb_equal, nb_block, offset;
301 guint64 tsc;
302 FILE *fp;
303 LttTime time, previous_time;
304 LttEvent *event = ltt_tracefile_get_event(tracefile);
305 //LttEventType *event_type;
306 struct marker_info *minfo;
307 int err;
308 gchar mod_name[PATH_MAX];
309
310 /* start_count is always initialized in this function _if_ there is always
311 * a block_start before a block_end.
312 */
313 //long long unsigned cycle_count, start_count=0, delta_cycle;
314
315
316 filename = g_string_new("");
317 strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile)));
318
319 sanitize_name(mod_name);
320
321 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile)));
322 g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles,
323 mod_name, ltt_tracefile_cpu(tracefile));
324 fp = fopen(filename->str, "w");
325 if(fp == NULL) g_error("Cannot open %s", filename->str);
326 g_string_free(filename, TRUE);
327 err = ltt_tracefile_seek_time(tracefile, ltt_time_zero);
328 if(err) goto close;
329
330 previous_time = ltt_time_zero;
331 nb_equal = 0;
332
333 do {
334 LttTracefile *tf_pos;
335 //event_type = ltt_event_eventtype(event);
336 minfo = marker_get_info_from_id(tracefile->mdata,
337 ltt_event_id(event));
338 time = ltt_event_time(event);
339 ltt_event_position(event, a_event_position);
340 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
341 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
342 fprintf(fp, "%s: %" PRIu64 " %lu.%09lu position %u/%u, tracefile %s\n",
343 g_quark_to_string(minfo->name),
344 tsc, (unsigned long)time.tv_sec,
345 (unsigned long)time.tv_nsec,
346 nb_block, offset,
347 g_quark_to_string(ltt_tracefile_name(tracefile)));
348
349 if(ltt_time_compare(time, previous_time) < 0) {
350 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
351 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
352 g_quark_to_string(ltt_tracefile_name(tracefile)),
353 ltt_tracefile_cpu(tracefile), nb_block, offset);
354 g_warning("last time %lu.%lu vs current %lu.%lu",
355 previous_time.tv_sec, previous_time.tv_nsec,
356 time.tv_sec, time.tv_nsec);
357 }
eed2ef37 358
359#if 0 //FIXME
90e19f82
AM
360 if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) {
361 start_count = cycle_count;
362 start_time = time;
363 }
364 else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) {
365 delta_cycle = cycle_count - start_count;
366 end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000;
367 end_nsec_nsec = time.tv_nsec;
368 end_nsec = end_nsec_sec + end_nsec_nsec;
369 start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec;
370 delta_nsec = end_nsec - start_nsec;
371 cycle_per_nsec = (double)delta_cycle / (double)delta_nsec;
372 nsec_per_cycle = (double)delta_nsec / (double)delta_cycle;
373 added_nsec = (double)delta_cycle * nsec_per_cycle;
374 interpolated_nsec = start_nsec + added_nsec;
375 added_nsec2 = (double)delta_cycle / cycle_per_nsec;
376 interpolated_nsec2 = start_nsec + added_nsec2;
377
378 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 }
380 else {
eed2ef37 381#endif //0
90e19f82
AM
382 if(ltt_time_compare(time, previous_time) == 0)
383 nb_equal++;
384 else if(nb_equal > 0) {
385 g_warning("Consecutive %d events with time %lu.%09lu",
386 nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec);
387 nb_equal = 0;
388 }
389 previous_time = time;
390 //}
391 } while((!ltt_tracefile_read(tracefile)));
eed2ef37 392
393close:
90e19f82 394 fclose(fp);
eed2ef37 395}
396
2bc1bcfb 397// TODO mdenis: adapt to babeltrace
00e74b69 398static gboolean process_traceset(void __UNUSED__ *hook_data,
90e19f82 399 void __UNUSED__ *call_data)
08b1c66e 400{
90e19f82
AM
401 GString *filename;
402 LttvTracesetStats *tscs;
403
404 LttvTracesetState *ts;
405
406 LttvTracesetContext *tc;
407
408 FILE *fp;
409
410 double t;
411
412 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
413 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
414 guint i, j, count;
415
90e19f82
AM
416 LttTime max_time = { G_MAXULONG, G_MAXULONG };
417
2bc1bcfb 418#ifdef BABEL_CLEANUP
419 LttTrace *trace;
420
90e19f82
AM
421 a_event_position = ltt_event_position_new();
422
423 GData **tracefiles_groups;
08b1c66e 424
90e19f82 425 struct compute_tracefile_group_args args;
08b1c66e 426
90e19f82
AM
427 args.func = compute_tracefile;
428 args.func_args = NULL;
08b1c66e 429
90e19f82
AM
430 if(a_dump_tracefiles != NULL) {
431 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
432 trace = lttv_trace(lttv_traceset_get(traceset, i));
433 tracefiles_groups = ltt_trace_get_tracefiles_groups(trace);
08b1c66e 434
90e19f82
AM
435 g_datalist_foreach(tracefiles_groups,
436 (GDataForeachFunc)compute_tracefile_group, &args);
08b1c66e 437
90e19f82
AM
438 }
439 }
2bc1bcfb 440#endif
08b1c66e 441
90e19f82
AM
442 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
443 ts = &tscs->parent;
444 tc = &tscs->parent.parent;
08b1c66e 445
90e19f82 446 lttv_context_init(tc, traceset);
08b1c66e 447
90e19f82
AM
448 /* For each case compute and print the elapsed time.
449 The first case is simply to run through all events with a
450 simple counter. */
f95bc830 451
90e19f82
AM
452 if(a_test1 || a_test_all) {
453 count = 0;
454 lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
455 t = run_one_test(ts, ltt_time_zero, max_time);
456 lttv_hooks_remove_data(event_hook, count_event, &count);
457 g_message("Processing trace while counting events (%u events in %g seconds)",
458 count, t);
459 }
eed2ef37 460
90e19f82 461 /* Run through all events computing the state. */
27304273 462
90e19f82
AM
463 if(a_test2 || a_test_all) {
464 lttv_state_add_event_hooks(ts);
465 t = run_one_test(ts, ltt_time_zero, max_time);
466 lttv_state_remove_event_hooks(ts);
467 g_message("Processing trace while updating state (%g seconds)", t);
468 }
08b1c66e 469
90e19f82
AM
470 /* Run through all events computing the state and writing it out
471 periodically. */
472
473 SaveState save_state;
474
475 save_state.interval = a_sample_interval;
476 save_state.size = a_sample_number;
477 save_state.fp = stderr;
478 save_state.write_time = g_new(LttTime, a_sample_number);
479
480
481 if(a_test3 || a_test_all) {
482 for(i = 0 ; i < 2 ; i++) {
483 save_state.count = 0;
484 save_state.position = 0;
485 save_state.version = i;
486 lttv_state_add_event_hooks(ts);
487 lttv_hooks_add(event_hook, save_state_event, &save_state,
488 LTTV_PRIO_DEFAULT);
489 t = run_one_test(ts, ltt_time_zero, max_time);
490 lttv_state_remove_event_hooks(ts);
491 lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
492 g_warning("Processing while updating/writing state (%g seconds)", t);
493 }
494 }
495
496 /* Run through all events computing the stats. */
497
498 if(a_test4 || a_test_all) {
499 if(lttv_profile_memory) {
500 g_message("Memory summary before computing stats");
501 g_mem_profile();
502 }
503
504 lttv_stats_add_event_hooks(tscs);
505 t = run_one_test(ts, ltt_time_zero, max_time);
506 lttv_stats_remove_event_hooks(tscs);
507 g_message("Processing trace while counting stats (%g seconds)", t);
508
509 if(lttv_profile_memory) {
510 g_message("Memory summary after computing stats");
511 g_mem_profile();
512 }
513
514 lttv_stats_sum_traceset(tscs, ltt_time_infinite);
515
516 if(lttv_profile_memory) {
517 g_message("Memory summary after summing stats");
518 g_mem_profile();
519 }
520
521 lttv_context_fini(tc);
522 lttv_context_init(tc, traceset);
523
524 if(lttv_profile_memory) {
525 g_message("Memory summary after cleaning up the stats");
526 g_mem_profile();
527 }
528 }
529
530 /* Run through all events computing the state and stats. */
531
532 if(a_test5 || a_test_all) {
533 if(lttv_profile_memory) {
534 g_message("Memory summary before computing state and stats");
535 g_mem_profile();
536 }
537
538 lttv_state_add_event_hooks(ts);
539 lttv_stats_add_event_hooks(tscs);
540 t = run_one_test(ts, ltt_time_zero, max_time);
541 lttv_state_remove_event_hooks(ts);
542 lttv_stats_remove_event_hooks(tscs);
543 g_message("Processing trace while counting state and stats (%g seconds)", t);
544
545 if(lttv_profile_memory) {
546 g_message("Memory summary after computing and state and stats");
547 g_mem_profile();
548 }
549
550 lttv_context_fini(tc);
551 lttv_context_init(tc, traceset);
552
553 if(lttv_profile_memory) {
554 g_message("Memory summary after cleaning up the stats");
555 g_mem_profile();
556 }
557 }
558
559 /* Run through all events computing and saving the state. */
560
561 if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
562 LTTV_PRIO_DEFAULT);
563
564 if(a_test6 || a_test_all) {
565 if(lttv_profile_memory) {
566 g_message("Memory summary before computing and saving state");
567 g_mem_profile();
568 }
569
570 lttv_state_add_event_hooks(ts);
571 lttv_state_save_add_event_hooks(ts);
572 if(a_save_state_copy)
573 lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
574 LTTV_PRIO_DEFAULT);
575 t = run_one_test(ts, ltt_time_zero, max_time);
576 lttv_state_remove_event_hooks(ts);
577 lttv_state_save_remove_event_hooks(ts);
578 if(a_save_state_copy)
579 lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
580
581 g_message("Processing trace while updating/saving state (%g seconds)", t);
582
583 if(lttv_profile_memory) {
584 g_message("Memory summary after computing/saving state");
585 g_mem_profile();
586 }
587 }
588
589 /* Seek a few times to each saved position */
590
591 if((a_test7 && a_test3) || a_test_all) {
592 g_assert(a_seek_number >= 0);
593 for(i = 0 ; i < (guint)a_seek_number ; i++) {
594 gint reverse_j; /* just to make sure j is unsigned */
595 for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
596 j = (guint)reverse_j;
597 lttv_state_add_event_hooks(ts);
598 t = run_one_test(ts, save_state.write_time[j],
599 save_state.write_time[j]);
600 lttv_state_remove_event_hooks(ts);
601 g_message("Seeking to %lu.%lu (%g seconds)",
602 save_state.write_time[j].tv_sec,
603 save_state.write_time[j].tv_nsec, t);
604
605 if(a_save_sample != NULL) {
606 filename = g_string_new("");
607 g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i);
608 fp = fopen(filename->str, "w");
609 if(fp == NULL) g_error("Cannot open %s", filename->str);
610 g_string_free(filename, TRUE);
611 lttv_state_write((LttvTraceState *)tc->traces[0],
612 save_state.write_time[j], fp);
613 fclose(fp);
614 }
615 //else lttv_state_write((LttvTraceState *)tc->traces[0],
616 // save_state.write_time[j], save_state.fp);
617 }
618 }
619 }
620
621 /* Seek at specified interval, using states computed in 6, making
622 * sure that there is no more than the number of events between
623 * state save interval to read before getting there.
624 */
625
626 if((a_test8 && a_test6) || a_test_all) {
627 g_message("Running test 8 : check save interval");
628 LttTime time = tc->time_span.start_time;
629 LttTime interval;
630 interval.tv_sec = 0;
631 interval.tv_nsec = 175674987;
632 guint count;
633
634 while(ltt_time_compare(time, tc->time_span.end_time) < 0) {
635 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
636 lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero);
637 lttv_state_traceset_seek_time_closest(ts, time);
638 /* We add no hook to the traceset, not necessary */
639 count = lttv_process_traceset_middle(&ts->parent,
640 time, G_MAXUINT, NULL);
641 g_info("Number of events to jump over : %u", count);
642
643 if(count > LTTV_STATE_SAVE_INTERVAL)
644 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.",
645 LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec);
646 time = ltt_time_add(time, interval);
647 }
648
649 }
650
651 if(a_test9 || a_test_all) {
652 double t0, t1;
653 /* Run seek_forward and seek_backward test */
654 guint count;
655 LttvTracesetContext *tsc = &ts->parent;
656 LttvTracesetContextPosition *saved_pos =
657 lttv_traceset_context_position_new(tsc);
658 g_message("Running test 9 : seek_forward and seek_backward");
659 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
660
661 count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
662 g_assert(count == 500);
663 lttv_traceset_context_position_save(tsc, saved_pos);
664 t0 = get_time();
665 count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL, NULL, NULL, NULL);
666 t1 = get_time();
667 g_message("Seek forward 150000 events in %g seconds", t1 - t0);
668 g_assert(count == 150000);
669 t0 = get_time();
670 count = lttv_process_traceset_seek_n_backward(tsc, 150000,
671 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
672 NULL, NULL, NULL, NULL, NULL);
673 t1 = get_time();
674 g_message("Seek backward 150000 events in %g seconds", t1 - t0);
675 g_assert(count == 150000);
676 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
677 g_warning("Problem with seek_n ! Positions differ. (1)");
678 }
679
680 lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
681 lttv_traceset_context_position_save(tsc, saved_pos);
682 lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
683 lttv_process_traceset_seek_n_backward(tsc, 15005,
684 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
685 NULL, NULL, NULL, NULL, NULL);
686 lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL, NULL, NULL, NULL);
687 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
688 g_warning("Problem with seek_n ! Positions differ. (2)");
689 }
690
691 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
692
693 count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
694 if(count > 0)
695 g_warning("Problem with seek_n ! Forward at end of traceset.");
696
697 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
698
699 lttv_traceset_context_position_save(tsc, saved_pos);
700 t0 = get_time();
701 lttv_process_traceset_seek_n_backward(tsc, 300,
702 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
703 NULL, NULL, NULL, NULL, NULL);
704 t1 = get_time();
705 g_message("Seek backward 300 events in %g seconds", t1 - t0);
706 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
707 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
708
709 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
710 g_warning("Problem with seek_n ! Positions differ. (4)");
711 }
712
713 lttv_traceset_context_position_save(tsc, saved_pos);
714 t0 = get_time();
715 lttv_process_traceset_seek_n_backward(tsc, 10,
716 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
717 NULL, NULL, NULL, NULL, NULL);
718 t1 = get_time();
719 g_message("Seek backward 10 events in %g seconds", t1 - t0);
720 t0 = get_time();
721 count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL, NULL, NULL, NULL);
722 t1 = get_time();
723 g_message("Seek forward 10 events in %g seconds", t1 - t0);
724
725
726 /* try a volountary error */
727 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
728
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 NULL, NULL, NULL, NULL, NULL);
733 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
734 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
735
736 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) {
737 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
738 }
739
740 /* Try a seek by closest time : Hint : try this one with and without states
741 * computed. */
742 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
743 count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
744 lttv_traceset_context_position_save(tsc, saved_pos);
745 t0 = get_time();
746 lttv_process_traceset_seek_n_backward(tsc, 100301,
747 seek_back_default_offset,
748 (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL,
749 NULL, NULL, NULL, NULL, NULL);
750 t1 = get_time();
751 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
752 t1 - t0);
753 count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL, NULL, NULL, NULL);
754
755 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
756 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
757 }
758
759 lttv_traceset_context_position_destroy(saved_pos);
760 }
761
762 if(a_test10 || a_test_all) {
763 g_message("Running test 10 : check seek traceset context position");
764 LttvTracesetContext *tsc = &ts->parent;
765 LttvTracesetContextPosition *saved_pos =
766 lttv_traceset_context_position_new(tsc);
767
768 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
769 lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
770 lttv_traceset_context_position_save(tsc, saved_pos);
771 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
772 g_critical("Error in seek position. (1)");
773
774 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
775 lttv_process_traceset_seek_n_backward(tsc, 500,
776 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
777 NULL, NULL, NULL, NULL, NULL);
778 lttv_traceset_context_position_save(tsc, saved_pos);
779
780 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
781 g_critical("Error in seek position. (2)");
782
783 lttv_traceset_context_position_destroy(saved_pos);
784 }
785
786 if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
787
788 g_free(save_state.write_time);
789 g_free(a_event_position);
790 lttv_context_fini(tc);
791 g_object_unref(tscs);
792
793 if(lttv_profile_memory) {
794 g_message("Memory summary at the end of batchtest");
795 g_mem_profile();
796 }
797
798 g_info("BatchTest end process traceset");
799 return 0;
08b1c66e 800}
801
802
803static void init()
804{
90e19f82
AM
805 LttvAttributeValue value;
806
807 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
808 gboolean retval;
809
810 g_info("Init batchtest.c");
811
812 /* Init GQuarks */
813 QUARK_BLOCK_START = g_quark_from_string("block_start");
814 QUARK_BLOCK_END = g_quark_from_string("block_end");
815
816
817 lttv_option_add("trace", 't',
818 "add a trace to the trace set to analyse",
819 "pathname of the directory containing the trace",
820 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
821
822 a_trace_event = FALSE;
08b1c66e 823
90e19f82
AM
824 a_dump_tracefiles = NULL;
825 lttv_option_add("dump-tracefiles", 'D',
826 "Write event by event the content of tracefiles",
827 "basename for the files where to dump events",
828 LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL);
829
830 a_save_sample = NULL;
831 lttv_option_add("save-sample", 's',
832 "Save state samples to multiple files",
833 "basename for the files containing the state samples",
834 LTTV_OPT_STRING, &a_save_sample, NULL, NULL);
835
836 a_save_state_copy = FALSE;
837 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
838 "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL);
839
840 a_save_interval = 100000;
841 lttv_option_add("save-interval", 'i',
842 "Interval between saving state",
843 "number of events before a block start triggers saving state",
844 LTTV_OPT_INT, &a_save_interval, NULL, NULL);
845
846 a_sample_interval = 100000;
847 lttv_option_add("sample-interval", 'S',
848 "Interval between sampling state",
849 "number of events before sampling and writing state",
850 LTTV_OPT_INT, &a_sample_interval, NULL, NULL);
851
852 a_sample_number = 20;
853 lttv_option_add("sample-number", 'N',
854 "Number of state samples",
855 "maximum number",
856 LTTV_OPT_INT, &a_sample_number, NULL, NULL);
857
858 a_seek_number = 200;
859 lttv_option_add("seek-number", 'K',
860 "Number of seek",
861 "number",
862 LTTV_OPT_INT, &a_seek_number, NULL, NULL);
863
864 a_test1 = FALSE;
865 lttv_option_add("test1", '1', "Test just counting events", "",
866 LTTV_OPT_NONE, &a_test1, NULL, NULL);
867
868 a_test2 = FALSE;
869 lttv_option_add("test2", '2', "Test computing the state", "",
870 LTTV_OPT_NONE, &a_test2, NULL, NULL);
871
872 a_test3 = FALSE;
873 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
874 "", LTTV_OPT_NONE, &a_test3, NULL, NULL);
875
876 a_test4 = FALSE;
877 lttv_option_add("test4", '4', "Test computing the stats", "",
878 LTTV_OPT_NONE, &a_test4, NULL, NULL);
879
880 a_test5 = FALSE;
881 lttv_option_add("test5", '5', "Test computing the state and stats", "",
882 LTTV_OPT_NONE, &a_test5, NULL, NULL);
883
884 a_test6 = FALSE;
885 lttv_option_add("test6", '6', "Test computing and saving the state", "",
886 LTTV_OPT_NONE, &a_test6, NULL, NULL);
887
888 a_test7 = FALSE;
889 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
890 "", LTTV_OPT_NONE, &a_test7, NULL, NULL);
891
892 a_test8 = FALSE;
893 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
894 "", LTTV_OPT_NONE, &a_test8, NULL, NULL);
895
896 a_test9 = FALSE;
897 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
898 "", LTTV_OPT_NONE, &a_test9, NULL, NULL);
899
900 a_test10 = FALSE;
901 lttv_option_add("test10", ' ', "Test seeking traceset by position",
902 "", LTTV_OPT_NONE, &a_test10, NULL, NULL);
903
904
905
906 a_test_all = FALSE;
907 lttv_option_add("testall", 'a', "Run all tests ", "",
908 LTTV_OPT_NONE, &a_test_all, NULL, NULL);
909
910 traceset = lttv_traceset_new();
911
912 before_traceset = lttv_hooks_new();
913 after_traceset = lttv_hooks_new();
914 before_trace = lttv_hooks_new();
915 after_trace = lttv_hooks_new();
916 before_tracefile = lttv_hooks_new();
917 after_tracefile = lttv_hooks_new();
918 //before_event = lttv_hooks_new();
919 //after_event = lttv_hooks_new();
920 event_hook = lttv_hooks_new();
921
922
923 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
924 LTTV_POINTER, &value);
925 g_assert(retval);
926 *(value.v_pointer) = before_traceset;
927 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
928 LTTV_POINTER, &value);
929 g_assert(retval);
930 *(value.v_pointer) = after_traceset;
931 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
932 LTTV_POINTER, &value);
933 g_assert(retval);
934 *(value.v_pointer) = before_trace;
935 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
936 LTTV_POINTER, &value);
937 g_assert(retval);
938 *(value.v_pointer) = after_trace;
939 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
940 LTTV_POINTER, &value);
941 g_assert(retval);
942 *(value.v_pointer) = before_tracefile;
943 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
944 LTTV_POINTER, &value);
945 g_assert(retval);
946 *(value.v_pointer) = after_tracefile;
947 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/before",
948 // LTTV_POINTER, &value);
949 //*(value.v_pointer) = before_event;
950 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/after",
951 // LTTV_POINTER, &value);
952 //*(value.v_pointer) = after_event;
953 retval= lttv_iattribute_find_by_path(attributes, "hooks/event",
954 LTTV_POINTER, &value);
955 g_assert(retval);
956 *(value.v_pointer) = event_hook;
957 retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before",
958 LTTV_POINTER, &value);
959 g_assert(retval);
960 g_assert((main_hooks = *(value.v_pointer)) != NULL);
961 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
08b1c66e 962}
963
964
965static void destroy()
966{
90e19f82
AM
967 guint i, nb;
968
969 LttvTrace *trace;
970
971 g_info("Destroy batchAnalysis.c");
972
973 lttv_option_remove("trace");
974 lttv_option_remove("dump-tracefiles");
975 lttv_option_remove("save-sample");
976 lttv_option_remove("save-state-copy");
977 lttv_option_remove("sample-interval");
978 lttv_option_remove("sample-number");
979 lttv_option_remove("seek-number");
980 lttv_option_remove("save-interval");
981 lttv_option_remove("test1");
982 lttv_option_remove("test2");
983 lttv_option_remove("test3");
984 lttv_option_remove("test4");
985 lttv_option_remove("test5");
986 lttv_option_remove("test6");
987 lttv_option_remove("test7");
988 lttv_option_remove("test8");
989 lttv_option_remove("test9");
990 lttv_option_remove("test10");
991 lttv_option_remove("testall");
992
993 lttv_hooks_destroy(before_traceset);
994 lttv_hooks_destroy(after_traceset);
995 lttv_hooks_destroy(before_trace);
996 lttv_hooks_destroy(after_trace);
997 lttv_hooks_destroy(before_tracefile);
998 lttv_hooks_destroy(after_tracefile);
999 //lttv_hooks_destroy(before_event);
1000 //lttv_hooks_destroy(after_event);
1001 lttv_hooks_destroy(event_hook);
1002 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
1003
1004 nb = lttv_traceset_number(traceset);
1005 for(i = 0 ; i < nb ; i++) {
1006 trace = lttv_traceset_get(traceset, i);
1007 lttv_traceset_remove(traceset,i);
2bc1bcfb 1008#ifdef BABEL_CLEANUP
90e19f82
AM
1009 ltt_trace_close(lttv_trace(trace));
1010 lttv_trace_destroy(trace);
2bc1bcfb 1011#endif
90e19f82
AM
1012 }
1013
1014 lttv_traceset_destroy(traceset);
08b1c66e 1015}
1016
1017
1018LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
90e19f82
AM
1019 "Run through a trace calling all the registered hooks for tests", \
1020 init, destroy, "state", "stats", "option" )
This page took 0.107762 seconds and 4 git commands to generate.