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