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