remove files unneeded for lttv
[lttv.git] / lttv / 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>
43ed82b5 28#include <inttypes.h>
08b1c66e 29#include <lttv/lttv.h>
30#include <lttv/attribute.h>
31#include <lttv/hook.h>
32#include <lttv/option.h>
33#include <lttv/module.h>
d8f124de 34#include <lttv/tracecontext.h>
08b1c66e 35#include <lttv/state.h>
36#include <lttv/stats.h>
37#include <ltt/trace.h>
38#include <ltt/event.h>
00e74b69 39
40#define __UNUSED__ __attribute__((__unused__))
08b1c66e 41
42static LttvTraceset *traceset;
43
44static LttvHooks
45 *before_traceset,
46 *after_traceset,
47 *before_trace,
48 *after_trace,
49 *before_tracefile,
50 *after_tracefile,
b8eccacd 51 //*before_event,
52 //*after_event,
53 *event_hook,
08b1c66e 54 *main_hooks;
55
56static char *a_trace;
57
58static char *a_dump_tracefiles;
59
60static char *a_save_sample;
61
62static int
63 a_sample_interval,
64 a_sample_number,
911b7a3c 65 a_seek_number,
08b1c66e 66 a_save_interval;
67
68static gboolean
f95bc830 69 a_trace_event,
70 a_save_state_copy,
08b1c66e 71 a_test1,
72 a_test2,
73 a_test3,
74 a_test4,
75 a_test5,
76 a_test6,
77 a_test7,
728d0c3e 78 a_test8,
33e44b82 79 a_test9,
9ba3aaaf 80 a_test10,
08b1c66e 81 a_test_all;
82
eed2ef37 83static GQuark QUARK_BLOCK_START,
84 QUARK_BLOCK_END;
85
f95bc830 86LttEventPosition *a_event_position;
87
08b1c66e 88typedef struct _save_state {
89 guint count;
90 FILE *fp;
91 guint interval;
92 guint position;
93 guint size;
94 LttTime *write_time;
95 guint version;
96} SaveState;
97
98
00e74b69 99static void lttv_trace_option(void __UNUSED__ *hook_data)
08b1c66e 100{
101 LttTrace *trace;
102
103 trace = ltt_trace_open(a_trace);
e45551ac 104 if(trace == NULL) {
105 g_critical("cannot open trace %s", a_trace);
106 } else {
107 lttv_traceset_add(traceset, lttv_trace_new(trace));
108 }
08b1c66e 109}
110
111static double get_time()
112{
113 GTimeVal gt;
114
115 g_get_current_time(&gt);
116 return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0;
117}
118
119static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
120{
121 double t0, t1;
122
00e74b69 123 unsigned int i;
f95bc830 124
b8eccacd 125 //lttv_traceset_context_add_hooks(&ts->parent,
126 //before_traceset, after_traceset, NULL, before_trace, after_trace,
127 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
128 lttv_process_traceset_begin(&ts->parent,
129 before_traceset,
130 before_trace,
131 before_tracefile,
132 event_hook,
133 NULL);
08b1c66e 134
f95bc830 135 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
136 ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval;
137 }
138
08b1c66e 139 t0 = get_time();
140 lttv_state_traceset_seek_time_closest(ts, start);
b8eccacd 141 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
142 lttv_process_traceset_middle(&ts->parent,
143 end,
144 G_MAXULONG,
145 NULL);
08b1c66e 146 t1 = get_time();
147
b8eccacd 148 //lttv_traceset_context_remove_hooks(&ts->parent,
149 //before_traceset, after_traceset, NULL, before_trace, after_trace,
150 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
151 lttv_process_traceset_end(&ts->parent,
152 after_traceset,
153 after_trace,
154 after_tracefile,
155 event_hook,
156 NULL);
08b1c66e 157
158 return t1 - t0;
159}
160
161
00e74b69 162gboolean trace_event(void __UNUSED__ *hook_data, void *call_data)
f95bc830 163{
164 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
165
eed2ef37 166 guint nb_block, offset;
f95bc830 167
eed2ef37 168 guint64 tsc;
f95bc830 169
eed2ef37 170 LttTracefile *tf;
171 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
172 ltt_event_position(e, a_event_position);
173 ltt_event_position_get(a_event_position, &tf, &nb_block, &offset, &tsc);
43ed82b5 174 fprintf(stderr, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64 "]\n",
750eb11a 175 g_quark_to_string(marker_get_info_from_id(tf->mdata,
29af7cfd 176 ltt_event_id(e))->name),
f95bc830 177 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec,
eed2ef37 178 nb_block, offset, tsc);
f95bc830 179 return FALSE;
180}
181
8fe3c6b6 182static LttTime count_previous_time = { 0, 0 };
f95bc830 183
00e74b69 184gboolean count_event(void *hook_data, void __UNUSED__ *call_data)
08b1c66e 185{
8fe3c6b6 186 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
187 LttTracefile *tracefile = tfs->parent.tf;
188 guint nb_block, offset;
189 LttTracefile *tf_pos;
190 guint64 tsc;
191 LttEvent * event = ltt_tracefile_get_event(tracefile);
192 LttTime time;
08b1c66e 193 guint *pcount = (guint *)hook_data;
194
195 (*pcount)++;
8fe3c6b6 196
197 time = ltt_event_time(event);
198 ltt_event_position(event, a_event_position);
199 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
200
201 if(ltt_time_compare(time, count_previous_time) < 0) {
36d36c9f 202 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
8fe3c6b6 203 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
204 g_quark_to_string(ltt_tracefile_name(tracefile)),
ae3d0f50 205 tfs->cpu, nb_block, offset);
8fe3c6b6 206 g_warning("last time %lu.%lu vs current %lu.%lu",
207 count_previous_time.tv_sec, count_previous_time.tv_nsec,
208 time.tv_sec, time.tv_nsec);
209 }
210 count_previous_time = time;
211
212
213
08b1c66e 214 return FALSE;
215}
216
217
f95bc830 218gboolean save_state_copy_event(void *hook_data, void *call_data)
219{
00e74b69 220 SaveState __UNUSED__ *save_state = (SaveState *)hook_data;
f95bc830 221
222 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
223
224 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
225
eed2ef37 226 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
227
f95bc830 228 GString *filename;
229
230 FILE *fp;
231
eed2ef37 232 if(ts->nb_event == 0 &&
750eb11a 233 marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id)->name
eed2ef37 234 == QUARK_BLOCK_START) {
f95bc830 235 if(a_save_sample != NULL) {
236 filename = g_string_new("");
237 g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample,
238 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
239 fp = fopen(filename->str, "w");
240 if(fp == NULL) g_error("Cannot open %s", filename->str);
241 g_string_free(filename, TRUE);
242 lttv_state_write(ts, tfs->parent.timestamp, fp);
243 fclose(fp);
244 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
245 }
246 return FALSE;
247}
248
249
08b1c66e 250gboolean save_state_event(void *hook_data, void *call_data)
251{
252 SaveState *save_state = (SaveState *)hook_data;
253
254 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
255
256 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
257
258 GString *filename;
259
260 FILE *fp;
261
262 (save_state->count)++;
263 if(save_state->count % save_state->interval == 0 &&
264 save_state->position < save_state->size) {
265 if(a_save_sample != NULL) {
266 filename = g_string_new("");
267 g_string_printf(filename, "%s.%u.xml.%u", a_save_sample,
268 save_state->position, save_state->version);
269 fp = fopen(filename->str, "w");
270 if(fp == NULL) g_error("Cannot open %s", filename->str);
271 g_string_free(filename, TRUE);
272 lttv_state_write(ts, tfs->parent.timestamp, fp);
273 fclose(fp);
f95bc830 274 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
08b1c66e 275
276 save_state->write_time[save_state->position] = tfs->parent.timestamp;
277 save_state->position++;
278 }
279 return FALSE;
280}
281
282
d3d34f49 283static void sanitize_name(gchar *name)
284{
285 while(*name != '\0') {
286 if(*name == '/') *name = '_';
287 name++;
288 }
289
290}
291
eed2ef37 292
27304273 293static void compute_tracefile(LttTracefile *tracefile, void *hook_data)
eed2ef37 294{
295 GString *filename;
d3d34f49 296 guint nb_equal, nb_block, offset;
eed2ef37 297 guint64 tsc;
298 FILE *fp;
299 LttTime time, previous_time;
27304273 300 LttEvent *event = ltt_tracefile_get_event(tracefile);
29af7cfd 301 //LttEventType *event_type;
302 struct marker_info *minfo;
eed2ef37 303 int err;
d3d34f49 304 gchar mod_name[PATH_MAX];
eed2ef37 305
306 /* start_count is always initialized in this function _if_ there is always
307 * a block_start before a block_end.
308 */
713b02e3 309 //long long unsigned cycle_count, start_count=0, delta_cycle;
eed2ef37 310
311
312 filename = g_string_new("");
d3d34f49 313 strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile)));
314
315 sanitize_name(mod_name);
316
d052ffc3 317 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile)));
d3d34f49 318 g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles,
ae3d0f50 319 mod_name, ltt_tracefile_cpu(tracefile));
eed2ef37 320 fp = fopen(filename->str, "w");
321 if(fp == NULL) g_error("Cannot open %s", filename->str);
322 g_string_free(filename, TRUE);
323 err = ltt_tracefile_seek_time(tracefile, ltt_time_zero);
324 if(err) goto close;
325
326 previous_time = ltt_time_zero;
327 nb_equal = 0;
328
329 do {
330 LttTracefile *tf_pos;
29af7cfd 331 //event_type = ltt_event_eventtype(event);
750eb11a 332 minfo = marker_get_info_from_id(tracefile->mdata,
29af7cfd 333 ltt_event_id(event));
eed2ef37 334 time = ltt_event_time(event);
335 ltt_event_position(event, a_event_position);
336 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
27304273 337 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
43ed82b5 338 fprintf(fp, "%s: %" PRIu64 " %lu.%09lu position %u/%u, tracefile %s\n",
29af7cfd 339 g_quark_to_string(minfo->name),
eed2ef37 340 tsc, (unsigned long)time.tv_sec,
341 (unsigned long)time.tv_nsec,
27304273 342 nb_block, offset,
343 g_quark_to_string(ltt_tracefile_name(tracefile)));
eed2ef37 344
345 if(ltt_time_compare(time, previous_time) < 0) {
36d36c9f 346 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
d3d34f49 347 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
d052ffc3 348 g_quark_to_string(ltt_tracefile_name(tracefile)),
ae3d0f50 349 ltt_tracefile_cpu(tracefile), nb_block, offset);
d052ffc3 350 g_warning("last time %lu.%lu vs current %lu.%lu",
351 previous_time.tv_sec, previous_time.tv_nsec,
352 time.tv_sec, time.tv_nsec);
eed2ef37 353 }
354
355#if 0 //FIXME
356 if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) {
357 start_count = cycle_count;
358 start_time = time;
359 }
360 else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) {
361 delta_cycle = cycle_count - start_count;
362 end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000;
363 end_nsec_nsec = time.tv_nsec;
364 end_nsec = end_nsec_sec + end_nsec_nsec;
365 start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec;
366 delta_nsec = end_nsec - start_nsec;
367 cycle_per_nsec = (double)delta_cycle / (double)delta_nsec;
368 nsec_per_cycle = (double)delta_nsec / (double)delta_cycle;
369 added_nsec = (double)delta_cycle * nsec_per_cycle;
370 interpolated_nsec = start_nsec + added_nsec;
371 added_nsec2 = (double)delta_cycle / cycle_per_nsec;
372 interpolated_nsec2 = start_nsec + added_nsec2;
373
374 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);
375 }
376 else {
377#endif //0
29af7cfd 378 if(ltt_time_compare(time, previous_time) == 0)
379 nb_equal++;
eed2ef37 380 else if(nb_equal > 0) {
381 g_warning("Consecutive %d events with time %lu.%09lu",
382 nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec);
383 nb_equal = 0;
384 }
385 previous_time = time;
386 //}
387 } while((!ltt_tracefile_read(tracefile)));
388
389close:
390 fclose(fp);
eed2ef37 391}
392
00e74b69 393static gboolean process_traceset(void __UNUSED__ *hook_data,
394 void __UNUSED__ *call_data)
08b1c66e 395{
eed2ef37 396 GString *filename;
08b1c66e 397 LttvTracesetStats *tscs;
398
399 LttvTracesetState *ts;
400
401 LttvTracesetContext *tc;
402
08b1c66e 403 FILE *fp;
404
405 double t;
406
eed2ef37 407 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
408 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
409 guint i, j, count;
08b1c66e 410
411 LttTrace *trace;
412
08b1c66e 413 LttTime max_time = { G_MAXULONG, G_MAXULONG };
414
f95bc830 415 a_event_position = ltt_event_position_new();
416
3865ea09 417 GData **tracefiles_groups;
eed2ef37 418
27304273 419 struct compute_tracefile_group_args args;
420
421 args.func = compute_tracefile;
422 args.func_args = NULL;
423
08b1c66e 424 if(a_dump_tracefiles != NULL) {
08b1c66e 425 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
426 trace = lttv_trace(lttv_traceset_get(traceset, i));
eed2ef37 427 tracefiles_groups = ltt_trace_get_tracefiles_groups(trace);
08b1c66e 428
3865ea09 429 g_datalist_foreach(tracefiles_groups,
eed2ef37 430 (GDataForeachFunc)compute_tracefile_group,
27304273 431 &args);
eed2ef37 432
08b1c66e 433 }
08b1c66e 434 }
435
436 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
437 ts = &tscs->parent;
438 tc = &tscs->parent.parent;
439
440 lttv_context_init(tc, traceset);
08b1c66e 441
442 /* For each case compute and print the elapsed time.
443 The first case is simply to run through all events with a
444 simple counter. */
445
446 if(a_test1 || a_test_all) {
447 count = 0;
b8eccacd 448 lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
eed2ef37 449 t = run_one_test(ts, ltt_time_zero, max_time);
b8eccacd 450 lttv_hooks_remove_data(event_hook, count_event, &count);
021eeb41 451 g_message(
08b1c66e 452 "Processing trace while counting events (%u events in %g seconds)",
453 count, t);
454 }
455
456 /* Run through all events computing the state. */
457
458 if(a_test2 || a_test_all) {
459 lttv_state_add_event_hooks(ts);
eed2ef37 460 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 461 lttv_state_remove_event_hooks(ts);
021eeb41 462 g_message("Processing trace while updating state (%g seconds)", t);
08b1c66e 463 }
464
465 /* Run through all events computing the state and writing it out
466 periodically. */
467
468 SaveState save_state;
469
470 save_state.interval = a_sample_interval;
471 save_state.size = a_sample_number;
472 save_state.fp = stderr;
473 save_state.write_time = g_new(LttTime, a_sample_number);
474
475
476 if(a_test3 || a_test_all) {
477 for(i = 0 ; i < 2 ; i++) {
478 save_state.count = 0;
479 save_state.position = 0;
480 save_state.version = i;
481 lttv_state_add_event_hooks(ts);
b8eccacd 482 lttv_hooks_add(event_hook, save_state_event, &save_state,
483 LTTV_PRIO_DEFAULT);
eed2ef37 484 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 485 lttv_state_remove_event_hooks(ts);
b8eccacd 486 lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
08b1c66e 487 g_warning("Processing while updating/writing state (%g seconds)", t);
488 }
489 }
490
491 /* Run through all events computing the stats. */
492
493 if(a_test4 || a_test_all) {
494 if(lttv_profile_memory) {
495 g_message("Memory summary before computing stats");
496 g_mem_profile();
497 }
498
499 lttv_stats_add_event_hooks(tscs);
eed2ef37 500 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 501 lttv_stats_remove_event_hooks(tscs);
021eeb41 502 g_message("Processing trace while counting stats (%g seconds)", t);
08b1c66e 503
504 if(lttv_profile_memory) {
505 g_message("Memory summary after computing stats");
506 g_mem_profile();
507 }
f95bc830 508
b91e751b 509 lttv_stats_sum_traceset(tscs, ltt_time_infinite);
f95bc830 510
511 if(lttv_profile_memory) {
512 g_message("Memory summary after summing 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 }
08b1c66e 523 }
524
525 /* Run through all events computing the state and stats. */
526
527 if(a_test5 || a_test_all) {
528 if(lttv_profile_memory) {
529 g_message("Memory summary before computing state and stats");
530 g_mem_profile();
531 }
532
533 lttv_state_add_event_hooks(ts);
534 lttv_stats_add_event_hooks(tscs);
eed2ef37 535 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 536 lttv_state_remove_event_hooks(ts);
537 lttv_stats_remove_event_hooks(tscs);
021eeb41 538 g_message(
08b1c66e 539 "Processing trace while counting state and stats (%g seconds)", t);
540
541 if(lttv_profile_memory) {
542 g_message("Memory summary after computing and state and stats");
543 g_mem_profile();
544 }
f95bc830 545
546 lttv_context_fini(tc);
547 lttv_context_init(tc, traceset);
548
549 if(lttv_profile_memory) {
550 g_message("Memory summary after cleaning up the stats");
551 g_mem_profile();
552 }
08b1c66e 553 }
554
555 /* Run through all events computing and saving the state. */
556
b8eccacd 557 if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
558 LTTV_PRIO_DEFAULT);
f95bc830 559
08b1c66e 560 if(a_test6 || a_test_all) {
561 if(lttv_profile_memory) {
562 g_message("Memory summary before computing and saving state");
563 g_mem_profile();
564 }
565
566 lttv_state_add_event_hooks(ts);
567 lttv_state_save_add_event_hooks(ts);
f95bc830 568 if(a_save_state_copy)
b8eccacd 569 lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
570 LTTV_PRIO_DEFAULT);
eed2ef37 571 t = run_one_test(ts, ltt_time_zero, max_time);
08b1c66e 572 lttv_state_remove_event_hooks(ts);
573 lttv_state_save_remove_event_hooks(ts);
f95bc830 574 if(a_save_state_copy)
b8eccacd 575 lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
f95bc830 576
021eeb41 577 g_message("Processing trace while updating/saving state (%g seconds)", t);
08b1c66e 578
579 if(lttv_profile_memory) {
580 g_message("Memory summary after computing/saving state");
581 g_mem_profile();
582 }
583 }
584
585 /* Seek a few times to each saved position */
586
587 if((a_test7 && a_test3) || a_test_all) {
00e74b69 588 g_assert(a_seek_number >= 0);
589 for(i = 0 ; i < (guint)a_seek_number ; i++) {
590 gint reverse_j; /* just to make sure j is unsigned */
591 for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
592 j = (guint)reverse_j;
08b1c66e 593 lttv_state_add_event_hooks(ts);
594 t = run_one_test(ts, save_state.write_time[j],
595 save_state.write_time[j]);
596 lttv_state_remove_event_hooks(ts);
021eeb41 597 g_message("Seeking to %lu.%lu (%g seconds)",
08b1c66e 598 save_state.write_time[j].tv_sec, save_state.write_time[j].tv_nsec,
599 t);
600
601 if(a_save_sample != NULL) {
602 filename = g_string_new("");
603 g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i);
604 fp = fopen(filename->str, "w");
605 if(fp == NULL) g_error("Cannot open %s", filename->str);
606 g_string_free(filename, TRUE);
607 lttv_state_write((LttvTraceState *)tc->traces[0],
608 save_state.write_time[j], fp);
609 fclose(fp);
610 }
f95bc830 611 //else lttv_state_write((LttvTraceState *)tc->traces[0],
612 // save_state.write_time[j], save_state.fp);
08b1c66e 613 }
614 }
615 }
616
728d0c3e 617 /* Seek at specified interval, using states computed in 6, making
618 * sure that there is no more than the number of events between
619 * state save interval to read before getting there.
620 */
621
622 if((a_test8 && a_test6) || a_test_all) {
623 g_message("Running test 8 : check save interval");
624 LttTime time = tc->time_span.start_time;
625 LttTime interval;
626 interval.tv_sec = 0;
627 interval.tv_nsec = 175674987;
628 guint count;
629
630 while(ltt_time_compare(time, tc->time_span.end_time) < 0) {
631 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
632 lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero);
633 lttv_state_traceset_seek_time_closest(ts, time);
634 /* We add no hook to the traceset, not necessary */
635 count = lttv_process_traceset_middle(&ts->parent,
636 time, G_MAXUINT, NULL);
637 g_info("Number of events to jump over : %u", count);
638
639 if(count > LTTV_STATE_SAVE_INTERVAL)
640 g_warning("Oops! Save interval is %u and it took %u events to seek to a time %lu.%lu supposed to be closer from the last saved state.",
641 LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec);
642 time = ltt_time_add(time, interval);
643 }
644
645 }
646
33e44b82 647 if(a_test9 || a_test_all) {
9ba3aaaf 648 double t0, t1;
33e44b82 649 /* Run seek_forward and seek_backward test */
33e44b82 650 guint count;
651 LttvTracesetContext *tsc = &ts->parent;
9ba3aaaf 652 LttvTracesetContextPosition *saved_pos =
653 lttv_traceset_context_position_new(tsc);
33e44b82 654 g_message("Running test 9 : seek_forward and seek_backward");
655 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
656
fb3d6047 657 count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 658 g_assert(count == 500);
659 lttv_traceset_context_position_save(tsc, saved_pos);
9ba3aaaf 660 t0 = get_time();
fb3d6047 661 count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL, NULL, NULL, NULL);
9ba3aaaf 662 t1 = get_time();
663 g_message("Seek forward 150000 events in %g seconds", t1 - t0);
33e44b82 664 g_assert(count == 150000);
9ba3aaaf 665 t0 = get_time();
33e44b82 666 count = lttv_process_traceset_seek_n_backward(tsc, 150000,
04f2543e 667 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 668 NULL, NULL, NULL, NULL, NULL);
9ba3aaaf 669 t1 = get_time();
670 g_message("Seek backward 150000 events in %g seconds", t1 - t0);
33e44b82 671 g_assert(count == 150000);
672 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
673 g_warning("Problem with seek_n ! Positions differ. (1)");
674 }
675
fb3d6047 676 lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 677 lttv_traceset_context_position_save(tsc, saved_pos);
fb3d6047 678 lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 679 lttv_process_traceset_seek_n_backward(tsc, 15005,
04f2543e 680 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 681 NULL, NULL, NULL, NULL, NULL);
682 lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 683 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
684 g_warning("Problem with seek_n ! Positions differ. (2)");
685 }
686
687 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
688
fb3d6047 689 count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 690 if(count > 0)
691 g_warning("Problem with seek_n ! Forward at end of traceset.");
692
693 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
694
695 lttv_traceset_context_position_save(tsc, saved_pos);
9ba3aaaf 696 t0 = get_time();
33e44b82 697 lttv_process_traceset_seek_n_backward(tsc, 300,
04f2543e 698 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 699 NULL, NULL, NULL, NULL, NULL);
9ba3aaaf 700 t1 = get_time();
701 g_message("Seek backward 300 events in %g seconds", t1 - t0);
fb3d6047 702 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
703 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 704
705 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
706 g_warning("Problem with seek_n ! Positions differ. (4)");
707 }
708
1caf96c1 709 lttv_traceset_context_position_save(tsc, saved_pos);
710 t0 = get_time();
711 lttv_process_traceset_seek_n_backward(tsc, 10,
04f2543e 712 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 713 NULL, NULL, NULL, NULL, NULL);
1caf96c1 714 t1 = get_time();
715 g_message("Seek backward 10 events in %g seconds", t1 - t0);
716 t0 = get_time();
fb3d6047 717 count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL, NULL, NULL, NULL);
1caf96c1 718 t1 = get_time();
719 g_message("Seek forward 10 events in %g seconds", t1 - t0);
720
721
33e44b82 722 /* try a volountary error */
723 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
724
725 lttv_traceset_context_position_save(tsc, saved_pos);
726 lttv_process_traceset_seek_n_backward(tsc, 301,
04f2543e 727 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 728 NULL, NULL, NULL, NULL, NULL);
729 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
730 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 731
732 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) {
733 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
734 }
735
736 /* Try a seek by closest time : Hint : try this one with and without states
737 * computed. */
738 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
fb3d6047 739 count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 740 lttv_traceset_context_position_save(tsc, saved_pos);
d448fce2 741 t0 = get_time();
33e44b82 742 lttv_process_traceset_seek_n_backward(tsc, 100301,
1caf96c1 743 seek_back_default_offset,
04f2543e 744 (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL,
fb3d6047 745 NULL, NULL, NULL, NULL, NULL);
d448fce2 746 t1 = get_time();
747 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
748 t1 - t0);
fb3d6047 749 count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL, NULL, NULL, NULL);
33e44b82 750
751 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
752 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
753 }
754
755 lttv_traceset_context_position_destroy(saved_pos);
756 }
9ba3aaaf 757
758 if(a_test10 || a_test_all) {
759 g_message("Running test 10 : check seek traceset context position");
760 LttvTracesetContext *tsc = &ts->parent;
761 LttvTracesetContextPosition *saved_pos =
762 lttv_traceset_context_position_new(tsc);
763
764 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
fb3d6047 765 lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
9ba3aaaf 766 lttv_traceset_context_position_save(tsc, saved_pos);
767 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
768 g_critical("Error in seek position. (1)");
769
770 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
771 lttv_process_traceset_seek_n_backward(tsc, 500,
04f2543e 772 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
fb3d6047 773 NULL, NULL, NULL, NULL, NULL);
9ba3aaaf 774 lttv_traceset_context_position_save(tsc, saved_pos);
775
776 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
777 g_critical("Error in seek position. (2)");
778
779 lttv_traceset_context_position_destroy(saved_pos);
780 }
781
b8eccacd 782 if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
f95bc830 783
08b1c66e 784 g_free(save_state.write_time);
f95bc830 785 g_free(a_event_position);
08b1c66e 786 lttv_context_fini(tc);
787 g_object_unref(tscs);
788
f95bc830 789 if(lttv_profile_memory) {
790 g_message("Memory summary at the end of batchtest");
791 g_mem_profile();
792 }
793
08b1c66e 794 g_info("BatchTest end process traceset");
00e74b69 795 return 0;
08b1c66e 796}
797
798
799static void init()
800{
801 LttvAttributeValue value;
802
803 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
804
805 g_info("Init batchtest.c");
806
eed2ef37 807 /* Init GQuarks */
808 QUARK_BLOCK_START = g_quark_from_string("block_start");
809 QUARK_BLOCK_END = g_quark_from_string("block_end");
810
811
08b1c66e 812 lttv_option_add("trace", 't',
813 "add a trace to the trace set to analyse",
814 "pathname of the directory containing the trace",
815 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
816
f95bc830 817 a_trace_event = FALSE;
818
08b1c66e 819 a_dump_tracefiles = NULL;
820 lttv_option_add("dump-tracefiles", 'D',
821 "Write event by event the content of tracefiles",
822 "basename for the files where to dump events",
823 LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL);
824
825 a_save_sample = NULL;
826 lttv_option_add("save-sample", 's',
827 "Save state samples to multiple files",
828 "basename for the files containing the state samples",
829 LTTV_OPT_STRING, &a_save_sample, NULL, NULL);
830
f95bc830 831 a_save_state_copy = FALSE;
832 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
833 "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL);
834
08b1c66e 835 a_save_interval = 100000;
836 lttv_option_add("save-interval", 'i',
837 "Interval between saving state",
838 "number of events before a block start triggers saving state",
839 LTTV_OPT_INT, &a_save_interval, NULL, NULL);
840
841 a_sample_interval = 100000;
842 lttv_option_add("sample-interval", 'S',
843 "Interval between sampling state",
844 "number of events before sampling and writing state",
845 LTTV_OPT_INT, &a_sample_interval, NULL, NULL);
846
847 a_sample_number = 20;
848 lttv_option_add("sample-number", 'N',
849 "Number of state samples",
850 "maximum number",
851 LTTV_OPT_INT, &a_sample_number, NULL, NULL);
852
911b7a3c 853 a_seek_number = 200;
854 lttv_option_add("seek-number", 'K',
855 "Number of seek",
856 "number",
857 LTTV_OPT_INT, &a_seek_number, NULL, NULL);
858
08b1c66e 859 a_test1 = FALSE;
860 lttv_option_add("test1", '1', "Test just counting events", "",
861 LTTV_OPT_NONE, &a_test1, NULL, NULL);
862
863 a_test2 = FALSE;
864 lttv_option_add("test2", '2', "Test computing the state", "",
865 LTTV_OPT_NONE, &a_test2, NULL, NULL);
866
867 a_test3 = FALSE;
868 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
869 "", LTTV_OPT_NONE, &a_test3, NULL, NULL);
870
871 a_test4 = FALSE;
872 lttv_option_add("test4", '4', "Test computing the stats", "",
873 LTTV_OPT_NONE, &a_test4, NULL, NULL);
874
875 a_test5 = FALSE;
876 lttv_option_add("test5", '5', "Test computing the state and stats", "",
877 LTTV_OPT_NONE, &a_test5, NULL, NULL);
878
879 a_test6 = FALSE;
880 lttv_option_add("test6", '6', "Test computing and saving the state", "",
881 LTTV_OPT_NONE, &a_test6, NULL, NULL);
882
883 a_test7 = FALSE;
884 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
885 "", LTTV_OPT_NONE, &a_test7, NULL, NULL);
886
728d0c3e 887 a_test8 = FALSE;
888 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
889 "", LTTV_OPT_NONE, &a_test8, NULL, NULL);
33e44b82 890
891 a_test9 = FALSE;
892 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
893 "", LTTV_OPT_NONE, &a_test9, NULL, NULL);
894
9ba3aaaf 895 a_test10 = FALSE;
896 lttv_option_add("test10", ' ', "Test seeking traceset by position",
897 "", LTTV_OPT_NONE, &a_test10, NULL, NULL);
898
899
728d0c3e 900
08b1c66e 901 a_test_all = FALSE;
902 lttv_option_add("testall", 'a', "Run all tests ", "",
903 LTTV_OPT_NONE, &a_test_all, NULL, NULL);
904
905 traceset = lttv_traceset_new();
906
907 before_traceset = lttv_hooks_new();
908 after_traceset = lttv_hooks_new();
909 before_trace = lttv_hooks_new();
910 after_trace = lttv_hooks_new();
911 before_tracefile = lttv_hooks_new();
912 after_tracefile = lttv_hooks_new();
b8eccacd 913 //before_event = lttv_hooks_new();
914 //after_event = lttv_hooks_new();
915 event_hook = lttv_hooks_new();
916
08b1c66e 917
918 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
919 LTTV_POINTER, &value));
920 *(value.v_pointer) = before_traceset;
921 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
922 LTTV_POINTER, &value));
923 *(value.v_pointer) = after_traceset;
924 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
925 LTTV_POINTER, &value));
926 *(value.v_pointer) = before_trace;
927 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
928 LTTV_POINTER, &value));
929 *(value.v_pointer) = after_trace;
930 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
931 LTTV_POINTER, &value));
932 *(value.v_pointer) = before_tracefile;
933 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
934 LTTV_POINTER, &value));
935 *(value.v_pointer) = after_tracefile;
b8eccacd 936 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
937 // LTTV_POINTER, &value));
938 //*(value.v_pointer) = before_event;
939 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
940 // LTTV_POINTER, &value));
941 //*(value.v_pointer) = after_event;
63a95338 942 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
08b1c66e 943 LTTV_POINTER, &value));
b8eccacd 944 *(value.v_pointer) = event_hook;
08b1c66e 945 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
946 LTTV_POINTER, &value));
947 g_assert((main_hooks = *(value.v_pointer)) != NULL);
b8eccacd 948 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
08b1c66e 949}
950
951
952static void destroy()
953{
954 guint i, nb;
955
956 LttvTrace *trace;
957
958 g_info("Destroy batchAnalysis.c");
959
960 lttv_option_remove("trace");
961 lttv_option_remove("dump-tracefiles");
962 lttv_option_remove("save-sample");
f95bc830 963 lttv_option_remove("save-state-copy");
08b1c66e 964 lttv_option_remove("sample-interval");
965 lttv_option_remove("sample-number");
911b7a3c 966 lttv_option_remove("seek-number");
08b1c66e 967 lttv_option_remove("save-interval");
968 lttv_option_remove("test1");
969 lttv_option_remove("test2");
970 lttv_option_remove("test3");
971 lttv_option_remove("test4");
972 lttv_option_remove("test5");
973 lttv_option_remove("test6");
974 lttv_option_remove("test7");
728d0c3e 975 lttv_option_remove("test8");
33e44b82 976 lttv_option_remove("test9");
9ba3aaaf 977 lttv_option_remove("test10");
08b1c66e 978 lttv_option_remove("testall");
979
980 lttv_hooks_destroy(before_traceset);
981 lttv_hooks_destroy(after_traceset);
982 lttv_hooks_destroy(before_trace);
983 lttv_hooks_destroy(after_trace);
984 lttv_hooks_destroy(before_tracefile);
985 lttv_hooks_destroy(after_tracefile);
b8eccacd 986 //lttv_hooks_destroy(before_event);
987 //lttv_hooks_destroy(after_event);
988 lttv_hooks_destroy(event_hook);
08b1c66e 989 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
990
991 nb = lttv_traceset_number(traceset);
992 for(i = 0 ; i < nb ; i++) {
993 trace = lttv_traceset_get(traceset, i);
443a558d 994 lttv_traceset_remove(traceset,i);
08b1c66e 995 ltt_trace_close(lttv_trace(trace));
996 lttv_trace_destroy(trace);
997 }
998
999 lttv_traceset_destroy(traceset);
1000}
1001
1002
1003LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
1004 "Run through a trace calling all the registered hooks for tests", \
1005 init, destroy, "state", "stats", "option" )
This page took 0.098561 seconds and 4 git commands to generate.