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