08b1c66e |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
19 | /* This module inserts a hook in the program main loop. This hook processes |
20 | all the events in the main tracefile while testing the speed and |
21 | functionality of the state and stats computations. */ |
22 | |
23 | |
24 | #include <lttv/lttv.h> |
25 | #include <lttv/attribute.h> |
26 | #include <lttv/hook.h> |
27 | #include <lttv/option.h> |
28 | #include <lttv/module.h> |
d8f124de |
29 | #include <lttv/tracecontext.h> |
08b1c66e |
30 | #include <lttv/state.h> |
31 | #include <lttv/stats.h> |
32 | #include <ltt/trace.h> |
33 | #include <ltt/event.h> |
338d4282 |
34 | #include <ltt/type.h> |
08b1c66e |
35 | |
36 | static LttvTraceset *traceset; |
37 | |
38 | static LttvHooks |
39 | *before_traceset, |
40 | *after_traceset, |
41 | *before_trace, |
42 | *after_trace, |
43 | *before_tracefile, |
44 | *after_tracefile, |
b8eccacd |
45 | //*before_event, |
46 | //*after_event, |
47 | *event_hook, |
08b1c66e |
48 | *main_hooks; |
49 | |
50 | static char *a_trace; |
51 | |
52 | static char *a_dump_tracefiles; |
53 | |
54 | static char *a_save_sample; |
55 | |
56 | static int |
57 | a_sample_interval, |
58 | a_sample_number, |
911b7a3c |
59 | a_seek_number, |
08b1c66e |
60 | a_save_interval; |
61 | |
62 | static gboolean |
f95bc830 |
63 | a_trace_event, |
64 | a_save_state_copy, |
08b1c66e |
65 | a_test1, |
66 | a_test2, |
67 | a_test3, |
68 | a_test4, |
69 | a_test5, |
70 | a_test6, |
71 | a_test7, |
72 | a_test_all; |
73 | |
f95bc830 |
74 | LttEventPosition *a_event_position; |
75 | |
08b1c66e |
76 | typedef struct _save_state { |
77 | guint count; |
78 | FILE *fp; |
79 | guint interval; |
80 | guint position; |
81 | guint size; |
82 | LttTime *write_time; |
83 | guint version; |
84 | } SaveState; |
85 | |
86 | |
87 | static void lttv_trace_option(void *hook_data) |
88 | { |
89 | LttTrace *trace; |
90 | |
91 | trace = ltt_trace_open(a_trace); |
92 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
93 | lttv_traceset_add(traceset, lttv_trace_new(trace)); |
94 | } |
95 | |
96 | static double get_time() |
97 | { |
98 | GTimeVal gt; |
99 | |
100 | g_get_current_time(>); |
101 | return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0; |
102 | } |
103 | |
104 | static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end) |
105 | { |
106 | double t0, t1; |
107 | |
f95bc830 |
108 | int i; |
109 | |
b8eccacd |
110 | //lttv_traceset_context_add_hooks(&ts->parent, |
111 | //before_traceset, after_traceset, NULL, before_trace, after_trace, |
112 | //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
113 | lttv_process_traceset_begin(&ts->parent, |
114 | before_traceset, |
115 | before_trace, |
116 | before_tracefile, |
117 | event_hook, |
118 | NULL); |
08b1c66e |
119 | |
f95bc830 |
120 | for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { |
121 | ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval; |
122 | } |
123 | |
08b1c66e |
124 | t0 = get_time(); |
125 | lttv_state_traceset_seek_time_closest(ts, start); |
b8eccacd |
126 | //lttv_process_traceset(&ts->parent, end, G_MAXULONG); |
127 | lttv_process_traceset_middle(&ts->parent, |
128 | end, |
129 | G_MAXULONG, |
130 | NULL); |
08b1c66e |
131 | t1 = get_time(); |
132 | |
b8eccacd |
133 | //lttv_traceset_context_remove_hooks(&ts->parent, |
134 | //before_traceset, after_traceset, NULL, before_trace, after_trace, |
135 | //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
136 | lttv_process_traceset_end(&ts->parent, |
137 | after_traceset, |
138 | after_trace, |
139 | after_tracefile, |
140 | event_hook, |
141 | NULL); |
08b1c66e |
142 | |
143 | return t1 - t0; |
144 | } |
145 | |
146 | |
f95bc830 |
147 | gboolean trace_event(void *hook_data, void *call_data) |
148 | { |
149 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
150 | |
151 | guint nb_block, nb_event; |
152 | |
153 | LttTracefile *tf; |
154 | |
155 | ltt_event_position(tfs->parent.e, a_event_position); |
156 | ltt_event_position_get(a_event_position, &nb_block, &nb_event, &tf); |
157 | fprintf(stderr,"Event %s %lu.%09lu [%lu %lu]\n", |
158 | ltt_eventtype_name(ltt_event_eventtype(tfs->parent.e)), |
159 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec, |
160 | nb_block, nb_event); |
161 | return FALSE; |
162 | } |
163 | |
164 | |
08b1c66e |
165 | gboolean count_event(void *hook_data, void *call_data) |
166 | { |
167 | guint *pcount = (guint *)hook_data; |
168 | |
169 | (*pcount)++; |
170 | return FALSE; |
171 | } |
172 | |
173 | |
f95bc830 |
174 | gboolean save_state_copy_event(void *hook_data, void *call_data) |
175 | { |
176 | SaveState *save_state = (SaveState *)hook_data; |
177 | |
178 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
179 | |
180 | LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; |
181 | |
182 | GString *filename; |
183 | |
184 | FILE *fp; |
185 | |
186 | if(ts->nb_event == 0 && strcmp(ltt_eventtype_name( |
187 | ltt_event_eventtype(tfs->parent.e)), "block_start") == 0) { |
188 | if(a_save_sample != NULL) { |
189 | filename = g_string_new(""); |
190 | g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample, |
191 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
192 | fp = fopen(filename->str, "w"); |
193 | if(fp == NULL) g_error("Cannot open %s", filename->str); |
194 | g_string_free(filename, TRUE); |
195 | lttv_state_write(ts, tfs->parent.timestamp, fp); |
196 | fclose(fp); |
197 | } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); |
198 | } |
199 | return FALSE; |
200 | } |
201 | |
202 | |
08b1c66e |
203 | gboolean save_state_event(void *hook_data, void *call_data) |
204 | { |
205 | SaveState *save_state = (SaveState *)hook_data; |
206 | |
207 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
208 | |
209 | LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; |
210 | |
211 | GString *filename; |
212 | |
213 | FILE *fp; |
214 | |
215 | (save_state->count)++; |
216 | if(save_state->count % save_state->interval == 0 && |
217 | save_state->position < save_state->size) { |
218 | if(a_save_sample != NULL) { |
219 | filename = g_string_new(""); |
220 | g_string_printf(filename, "%s.%u.xml.%u", a_save_sample, |
221 | save_state->position, save_state->version); |
222 | fp = fopen(filename->str, "w"); |
223 | if(fp == NULL) g_error("Cannot open %s", filename->str); |
224 | g_string_free(filename, TRUE); |
225 | lttv_state_write(ts, tfs->parent.timestamp, fp); |
226 | fclose(fp); |
f95bc830 |
227 | } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); |
08b1c66e |
228 | |
229 | save_state->write_time[save_state->position] = tfs->parent.timestamp; |
230 | save_state->position++; |
231 | } |
232 | return FALSE; |
233 | } |
234 | |
235 | |
236 | static gboolean process_traceset(void *hook_data, void *call_data) |
237 | { |
238 | LttvTracesetStats *tscs; |
239 | |
240 | LttvTracesetState *ts; |
241 | |
242 | LttvTracesetContext *tc; |
243 | |
244 | GString *filename; |
245 | |
246 | FILE *fp; |
247 | |
248 | double t; |
249 | |
250 | guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal; |
251 | |
252 | LttTrace *trace; |
253 | |
254 | LttTracefile *tracefile, *tf; |
255 | |
256 | LttEvent *event; |
257 | |
258 | LttFacility *facility; |
259 | |
260 | LttType *type; |
261 | |
262 | LttEventType *event_type; |
263 | |
264 | LttTime time, previous_time; |
265 | |
338d4282 |
266 | long long unsigned cycle_count, start_count, delta_cycle; |
267 | |
268 | long long unsigned start_nsec, end_nsec, delta_nsec, added_nsec, added_nsec2; |
269 | |
270 | double cycle_per_nsec, nsec_per_cycle; |
271 | |
272 | long long interpolated_nsec, interpolated_nsec2, end_nsec_sec, end_nsec_nsec; |
273 | |
274 | LttTime start_time; |
275 | |
08b1c66e |
276 | LttTime zero_time = ltt_time_zero; |
277 | |
278 | LttTime max_time = { G_MAXULONG, G_MAXULONG }; |
279 | |
f95bc830 |
280 | a_event_position = ltt_event_position_new(); |
281 | |
08b1c66e |
282 | if(a_dump_tracefiles != NULL) { |
08b1c66e |
283 | for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { |
284 | trace = lttv_trace(lttv_traceset_get(traceset, i)); |
285 | nb_control = ltt_trace_control_tracefile_number(trace); |
286 | nb_tracefile = nb_control + ltt_trace_per_cpu_tracefile_number(trace); |
287 | for(j = 0 ; j < nb_tracefile ; j++) { |
288 | if(j < nb_control) { |
289 | tracefile = ltt_trace_control_tracefile_get(trace,j); |
290 | } |
291 | else { |
292 | tracefile = ltt_trace_per_cpu_tracefile_get(trace,j - nb_control); |
293 | } |
294 | |
295 | filename = g_string_new(""); |
296 | g_string_printf(filename, "%s.%u.%u.trace", a_dump_tracefiles, i, j); |
297 | fp = fopen(filename->str, "w"); |
298 | if(fp == NULL) g_error("Cannot open %s", filename->str); |
299 | g_string_free(filename, TRUE); |
300 | ltt_tracefile_seek_time(tracefile, zero_time); |
301 | previous_time = zero_time; |
302 | nb_equal = 0; |
303 | while((event = ltt_tracefile_read(tracefile)) != NULL) { |
304 | facility = ltt_event_facility(event); |
305 | event_type = ltt_event_eventtype(event); |
306 | time = ltt_event_time(event); |
338d4282 |
307 | cycle_count = ltt_event_cycle_count(event); |
f95bc830 |
308 | ltt_event_position(event, a_event_position); |
309 | ltt_event_position_get(a_event_position, &nb_block, &nb_event, &tf); |
338d4282 |
310 | fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n", |
08b1c66e |
311 | ltt_facility_name(facility), ltt_eventtype_name(event_type), |
338d4282 |
312 | cycle_count, (unsigned long)time.tv_sec, |
313 | (unsigned long)time.tv_nsec, |
314 | nb_block, nb_event); |
08b1c66e |
315 | |
316 | if(ltt_time_compare(time, previous_time) < 0) { |
317 | g_warning("Time decreasing trace %d tracefile %d position %u/%u", |
318 | i, j, nb_block, nb_event); |
319 | } |
338d4282 |
320 | |
321 | if(strcmp(ltt_eventtype_name(event_type),"block_start") == 0) { |
322 | start_count = cycle_count; |
323 | start_time = time; |
324 | } |
325 | else if(strcmp(ltt_eventtype_name(event_type),"block_end") == 0) { |
326 | delta_cycle = cycle_count - start_count; |
327 | end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000; |
328 | end_nsec_nsec = time.tv_nsec; |
329 | end_nsec = end_nsec_sec + end_nsec_nsec; |
330 | start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec; |
331 | delta_nsec = end_nsec - start_nsec; |
332 | cycle_per_nsec = (double)delta_cycle / (double)delta_nsec; |
333 | nsec_per_cycle = (double)delta_nsec / (double)delta_cycle; |
334 | added_nsec = (double)delta_cycle * nsec_per_cycle; |
335 | interpolated_nsec = start_nsec + added_nsec; |
336 | added_nsec2 = (double)delta_cycle / cycle_per_nsec; |
337 | interpolated_nsec2 = start_nsec + added_nsec2; |
338 | |
339 | 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); |
340 | } |
341 | else { |
342 | if(ltt_time_compare(time, previous_time) == 0) nb_equal++; |
343 | else if(nb_equal > 0) { |
344 | g_warning("Consecutive %d events with time %lu.%09lu", |
345 | nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec); |
346 | nb_equal = 0; |
347 | } |
348 | previous_time = time; |
349 | } |
08b1c66e |
350 | } |
351 | fclose(fp); |
352 | } |
353 | } |
08b1c66e |
354 | } |
355 | |
356 | tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); |
357 | ts = &tscs->parent; |
358 | tc = &tscs->parent.parent; |
359 | |
360 | lttv_context_init(tc, traceset); |
08b1c66e |
361 | |
362 | /* For each case compute and print the elapsed time. |
363 | The first case is simply to run through all events with a |
364 | simple counter. */ |
365 | |
366 | if(a_test1 || a_test_all) { |
367 | count = 0; |
b8eccacd |
368 | lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT); |
08b1c66e |
369 | t = run_one_test(ts, zero_time, max_time); |
b8eccacd |
370 | lttv_hooks_remove_data(event_hook, count_event, &count); |
08b1c66e |
371 | g_warning( |
372 | "Processing trace while counting events (%u events in %g seconds)", |
373 | count, t); |
374 | } |
375 | |
376 | /* Run through all events computing the state. */ |
377 | |
378 | if(a_test2 || a_test_all) { |
379 | lttv_state_add_event_hooks(ts); |
380 | t = run_one_test(ts, zero_time, max_time); |
381 | lttv_state_remove_event_hooks(ts); |
382 | g_warning("Processing trace while updating state (%g seconds)", t); |
383 | } |
384 | |
385 | /* Run through all events computing the state and writing it out |
386 | periodically. */ |
387 | |
388 | SaveState save_state; |
389 | |
390 | save_state.interval = a_sample_interval; |
391 | save_state.size = a_sample_number; |
392 | save_state.fp = stderr; |
393 | save_state.write_time = g_new(LttTime, a_sample_number); |
394 | |
395 | |
396 | if(a_test3 || a_test_all) { |
397 | for(i = 0 ; i < 2 ; i++) { |
398 | save_state.count = 0; |
399 | save_state.position = 0; |
400 | save_state.version = i; |
401 | lttv_state_add_event_hooks(ts); |
b8eccacd |
402 | lttv_hooks_add(event_hook, save_state_event, &save_state, |
403 | LTTV_PRIO_DEFAULT); |
08b1c66e |
404 | t = run_one_test(ts, zero_time, max_time); |
405 | lttv_state_remove_event_hooks(ts); |
b8eccacd |
406 | lttv_hooks_remove_data(event_hook, save_state_event, &save_state); |
08b1c66e |
407 | g_warning("Processing while updating/writing state (%g seconds)", t); |
408 | } |
409 | } |
410 | |
411 | /* Run through all events computing the stats. */ |
412 | |
413 | if(a_test4 || a_test_all) { |
414 | if(lttv_profile_memory) { |
415 | g_message("Memory summary before computing stats"); |
416 | g_mem_profile(); |
417 | } |
418 | |
419 | lttv_stats_add_event_hooks(tscs); |
420 | t = run_one_test(ts, zero_time, max_time); |
421 | lttv_stats_remove_event_hooks(tscs); |
422 | g_warning("Processing trace while counting stats (%g seconds)", t); |
423 | |
424 | if(lttv_profile_memory) { |
425 | g_message("Memory summary after computing stats"); |
426 | g_mem_profile(); |
427 | } |
f95bc830 |
428 | |
429 | lttv_stats_sum_traceset(tscs); |
430 | |
431 | if(lttv_profile_memory) { |
432 | g_message("Memory summary after summing stats"); |
433 | g_mem_profile(); |
434 | } |
435 | |
436 | lttv_context_fini(tc); |
437 | lttv_context_init(tc, traceset); |
438 | |
439 | if(lttv_profile_memory) { |
440 | g_message("Memory summary after cleaning up the stats"); |
441 | g_mem_profile(); |
442 | } |
08b1c66e |
443 | } |
444 | |
445 | /* Run through all events computing the state and stats. */ |
446 | |
447 | if(a_test5 || a_test_all) { |
448 | if(lttv_profile_memory) { |
449 | g_message("Memory summary before computing state and stats"); |
450 | g_mem_profile(); |
451 | } |
452 | |
453 | lttv_state_add_event_hooks(ts); |
454 | lttv_stats_add_event_hooks(tscs); |
455 | t = run_one_test(ts, zero_time, max_time); |
456 | lttv_state_remove_event_hooks(ts); |
457 | lttv_stats_remove_event_hooks(tscs); |
458 | g_warning( |
459 | "Processing trace while counting state and stats (%g seconds)", t); |
460 | |
461 | if(lttv_profile_memory) { |
462 | g_message("Memory summary after computing and state and stats"); |
463 | g_mem_profile(); |
464 | } |
f95bc830 |
465 | |
466 | lttv_context_fini(tc); |
467 | lttv_context_init(tc, traceset); |
468 | |
469 | if(lttv_profile_memory) { |
470 | g_message("Memory summary after cleaning up the stats"); |
471 | g_mem_profile(); |
472 | } |
08b1c66e |
473 | } |
474 | |
475 | /* Run through all events computing and saving the state. */ |
476 | |
b8eccacd |
477 | if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL, |
478 | LTTV_PRIO_DEFAULT); |
f95bc830 |
479 | |
08b1c66e |
480 | if(a_test6 || a_test_all) { |
481 | if(lttv_profile_memory) { |
482 | g_message("Memory summary before computing and saving state"); |
483 | g_mem_profile(); |
484 | } |
485 | |
486 | lttv_state_add_event_hooks(ts); |
487 | lttv_state_save_add_event_hooks(ts); |
f95bc830 |
488 | if(a_save_state_copy) |
b8eccacd |
489 | lttv_hooks_add(event_hook, save_state_copy_event, &save_state, |
490 | LTTV_PRIO_DEFAULT); |
08b1c66e |
491 | t = run_one_test(ts, zero_time, max_time); |
492 | lttv_state_remove_event_hooks(ts); |
493 | lttv_state_save_remove_event_hooks(ts); |
f95bc830 |
494 | if(a_save_state_copy) |
b8eccacd |
495 | lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state); |
f95bc830 |
496 | |
08b1c66e |
497 | g_warning("Processing trace while updating/saving state (%g seconds)", t); |
498 | |
499 | if(lttv_profile_memory) { |
500 | g_message("Memory summary after computing/saving state"); |
501 | g_mem_profile(); |
502 | } |
503 | } |
504 | |
505 | /* Seek a few times to each saved position */ |
506 | |
507 | if((a_test7 && a_test3) || a_test_all) { |
508 | int i, j; |
509 | |
911b7a3c |
510 | for(i = 0 ; i < a_seek_number ; i++) { |
08b1c66e |
511 | for(j = save_state.position - 1 ; j >= 0 ; j--) { |
512 | lttv_state_add_event_hooks(ts); |
513 | t = run_one_test(ts, save_state.write_time[j], |
514 | save_state.write_time[j]); |
515 | lttv_state_remove_event_hooks(ts); |
516 | g_warning("Seeking to %lu.%lu (%g seconds)", |
517 | save_state.write_time[j].tv_sec, save_state.write_time[j].tv_nsec, |
518 | t); |
519 | |
520 | if(a_save_sample != NULL) { |
521 | filename = g_string_new(""); |
522 | g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i); |
523 | fp = fopen(filename->str, "w"); |
524 | if(fp == NULL) g_error("Cannot open %s", filename->str); |
525 | g_string_free(filename, TRUE); |
526 | lttv_state_write((LttvTraceState *)tc->traces[0], |
527 | save_state.write_time[j], fp); |
528 | fclose(fp); |
529 | } |
f95bc830 |
530 | //else lttv_state_write((LttvTraceState *)tc->traces[0], |
531 | // save_state.write_time[j], save_state.fp); |
08b1c66e |
532 | } |
533 | } |
534 | } |
535 | |
b8eccacd |
536 | if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL); |
f95bc830 |
537 | |
08b1c66e |
538 | g_free(save_state.write_time); |
f95bc830 |
539 | g_free(a_event_position); |
08b1c66e |
540 | lttv_context_fini(tc); |
541 | g_object_unref(tscs); |
542 | |
f95bc830 |
543 | if(lttv_profile_memory) { |
544 | g_message("Memory summary at the end of batchtest"); |
545 | g_mem_profile(); |
546 | } |
547 | |
08b1c66e |
548 | g_info("BatchTest end process traceset"); |
549 | } |
550 | |
551 | |
552 | static void init() |
553 | { |
554 | LttvAttributeValue value; |
555 | |
556 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
557 | |
558 | g_info("Init batchtest.c"); |
559 | |
560 | lttv_option_add("trace", 't', |
561 | "add a trace to the trace set to analyse", |
562 | "pathname of the directory containing the trace", |
563 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
564 | |
f95bc830 |
565 | a_trace_event = FALSE; |
566 | |
08b1c66e |
567 | a_dump_tracefiles = NULL; |
568 | lttv_option_add("dump-tracefiles", 'D', |
569 | "Write event by event the content of tracefiles", |
570 | "basename for the files where to dump events", |
571 | LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL); |
572 | |
573 | a_save_sample = NULL; |
574 | lttv_option_add("save-sample", 's', |
575 | "Save state samples to multiple files", |
576 | "basename for the files containing the state samples", |
577 | LTTV_OPT_STRING, &a_save_sample, NULL, NULL); |
578 | |
f95bc830 |
579 | a_save_state_copy = FALSE; |
580 | lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking", |
581 | "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL); |
582 | |
08b1c66e |
583 | a_save_interval = 100000; |
584 | lttv_option_add("save-interval", 'i', |
585 | "Interval between saving state", |
586 | "number of events before a block start triggers saving state", |
587 | LTTV_OPT_INT, &a_save_interval, NULL, NULL); |
588 | |
589 | a_sample_interval = 100000; |
590 | lttv_option_add("sample-interval", 'S', |
591 | "Interval between sampling state", |
592 | "number of events before sampling and writing state", |
593 | LTTV_OPT_INT, &a_sample_interval, NULL, NULL); |
594 | |
595 | a_sample_number = 20; |
596 | lttv_option_add("sample-number", 'N', |
597 | "Number of state samples", |
598 | "maximum number", |
599 | LTTV_OPT_INT, &a_sample_number, NULL, NULL); |
600 | |
911b7a3c |
601 | a_seek_number = 200; |
602 | lttv_option_add("seek-number", 'K', |
603 | "Number of seek", |
604 | "number", |
605 | LTTV_OPT_INT, &a_seek_number, NULL, NULL); |
606 | |
08b1c66e |
607 | a_test1 = FALSE; |
608 | lttv_option_add("test1", '1', "Test just counting events", "", |
609 | LTTV_OPT_NONE, &a_test1, NULL, NULL); |
610 | |
611 | a_test2 = FALSE; |
612 | lttv_option_add("test2", '2', "Test computing the state", "", |
613 | LTTV_OPT_NONE, &a_test2, NULL, NULL); |
614 | |
615 | a_test3 = FALSE; |
616 | lttv_option_add("test3", '3', "Test computing the state, writing out a few", |
617 | "", LTTV_OPT_NONE, &a_test3, NULL, NULL); |
618 | |
619 | a_test4 = FALSE; |
620 | lttv_option_add("test4", '4', "Test computing the stats", "", |
621 | LTTV_OPT_NONE, &a_test4, NULL, NULL); |
622 | |
623 | a_test5 = FALSE; |
624 | lttv_option_add("test5", '5', "Test computing the state and stats", "", |
625 | LTTV_OPT_NONE, &a_test5, NULL, NULL); |
626 | |
627 | a_test6 = FALSE; |
628 | lttv_option_add("test6", '6', "Test computing and saving the state", "", |
629 | LTTV_OPT_NONE, &a_test6, NULL, NULL); |
630 | |
631 | a_test7 = FALSE; |
632 | lttv_option_add("test7", '7', "Test seeking to positions written out in 3", |
633 | "", LTTV_OPT_NONE, &a_test7, NULL, NULL); |
634 | |
635 | a_test_all = FALSE; |
636 | lttv_option_add("testall", 'a', "Run all tests ", "", |
637 | LTTV_OPT_NONE, &a_test_all, NULL, NULL); |
638 | |
639 | traceset = lttv_traceset_new(); |
640 | |
641 | before_traceset = lttv_hooks_new(); |
642 | after_traceset = lttv_hooks_new(); |
643 | before_trace = lttv_hooks_new(); |
644 | after_trace = lttv_hooks_new(); |
645 | before_tracefile = lttv_hooks_new(); |
646 | after_tracefile = lttv_hooks_new(); |
b8eccacd |
647 | //before_event = lttv_hooks_new(); |
648 | //after_event = lttv_hooks_new(); |
649 | event_hook = lttv_hooks_new(); |
650 | |
08b1c66e |
651 | |
652 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
653 | LTTV_POINTER, &value)); |
654 | *(value.v_pointer) = before_traceset; |
655 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
656 | LTTV_POINTER, &value)); |
657 | *(value.v_pointer) = after_traceset; |
658 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
659 | LTTV_POINTER, &value)); |
660 | *(value.v_pointer) = before_trace; |
661 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
662 | LTTV_POINTER, &value)); |
663 | *(value.v_pointer) = after_trace; |
664 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
665 | LTTV_POINTER, &value)); |
666 | *(value.v_pointer) = before_tracefile; |
667 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
668 | LTTV_POINTER, &value)); |
669 | *(value.v_pointer) = after_tracefile; |
b8eccacd |
670 | //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
671 | // LTTV_POINTER, &value)); |
672 | //*(value.v_pointer) = before_event; |
673 | //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
674 | // LTTV_POINTER, &value)); |
675 | //*(value.v_pointer) = after_event; |
63a95338 |
676 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event", |
08b1c66e |
677 | LTTV_POINTER, &value)); |
b8eccacd |
678 | *(value.v_pointer) = event_hook; |
08b1c66e |
679 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
680 | LTTV_POINTER, &value)); |
681 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
b8eccacd |
682 | lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT); |
08b1c66e |
683 | } |
684 | |
685 | |
686 | static void destroy() |
687 | { |
688 | guint i, nb; |
689 | |
690 | LttvTrace *trace; |
691 | |
692 | g_info("Destroy batchAnalysis.c"); |
693 | |
694 | lttv_option_remove("trace"); |
695 | lttv_option_remove("dump-tracefiles"); |
696 | lttv_option_remove("save-sample"); |
f95bc830 |
697 | lttv_option_remove("save-state-copy"); |
08b1c66e |
698 | lttv_option_remove("sample-interval"); |
699 | lttv_option_remove("sample-number"); |
911b7a3c |
700 | lttv_option_remove("seek-number"); |
08b1c66e |
701 | lttv_option_remove("save-interval"); |
702 | lttv_option_remove("test1"); |
703 | lttv_option_remove("test2"); |
704 | lttv_option_remove("test3"); |
705 | lttv_option_remove("test4"); |
706 | lttv_option_remove("test5"); |
707 | lttv_option_remove("test6"); |
708 | lttv_option_remove("test7"); |
709 | lttv_option_remove("testall"); |
710 | |
711 | lttv_hooks_destroy(before_traceset); |
712 | lttv_hooks_destroy(after_traceset); |
713 | lttv_hooks_destroy(before_trace); |
714 | lttv_hooks_destroy(after_trace); |
715 | lttv_hooks_destroy(before_tracefile); |
716 | lttv_hooks_destroy(after_tracefile); |
b8eccacd |
717 | //lttv_hooks_destroy(before_event); |
718 | //lttv_hooks_destroy(after_event); |
719 | lttv_hooks_destroy(event_hook); |
08b1c66e |
720 | lttv_hooks_remove_data(main_hooks, process_traceset, NULL); |
721 | |
722 | nb = lttv_traceset_number(traceset); |
723 | for(i = 0 ; i < nb ; i++) { |
724 | trace = lttv_traceset_get(traceset, i); |
725 | ltt_trace_close(lttv_trace(trace)); |
726 | lttv_trace_destroy(trace); |
727 | } |
728 | |
729 | lttv_traceset_destroy(traceset); |
730 | } |
731 | |
732 | |
733 | LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \ |
734 | "Run through a trace calling all the registered hooks for tests", \ |
735 | init, destroy, "state", "stats", "option" ) |