fix multiversion traces handling
[lttv.git] / ltt / branches / poly / 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
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
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>
08b1c66e 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>
d8f124de 33#include <lttv/tracecontext.h>
08b1c66e 34#include <lttv/state.h>
35#include <lttv/stats.h>
36#include <ltt/trace.h>
37#include <ltt/event.h>
338d4282 38#include <ltt/type.h>
00e74b69 39#include <ltt/facility.h>
40
41#define __UNUSED__ __attribute__((__unused__))
08b1c66e 42
43static LttvTraceset *traceset;
44
45static LttvHooks
46 *before_traceset,
47 *after_traceset,
48 *before_trace,
49 *after_trace,
50 *before_tracefile,
51 *after_tracefile,
b8eccacd 52 //*before_event,
53 //*after_event,
54 *event_hook,
08b1c66e 55 *main_hooks;
56
57static char *a_trace;
58
59static char *a_dump_tracefiles;
60
61static char *a_save_sample;
62
63static int
64 a_sample_interval,
65 a_sample_number,
911b7a3c 66 a_seek_number,
08b1c66e 67 a_save_interval;
68
69static gboolean
f95bc830 70 a_trace_event,
71 a_save_state_copy,
08b1c66e 72 a_test1,
73 a_test2,
74 a_test3,
75 a_test4,
76 a_test5,
77 a_test6,
78 a_test7,
79 a_test_all;
80
eed2ef37 81static GQuark QUARK_BLOCK_START,
82 QUARK_BLOCK_END;
83
f95bc830 84LttEventPosition *a_event_position;
85
08b1c66e 86typedef struct _save_state {
87 guint count;
88 FILE *fp;
89 guint interval;
90 guint position;
91 guint size;
92 LttTime *write_time;
93 guint version;
94} SaveState;
95
96
00e74b69 97static void lttv_trace_option(void __UNUSED__ *hook_data)
08b1c66e 98{
99 LttTrace *trace;
100
101 trace = ltt_trace_open(a_trace);
e45551ac 102 if(trace == NULL) {
103 g_critical("cannot open trace %s", a_trace);
104 } else {
105 lttv_traceset_add(traceset, lttv_trace_new(trace));
106 }
08b1c66e 107}
108
109static double get_time()
110{
111 GTimeVal gt;
112
113 g_get_current_time(&gt);
114 return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0;
115}
116
117static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
118{
119 double t0, t1;
120
00e74b69 121 unsigned int i;
f95bc830 122
b8eccacd 123 //lttv_traceset_context_add_hooks(&ts->parent,
124 //before_traceset, after_traceset, NULL, before_trace, after_trace,
125 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
126 lttv_process_traceset_begin(&ts->parent,
127 before_traceset,
128 before_trace,
129 before_tracefile,
130 event_hook,
131 NULL);
08b1c66e 132
f95bc830 133 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
134 ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval;
135 }
136
08b1c66e 137 t0 = get_time();
138 lttv_state_traceset_seek_time_closest(ts, start);
b8eccacd 139 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
140 lttv_process_traceset_middle(&ts->parent,
141 end,
142 G_MAXULONG,
143 NULL);
08b1c66e 144 t1 = get_time();
145
b8eccacd 146 //lttv_traceset_context_remove_hooks(&ts->parent,
147 //before_traceset, after_traceset, NULL, before_trace, after_trace,
148 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
149 lttv_process_traceset_end(&ts->parent,
150 after_traceset,
151 after_trace,
152 after_tracefile,
153 event_hook,
154 NULL);
08b1c66e 155
156 return t1 - t0;
157}
158
159
00e74b69 160gboolean trace_event(void __UNUSED__ *hook_data, void *call_data)
f95bc830 161{
162 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
163
eed2ef37 164 guint nb_block, offset;
f95bc830 165
eed2ef37 166 guint64 tsc;
f95bc830 167
eed2ef37 168 LttTracefile *tf;
169 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
170 ltt_event_position(e, a_event_position);
171 ltt_event_position_get(a_event_position, &tf, &nb_block, &offset, &tsc);
172 fprintf(stderr,"Event %s %lu.%09lu [%u %u tsc %llu]\n",
173 g_quark_to_string(ltt_eventtype_name(ltt_event_eventtype(e))),
f95bc830 174 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec,
eed2ef37 175 nb_block, offset, tsc);
f95bc830 176 return FALSE;
177}
178
179
00e74b69 180gboolean count_event(void *hook_data, void __UNUSED__ *call_data)
08b1c66e 181{
182 guint *pcount = (guint *)hook_data;
183
184 (*pcount)++;
185 return FALSE;
186}
187
188
f95bc830 189gboolean save_state_copy_event(void *hook_data, void *call_data)
190{
00e74b69 191 SaveState __UNUSED__ *save_state = (SaveState *)hook_data;
f95bc830 192
193 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
194
195 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
196
eed2ef37 197 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
198
f95bc830 199 GString *filename;
200
201 FILE *fp;
202
eed2ef37 203 if(ts->nb_event == 0 &&
204 ltt_eventtype_name(ltt_event_eventtype(e))
205 == QUARK_BLOCK_START) {
f95bc830 206 if(a_save_sample != NULL) {
207 filename = g_string_new("");
208 g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample,
209 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
210 fp = fopen(filename->str, "w");
211 if(fp == NULL) g_error("Cannot open %s", filename->str);
212 g_string_free(filename, TRUE);
213 lttv_state_write(ts, tfs->parent.timestamp, fp);
214 fclose(fp);
215 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
216 }
217 return FALSE;
218}
219
220
08b1c66e 221gboolean save_state_event(void *hook_data, void *call_data)
222{
223 SaveState *save_state = (SaveState *)hook_data;
224
225 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
226
227 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
228
229 GString *filename;
230
231 FILE *fp;
232
233 (save_state->count)++;
234 if(save_state->count % save_state->interval == 0 &&
235 save_state->position < save_state->size) {
236 if(a_save_sample != NULL) {
237 filename = g_string_new("");
238 g_string_printf(filename, "%s.%u.xml.%u", a_save_sample,
239 save_state->position, save_state->version);
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);
244 fclose(fp);
f95bc830 245 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
08b1c66e 246
247 save_state->write_time[save_state->position] = tfs->parent.timestamp;
248 save_state->position++;
249 }
250 return FALSE;
251}
252
253
d3d34f49 254static void sanitize_name(gchar *name)
255{
256 while(*name != '\0') {
257 if(*name == '/') *name = '_';
258 name++;
259 }
260
261}
262
eed2ef37 263
27304273 264static void compute_tracefile(LttTracefile *tracefile, void *hook_data)
eed2ef37 265{
266 GString *filename;
d3d34f49 267 guint nb_equal, nb_block, offset;
eed2ef37 268 guint64 tsc;
269 FILE *fp;
270 LttTime time, previous_time;
27304273 271 LttEvent *event = ltt_tracefile_get_event(tracefile);
eed2ef37 272 LttFacility *facility;
273 LttEventType *event_type;
274 int err;
d3d34f49 275 gchar mod_name[PATH_MAX];
eed2ef37 276
277 /* start_count is always initialized in this function _if_ there is always
278 * a block_start before a block_end.
279 */
280 long long unsigned cycle_count, start_count=0, delta_cycle;
281
282
283 filename = g_string_new("");
d3d34f49 284 strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile)));
285
286 sanitize_name(mod_name);
287
d052ffc3 288 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile)));
d3d34f49 289 g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles,
290 mod_name, ltt_tracefile_num(tracefile));
eed2ef37 291 fp = fopen(filename->str, "w");
292 if(fp == NULL) g_error("Cannot open %s", filename->str);
293 g_string_free(filename, TRUE);
294 err = ltt_tracefile_seek_time(tracefile, ltt_time_zero);
295 if(err) goto close;
296
297 previous_time = ltt_time_zero;
298 nb_equal = 0;
299
300 do {
301 LttTracefile *tf_pos;
302 facility = ltt_event_facility(event);
303 event_type = ltt_event_eventtype(event);
304 time = ltt_event_time(event);
305 ltt_event_position(event, a_event_position);
306 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
27304273 307 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
308 fprintf(fp, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
309 g_quark_to_string(ltt_facility_name(facility)),
310 g_quark_to_string(ltt_eventtype_name(event_type)),
eed2ef37 311 tsc, (unsigned long)time.tv_sec,
312 (unsigned long)time.tv_nsec,
27304273 313 nb_block, offset,
314 g_quark_to_string(ltt_tracefile_name(tracefile)));
eed2ef37 315
316 if(ltt_time_compare(time, previous_time) < 0) {
d052ffc3 317 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/%u",
d3d34f49 318 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
d052ffc3 319 g_quark_to_string(ltt_tracefile_name(tracefile)),
320 ltt_tracefile_num(tracefile), nb_block, offset);
321 g_warning("last time %lu.%lu vs current %lu.%lu",
322 previous_time.tv_sec, previous_time.tv_nsec,
323 time.tv_sec, time.tv_nsec);
eed2ef37 324 }
325
326#if 0 //FIXME
327 if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) {
328 start_count = cycle_count;
329 start_time = time;
330 }
331 else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) {
332 delta_cycle = cycle_count - start_count;
333 end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000;
334 end_nsec_nsec = time.tv_nsec;
335 end_nsec = end_nsec_sec + end_nsec_nsec;
336 start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec;
337 delta_nsec = end_nsec - start_nsec;
338 cycle_per_nsec = (double)delta_cycle / (double)delta_nsec;
339 nsec_per_cycle = (double)delta_nsec / (double)delta_cycle;
340 added_nsec = (double)delta_cycle * nsec_per_cycle;
341 interpolated_nsec = start_nsec + added_nsec;
342 added_nsec2 = (double)delta_cycle / cycle_per_nsec;
343 interpolated_nsec2 = start_nsec + added_nsec2;
344
345 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);
346 }
347 else {
348#endif //0
349 if(ltt_time_compare(time, previous_time) == 0) nb_equal++;
350 else if(nb_equal > 0) {
351 g_warning("Consecutive %d events with time %lu.%09lu",
352 nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec);
353 nb_equal = 0;
354 }
355 previous_time = time;
356 //}
357 } while((!ltt_tracefile_read(tracefile)));
358
359close:
360 fclose(fp);
eed2ef37 361}
362
00e74b69 363static gboolean process_traceset(void __UNUSED__ *hook_data,
364 void __UNUSED__ *call_data)
08b1c66e 365{
eed2ef37 366 GString *filename;
08b1c66e 367 LttvTracesetStats *tscs;
368
369 LttvTracesetState *ts;
370
371 LttvTracesetContext *tc;
372
08b1c66e 373 FILE *fp;
374
375 double t;
376
eed2ef37 377 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
378 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
379 guint i, j, count;
08b1c66e 380
381 LttTrace *trace;
382
338d4282 383 long long unsigned start_nsec, end_nsec, delta_nsec, added_nsec, added_nsec2;
384
385 double cycle_per_nsec, nsec_per_cycle;
386
387 long long interpolated_nsec, interpolated_nsec2, end_nsec_sec, end_nsec_nsec;
388
389 LttTime start_time;
390
08b1c66e 391 LttTime max_time = { G_MAXULONG, G_MAXULONG };
392
f95bc830 393 a_event_position = ltt_event_position_new();
394
3865ea09 395 GData **tracefiles_groups;
eed2ef37 396
27304273 397 struct compute_tracefile_group_args args;
398
399 args.func = compute_tracefile;
400 args.func_args = NULL;
401
08b1c66e 402 if(a_dump_tracefiles != NULL) {
08b1c66e 403 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
404 trace = lttv_trace(lttv_traceset_get(traceset, i));
eed2ef37 405 tracefiles_groups = ltt_trace_get_tracefiles_groups(trace);
08b1c66e 406
3865ea09 407 g_datalist_foreach(tracefiles_groups,
eed2ef37 408 (GDataForeachFunc)compute_tracefile_group,
27304273 409 &args);
eed2ef37 410
08b1c66e 411 }
08b1c66e 412 }
413
414 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
415 ts = &tscs->parent;
416 tc = &tscs->parent.parent;
417
418 lttv_context_init(tc, traceset);
08b1c66e 419
420 /* For each case compute and print the elapsed time.
421 The first case is simply to run through all events with a
422 simple counter. */
423
424 if(a_test1 || a_test_all) {
425 count = 0;
b8eccacd 426 lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
eed2ef37 427 t = run_one_test(ts, ltt_time_zero, max_time);
b8eccacd 428 lttv_hooks_remove_data(event_hook, count_event, &count);
021eeb41 429 g_message(
08b1c66e 430 "Processing trace while counting events (%u events in %g seconds)",
431 count, t);
432 }
433
434 /* Run through all events computing the state. */
435
436 if(a_test2 || a_test_all) {
437 lttv_state_add_event_hooks(ts);
eed2ef37 438 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 439 lttv_state_remove_event_hooks(ts);
021eeb41 440 g_message("Processing trace while updating state (%g seconds)", t);
08b1c66e 441 }
442
443 /* Run through all events computing the state and writing it out
444 periodically. */
445
446 SaveState save_state;
447
448 save_state.interval = a_sample_interval;
449 save_state.size = a_sample_number;
450 save_state.fp = stderr;
451 save_state.write_time = g_new(LttTime, a_sample_number);
452
453
454 if(a_test3 || a_test_all) {
455 for(i = 0 ; i < 2 ; i++) {
456 save_state.count = 0;
457 save_state.position = 0;
458 save_state.version = i;
459 lttv_state_add_event_hooks(ts);
b8eccacd 460 lttv_hooks_add(event_hook, save_state_event, &save_state,
461 LTTV_PRIO_DEFAULT);
eed2ef37 462 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 463 lttv_state_remove_event_hooks(ts);
b8eccacd 464 lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
08b1c66e 465 g_warning("Processing while updating/writing state (%g seconds)", t);
466 }
467 }
468
469 /* Run through all events computing the stats. */
470
471 if(a_test4 || a_test_all) {
472 if(lttv_profile_memory) {
473 g_message("Memory summary before computing stats");
474 g_mem_profile();
475 }
476
477 lttv_stats_add_event_hooks(tscs);
eed2ef37 478 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 479 lttv_stats_remove_event_hooks(tscs);
021eeb41 480 g_message("Processing trace while counting stats (%g seconds)", t);
08b1c66e 481
482 if(lttv_profile_memory) {
483 g_message("Memory summary after computing stats");
484 g_mem_profile();
485 }
f95bc830 486
487 lttv_stats_sum_traceset(tscs);
488
489 if(lttv_profile_memory) {
490 g_message("Memory summary after summing stats");
491 g_mem_profile();
492 }
493
494 lttv_context_fini(tc);
495 lttv_context_init(tc, traceset);
496
497 if(lttv_profile_memory) {
498 g_message("Memory summary after cleaning up the stats");
499 g_mem_profile();
500 }
08b1c66e 501 }
502
503 /* Run through all events computing the state and stats. */
504
505 if(a_test5 || a_test_all) {
506 if(lttv_profile_memory) {
507 g_message("Memory summary before computing state and stats");
508 g_mem_profile();
509 }
510
511 lttv_state_add_event_hooks(ts);
512 lttv_stats_add_event_hooks(tscs);
eed2ef37 513 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 514 lttv_state_remove_event_hooks(ts);
515 lttv_stats_remove_event_hooks(tscs);
021eeb41 516 g_message(
08b1c66e 517 "Processing trace while counting state and stats (%g seconds)", t);
518
519 if(lttv_profile_memory) {
520 g_message("Memory summary after computing and state and stats");
521 g_mem_profile();
522 }
f95bc830 523
524 lttv_context_fini(tc);
525 lttv_context_init(tc, traceset);
526
527 if(lttv_profile_memory) {
528 g_message("Memory summary after cleaning up the stats");
529 g_mem_profile();
530 }
08b1c66e 531 }
532
533 /* Run through all events computing and saving the state. */
534
b8eccacd 535 if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
536 LTTV_PRIO_DEFAULT);
f95bc830 537
08b1c66e 538 if(a_test6 || a_test_all) {
539 if(lttv_profile_memory) {
540 g_message("Memory summary before computing and saving state");
541 g_mem_profile();
542 }
543
544 lttv_state_add_event_hooks(ts);
545 lttv_state_save_add_event_hooks(ts);
f95bc830 546 if(a_save_state_copy)
b8eccacd 547 lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
548 LTTV_PRIO_DEFAULT);
eed2ef37 549 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 550 lttv_state_remove_event_hooks(ts);
551 lttv_state_save_remove_event_hooks(ts);
f95bc830 552 if(a_save_state_copy)
b8eccacd 553 lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
f95bc830 554
021eeb41 555 g_message("Processing trace while updating/saving state (%g seconds)", t);
08b1c66e 556
557 if(lttv_profile_memory) {
558 g_message("Memory summary after computing/saving state");
559 g_mem_profile();
560 }
561 }
562
563 /* Seek a few times to each saved position */
564
565 if((a_test7 && a_test3) || a_test_all) {
00e74b69 566 g_assert(a_seek_number >= 0);
567 for(i = 0 ; i < (guint)a_seek_number ; i++) {
568 gint reverse_j; /* just to make sure j is unsigned */
569 for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
570 j = (guint)reverse_j;
08b1c66e 571 lttv_state_add_event_hooks(ts);
572 t = run_one_test(ts, save_state.write_time[j],
573 save_state.write_time[j]);
574 lttv_state_remove_event_hooks(ts);
021eeb41 575 g_message("Seeking to %lu.%lu (%g seconds)",
08b1c66e 576 save_state.write_time[j].tv_sec, save_state.write_time[j].tv_nsec,
577 t);
578
579 if(a_save_sample != NULL) {
580 filename = g_string_new("");
581 g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i);
582 fp = fopen(filename->str, "w");
583 if(fp == NULL) g_error("Cannot open %s", filename->str);
584 g_string_free(filename, TRUE);
585 lttv_state_write((LttvTraceState *)tc->traces[0],
586 save_state.write_time[j], fp);
587 fclose(fp);
588 }
f95bc830 589 //else lttv_state_write((LttvTraceState *)tc->traces[0],
590 // save_state.write_time[j], save_state.fp);
08b1c66e 591 }
592 }
593 }
594
b8eccacd 595 if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
f95bc830 596
08b1c66e 597 g_free(save_state.write_time);
f95bc830 598 g_free(a_event_position);
08b1c66e 599 lttv_context_fini(tc);
600 g_object_unref(tscs);
601
f95bc830 602 if(lttv_profile_memory) {
603 g_message("Memory summary at the end of batchtest");
604 g_mem_profile();
605 }
606
08b1c66e 607 g_info("BatchTest end process traceset");
00e74b69 608 return 0;
08b1c66e 609}
610
611
612static void init()
613{
614 LttvAttributeValue value;
615
616 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
617
618 g_info("Init batchtest.c");
619
eed2ef37 620 /* Init GQuarks */
621 QUARK_BLOCK_START = g_quark_from_string("block_start");
622 QUARK_BLOCK_END = g_quark_from_string("block_end");
623
624
08b1c66e 625 lttv_option_add("trace", 't',
626 "add a trace to the trace set to analyse",
627 "pathname of the directory containing the trace",
628 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
629
f95bc830 630 a_trace_event = FALSE;
631
08b1c66e 632 a_dump_tracefiles = NULL;
633 lttv_option_add("dump-tracefiles", 'D',
634 "Write event by event the content of tracefiles",
635 "basename for the files where to dump events",
636 LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL);
637
638 a_save_sample = NULL;
639 lttv_option_add("save-sample", 's',
640 "Save state samples to multiple files",
641 "basename for the files containing the state samples",
642 LTTV_OPT_STRING, &a_save_sample, NULL, NULL);
643
f95bc830 644 a_save_state_copy = FALSE;
645 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
646 "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL);
647
08b1c66e 648 a_save_interval = 100000;
649 lttv_option_add("save-interval", 'i',
650 "Interval between saving state",
651 "number of events before a block start triggers saving state",
652 LTTV_OPT_INT, &a_save_interval, NULL, NULL);
653
654 a_sample_interval = 100000;
655 lttv_option_add("sample-interval", 'S',
656 "Interval between sampling state",
657 "number of events before sampling and writing state",
658 LTTV_OPT_INT, &a_sample_interval, NULL, NULL);
659
660 a_sample_number = 20;
661 lttv_option_add("sample-number", 'N',
662 "Number of state samples",
663 "maximum number",
664 LTTV_OPT_INT, &a_sample_number, NULL, NULL);
665
911b7a3c 666 a_seek_number = 200;
667 lttv_option_add("seek-number", 'K',
668 "Number of seek",
669 "number",
670 LTTV_OPT_INT, &a_seek_number, NULL, NULL);
671
08b1c66e 672 a_test1 = FALSE;
673 lttv_option_add("test1", '1', "Test just counting events", "",
674 LTTV_OPT_NONE, &a_test1, NULL, NULL);
675
676 a_test2 = FALSE;
677 lttv_option_add("test2", '2', "Test computing the state", "",
678 LTTV_OPT_NONE, &a_test2, NULL, NULL);
679
680 a_test3 = FALSE;
681 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
682 "", LTTV_OPT_NONE, &a_test3, NULL, NULL);
683
684 a_test4 = FALSE;
685 lttv_option_add("test4", '4', "Test computing the stats", "",
686 LTTV_OPT_NONE, &a_test4, NULL, NULL);
687
688 a_test5 = FALSE;
689 lttv_option_add("test5", '5', "Test computing the state and stats", "",
690 LTTV_OPT_NONE, &a_test5, NULL, NULL);
691
692 a_test6 = FALSE;
693 lttv_option_add("test6", '6', "Test computing and saving the state", "",
694 LTTV_OPT_NONE, &a_test6, NULL, NULL);
695
696 a_test7 = FALSE;
697 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
698 "", LTTV_OPT_NONE, &a_test7, NULL, NULL);
699
700 a_test_all = FALSE;
701 lttv_option_add("testall", 'a', "Run all tests ", "",
702 LTTV_OPT_NONE, &a_test_all, NULL, NULL);
703
704 traceset = lttv_traceset_new();
705
706 before_traceset = lttv_hooks_new();
707 after_traceset = lttv_hooks_new();
708 before_trace = lttv_hooks_new();
709 after_trace = lttv_hooks_new();
710 before_tracefile = lttv_hooks_new();
711 after_tracefile = lttv_hooks_new();
b8eccacd 712 //before_event = lttv_hooks_new();
713 //after_event = lttv_hooks_new();
714 event_hook = lttv_hooks_new();
715
08b1c66e 716
717 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
718 LTTV_POINTER, &value));
719 *(value.v_pointer) = before_traceset;
720 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
721 LTTV_POINTER, &value));
722 *(value.v_pointer) = after_traceset;
723 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
724 LTTV_POINTER, &value));
725 *(value.v_pointer) = before_trace;
726 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
727 LTTV_POINTER, &value));
728 *(value.v_pointer) = after_trace;
729 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
730 LTTV_POINTER, &value));
731 *(value.v_pointer) = before_tracefile;
732 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
733 LTTV_POINTER, &value));
734 *(value.v_pointer) = after_tracefile;
b8eccacd 735 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
736 // LTTV_POINTER, &value));
737 //*(value.v_pointer) = before_event;
738 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
739 // LTTV_POINTER, &value));
740 //*(value.v_pointer) = after_event;
63a95338 741 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
08b1c66e 742 LTTV_POINTER, &value));
b8eccacd 743 *(value.v_pointer) = event_hook;
08b1c66e 744 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
745 LTTV_POINTER, &value));
746 g_assert((main_hooks = *(value.v_pointer)) != NULL);
b8eccacd 747 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
08b1c66e 748}
749
750
751static void destroy()
752{
753 guint i, nb;
754
755 LttvTrace *trace;
756
757 g_info("Destroy batchAnalysis.c");
758
759 lttv_option_remove("trace");
760 lttv_option_remove("dump-tracefiles");
761 lttv_option_remove("save-sample");
f95bc830 762 lttv_option_remove("save-state-copy");
08b1c66e 763 lttv_option_remove("sample-interval");
764 lttv_option_remove("sample-number");
911b7a3c 765 lttv_option_remove("seek-number");
08b1c66e 766 lttv_option_remove("save-interval");
767 lttv_option_remove("test1");
768 lttv_option_remove("test2");
769 lttv_option_remove("test3");
770 lttv_option_remove("test4");
771 lttv_option_remove("test5");
772 lttv_option_remove("test6");
773 lttv_option_remove("test7");
774 lttv_option_remove("testall");
775
776 lttv_hooks_destroy(before_traceset);
777 lttv_hooks_destroy(after_traceset);
778 lttv_hooks_destroy(before_trace);
779 lttv_hooks_destroy(after_trace);
780 lttv_hooks_destroy(before_tracefile);
781 lttv_hooks_destroy(after_tracefile);
b8eccacd 782 //lttv_hooks_destroy(before_event);
783 //lttv_hooks_destroy(after_event);
784 lttv_hooks_destroy(event_hook);
08b1c66e 785 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
786
787 nb = lttv_traceset_number(traceset);
788 for(i = 0 ; i < nb ; i++) {
789 trace = lttv_traceset_get(traceset, i);
443a558d 790 lttv_traceset_remove(traceset,i);
08b1c66e 791 ltt_trace_close(lttv_trace(trace));
792 lttv_trace_destroy(trace);
793 }
794
795 lttv_traceset_destroy(traceset);
796}
797
798
799LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
800 "Run through a trace calling all the registered hooks for tests", \
801 init, destroy, "state", "stats", "option" )
This page took 0.062038 seconds and 4 git commands to generate.