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