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