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