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