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