update compat
[lttv.git] / lttv / lttv / batchtest.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 /* This module inserts a hook in the program main loop. This hook processes
20 all the events in the main tracefile while testing the speed and
21 functionality of the state and stats computations. */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <string.h>
28 #include <inttypes.h>
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>
34 #include <lttv/tracecontext.h>
35 #include <lttv/state.h>
36 #include <lttv/stats.h>
37 #include <ltt/trace.h>
38 #include <ltt/event.h>
39
40 #define __UNUSED__ __attribute__((__unused__))
41
42 static LttvTraceset *traceset;
43
44 static LttvHooks
45 *before_traceset,
46 *after_traceset,
47 *before_trace,
48 *after_trace,
49 *before_tracefile,
50 *after_tracefile,
51 //*before_event,
52 //*after_event,
53 *event_hook,
54 *main_hooks;
55
56 static char *a_trace;
57
58 static char *a_dump_tracefiles;
59
60 static char *a_save_sample;
61
62 static int
63 a_sample_interval,
64 a_sample_number,
65 a_seek_number,
66 a_save_interval;
67
68 static gboolean
69 a_trace_event,
70 a_save_state_copy,
71 a_test1,
72 a_test2,
73 a_test3,
74 a_test4,
75 a_test5,
76 a_test6,
77 a_test7,
78 a_test8,
79 a_test9,
80 a_test10,
81 a_test_all;
82
83 static GQuark QUARK_BLOCK_START,
84 QUARK_BLOCK_END;
85
86 LttEventPosition *a_event_position;
87
88 typedef 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
99 static void lttv_trace_option(void __UNUSED__ *hook_data)
100 {
101 LttTrace *trace;
102
103 trace = ltt_trace_open(a_trace);
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 }
109 }
110
111 static 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
119 static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
120 {
121 double t0, t1;
122
123 unsigned int i;
124
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);
134
135 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
136 ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval;
137 }
138
139 t0 = get_time();
140 lttv_state_traceset_seek_time_closest(ts, start);
141 //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
142 lttv_process_traceset_middle(&ts->parent,
143 end,
144 G_MAXULONG,
145 NULL);
146 t1 = get_time();
147
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);
157
158 return t1 - t0;
159 }
160
161
162 gboolean trace_event(void __UNUSED__ *hook_data, void *call_data)
163 {
164 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
165
166 guint nb_block, offset;
167
168 guint64 tsc;
169
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);
174 fprintf(stderr, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64 "]\n",
175 g_quark_to_string(marker_get_info_from_id(tf->mdata,
176 ltt_event_id(e))->name),
177 tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec,
178 nb_block, offset, tsc);
179 return FALSE;
180 }
181
182 static LttTime count_previous_time = { 0, 0 };
183
184 gboolean count_event(void *hook_data, void __UNUSED__ *call_data)
185 {
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;
193 guint *pcount = (guint *)hook_data;
194
195 (*pcount)++;
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) {
202 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
203 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
204 g_quark_to_string(ltt_tracefile_name(tracefile)),
205 tfs->cpu, nb_block, offset);
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
214 return FALSE;
215 }
216
217
218 gboolean save_state_copy_event(void *hook_data, void *call_data)
219 {
220 SaveState __UNUSED__ *save_state = (SaveState *)hook_data;
221
222 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
223
224 LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
225
226 LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf);
227
228 GString *filename;
229
230 FILE *fp;
231
232 if(ts->nb_event == 0 &&
233 marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id)->name
234 == QUARK_BLOCK_START) {
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
250 gboolean 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);
274 } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp);
275
276 save_state->write_time[save_state->position] = tfs->parent.timestamp;
277 save_state->position++;
278 }
279 return FALSE;
280 }
281
282
283 static void sanitize_name(gchar *name)
284 {
285 while(*name != '\0') {
286 if(*name == '/') *name = '_';
287 name++;
288 }
289
290 }
291
292
293 static void compute_tracefile(LttTracefile *tracefile, void *hook_data)
294 {
295 GString *filename;
296 guint nb_equal, nb_block, offset;
297 guint64 tsc;
298 FILE *fp;
299 LttTime time, previous_time;
300 LttEvent *event = ltt_tracefile_get_event(tracefile);
301 //LttEventType *event_type;
302 struct marker_info *minfo;
303 int err;
304 gchar mod_name[PATH_MAX];
305
306 /* start_count is always initialized in this function _if_ there is always
307 * a block_start before a block_end.
308 */
309 //long long unsigned cycle_count, start_count=0, delta_cycle;
310
311
312 filename = g_string_new("");
313 strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile)));
314
315 sanitize_name(mod_name);
316
317 g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile)));
318 g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles,
319 mod_name, ltt_tracefile_cpu(tracefile));
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;
331 //event_type = ltt_event_eventtype(event);
332 minfo = marker_get_info_from_id(tracefile->mdata,
333 ltt_event_id(event));
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);
337 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
338 fprintf(fp, "%s: %" PRIu64 " %lu.%09lu position %u/%u, tracefile %s\n",
339 g_quark_to_string(minfo->name),
340 tsc, (unsigned long)time.tv_sec,
341 (unsigned long)time.tv_nsec,
342 nb_block, offset,
343 g_quark_to_string(ltt_tracefile_name(tracefile)));
344
345 if(ltt_time_compare(time, previous_time) < 0) {
346 g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x",
347 g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))),
348 g_quark_to_string(ltt_tracefile_name(tracefile)),
349 ltt_tracefile_cpu(tracefile), nb_block, offset);
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);
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
378 if(ltt_time_compare(time, previous_time) == 0)
379 nb_equal++;
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
389 close:
390 fclose(fp);
391 }
392
393 static gboolean process_traceset(void __UNUSED__ *hook_data,
394 void __UNUSED__ *call_data)
395 {
396 GString *filename;
397 LttvTracesetStats *tscs;
398
399 LttvTracesetState *ts;
400
401 LttvTracesetContext *tc;
402
403 FILE *fp;
404
405 double t;
406
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;
410
411 LttTrace *trace;
412
413 LttTime max_time = { G_MAXULONG, G_MAXULONG };
414
415 a_event_position = ltt_event_position_new();
416
417 GData **tracefiles_groups;
418
419 struct compute_tracefile_group_args args;
420
421 args.func = compute_tracefile;
422 args.func_args = NULL;
423
424 if(a_dump_tracefiles != NULL) {
425 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
426 trace = lttv_trace(lttv_traceset_get(traceset, i));
427 tracefiles_groups = ltt_trace_get_tracefiles_groups(trace);
428
429 g_datalist_foreach(tracefiles_groups,
430 (GDataForeachFunc)compute_tracefile_group, &args);
431
432 }
433 }
434
435 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
436 ts = &tscs->parent;
437 tc = &tscs->parent.parent;
438
439 lttv_context_init(tc, traceset);
440
441 /* For each case compute and print the elapsed time.
442 The first case is simply to run through all events with a
443 simple counter. */
444
445 if(a_test1 || a_test_all) {
446 count = 0;
447 lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
448 t = run_one_test(ts, ltt_time_zero, max_time);
449 lttv_hooks_remove_data(event_hook, count_event, &count);
450 g_message("Processing trace while counting events (%u events in %g seconds)",
451 count, t);
452 }
453
454 /* Run through all events computing the state. */
455
456 if(a_test2 || a_test_all) {
457 lttv_state_add_event_hooks(ts);
458 t = run_one_test(ts, ltt_time_zero, max_time);
459 lttv_state_remove_event_hooks(ts);
460 g_message("Processing trace while updating state (%g seconds)", t);
461 }
462
463 /* Run through all events computing the state and writing it out
464 periodically. */
465
466 SaveState save_state;
467
468 save_state.interval = a_sample_interval;
469 save_state.size = a_sample_number;
470 save_state.fp = stderr;
471 save_state.write_time = g_new(LttTime, a_sample_number);
472
473
474 if(a_test3 || a_test_all) {
475 for(i = 0 ; i < 2 ; i++) {
476 save_state.count = 0;
477 save_state.position = 0;
478 save_state.version = i;
479 lttv_state_add_event_hooks(ts);
480 lttv_hooks_add(event_hook, save_state_event, &save_state,
481 LTTV_PRIO_DEFAULT);
482 t = run_one_test(ts, ltt_time_zero, max_time);
483 lttv_state_remove_event_hooks(ts);
484 lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
485 g_warning("Processing while updating/writing state (%g seconds)", t);
486 }
487 }
488
489 /* Run through all events computing the stats. */
490
491 if(a_test4 || a_test_all) {
492 if(lttv_profile_memory) {
493 g_message("Memory summary before computing stats");
494 g_mem_profile();
495 }
496
497 lttv_stats_add_event_hooks(tscs);
498 t = run_one_test(ts, ltt_time_zero, max_time);
499 lttv_stats_remove_event_hooks(tscs);
500 g_message("Processing trace while counting stats (%g seconds)", t);
501
502 if(lttv_profile_memory) {
503 g_message("Memory summary after computing stats");
504 g_mem_profile();
505 }
506
507 lttv_stats_sum_traceset(tscs, ltt_time_infinite);
508
509 if(lttv_profile_memory) {
510 g_message("Memory summary after summing stats");
511 g_mem_profile();
512 }
513
514 lttv_context_fini(tc);
515 lttv_context_init(tc, traceset);
516
517 if(lttv_profile_memory) {
518 g_message("Memory summary after cleaning up the stats");
519 g_mem_profile();
520 }
521 }
522
523 /* Run through all events computing the state and stats. */
524
525 if(a_test5 || a_test_all) {
526 if(lttv_profile_memory) {
527 g_message("Memory summary before computing state and stats");
528 g_mem_profile();
529 }
530
531 lttv_state_add_event_hooks(ts);
532 lttv_stats_add_event_hooks(tscs);
533 t = run_one_test(ts, ltt_time_zero, max_time);
534 lttv_state_remove_event_hooks(ts);
535 lttv_stats_remove_event_hooks(tscs);
536 g_message("Processing trace while counting state and stats (%g seconds)", t);
537
538 if(lttv_profile_memory) {
539 g_message("Memory summary after computing and state and stats");
540 g_mem_profile();
541 }
542
543 lttv_context_fini(tc);
544 lttv_context_init(tc, traceset);
545
546 if(lttv_profile_memory) {
547 g_message("Memory summary after cleaning up the stats");
548 g_mem_profile();
549 }
550 }
551
552 /* Run through all events computing and saving the state. */
553
554 if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
555 LTTV_PRIO_DEFAULT);
556
557 if(a_test6 || a_test_all) {
558 if(lttv_profile_memory) {
559 g_message("Memory summary before computing and saving state");
560 g_mem_profile();
561 }
562
563 lttv_state_add_event_hooks(ts);
564 lttv_state_save_add_event_hooks(ts);
565 if(a_save_state_copy)
566 lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
567 LTTV_PRIO_DEFAULT);
568 t = run_one_test(ts, ltt_time_zero, max_time);
569 lttv_state_remove_event_hooks(ts);
570 lttv_state_save_remove_event_hooks(ts);
571 if(a_save_state_copy)
572 lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
573
574 g_message("Processing trace while updating/saving state (%g seconds)", t);
575
576 if(lttv_profile_memory) {
577 g_message("Memory summary after computing/saving state");
578 g_mem_profile();
579 }
580 }
581
582 /* Seek a few times to each saved position */
583
584 if((a_test7 && a_test3) || a_test_all) {
585 g_assert(a_seek_number >= 0);
586 for(i = 0 ; i < (guint)a_seek_number ; i++) {
587 gint reverse_j; /* just to make sure j is unsigned */
588 for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
589 j = (guint)reverse_j;
590 lttv_state_add_event_hooks(ts);
591 t = run_one_test(ts, save_state.write_time[j],
592 save_state.write_time[j]);
593 lttv_state_remove_event_hooks(ts);
594 g_message("Seeking to %lu.%lu (%g seconds)",
595 save_state.write_time[j].tv_sec,
596 save_state.write_time[j].tv_nsec, t);
597
598 if(a_save_sample != NULL) {
599 filename = g_string_new("");
600 g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i);
601 fp = fopen(filename->str, "w");
602 if(fp == NULL) g_error("Cannot open %s", filename->str);
603 g_string_free(filename, TRUE);
604 lttv_state_write((LttvTraceState *)tc->traces[0],
605 save_state.write_time[j], fp);
606 fclose(fp);
607 }
608 //else lttv_state_write((LttvTraceState *)tc->traces[0],
609 // save_state.write_time[j], save_state.fp);
610 }
611 }
612 }
613
614 /* Seek at specified interval, using states computed in 6, making
615 * sure that there is no more than the number of events between
616 * state save interval to read before getting there.
617 */
618
619 if((a_test8 && a_test6) || a_test_all) {
620 g_message("Running test 8 : check save interval");
621 LttTime time = tc->time_span.start_time;
622 LttTime interval;
623 interval.tv_sec = 0;
624 interval.tv_nsec = 175674987;
625 guint count;
626
627 while(ltt_time_compare(time, tc->time_span.end_time) < 0) {
628 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
629 lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero);
630 lttv_state_traceset_seek_time_closest(ts, time);
631 /* We add no hook to the traceset, not necessary */
632 count = lttv_process_traceset_middle(&ts->parent,
633 time, G_MAXUINT, NULL);
634 g_info("Number of events to jump over : %u", count);
635
636 if(count > LTTV_STATE_SAVE_INTERVAL)
637 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.",
638 LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec);
639 time = ltt_time_add(time, interval);
640 }
641
642 }
643
644 if(a_test9 || a_test_all) {
645 double t0, t1;
646 /* Run seek_forward and seek_backward test */
647 guint count;
648 LttvTracesetContext *tsc = &ts->parent;
649 LttvTracesetContextPosition *saved_pos =
650 lttv_traceset_context_position_new(tsc);
651 g_message("Running test 9 : seek_forward and seek_backward");
652 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
653
654 count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
655 g_assert(count == 500);
656 lttv_traceset_context_position_save(tsc, saved_pos);
657 t0 = get_time();
658 count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL, NULL, NULL, NULL);
659 t1 = get_time();
660 g_message("Seek forward 150000 events in %g seconds", t1 - t0);
661 g_assert(count == 150000);
662 t0 = get_time();
663 count = lttv_process_traceset_seek_n_backward(tsc, 150000,
664 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
665 NULL, NULL, NULL, NULL, NULL);
666 t1 = get_time();
667 g_message("Seek backward 150000 events in %g seconds", t1 - t0);
668 g_assert(count == 150000);
669 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
670 g_warning("Problem with seek_n ! Positions differ. (1)");
671 }
672
673 lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL);
674 lttv_traceset_context_position_save(tsc, saved_pos);
675 lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
676 lttv_process_traceset_seek_n_backward(tsc, 15005,
677 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
678 NULL, NULL, NULL, NULL, NULL);
679 lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL, NULL, NULL, NULL);
680 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
681 g_warning("Problem with seek_n ! Positions differ. (2)");
682 }
683
684 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
685
686 count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL);
687 if(count > 0)
688 g_warning("Problem with seek_n ! Forward at end of traceset.");
689
690 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
691
692 lttv_traceset_context_position_save(tsc, saved_pos);
693 t0 = get_time();
694 lttv_process_traceset_seek_n_backward(tsc, 300,
695 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
696 NULL, NULL, NULL, NULL, NULL);
697 t1 = get_time();
698 g_message("Seek backward 300 events in %g seconds", t1 - t0);
699 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
700 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
701
702 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
703 g_warning("Problem with seek_n ! Positions differ. (4)");
704 }
705
706 lttv_traceset_context_position_save(tsc, saved_pos);
707 t0 = get_time();
708 lttv_process_traceset_seek_n_backward(tsc, 10,
709 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
710 NULL, NULL, NULL, NULL, NULL);
711 t1 = get_time();
712 g_message("Seek backward 10 events in %g seconds", t1 - t0);
713 t0 = get_time();
714 count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL, NULL, NULL, NULL);
715 t1 = get_time();
716 g_message("Seek forward 10 events in %g seconds", t1 - t0);
717
718
719 /* try a volountary error */
720 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
721
722 lttv_traceset_context_position_save(tsc, saved_pos);
723 lttv_process_traceset_seek_n_backward(tsc, 301,
724 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
725 NULL, NULL, NULL, NULL, NULL);
726 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL);
727 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL);
728
729 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) {
730 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
731 }
732
733 /* Try a seek by closest time : Hint : try this one with and without states
734 * computed. */
735 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
736 count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
737 lttv_traceset_context_position_save(tsc, saved_pos);
738 t0 = get_time();
739 lttv_process_traceset_seek_n_backward(tsc, 100301,
740 seek_back_default_offset,
741 (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL,
742 NULL, NULL, NULL, NULL, NULL);
743 t1 = get_time();
744 g_message("Seek backward 100301 events (with seek closest) in %g seconds",
745 t1 - t0);
746 count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL, NULL, NULL, NULL);
747
748 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
749 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
750 }
751
752 lttv_traceset_context_position_destroy(saved_pos);
753 }
754
755 if(a_test10 || a_test_all) {
756 g_message("Running test 10 : check seek traceset context position");
757 LttvTracesetContext *tsc = &ts->parent;
758 LttvTracesetContextPosition *saved_pos =
759 lttv_traceset_context_position_new(tsc);
760
761 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
762 lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL);
763 lttv_traceset_context_position_save(tsc, saved_pos);
764 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
765 g_critical("Error in seek position. (1)");
766
767 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
768 lttv_process_traceset_seek_n_backward(tsc, 500,
769 seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
770 NULL, NULL, NULL, NULL, NULL);
771 lttv_traceset_context_position_save(tsc, saved_pos);
772
773 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
774 g_critical("Error in seek position. (2)");
775
776 lttv_traceset_context_position_destroy(saved_pos);
777 }
778
779 if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
780
781 g_free(save_state.write_time);
782 g_free(a_event_position);
783 lttv_context_fini(tc);
784 g_object_unref(tscs);
785
786 if(lttv_profile_memory) {
787 g_message("Memory summary at the end of batchtest");
788 g_mem_profile();
789 }
790
791 g_info("BatchTest end process traceset");
792 return 0;
793 }
794
795
796 static void init()
797 {
798 LttvAttributeValue value;
799
800 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
801 gboolean retval;
802
803 g_info("Init batchtest.c");
804
805 /* Init GQuarks */
806 QUARK_BLOCK_START = g_quark_from_string("block_start");
807 QUARK_BLOCK_END = g_quark_from_string("block_end");
808
809
810 lttv_option_add("trace", 't',
811 "add a trace to the trace set to analyse",
812 "pathname of the directory containing the trace",
813 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
814
815 a_trace_event = FALSE;
816
817 a_dump_tracefiles = NULL;
818 lttv_option_add("dump-tracefiles", 'D',
819 "Write event by event the content of tracefiles",
820 "basename for the files where to dump events",
821 LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL);
822
823 a_save_sample = NULL;
824 lttv_option_add("save-sample", 's',
825 "Save state samples to multiple files",
826 "basename for the files containing the state samples",
827 LTTV_OPT_STRING, &a_save_sample, NULL, NULL);
828
829 a_save_state_copy = FALSE;
830 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
831 "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL);
832
833 a_save_interval = 100000;
834 lttv_option_add("save-interval", 'i',
835 "Interval between saving state",
836 "number of events before a block start triggers saving state",
837 LTTV_OPT_INT, &a_save_interval, NULL, NULL);
838
839 a_sample_interval = 100000;
840 lttv_option_add("sample-interval", 'S',
841 "Interval between sampling state",
842 "number of events before sampling and writing state",
843 LTTV_OPT_INT, &a_sample_interval, NULL, NULL);
844
845 a_sample_number = 20;
846 lttv_option_add("sample-number", 'N',
847 "Number of state samples",
848 "maximum number",
849 LTTV_OPT_INT, &a_sample_number, NULL, NULL);
850
851 a_seek_number = 200;
852 lttv_option_add("seek-number", 'K',
853 "Number of seek",
854 "number",
855 LTTV_OPT_INT, &a_seek_number, NULL, NULL);
856
857 a_test1 = FALSE;
858 lttv_option_add("test1", '1', "Test just counting events", "",
859 LTTV_OPT_NONE, &a_test1, NULL, NULL);
860
861 a_test2 = FALSE;
862 lttv_option_add("test2", '2', "Test computing the state", "",
863 LTTV_OPT_NONE, &a_test2, NULL, NULL);
864
865 a_test3 = FALSE;
866 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
867 "", LTTV_OPT_NONE, &a_test3, NULL, NULL);
868
869 a_test4 = FALSE;
870 lttv_option_add("test4", '4', "Test computing the stats", "",
871 LTTV_OPT_NONE, &a_test4, NULL, NULL);
872
873 a_test5 = FALSE;
874 lttv_option_add("test5", '5', "Test computing the state and stats", "",
875 LTTV_OPT_NONE, &a_test5, NULL, NULL);
876
877 a_test6 = FALSE;
878 lttv_option_add("test6", '6', "Test computing and saving the state", "",
879 LTTV_OPT_NONE, &a_test6, NULL, NULL);
880
881 a_test7 = FALSE;
882 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
883 "", LTTV_OPT_NONE, &a_test7, NULL, NULL);
884
885 a_test8 = FALSE;
886 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
887 "", LTTV_OPT_NONE, &a_test8, NULL, NULL);
888
889 a_test9 = FALSE;
890 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
891 "", LTTV_OPT_NONE, &a_test9, NULL, NULL);
892
893 a_test10 = FALSE;
894 lttv_option_add("test10", ' ', "Test seeking traceset by position",
895 "", LTTV_OPT_NONE, &a_test10, NULL, NULL);
896
897
898
899 a_test_all = FALSE;
900 lttv_option_add("testall", 'a', "Run all tests ", "",
901 LTTV_OPT_NONE, &a_test_all, NULL, NULL);
902
903 traceset = lttv_traceset_new();
904
905 before_traceset = lttv_hooks_new();
906 after_traceset = lttv_hooks_new();
907 before_trace = lttv_hooks_new();
908 after_trace = lttv_hooks_new();
909 before_tracefile = lttv_hooks_new();
910 after_tracefile = lttv_hooks_new();
911 //before_event = lttv_hooks_new();
912 //after_event = lttv_hooks_new();
913 event_hook = lttv_hooks_new();
914
915
916 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
917 LTTV_POINTER, &value);
918 g_assert(retval);
919 *(value.v_pointer) = before_traceset;
920 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
921 LTTV_POINTER, &value);
922 g_assert(retval);
923 *(value.v_pointer) = after_traceset;
924 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
925 LTTV_POINTER, &value);
926 g_assert(retval);
927 *(value.v_pointer) = before_trace;
928 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
929 LTTV_POINTER, &value);
930 g_assert(retval);
931 *(value.v_pointer) = after_trace;
932 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
933 LTTV_POINTER, &value);
934 g_assert(retval);
935 *(value.v_pointer) = before_tracefile;
936 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
937 LTTV_POINTER, &value);
938 g_assert(retval);
939 *(value.v_pointer) = after_tracefile;
940 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/before",
941 // LTTV_POINTER, &value);
942 //*(value.v_pointer) = before_event;
943 //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/after",
944 // LTTV_POINTER, &value);
945 //*(value.v_pointer) = after_event;
946 retval= lttv_iattribute_find_by_path(attributes, "hooks/event",
947 LTTV_POINTER, &value);
948 g_assert(retval);
949 *(value.v_pointer) = event_hook;
950 retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before",
951 LTTV_POINTER, &value);
952 g_assert(retval);
953 g_assert((main_hooks = *(value.v_pointer)) != NULL);
954 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
955 }
956
957
958 static void destroy()
959 {
960 guint i, nb;
961
962 LttvTrace *trace;
963
964 g_info("Destroy batchAnalysis.c");
965
966 lttv_option_remove("trace");
967 lttv_option_remove("dump-tracefiles");
968 lttv_option_remove("save-sample");
969 lttv_option_remove("save-state-copy");
970 lttv_option_remove("sample-interval");
971 lttv_option_remove("sample-number");
972 lttv_option_remove("seek-number");
973 lttv_option_remove("save-interval");
974 lttv_option_remove("test1");
975 lttv_option_remove("test2");
976 lttv_option_remove("test3");
977 lttv_option_remove("test4");
978 lttv_option_remove("test5");
979 lttv_option_remove("test6");
980 lttv_option_remove("test7");
981 lttv_option_remove("test8");
982 lttv_option_remove("test9");
983 lttv_option_remove("test10");
984 lttv_option_remove("testall");
985
986 lttv_hooks_destroy(before_traceset);
987 lttv_hooks_destroy(after_traceset);
988 lttv_hooks_destroy(before_trace);
989 lttv_hooks_destroy(after_trace);
990 lttv_hooks_destroy(before_tracefile);
991 lttv_hooks_destroy(after_tracefile);
992 //lttv_hooks_destroy(before_event);
993 //lttv_hooks_destroy(after_event);
994 lttv_hooks_destroy(event_hook);
995 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
996
997 nb = lttv_traceset_number(traceset);
998 for(i = 0 ; i < nb ; i++) {
999 trace = lttv_traceset_get(traceset, i);
1000 lttv_traceset_remove(traceset,i);
1001 ltt_trace_close(lttv_trace(trace));
1002 lttv_trace_destroy(trace);
1003 }
1004
1005 lttv_traceset_destroy(traceset);
1006 }
1007
1008
1009 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
1010 "Run through a trace calling all the registered hooks for tests", \
1011 init, destroy, "state", "stats", "option" )
This page took 0.059377 seconds and 4 git commands to generate.