seek forward and backward fixed
[lttv.git] / ltt / branches / poly / 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 #include <ltt/type.h>
39 #include <ltt/facility.h>
40
41 #define __UNUSED__ __attribute__((__unused__))
42
43 static LttvTraceset *traceset;
44
45 static LttvHooks
46 *before_traceset,
47 *after_traceset,
48 *before_trace,
49 *after_trace,
50 *before_tracefile,
51 *after_tracefile,
52 //*before_event,
53 //*after_event,
54 *event_hook,
55 *main_hooks;
56
57 static char *a_trace;
58
59 static char *a_dump_tracefiles;
60
61 static char *a_save_sample;
62
63 static int
64 a_sample_interval,
65 a_sample_number,
66 a_seek_number,
67 a_save_interval;
68
69 static gboolean
70 a_trace_event,
71 a_save_state_copy,
72 a_test1,
73 a_test2,
74 a_test3,
75 a_test4,
76 a_test5,
77 a_test6,
78 a_test7,
79 a_test8,
80 a_test9,
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 %llu]\n",
175 g_quark_to_string(ltt_eventtype_name(ltt_event_eventtype(e))),
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 ltt_tracefile_num(tracefile), 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 ltt_eventtype_name(ltt_event_eventtype(e))
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 LttFacility *facility;
301 LttEventType *event_type;
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_num(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 facility = ltt_event_facility(event);
331 event_type = ltt_event_eventtype(event);
332 time = ltt_event_time(event);
333 ltt_event_position(event, a_event_position);
334 ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc);
335 //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n",
336 fprintf(fp, "%s.%s: %llu %lu.%09lu position %u/%u, tracefile %s\n",
337 g_quark_to_string(ltt_facility_name(facility)),
338 g_quark_to_string(ltt_eventtype_name(event_type)),
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_num(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) nb_equal++;
378 else if(nb_equal > 0) {
379 g_warning("Consecutive %d events with time %lu.%09lu",
380 nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec);
381 nb_equal = 0;
382 }
383 previous_time = time;
384 //}
385 } while((!ltt_tracefile_read(tracefile)));
386
387 close:
388 fclose(fp);
389 }
390
391 static gboolean process_traceset(void __UNUSED__ *hook_data,
392 void __UNUSED__ *call_data)
393 {
394 GString *filename;
395 LttvTracesetStats *tscs;
396
397 LttvTracesetState *ts;
398
399 LttvTracesetContext *tc;
400
401 FILE *fp;
402
403 double t;
404
405 //guint count, nb_control, nb_tracefile, nb_block, nb_event;
406 //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
407 guint i, j, count;
408
409 LttTrace *trace;
410
411 long long unsigned start_nsec, end_nsec, delta_nsec, added_nsec, added_nsec2;
412
413 double cycle_per_nsec, nsec_per_cycle;
414
415 long long interpolated_nsec, interpolated_nsec2, end_nsec_sec, end_nsec_nsec;
416
417 LttTime start_time;
418
419 LttTime max_time = { G_MAXULONG, G_MAXULONG };
420
421 a_event_position = ltt_event_position_new();
422
423 GData **tracefiles_groups;
424
425 struct compute_tracefile_group_args args;
426
427 args.func = compute_tracefile;
428 args.func_args = NULL;
429
430 if(a_dump_tracefiles != NULL) {
431 for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
432 trace = lttv_trace(lttv_traceset_get(traceset, i));
433 tracefiles_groups = ltt_trace_get_tracefiles_groups(trace);
434
435 g_datalist_foreach(tracefiles_groups,
436 (GDataForeachFunc)compute_tracefile_group,
437 &args);
438
439 }
440 }
441
442 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
443 ts = &tscs->parent;
444 tc = &tscs->parent.parent;
445
446 lttv_context_init(tc, traceset);
447
448 /* For each case compute and print the elapsed time.
449 The first case is simply to run through all events with a
450 simple counter. */
451
452 if(a_test1 || a_test_all) {
453 count = 0;
454 lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
455 t = run_one_test(ts, ltt_time_zero, max_time);
456 lttv_hooks_remove_data(event_hook, count_event, &count);
457 g_message(
458 "Processing trace while counting events (%u events in %g seconds)",
459 count, t);
460 }
461
462 /* Run through all events computing the state. */
463
464 if(a_test2 || a_test_all) {
465 lttv_state_add_event_hooks(ts);
466 t = run_one_test(ts, ltt_time_zero, max_time);
467 lttv_state_remove_event_hooks(ts);
468 g_message("Processing trace while updating state (%g seconds)", t);
469 }
470
471 /* Run through all events computing the state and writing it out
472 periodically. */
473
474 SaveState save_state;
475
476 save_state.interval = a_sample_interval;
477 save_state.size = a_sample_number;
478 save_state.fp = stderr;
479 save_state.write_time = g_new(LttTime, a_sample_number);
480
481
482 if(a_test3 || a_test_all) {
483 for(i = 0 ; i < 2 ; i++) {
484 save_state.count = 0;
485 save_state.position = 0;
486 save_state.version = i;
487 lttv_state_add_event_hooks(ts);
488 lttv_hooks_add(event_hook, save_state_event, &save_state,
489 LTTV_PRIO_DEFAULT);
490 t = run_one_test(ts, ltt_time_zero, max_time);
491 lttv_state_remove_event_hooks(ts);
492 lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
493 g_warning("Processing while updating/writing state (%g seconds)", t);
494 }
495 }
496
497 /* Run through all events computing the stats. */
498
499 if(a_test4 || a_test_all) {
500 if(lttv_profile_memory) {
501 g_message("Memory summary before computing stats");
502 g_mem_profile();
503 }
504
505 lttv_stats_add_event_hooks(tscs);
506 t = run_one_test(ts, ltt_time_zero, max_time);
507 lttv_stats_remove_event_hooks(tscs);
508 g_message("Processing trace while counting stats (%g seconds)", t);
509
510 if(lttv_profile_memory) {
511 g_message("Memory summary after computing stats");
512 g_mem_profile();
513 }
514
515 lttv_stats_sum_traceset(tscs);
516
517 if(lttv_profile_memory) {
518 g_message("Memory summary after summing stats");
519 g_mem_profile();
520 }
521
522 lttv_context_fini(tc);
523 lttv_context_init(tc, traceset);
524
525 if(lttv_profile_memory) {
526 g_message("Memory summary after cleaning up the stats");
527 g_mem_profile();
528 }
529 }
530
531 /* Run through all events computing the state and stats. */
532
533 if(a_test5 || a_test_all) {
534 if(lttv_profile_memory) {
535 g_message("Memory summary before computing state and stats");
536 g_mem_profile();
537 }
538
539 lttv_state_add_event_hooks(ts);
540 lttv_stats_add_event_hooks(tscs);
541 t = run_one_test(ts, ltt_time_zero, max_time);
542 lttv_state_remove_event_hooks(ts);
543 lttv_stats_remove_event_hooks(tscs);
544 g_message(
545 "Processing trace while counting state and stats (%g seconds)", t);
546
547 if(lttv_profile_memory) {
548 g_message("Memory summary after computing and state and stats");
549 g_mem_profile();
550 }
551
552 lttv_context_fini(tc);
553 lttv_context_init(tc, traceset);
554
555 if(lttv_profile_memory) {
556 g_message("Memory summary after cleaning up the stats");
557 g_mem_profile();
558 }
559 }
560
561 /* Run through all events computing and saving the state. */
562
563 if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
564 LTTV_PRIO_DEFAULT);
565
566 if(a_test6 || a_test_all) {
567 if(lttv_profile_memory) {
568 g_message("Memory summary before computing and saving state");
569 g_mem_profile();
570 }
571
572 lttv_state_add_event_hooks(ts);
573 lttv_state_save_add_event_hooks(ts);
574 if(a_save_state_copy)
575 lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
576 LTTV_PRIO_DEFAULT);
577 t = run_one_test(ts, ltt_time_zero, max_time);
578 lttv_state_remove_event_hooks(ts);
579 lttv_state_save_remove_event_hooks(ts);
580 if(a_save_state_copy)
581 lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
582
583 g_message("Processing trace while updating/saving state (%g seconds)", t);
584
585 if(lttv_profile_memory) {
586 g_message("Memory summary after computing/saving state");
587 g_mem_profile();
588 }
589 }
590
591 /* Seek a few times to each saved position */
592
593 if((a_test7 && a_test3) || a_test_all) {
594 g_assert(a_seek_number >= 0);
595 for(i = 0 ; i < (guint)a_seek_number ; i++) {
596 gint reverse_j; /* just to make sure j is unsigned */
597 for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
598 j = (guint)reverse_j;
599 lttv_state_add_event_hooks(ts);
600 t = run_one_test(ts, save_state.write_time[j],
601 save_state.write_time[j]);
602 lttv_state_remove_event_hooks(ts);
603 g_message("Seeking to %lu.%lu (%g seconds)",
604 save_state.write_time[j].tv_sec, save_state.write_time[j].tv_nsec,
605 t);
606
607 if(a_save_sample != NULL) {
608 filename = g_string_new("");
609 g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i);
610 fp = fopen(filename->str, "w");
611 if(fp == NULL) g_error("Cannot open %s", filename->str);
612 g_string_free(filename, TRUE);
613 lttv_state_write((LttvTraceState *)tc->traces[0],
614 save_state.write_time[j], fp);
615 fclose(fp);
616 }
617 //else lttv_state_write((LttvTraceState *)tc->traces[0],
618 // save_state.write_time[j], save_state.fp);
619 }
620 }
621 }
622
623 /* Seek at specified interval, using states computed in 6, making
624 * sure that there is no more than the number of events between
625 * state save interval to read before getting there.
626 */
627
628 if((a_test8 && a_test6) || a_test_all) {
629 g_message("Running test 8 : check save interval");
630 LttTime time = tc->time_span.start_time;
631 LttTime interval;
632 interval.tv_sec = 0;
633 interval.tv_nsec = 175674987;
634 guint count;
635
636 while(ltt_time_compare(time, tc->time_span.end_time) < 0) {
637 //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
638 lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero);
639 lttv_state_traceset_seek_time_closest(ts, time);
640 /* We add no hook to the traceset, not necessary */
641 count = lttv_process_traceset_middle(&ts->parent,
642 time, G_MAXUINT, NULL);
643 g_info("Number of events to jump over : %u", count);
644
645 if(count > LTTV_STATE_SAVE_INTERVAL)
646 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.",
647 LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec);
648 time = ltt_time_add(time, interval);
649 }
650
651 }
652
653 if(a_test9 || a_test_all) {
654 /* Run seek_forward and seek_backward test */
655 LttvTracesetContextPosition *saved_pos =
656 lttv_traceset_context_position_new();
657 guint count;
658 LttvTracesetContext *tsc = &ts->parent;
659 g_message("Running test 9 : seek_forward and seek_backward");
660 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
661
662 count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL);
663 g_assert(count == 500);
664 lttv_traceset_context_position_save(tsc, saved_pos);
665 count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL);
666 g_assert(count == 150000);
667 count = lttv_process_traceset_seek_n_backward(tsc, 150000,
668 seek_back_default_offset, lttv_process_traceset_seek_time, NULL);
669 g_assert(count == 150000);
670 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
671 g_warning("Problem with seek_n ! Positions differ. (1)");
672 }
673
674 lttv_process_traceset_seek_n_forward(tsc, 500, NULL);
675 lttv_traceset_context_position_save(tsc, saved_pos);
676 lttv_process_traceset_seek_n_forward(tsc, 15000, NULL);
677 lttv_process_traceset_seek_n_backward(tsc, 15005,
678 seek_back_default_offset, lttv_process_traceset_seek_time, NULL);
679 lttv_process_traceset_seek_n_forward(tsc, 5, 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);
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 lttv_process_traceset_seek_n_backward(tsc, 300,
694 seek_back_default_offset, lttv_process_traceset_seek_time, NULL);
695 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL);
696 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL);
697
698 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
699 g_warning("Problem with seek_n ! Positions differ. (4)");
700 }
701
702 /* try a volountary error */
703 lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
704
705 lttv_traceset_context_position_save(tsc, saved_pos);
706 lttv_process_traceset_seek_n_backward(tsc, 301,
707 seek_back_default_offset, lttv_process_traceset_seek_time, NULL);
708 count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL);
709 count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL);
710
711 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) {
712 g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
713 }
714
715 /* Try a seek by closest time : Hint : try this one with and without states
716 * computed. */
717 lttv_process_traceset_seek_time(tsc, ltt_time_zero);
718 count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL);
719 lttv_traceset_context_position_save(tsc, saved_pos);
720 lttv_process_traceset_seek_n_backward(tsc, 100301,
721 //seek_back_default_offset, lttv_state_traceset_seek_time_closest, NULL);
722 seek_back_default_offset, lttv_process_traceset_seek_time, NULL);
723 count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL);
724
725 if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
726 g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
727 }
728
729 lttv_traceset_context_position_destroy(saved_pos);
730 }
731 if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
732
733 g_free(save_state.write_time);
734 g_free(a_event_position);
735 lttv_context_fini(tc);
736 g_object_unref(tscs);
737
738 if(lttv_profile_memory) {
739 g_message("Memory summary at the end of batchtest");
740 g_mem_profile();
741 }
742
743 g_info("BatchTest end process traceset");
744 return 0;
745 }
746
747
748 static void init()
749 {
750 LttvAttributeValue value;
751
752 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
753
754 g_info("Init batchtest.c");
755
756 /* Init GQuarks */
757 QUARK_BLOCK_START = g_quark_from_string("block_start");
758 QUARK_BLOCK_END = g_quark_from_string("block_end");
759
760
761 lttv_option_add("trace", 't',
762 "add a trace to the trace set to analyse",
763 "pathname of the directory containing the trace",
764 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
765
766 a_trace_event = FALSE;
767
768 a_dump_tracefiles = NULL;
769 lttv_option_add("dump-tracefiles", 'D',
770 "Write event by event the content of tracefiles",
771 "basename for the files where to dump events",
772 LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL);
773
774 a_save_sample = NULL;
775 lttv_option_add("save-sample", 's',
776 "Save state samples to multiple files",
777 "basename for the files containing the state samples",
778 LTTV_OPT_STRING, &a_save_sample, NULL, NULL);
779
780 a_save_state_copy = FALSE;
781 lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking",
782 "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL);
783
784 a_save_interval = 100000;
785 lttv_option_add("save-interval", 'i',
786 "Interval between saving state",
787 "number of events before a block start triggers saving state",
788 LTTV_OPT_INT, &a_save_interval, NULL, NULL);
789
790 a_sample_interval = 100000;
791 lttv_option_add("sample-interval", 'S',
792 "Interval between sampling state",
793 "number of events before sampling and writing state",
794 LTTV_OPT_INT, &a_sample_interval, NULL, NULL);
795
796 a_sample_number = 20;
797 lttv_option_add("sample-number", 'N',
798 "Number of state samples",
799 "maximum number",
800 LTTV_OPT_INT, &a_sample_number, NULL, NULL);
801
802 a_seek_number = 200;
803 lttv_option_add("seek-number", 'K',
804 "Number of seek",
805 "number",
806 LTTV_OPT_INT, &a_seek_number, NULL, NULL);
807
808 a_test1 = FALSE;
809 lttv_option_add("test1", '1', "Test just counting events", "",
810 LTTV_OPT_NONE, &a_test1, NULL, NULL);
811
812 a_test2 = FALSE;
813 lttv_option_add("test2", '2', "Test computing the state", "",
814 LTTV_OPT_NONE, &a_test2, NULL, NULL);
815
816 a_test3 = FALSE;
817 lttv_option_add("test3", '3', "Test computing the state, writing out a few",
818 "", LTTV_OPT_NONE, &a_test3, NULL, NULL);
819
820 a_test4 = FALSE;
821 lttv_option_add("test4", '4', "Test computing the stats", "",
822 LTTV_OPT_NONE, &a_test4, NULL, NULL);
823
824 a_test5 = FALSE;
825 lttv_option_add("test5", '5', "Test computing the state and stats", "",
826 LTTV_OPT_NONE, &a_test5, NULL, NULL);
827
828 a_test6 = FALSE;
829 lttv_option_add("test6", '6', "Test computing and saving the state", "",
830 LTTV_OPT_NONE, &a_test6, NULL, NULL);
831
832 a_test7 = FALSE;
833 lttv_option_add("test7", '7', "Test seeking to positions written out in 3",
834 "", LTTV_OPT_NONE, &a_test7, NULL, NULL);
835
836 a_test8 = FALSE;
837 lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits",
838 "", LTTV_OPT_NONE, &a_test8, NULL, NULL);
839
840 a_test9 = FALSE;
841 lttv_option_add("test9", '9', "Test seeking backward/forward positions",
842 "", LTTV_OPT_NONE, &a_test9, NULL, NULL);
843
844
845 a_test_all = FALSE;
846 lttv_option_add("testall", 'a', "Run all tests ", "",
847 LTTV_OPT_NONE, &a_test_all, NULL, NULL);
848
849 traceset = lttv_traceset_new();
850
851 before_traceset = lttv_hooks_new();
852 after_traceset = lttv_hooks_new();
853 before_trace = lttv_hooks_new();
854 after_trace = lttv_hooks_new();
855 before_tracefile = lttv_hooks_new();
856 after_tracefile = lttv_hooks_new();
857 //before_event = lttv_hooks_new();
858 //after_event = lttv_hooks_new();
859 event_hook = lttv_hooks_new();
860
861
862 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
863 LTTV_POINTER, &value));
864 *(value.v_pointer) = before_traceset;
865 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
866 LTTV_POINTER, &value));
867 *(value.v_pointer) = after_traceset;
868 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
869 LTTV_POINTER, &value));
870 *(value.v_pointer) = before_trace;
871 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
872 LTTV_POINTER, &value));
873 *(value.v_pointer) = after_trace;
874 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
875 LTTV_POINTER, &value));
876 *(value.v_pointer) = before_tracefile;
877 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
878 LTTV_POINTER, &value));
879 *(value.v_pointer) = after_tracefile;
880 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
881 // LTTV_POINTER, &value));
882 //*(value.v_pointer) = before_event;
883 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
884 // LTTV_POINTER, &value));
885 //*(value.v_pointer) = after_event;
886 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
887 LTTV_POINTER, &value));
888 *(value.v_pointer) = event_hook;
889 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
890 LTTV_POINTER, &value));
891 g_assert((main_hooks = *(value.v_pointer)) != NULL);
892 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
893 }
894
895
896 static void destroy()
897 {
898 guint i, nb;
899
900 LttvTrace *trace;
901
902 g_info("Destroy batchAnalysis.c");
903
904 lttv_option_remove("trace");
905 lttv_option_remove("dump-tracefiles");
906 lttv_option_remove("save-sample");
907 lttv_option_remove("save-state-copy");
908 lttv_option_remove("sample-interval");
909 lttv_option_remove("sample-number");
910 lttv_option_remove("seek-number");
911 lttv_option_remove("save-interval");
912 lttv_option_remove("test1");
913 lttv_option_remove("test2");
914 lttv_option_remove("test3");
915 lttv_option_remove("test4");
916 lttv_option_remove("test5");
917 lttv_option_remove("test6");
918 lttv_option_remove("test7");
919 lttv_option_remove("test8");
920 lttv_option_remove("test9");
921 lttv_option_remove("testall");
922
923 lttv_hooks_destroy(before_traceset);
924 lttv_hooks_destroy(after_traceset);
925 lttv_hooks_destroy(before_trace);
926 lttv_hooks_destroy(after_trace);
927 lttv_hooks_destroy(before_tracefile);
928 lttv_hooks_destroy(after_tracefile);
929 //lttv_hooks_destroy(before_event);
930 //lttv_hooks_destroy(after_event);
931 lttv_hooks_destroy(event_hook);
932 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
933
934 nb = lttv_traceset_number(traceset);
935 for(i = 0 ; i < nb ; i++) {
936 trace = lttv_traceset_get(traceset, i);
937 lttv_traceset_remove(traceset,i);
938 ltt_trace_close(lttv_trace(trace));
939 lttv_trace_destroy(trace);
940 }
941
942 lttv_traceset_destroy(traceset);
943 }
944
945
946 LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \
947 "Run through a trace calling all the registered hooks for tests", \
948 init, destroy, "state", "stats", "option" )
This page took 0.06311 seconds and 4 git commands to generate.