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