Commit | Line | Data |
---|---|---|
9c312311 | 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 | ||
4e4d11b3 | 19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> | |
21 | #endif | |
b445142a | 22 | |
9f797243 | 23 | #include <stdio.h> |
43ed82b5 | 24 | #include <inttypes.h> |
08b1c66e | 25 | #include <lttv/module.h> |
b445142a | 26 | #include <lttv/stats.h> |
2a2fa4f0 | 27 | #include <lttv/lttv.h> |
f95bc830 | 28 | #include <lttv/attribute.h> |
b445142a | 29 | #include <ltt/trace.h> |
30 | #include <ltt/event.h> | |
31 | ||
9f797243 | 32 | #define BUF_SIZE 256 |
14236daa | 33 | #define MAX_64_HEX_STRING_LEN 19 |
9f797243 | 34 | |
b445142a | 35 | GQuark |
90e19f82 AM |
36 | LTTV_STATS_PROCESS_UNKNOWN, |
37 | LTTV_STATS_PROCESSES, | |
38 | LTTV_STATS_CPU, | |
39 | LTTV_STATS_MODE_TYPES, | |
40 | LTTV_STATS_MODES, | |
41 | LTTV_STATS_SUBMODES, | |
42 | LTTV_STATS_FUNCTIONS, | |
43 | LTTV_STATS_EVENT_TYPES, | |
44 | LTTV_STATS_CPU_TIME, | |
45 | LTTV_STATS_CUMULATIVE_CPU_TIME, | |
46 | LTTV_STATS_ELAPSED_TIME, | |
47 | LTTV_STATS_EVENTS, | |
48 | LTTV_STATS_EVENTS_COUNT, | |
49 | LTTV_STATS_USE_COUNT, | |
50 | LTTV_STATS, | |
90e19f82 AM |
51 | LTTV_STATS_SUMMED, |
52 | LTTV_STATS_BEFORE_HOOKS, | |
53 | LTTV_STATS_AFTER_HOOKS; | |
54 | ||
516a8712 | 55 | static void find_event_tree(LttvCPUStats *cpu_stats, GQuark pid_time, |
90e19f82 AM |
56 | guint cpu, guint64 function, |
57 | GQuark mode, GQuark sub_mode, LttvAttribute **events_tree, | |
58 | LttvAttribute **event_types_tree); | |
b445142a | 59 | |
d730b5c8 | 60 | |
61 | static void lttv_stats_init(LttvTracesetStats *self) | |
b445142a | 62 | { |
516a8712 | 63 | guint i, j, nb_trace, nb_cpu, nb_tracefile; |
b445142a | 64 | |
90e19f82 | 65 | LttvTraceContext *tc; |
b445142a | 66 | |
90e19f82 | 67 | LttvTraceStats *tcs; |
b445142a | 68 | |
90e19f82 AM |
69 | LttvTracefileContext **tfs; |
70 | LttvTracefileStats *tfcs; | |
516a8712 | 71 | LttvCPUStats *cpu_stats; |
f95bc830 | 72 | |
90e19f82 | 73 | LttvAttributeValue v; |
f95bc830 | 74 | |
90e19f82 | 75 | LttvTraceset *ts = self->parent.parent.ts; |
f95bc830 | 76 | |
90e19f82 AM |
77 | self->stats = lttv_attribute_find_subdir( |
78 | lttv_traceset_attribute(self->parent.parent.ts), LTTV_STATS); | |
79 | lttv_attribute_find(lttv_traceset_attribute(self->parent.parent.ts), | |
80 | LTTV_STATS_USE_COUNT, | |
81 | LTTV_UINT, &v); | |
f95bc830 | 82 | |
90e19f82 AM |
83 | (*(v.v_uint))++; |
84 | if(*(v.v_uint) == 1) { | |
85 | g_assert(lttv_attribute_get_number(self->stats) == 0); | |
86 | } | |
b445142a | 87 | |
90e19f82 | 88 | nb_trace = lttv_traceset_number(ts); |
f95bc830 | 89 | |
90e19f82 AM |
90 | for(i = 0 ; i < nb_trace ; i++) { |
91 | tc = self->parent.parent.traces[i]; | |
92 | tcs = LTTV_TRACE_STATS(tc); | |
f95bc830 | 93 | |
90e19f82 AM |
94 | tcs->stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, |
95 | LTTV_STATS); | |
90e19f82 AM |
96 | lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, |
97 | LTTV_UINT, &v); | |
b445142a | 98 | |
90e19f82 AM |
99 | (*(v.v_uint))++; |
100 | if(*(v.v_uint) == 1) { | |
101 | g_assert(lttv_attribute_get_number(tcs->stats) == 0); | |
102 | } | |
b445142a | 103 | |
516a8712 MD |
104 | nb_cpu = ltt_trace_get_num_cpu(tc->t); |
105 | tcs->cpu_stats = g_new(LttvCPUStats, nb_cpu); | |
106 | for(j = 0 ; j < nb_cpu; j++) { | |
107 | cpu_stats = &tcs->cpu_stats[j]; | |
108 | cpu_stats->cpu = j; | |
109 | cpu_stats->tcs = tcs; | |
110 | find_event_tree(cpu_stats, LTTV_STATS_PROCESS_UNKNOWN, | |
111 | cpu_stats->cpu, | |
112 | 0x0ULL, | |
113 | LTTV_STATE_MODE_UNKNOWN, | |
114 | LTTV_STATE_SUBMODE_UNKNOWN, &cpu_stats->current_events_tree, | |
115 | &cpu_stats->current_event_types_tree); | |
116 | } | |
90e19f82 | 117 | nb_tracefile = tc->tracefiles->len; |
516a8712 | 118 | for (j = 0; j < nb_tracefile; j++) { |
90e19f82 AM |
119 | tfs = &g_array_index(tc->tracefiles, LttvTracefileContext*, j); |
120 | tfcs = LTTV_TRACEFILE_STATS(*tfs); | |
516a8712 | 121 | tfcs->cpu_stats = &tcs->cpu_stats[tfcs->parent.cpu]; |
90e19f82 AM |
122 | } |
123 | } | |
d730b5c8 | 124 | |
b445142a | 125 | } |
126 | ||
d730b5c8 | 127 | static void lttv_stats_fini(LttvTracesetStats *self) |
b445142a | 128 | { |
516a8712 | 129 | guint i, j, nb_trace, nb_cpu, nb_tracefile; |
90e19f82 AM |
130 | |
131 | LttvTraceset *ts; | |
b445142a | 132 | |
90e19f82 | 133 | LttvTraceContext *tc; |
b445142a | 134 | |
90e19f82 | 135 | LttvTraceStats *tcs; |
b445142a | 136 | |
90e19f82 | 137 | LttvTracefileContext *tfc; |
b445142a | 138 | |
90e19f82 | 139 | LttvTracefileStats *tfcs; |
b445142a | 140 | |
516a8712 | 141 | LttvCPUStats *cpu_stats; |
f95bc830 | 142 | |
516a8712 | 143 | LttvAttributeValue v; |
f95bc830 | 144 | |
90e19f82 AM |
145 | lttv_attribute_find(self->parent.parent.ts_a, LTTV_STATS_USE_COUNT, |
146 | LTTV_UINT, &v); | |
147 | (*(v.v_uint))--; | |
f95bc830 | 148 | |
90e19f82 AM |
149 | if(*(v.v_uint) == 0) { |
150 | lttv_attribute_remove_by_name(self->parent.parent.ts_a, LTTV_STATS); | |
151 | } | |
152 | self->stats = NULL; | |
f95bc830 | 153 | |
90e19f82 AM |
154 | ts = self->parent.parent.ts; |
155 | nb_trace = lttv_traceset_number(ts); | |
b445142a | 156 | |
90e19f82 AM |
157 | for(i = 0 ; i < nb_trace ; i++) { |
158 | tcs = (LttvTraceStats *)(tc = (LTTV_TRACESET_CONTEXT(self)->traces[i])); | |
f95bc830 | 159 | |
90e19f82 AM |
160 | lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, |
161 | LTTV_UINT, &v); | |
162 | (*(v.v_uint))--; | |
f95bc830 | 163 | |
516a8712 MD |
164 | if(*(v.v_uint) == 0) |
165 | lttv_attribute_remove_by_name(tcs->parent.parent.t_a, LTTV_STATS); | |
90e19f82 | 166 | tcs->stats = NULL; |
b445142a | 167 | |
90e19f82 | 168 | nb_tracefile = tc->tracefiles->len; |
516a8712 | 169 | for (j = 0; j < nb_tracefile; j++) { |
90e19f82 | 170 | tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, j); |
516a8712 MD |
171 | tfcs = LTTV_TRACEFILE_STATS(tfc); |
172 | tfcs->cpu_stats = NULL; | |
173 | } | |
174 | ||
175 | nb_cpu = ltt_trace_get_num_cpu(tc->t); | |
176 | ||
177 | for(j = 0 ; j < nb_cpu; j++) { | |
178 | cpu_stats = &tcs->cpu_stats[j]; | |
179 | cpu_stats->current_events_tree = NULL; | |
180 | cpu_stats->current_event_types_tree = NULL; | |
90e19f82 | 181 | } |
516a8712 | 182 | g_free(tcs->cpu_stats); |
90e19f82 | 183 | } |
d730b5c8 | 184 | } |
185 | ||
186 | ||
187 | void lttv_stats_reset(LttvTracesetStats *self) | |
188 | { | |
90e19f82 AM |
189 | lttv_stats_fini(self); |
190 | lttv_stats_init(self); | |
d730b5c8 | 191 | } |
192 | ||
193 | ||
194 | ||
90e19f82 | 195 | static void init(LttvTracesetStats *self, LttvTraceset *ts) |
d730b5c8 | 196 | { |
90e19f82 AM |
197 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> |
198 | init((LttvTracesetContext *)self, ts); | |
199 | ||
200 | lttv_stats_init(self); | |
d730b5c8 | 201 | } |
202 | ||
203 | ||
90e19f82 | 204 | static void fini(LttvTracesetStats *self) |
d730b5c8 | 205 | { |
90e19f82 | 206 | lttv_stats_fini(self); |
d730b5c8 | 207 | |
90e19f82 AM |
208 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> |
209 | fini((LttvTracesetContext *)self); | |
b445142a | 210 | } |
211 | ||
212 | ||
90e19f82 | 213 | static LttvTracesetContext *new_traceset_context(LttvTracesetContext *self) |
b445142a | 214 | { |
90e19f82 | 215 | return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATS_TYPE, NULL)); |
b445142a | 216 | } |
217 | ||
218 | ||
90e19f82 | 219 | static LttvTraceContext *new_trace_context(LttvTracesetContext *self) |
b445142a | 220 | { |
90e19f82 | 221 | return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATS_TYPE, NULL)); |
b445142a | 222 | } |
223 | ||
224 | ||
90e19f82 | 225 | static LttvTracefileContext *new_tracefile_context(LttvTracesetContext *self) |
b445142a | 226 | { |
90e19f82 | 227 | return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATS_TYPE, NULL)); |
b445142a | 228 | } |
229 | ||
230 | ||
90e19f82 AM |
231 | static void traceset_stats_instance_init (GTypeInstance *instance, |
232 | gpointer g_class) | |
b445142a | 233 | { |
234 | } | |
235 | ||
236 | ||
90e19f82 | 237 | static void traceset_stats_finalize (LttvTracesetStats *self) |
b445142a | 238 | { |
90e19f82 AM |
239 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> |
240 | finalize(G_OBJECT(self)); | |
b445142a | 241 | } |
242 | ||
243 | ||
90e19f82 | 244 | static void traceset_stats_class_init (LttvTracesetContextClass *klass) |
b445142a | 245 | { |
90e19f82 | 246 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
b445142a | 247 | |
90e19f82 AM |
248 | gobject_class->finalize = (void (*)(GObject *self)) traceset_stats_finalize; |
249 | klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; | |
250 | klass->fini = (void (*)(LttvTracesetContext *self))fini; | |
251 | klass->new_traceset_context = new_traceset_context; | |
252 | klass->new_trace_context = new_trace_context; | |
253 | klass->new_tracefile_context = new_tracefile_context; | |
b445142a | 254 | } |
255 | ||
256 | ||
90e19f82 | 257 | GType lttv_traceset_stats_get_type(void) |
b445142a | 258 | { |
90e19f82 AM |
259 | static GType type = 0; |
260 | if (type == 0) { | |
261 | static const GTypeInfo info = { | |
262 | sizeof (LttvTracesetStatsClass), | |
263 | NULL, /* base_init */ | |
264 | NULL, /* base_finalize */ | |
265 | (GClassInitFunc) traceset_stats_class_init, /* class_init */ | |
266 | NULL, /* class_finalize */ | |
267 | NULL, /* class_data */ | |
268 | sizeof (LttvTracesetStats), | |
269 | 0, /* n_preallocs */ | |
270 | (GInstanceInitFunc) traceset_stats_instance_init, /* instance_init */ | |
271 | NULL /* Value handling */ | |
272 | }; | |
b445142a | 273 | |
90e19f82 AM |
274 | type = g_type_register_static (LTTV_TRACESET_STATE_TYPE, |
275 | "LttvTracesetStatsType", &info, 0); | |
276 | } | |
277 | return type; | |
b445142a | 278 | } |
279 | ||
280 | ||
90e19f82 AM |
281 | static void trace_stats_instance_init (GTypeInstance *instance, |
282 | gpointer g_class) | |
b445142a | 283 | { |
284 | } | |
285 | ||
286 | ||
90e19f82 | 287 | static void trace_stats_finalize (LttvTraceStats *self) |
b445142a | 288 | { |
90e19f82 AM |
289 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_STATE_TYPE))-> |
290 | finalize(G_OBJECT(self)); | |
b445142a | 291 | } |
292 | ||
293 | ||
90e19f82 | 294 | static void trace_stats_class_init (LttvTraceContextClass *klass) |
b445142a | 295 | { |
90e19f82 | 296 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
b445142a | 297 | |
90e19f82 | 298 | gobject_class->finalize = (void (*)(GObject *self)) trace_stats_finalize; |
b445142a | 299 | } |
300 | ||
301 | ||
90e19f82 | 302 | GType lttv_trace_stats_get_type(void) |
b445142a | 303 | { |
90e19f82 AM |
304 | static GType type = 0; |
305 | if (type == 0) { | |
306 | static const GTypeInfo info = { | |
307 | sizeof (LttvTraceStatsClass), | |
308 | NULL, /* base_init */ | |
309 | NULL, /* base_finalize */ | |
310 | (GClassInitFunc) trace_stats_class_init, /* class_init */ | |
311 | NULL, /* class_finalize */ | |
312 | NULL, /* class_data */ | |
313 | sizeof (LttvTraceStats), | |
314 | 0, /* n_preallocs */ | |
315 | (GInstanceInitFunc) trace_stats_instance_init, /* instance_init */ | |
316 | NULL /* Value handling */ | |
317 | }; | |
b445142a | 318 | |
90e19f82 AM |
319 | type = g_type_register_static (LTTV_TRACE_STATE_TYPE, |
320 | "LttvTraceStatsType", &info, 0); | |
321 | } | |
322 | return type; | |
b445142a | 323 | } |
324 | ||
325 | ||
90e19f82 AM |
326 | static void tracefile_stats_instance_init (GTypeInstance *instance, |
327 | gpointer g_class) | |
b445142a | 328 | { |
329 | } | |
330 | ||
331 | ||
90e19f82 | 332 | static void tracefile_stats_finalize (LttvTracefileStats *self) |
b445142a | 333 | { |
90e19f82 AM |
334 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_STATE_TYPE))-> |
335 | finalize(G_OBJECT(self)); | |
b445142a | 336 | } |
337 | ||
338 | ||
90e19f82 | 339 | static void tracefile_stats_class_init (LttvTracefileStatsClass *klass) |
b445142a | 340 | { |
90e19f82 | 341 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
b445142a | 342 | |
90e19f82 | 343 | gobject_class->finalize = (void (*)(GObject *self)) tracefile_stats_finalize; |
b445142a | 344 | } |
345 | ||
346 | ||
90e19f82 | 347 | GType lttv_tracefile_stats_get_type(void) |
b445142a | 348 | { |
90e19f82 AM |
349 | static GType type = 0; |
350 | if (type == 0) { | |
351 | static const GTypeInfo info = { | |
352 | sizeof (LttvTracefileStatsClass), | |
353 | NULL, /* base_init */ | |
354 | NULL, /* base_finalize */ | |
355 | (GClassInitFunc) tracefile_stats_class_init, /* class_init */ | |
356 | NULL, /* class_finalize */ | |
357 | NULL, /* class_data */ | |
358 | sizeof (LttvTracefileStats), | |
359 | 0, /* n_preallocs */ | |
360 | (GInstanceInitFunc) tracefile_stats_instance_init, /* instance_init */ | |
361 | NULL /* Value handling */ | |
362 | }; | |
b445142a | 363 | |
90e19f82 AM |
364 | type = g_type_register_static (LTTV_TRACEFILE_STATE_TYPE, |
365 | "LttvTracefileStatsType", &info, 0); | |
366 | } | |
367 | return type; | |
b445142a | 368 | } |
369 | ||
516a8712 | 370 | static void find_event_tree(LttvCPUStats *cpu_stats, |
90e19f82 AM |
371 | GQuark pid_time, |
372 | guint cpu, | |
373 | guint64 function, | |
374 | GQuark mode, | |
375 | GQuark sub_mode, | |
376 | LttvAttribute **events_tree, | |
377 | LttvAttribute **event_types_tree) | |
b445142a | 378 | { |
90e19f82 AM |
379 | LttvAttribute *a; |
380 | gchar fstring[MAX_64_HEX_STRING_LEN]; | |
381 | gint ret; | |
14236daa | 382 | |
90e19f82 AM |
383 | ret = snprintf(fstring, MAX_64_HEX_STRING_LEN-1, |
384 | "0x%" PRIX64, function) > 0; | |
385 | g_assert(ret > 0); | |
386 | fstring[MAX_64_HEX_STRING_LEN-1] = '\0'; | |
b445142a | 387 | |
516a8712 | 388 | LttvTraceStats *tcs = cpu_stats->tcs; |
90e19f82 AM |
389 | a = lttv_attribute_find_subdir(tcs->stats, LTTV_STATS_PROCESSES); |
390 | a = lttv_attribute_find_subdir(a, pid_time); | |
391 | a = lttv_attribute_find_subdir(a, LTTV_STATS_CPU); | |
392 | a = lttv_attribute_find_subdir_unnamed(a, cpu); | |
393 | a = lttv_attribute_find_subdir(a, LTTV_STATS_FUNCTIONS); | |
394 | a = lttv_attribute_find_subdir(a, g_quark_from_string(fstring)); | |
395 | a = lttv_attribute_find_subdir(a, LTTV_STATS_MODE_TYPES); | |
396 | a = lttv_attribute_find_subdir(a, mode); | |
397 | a = lttv_attribute_find_subdir(a, LTTV_STATS_SUBMODES); | |
398 | a = lttv_attribute_find_subdir(a, sub_mode); | |
399 | *events_tree = a; | |
400 | a = lttv_attribute_find_subdir(a, LTTV_STATS_EVENT_TYPES); | |
401 | *event_types_tree = a; | |
b445142a | 402 | } |
403 | ||
516a8712 | 404 | static void update_event_tree(LttvCPUStats *cpu_stats) |
b445142a | 405 | { |
516a8712 MD |
406 | LttvTraceStats *tcs = cpu_stats->tcs; |
407 | guint cpu = cpu_stats->cpu; | |
408 | LttvTraceState *ts = &tcs->parent; | |
90e19f82 AM |
409 | LttvProcessState *process = ts->running_process[cpu]; |
410 | LttvExecutionState *es = process->state; | |
b445142a | 411 | |
516a8712 | 412 | find_event_tree(cpu_stats, process->pid_time, |
90e19f82 AM |
413 | cpu, |
414 | process->current_function, | |
516a8712 MD |
415 | es->t, es->n, &(cpu_stats->current_events_tree), |
416 | &(cpu_stats->current_event_types_tree)); | |
b445142a | 417 | } |
418 | ||
516a8712 | 419 | /* Update the trace event tree each cpu */ |
89f8741a | 420 | static void update_trace_event_tree(LttvTraceStats *tcs) |
d3670e3d | 421 | { |
516a8712 | 422 | LttvCPUStats *cpu_stats; |
90e19f82 | 423 | LttvTraceContext *tc = (LttvTraceContext*)tcs; |
516a8712 MD |
424 | guint j, nb_cpu; |
425 | ||
426 | /* For each cpu, update the event tree */ | |
427 | nb_cpu = ltt_trace_get_num_cpu(tc->t); | |
428 | for(j = 0; j < nb_cpu; j++) { | |
429 | cpu_stats = &tcs->cpu_stats[j]; | |
430 | update_event_tree(cpu_stats); | |
90e19f82 | 431 | } |
d3670e3d | 432 | } |
b445142a | 433 | |
434 | static void mode_change(LttvTracefileStats *tfcs) | |
435 | { | |
90e19f82 AM |
436 | LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; |
437 | guint cpu = tfcs->parent.cpu; | |
438 | LttvProcessState *process = ts->running_process[cpu]; | |
439 | LttvAttributeValue cpu_time; | |
b445142a | 440 | |
90e19f82 | 441 | LttTime delta; |
b445142a | 442 | |
90e19f82 AM |
443 | if(process->state->s == LTTV_STATE_RUN && |
444 | process->state->t != LTTV_STATE_MODE_UNKNOWN) | |
445 | delta = ltt_time_sub(tfcs->parent.parent.timestamp, | |
446 | process->state->change); | |
447 | else | |
448 | delta = ltt_time_zero; | |
b49e54b4 | 449 | |
516a8712 | 450 | lttv_attribute_find(tfcs->cpu_stats->current_events_tree, LTTV_STATS_CPU_TIME, |
90e19f82 AM |
451 | LTTV_TIME, &cpu_time); |
452 | *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); | |
b445142a | 453 | |
90e19f82 AM |
454 | process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, |
455 | delta); | |
b49e54b4 | 456 | } |
b445142a | 457 | |
b49e54b4 | 458 | /* Note : every mode_end must come with a cumulative cpu time update in the |
d3670e3d | 459 | * after hook. */ |
b445142a | 460 | static void mode_end(LttvTracefileStats *tfcs) |
461 | { | |
90e19f82 AM |
462 | LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; |
463 | guint cpu = tfcs->parent.cpu; | |
464 | LttvProcessState *process = ts->running_process[cpu]; | |
465 | LttvAttributeValue elapsed_time, cpu_time, cum_cpu_time; | |
b445142a | 466 | |
90e19f82 | 467 | LttTime delta; |
b445142a | 468 | |
90e19f82 | 469 | /* FIXME put there in case of a missing update after a state modification */ |
516a8712 | 470 | //void *lasttree = tfcs->cpu_stats->current_events_tree; |
90e19f82 | 471 | //update_event_tree(tfcs); |
516a8712 MD |
472 | //g_assert (lasttree == tfcs->cpu_stats->current_events_tree); |
473 | lttv_attribute_find(tfcs->cpu_stats->current_events_tree, LTTV_STATS_ELAPSED_TIME, | |
90e19f82 | 474 | LTTV_TIME, &elapsed_time); |
d3670e3d | 475 | |
90e19f82 AM |
476 | if(process->state->t != LTTV_STATE_MODE_UNKNOWN) { |
477 | delta = ltt_time_sub(tfcs->parent.parent.timestamp, | |
478 | process->state->entry); | |
479 | } else | |
480 | delta = ltt_time_zero; | |
d3670e3d | 481 | |
90e19f82 | 482 | *(elapsed_time.v_time) = ltt_time_add(*(elapsed_time.v_time), delta); |
b445142a | 483 | |
516a8712 | 484 | lttv_attribute_find(tfcs->cpu_stats->current_events_tree, LTTV_STATS_CPU_TIME, |
90e19f82 | 485 | LTTV_TIME, &cpu_time); |
d3670e3d | 486 | |
90e19f82 AM |
487 | /* if it is a running mode, we must count its cpu time */ |
488 | if(process->state->s == LTTV_STATE_RUN && | |
489 | process->state->t != LTTV_STATE_MODE_UNKNOWN) | |
490 | delta = ltt_time_sub(tfcs->parent.parent.timestamp, | |
491 | process->state->change); | |
492 | else | |
493 | delta = ltt_time_zero; | |
d3670e3d | 494 | |
90e19f82 AM |
495 | *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); |
496 | process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, | |
497 | delta); | |
b49e54b4 | 498 | |
516a8712 | 499 | lttv_attribute_find(tfcs->cpu_stats->current_events_tree, LTTV_STATS_CUMULATIVE_CPU_TIME, |
90e19f82 AM |
500 | LTTV_TIME, &cum_cpu_time); |
501 | *(cum_cpu_time.v_time) = ltt_time_add(*(cum_cpu_time.v_time), | |
502 | process->state->cum_cpu_time); | |
b445142a | 503 | } |
504 | ||
505 | ||
b49e54b4 | 506 | static void after_mode_end(LttvTracefileStats *tfcs) |
507 | { | |
90e19f82 AM |
508 | LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; |
509 | guint cpu = tfcs->parent.cpu; | |
510 | LttvProcessState *process = ts->running_process[cpu]; | |
b49e54b4 | 511 | |
90e19f82 | 512 | LttTime nested_delta; |
b49e54b4 | 513 | |
90e19f82 AM |
514 | nested_delta = process->state->cum_cpu_time; |
515 | process->state->cum_cpu_time = ltt_time_zero; /* For after traceset hook */ | |
b49e54b4 | 516 | |
516a8712 | 517 | update_event_tree(tfcs->cpu_stats); |
b49e54b4 | 518 | |
90e19f82 AM |
519 | process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, |
520 | nested_delta); | |
b49e54b4 | 521 | } |
522 | ||
b445142a | 523 | static gboolean before_syscall_entry(void *hook_data, void *call_data) |
524 | { | |
90e19f82 AM |
525 | mode_change((LttvTracefileStats *)call_data); |
526 | return FALSE; | |
b445142a | 527 | } |
528 | ||
529 | ||
530 | static gboolean after_syscall_entry(void *hook_data, void *call_data) | |
531 | { | |
516a8712 | 532 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 533 | return FALSE; |
b445142a | 534 | } |
535 | ||
536 | ||
89f8741a | 537 | static gboolean before_syscall_exit(void *hook_data, void *call_data) |
b445142a | 538 | { |
90e19f82 AM |
539 | mode_end((LttvTracefileStats *)call_data); |
540 | return FALSE; | |
b445142a | 541 | } |
542 | ||
543 | ||
544 | static gboolean after_syscall_exit(void *hook_data, void *call_data) | |
545 | { | |
90e19f82 AM |
546 | after_mode_end((LttvTracefileStats *)call_data); |
547 | return FALSE; | |
b445142a | 548 | } |
549 | ||
550 | ||
89f8741a | 551 | static gboolean before_trap_entry(void *hook_data, void *call_data) |
b445142a | 552 | { |
90e19f82 AM |
553 | mode_change((LttvTracefileStats *)call_data); |
554 | return FALSE; | |
b445142a | 555 | } |
556 | ||
557 | ||
558 | static gboolean after_trap_entry(void *hook_data, void *call_data) | |
559 | { | |
516a8712 | 560 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 561 | return FALSE; |
b445142a | 562 | } |
563 | ||
564 | ||
89f8741a | 565 | static gboolean before_trap_exit(void *hook_data, void *call_data) |
b445142a | 566 | { |
90e19f82 AM |
567 | mode_end((LttvTracefileStats *)call_data); |
568 | return FALSE; | |
b445142a | 569 | } |
570 | ||
571 | ||
89f8741a | 572 | static gboolean after_trap_exit(void *hook_data, void *call_data) |
b445142a | 573 | { |
90e19f82 AM |
574 | after_mode_end((LttvTracefileStats *)call_data); |
575 | return FALSE; | |
b445142a | 576 | } |
577 | ||
578 | ||
89f8741a | 579 | static gboolean before_irq_entry(void *hook_data, void *call_data) |
b445142a | 580 | { |
90e19f82 AM |
581 | mode_change((LttvTracefileStats *)call_data); |
582 | return FALSE; | |
b445142a | 583 | } |
584 | ||
89f8741a | 585 | static gboolean after_irq_entry(void *hook_data, void *call_data) |
b445142a | 586 | { |
516a8712 | 587 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 588 | return FALSE; |
b445142a | 589 | } |
590 | ||
591 | ||
89f8741a | 592 | static gboolean before_irq_exit(void *hook_data, void *call_data) |
b445142a | 593 | { |
90e19f82 AM |
594 | mode_end((LttvTracefileStats *)call_data); |
595 | return FALSE; | |
b445142a | 596 | } |
597 | ||
598 | ||
89f8741a | 599 | static gboolean after_irq_exit(void *hook_data, void *call_data) |
b445142a | 600 | { |
90e19f82 AM |
601 | after_mode_end((LttvTracefileStats *)call_data); |
602 | return FALSE; | |
b445142a | 603 | } |
604 | ||
605 | ||
89f8741a | 606 | static gboolean before_soft_irq_entry(void *hook_data, void *call_data) |
faf074a3 | 607 | { |
90e19f82 AM |
608 | mode_change((LttvTracefileStats *)call_data); |
609 | return FALSE; | |
faf074a3 | 610 | } |
611 | ||
89f8741a | 612 | static gboolean after_soft_irq_entry(void *hook_data, void *call_data) |
faf074a3 | 613 | { |
516a8712 | 614 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 615 | return FALSE; |
faf074a3 | 616 | } |
617 | ||
89f8741a | 618 | static gboolean before_soft_irq_exit(void *hook_data, void *call_data) |
faf074a3 | 619 | { |
90e19f82 AM |
620 | mode_end((LttvTracefileStats *)call_data); |
621 | return FALSE; | |
faf074a3 | 622 | } |
623 | ||
624 | ||
89f8741a | 625 | static gboolean after_soft_irq_exit(void *hook_data, void *call_data) |
faf074a3 | 626 | { |
90e19f82 AM |
627 | after_mode_end((LttvTracefileStats *)call_data); |
628 | return FALSE; | |
faf074a3 | 629 | } |
630 | ||
89f8741a | 631 | static gboolean before_function_entry(void *hook_data, void *call_data) |
14236daa | 632 | { |
90e19f82 AM |
633 | mode_change((LttvTracefileStats *)call_data); |
634 | return FALSE; | |
14236daa | 635 | } |
636 | ||
89f8741a | 637 | static gboolean after_function_entry(void *hook_data, void *call_data) |
14236daa | 638 | { |
516a8712 | 639 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 640 | return FALSE; |
14236daa | 641 | } |
642 | ||
89f8741a | 643 | static gboolean before_function_exit(void *hook_data, void *call_data) |
14236daa | 644 | { |
90e19f82 AM |
645 | mode_end((LttvTracefileStats *)call_data); |
646 | return FALSE; | |
14236daa | 647 | } |
648 | ||
89f8741a | 649 | static gboolean after_function_exit(void *hook_data, void *call_data) |
14236daa | 650 | { |
90e19f82 AM |
651 | after_mode_end((LttvTracefileStats *)call_data); |
652 | return FALSE; | |
14236daa | 653 | } |
654 | ||
faf074a3 | 655 | |
89f8741a | 656 | static gboolean before_schedchange(void *hook_data, void *call_data) |
b445142a | 657 | { |
90e19f82 | 658 | LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; |
b445142a | 659 | |
90e19f82 AM |
660 | /* compute the time for the process to schedule out */ |
661 | mode_change(tfcs); | |
662 | ||
663 | return FALSE; | |
b49e54b4 | 664 | } |
b445142a | 665 | |
89f8741a | 666 | static gboolean after_schedchange(void *hook_data, void *call_data) |
b49e54b4 | 667 | { |
90e19f82 AM |
668 | LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; |
669 | ||
670 | LttvTraceState *ts = (LttvTraceState*)tfcs->parent.parent.t_context; | |
b49e54b4 | 671 | |
90e19f82 | 672 | LttvProcessState *process; |
b49e54b4 | 673 | |
90e19f82 AM |
674 | /* get the information for the process scheduled in */ |
675 | guint cpu = tfcs->parent.cpu; | |
676 | process = ts->running_process[cpu]; | |
c0cb4d12 | 677 | |
516a8712 | 678 | find_event_tree(tfcs->cpu_stats, process->pid_time, |
90e19f82 AM |
679 | cpu, |
680 | process->current_function, | |
516a8712 MD |
681 | process->state->t, process->state->n, |
682 | &(tfcs->cpu_stats->current_events_tree), | |
683 | &(tfcs->cpu_stats->current_event_types_tree)); | |
b445142a | 684 | |
90e19f82 AM |
685 | /* compute the time waiting for the process to schedule in */ |
686 | mode_change(tfcs); | |
b445142a | 687 | |
90e19f82 | 688 | return FALSE; |
b49e54b4 | 689 | } |
b445142a | 690 | |
89f8741a | 691 | static gboolean process_fork(void *hook_data, void *call_data) |
b445142a | 692 | { |
90e19f82 | 693 | return FALSE; |
b445142a | 694 | } |
695 | ||
89f8741a | 696 | static gboolean process_exit(void *hook_data, void *call_data) |
b445142a | 697 | { |
516a8712 | 698 | update_event_tree(((LttvTracefileStats *)call_data)->cpu_stats); |
90e19f82 | 699 | return FALSE; |
b445142a | 700 | } |
701 | ||
89f8741a | 702 | static gboolean before_enum_process_state(void *hook_data, void *call_data) |
954417fa | 703 | { |
d3670e3d | 704 | #if 0 |
90e19f82 AM |
705 | /* Broken : adds up time in the current process doing the dump */ |
706 | LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; | |
707 | mode_end(tfcs); | |
708 | after_mode_end(tfcs); | |
709 | mode_change(tfcs); | |
d3670e3d | 710 | #endif //0 |
90e19f82 | 711 | return FALSE; |
954417fa | 712 | } |
713 | ||
89f8741a | 714 | static gboolean after_enum_process_state(void *hook_data, void *call_data) |
954417fa | 715 | { |
90e19f82 AM |
716 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
717 | LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; | |
718 | update_trace_event_tree(tcs); | |
719 | return FALSE; | |
d3670e3d | 720 | } |
721 | ||
722 | static gboolean after_statedump_end(void *hook_data, void *call_data) | |
723 | { | |
90e19f82 AM |
724 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
725 | LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; | |
726 | update_trace_event_tree(tcs); | |
727 | return FALSE; | |
954417fa | 728 | } |
729 | ||
89f8741a | 730 | static gboolean process_free(void *hook_data, void *call_data) |
eed2ef37 | 731 | { |
90e19f82 | 732 | return FALSE; |
eed2ef37 | 733 | } |
b445142a | 734 | |
89f8741a | 735 | static gboolean every_event(void *hook_data, void *call_data) |
b445142a | 736 | { |
90e19f82 | 737 | LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; |
b445142a | 738 | |
90e19f82 | 739 | LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); |
eed2ef37 | 740 | |
90e19f82 | 741 | LttvAttributeValue v; |
b445142a | 742 | |
90e19f82 | 743 | struct marker_info *info; |
68003874 | 744 | |
90e19f82 AM |
745 | /* The current branch corresponds to the tracefile/process/interrupt state. |
746 | Statistics are added within it, to count the number of events of this | |
747 | type occuring in this context. A quark has been pre-allocated for each | |
748 | event type and is used as name. */ | |
b445142a | 749 | |
90e19f82 | 750 | info = marker_get_info_from_id(tfcs->parent.parent.tf->mdata, e->event_id); |
68003874 | 751 | |
516a8712 | 752 | lttv_attribute_find(tfcs->cpu_stats->current_event_types_tree, |
90e19f82 AM |
753 | info->name, LTTV_UINT, &v); |
754 | (*(v.v_uint))++; | |
755 | return FALSE; | |
b445142a | 756 | } |
757 | ||
b91e751b | 758 | struct cleanup_state_struct { |
90e19f82 AM |
759 | LttvTraceState *ts; |
760 | LttTime current_time; | |
b91e751b | 761 | }; |
762 | ||
763 | //static void lttv_stats_cleanup_process_state(LttvTraceState *ts, | |
90e19f82 | 764 | // LttvProcessState *process, LttTime current_time) |
b91e751b | 765 | static void lttv_stats_cleanup_process_state(gpointer key, gpointer value, |
90e19f82 AM |
766 | gpointer user_data) |
767 | { | |
768 | struct cleanup_state_struct *cleanup_closure = | |
769 | (struct cleanup_state_struct *)user_data; | |
770 | LttvTraceState *ts = cleanup_closure->ts; | |
771 | LttvProcessState *process = (LttvProcessState *)value; | |
772 | LttTime current_time = cleanup_closure->current_time; | |
773 | LttvTracefileStats **tfs = (LttvTracefileStats **) | |
774 | &g_array_index(ts->parent.tracefiles, LttvTracefileContext*, | |
775 | process->cpu); | |
776 | int cleanup_empty = 0; | |
777 | LttTime nested_delta = ltt_time_zero; | |
778 | ||
779 | /* FIXME : ok, this is a hack. The time is infinite here :( */ | |
780 | //LttTime save_time = (*tfs)->parent.parent.timestamp; | |
781 | //LttTime start, end; | |
782 | //ltt_trace_time_span_get(ts->parent.t, &start, &end); | |
783 | //(*tfs)->parent.parent.timestamp = end; | |
784 | ||
785 | do { | |
786 | if(ltt_time_compare(process->state->cum_cpu_time, ltt_time_zero) != 0) { | |
516a8712 | 787 | find_event_tree((*tfs)->cpu_stats, process->pid_time, |
90e19f82 AM |
788 | process->cpu, |
789 | process->current_function, | |
516a8712 MD |
790 | process->state->t, process->state->n, |
791 | &((*tfs)->cpu_stats->current_events_tree), | |
792 | &((*tfs)->cpu_stats->current_event_types_tree)); | |
90e19f82 AM |
793 | /* Call mode_end only if not at end of trace */ |
794 | if(ltt_time_compare(current_time, ltt_time_infinite) != 0) | |
795 | mode_end(*tfs); | |
796 | nested_delta = process->state->cum_cpu_time; | |
797 | } | |
798 | cleanup_empty = lttv_state_pop_state_cleanup(process, | |
799 | (LttvTracefileState *)*tfs); | |
800 | process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, | |
801 | nested_delta); | |
802 | ||
803 | } while(cleanup_empty != 1); | |
804 | ||
805 | //(*tfs)->parent.parent.timestamp = save_time; | |
b49e54b4 | 806 | } |
807 | ||
d3670e3d | 808 | /* For each cpu, for each of their stacked states, |
b49e54b4 | 809 | * perform sum of needed values. */ |
b91e751b | 810 | static void lttv_stats_cleanup_state(LttvTraceStats *tcs, LttTime current_time) |
b49e54b4 | 811 | { |
90e19f82 AM |
812 | LttvTraceState *ts = (LttvTraceState *)tcs; |
813 | struct cleanup_state_struct cleanup_closure; | |
b91e751b | 814 | #if 0 |
90e19f82 | 815 | guint nb_cpus, i; |
d3670e3d | 816 | |
90e19f82 AM |
817 | nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); |
818 | ||
819 | for(i=0; i<nb_cpus; i++) { | |
820 | lttv_stats_cleanup_process_state(ts, ts->running_process[i], current_time); | |
821 | } | |
b91e751b | 822 | #endif //0 |
90e19f82 AM |
823 | cleanup_closure.ts = ts; |
824 | cleanup_closure.current_time = current_time; | |
825 | g_hash_table_foreach(ts->processes, lttv_stats_cleanup_process_state, | |
826 | &cleanup_closure); | |
827 | } | |
828 | ||
829 | void lttv_stats_sum_trace(LttvTraceStats *self, LttvAttribute *ts_stats, | |
830 | LttTime current_time) | |
831 | { | |
832 | LttvAttribute *sum_container = self->stats; | |
833 | ||
90e19f82 AM |
834 | LttvAttributeValue value; |
835 | ||
836 | LttvAttributeName name; | |
837 | ||
838 | gboolean is_named; | |
839 | ||
840 | unsigned sum; | |
841 | ||
842 | int trace_is_summed; | |
843 | ||
844 | int i, j, k, l, m, nb_process, nb_cpu, nb_mode_type, nb_submode, | |
845 | nb_event_type, nf, nb_functions; | |
846 | ||
847 | LttvAttribute *main_tree, *processes_tree, *process_tree, *cpus_tree, | |
848 | *cpu_tree, *mode_tree, *mode_types_tree, *submodes_tree, | |
849 | *submode_tree, *event_types_tree, *mode_events_tree, | |
850 | *cpu_functions_tree, | |
851 | *function_tree, | |
852 | *function_mode_types_tree, | |
853 | *trace_cpu_tree; | |
854 | ||
855 | ||
856 | main_tree = sum_container; | |
857 | ||
858 | lttv_attribute_find(sum_container, | |
859 | LTTV_STATS_SUMMED, | |
860 | LTTV_UINT, &value); | |
861 | trace_is_summed = *(value.v_uint); | |
862 | *(value.v_uint) = 1; | |
863 | ||
864 | /* First cleanup the state : sum all stalled information (never ending | |
865 | * states). */ | |
866 | if(!trace_is_summed) | |
867 | lttv_stats_cleanup_state(self, current_time); | |
868 | ||
869 | processes_tree = lttv_attribute_find_subdir(main_tree, | |
870 | LTTV_STATS_PROCESSES); | |
871 | nb_process = lttv_attribute_get_number(processes_tree); | |
872 | ||
873 | for(i = 0 ; i < nb_process ; i++) { | |
e865422c | 874 | lttv_attribute_get(processes_tree, i, &name, &value, &is_named); |
90e19f82 AM |
875 | process_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); |
876 | ||
877 | cpus_tree = lttv_attribute_find_subdir(process_tree, LTTV_STATS_CPU); | |
878 | nb_cpu = lttv_attribute_get_number(cpus_tree); | |
879 | ||
880 | for(j = 0 ; j < nb_cpu ; j++) { | |
e865422c | 881 | lttv_attribute_get(cpus_tree, j, &name, &value, &is_named); |
90e19f82 AM |
882 | cpu_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); |
883 | ||
884 | trace_cpu_tree = lttv_attribute_find_subdir(main_tree, | |
885 | LTTV_STATS_CPU); | |
886 | trace_cpu_tree = lttv_attribute_find_subdir_unnamed(trace_cpu_tree, name); | |
887 | cpu_functions_tree = lttv_attribute_find_subdir(cpu_tree, | |
888 | LTTV_STATS_FUNCTIONS); | |
889 | nb_functions = lttv_attribute_get_number(cpu_functions_tree); | |
890 | ||
891 | for(nf=0; nf < nb_functions; nf++) { | |
e865422c | 892 | lttv_attribute_get(cpu_functions_tree, nf, &name, &value, |
90e19f82 AM |
893 | &is_named); |
894 | function_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); | |
895 | function_mode_types_tree = lttv_attribute_find_subdir(function_tree, | |
896 | LTTV_STATS_MODE_TYPES); | |
897 | nb_mode_type = lttv_attribute_get_number(function_mode_types_tree); | |
898 | for(k = 0 ; k < nb_mode_type ; k++) { | |
e865422c | 899 | lttv_attribute_get(function_mode_types_tree, k, &name, |
90e19f82 AM |
900 | &value, &is_named); |
901 | mode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); | |
902 | ||
903 | submodes_tree = lttv_attribute_find_subdir(mode_tree, | |
904 | LTTV_STATS_SUBMODES); | |
905 | mode_events_tree = lttv_attribute_find_subdir(mode_tree, | |
906 | LTTV_STATS_EVENTS); | |
907 | mode_types_tree = lttv_attribute_find_subdir(mode_tree, | |
908 | LTTV_STATS_MODE_TYPES); | |
909 | ||
910 | nb_submode = lttv_attribute_get_number(submodes_tree); | |
911 | ||
912 | for(l = 0 ; l < nb_submode ; l++) { | |
e865422c | 913 | lttv_attribute_get(submodes_tree, l, &name, &value, |
90e19f82 AM |
914 | &is_named); |
915 | submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); | |
916 | ||
917 | event_types_tree = lttv_attribute_find_subdir(submode_tree, | |
918 | LTTV_STATS_EVENT_TYPES); | |
919 | nb_event_type = lttv_attribute_get_number(event_types_tree); | |
920 | ||
921 | sum = 0; | |
922 | for(m = 0 ; m < nb_event_type ; m++) { | |
e865422c | 923 | lttv_attribute_get(event_types_tree, m, &name, |
90e19f82 AM |
924 | &value, &is_named); |
925 | sum += *(value.v_uint); | |
926 | } | |
927 | lttv_attribute_find(submode_tree, LTTV_STATS_EVENTS_COUNT, | |
928 | LTTV_UINT, &value); | |
929 | *(value.v_uint) = sum; | |
930 | ||
e865422c | 931 | lttv_attribute_get(submodes_tree, l, &name, &value, |
90e19f82 AM |
932 | &is_named); |
933 | submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); | |
934 | if(!trace_is_summed) { | |
935 | lttv_attribute_recursive_add(mode_events_tree, event_types_tree); | |
936 | lttv_attribute_recursive_add(mode_types_tree, submode_tree); | |
937 | } | |
938 | } | |
939 | if(!trace_is_summed) { | |
940 | lttv_attribute_recursive_add(function_tree, mode_types_tree); | |
941 | } | |
942 | } | |
943 | if(!trace_is_summed) { | |
944 | lttv_attribute_recursive_add(cpu_tree, function_tree); | |
945 | lttv_attribute_recursive_add(process_tree, function_tree); | |
946 | lttv_attribute_recursive_add(trace_cpu_tree, function_tree); | |
947 | lttv_attribute_recursive_add(main_tree, function_tree); | |
948 | } | |
949 | lttv_attribute_recursive_add(ts_stats, function_tree); | |
950 | } | |
951 | } | |
952 | } | |
f95bc830 | 953 | } |
954 | ||
955 | ||
d3e01c7a | 956 | gboolean lttv_stats_sum_traceset_hook(void *hook_data, void *call_data) |
957 | { | |
90e19f82 AM |
958 | struct sum_traceset_closure *closure = |
959 | (struct sum_traceset_closure *)call_data; | |
960 | lttv_stats_sum_traceset(closure->tss, closure->current_time); | |
961 | return 0; | |
d3e01c7a | 962 | } |
963 | ||
90e19f82 | 964 | void lttv_stats_sum_traceset(LttvTracesetStats *self, LttTime current_time) |
f95bc830 | 965 | { |
90e19f82 AM |
966 | LttvTraceset *traceset = self->parent.parent.ts; |
967 | LttvAttribute *sum_container = self->stats; | |
f95bc830 | 968 | |
90e19f82 | 969 | LttvTraceStats *tcs; |
f95bc830 | 970 | |
90e19f82 | 971 | int i, nb_trace; |
f95bc830 | 972 | |
90e19f82 | 973 | LttvAttributeValue value; |
f95bc830 | 974 | |
90e19f82 AM |
975 | lttv_attribute_find(sum_container, LTTV_STATS_SUMMED, |
976 | LTTV_UINT, &value); | |
977 | if(*(value.v_uint) != 0) return; | |
978 | *(value.v_uint) = 1; | |
f95bc830 | 979 | |
90e19f82 | 980 | nb_trace = lttv_traceset_number(traceset); |
f95bc830 | 981 | |
90e19f82 AM |
982 | for(i = 0 ; i < nb_trace ; i++) { |
983 | tcs = (LttvTraceStats *)(self->parent.parent.traces[i]); | |
984 | lttv_stats_sum_trace(tcs, self->stats, current_time); | |
985 | // lttv_attribute_recursive_add(sum_container, tcs->stats); | |
986 | } | |
b445142a | 987 | } |
988 | ||
989 | ||
d3e01c7a | 990 | // Hook wrapper. call_data is a traceset context. |
00e74b69 | 991 | gboolean lttv_stats_hook_add_event_hooks(void *hook_data, void *call_data) |
d3e01c7a | 992 | { |
90e19f82 | 993 | LttvTracesetStats *tss = (LttvTracesetStats*)call_data; |
d3e01c7a | 994 | |
90e19f82 | 995 | lttv_stats_add_event_hooks(tss); |
d3e01c7a | 996 | |
90e19f82 | 997 | return 0; |
d3e01c7a | 998 | } |
999 | ||
00e74b69 | 1000 | void lttv_stats_add_event_hooks(LttvTracesetStats *self) |
b445142a | 1001 | { |
90e19f82 AM |
1002 | LttvTraceset *traceset = self->parent.parent.ts; |
1003 | ||
1004 | guint i, j, k, nb_trace, nb_tracefile; | |
1005 | ||
1006 | LttvTraceStats *ts; | |
1007 | ||
1008 | LttvTracefileStats *tfs; | |
1009 | ||
1010 | GArray *hooks, *before_hooks, *after_hooks; | |
1011 | ||
1012 | LttvTraceHook *th; | |
1013 | ||
1014 | LttvAttributeValue val; | |
1015 | ||
1016 | nb_trace = lttv_traceset_number(traceset); | |
1017 | for(i = 0 ; i < nb_trace ; i++) { | |
1018 | ts = (LttvTraceStats *)self->parent.parent.traces[i]; | |
1019 | ||
1020 | /* Find the eventtype id for the following events and register the | |
1021 | associated by id hooks. */ | |
1022 | ||
1023 | hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 12); | |
1024 | ||
1025 | lttv_trace_find_hook(ts->parent.parent.t, | |
1026 | LTT_CHANNEL_KERNEL, | |
1027 | LTT_EVENT_SYSCALL_ENTRY, | |
1028 | FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), | |
1029 | before_syscall_entry, NULL, | |
1030 | &hooks); | |
1031 | ||
1032 | lttv_trace_find_hook(ts->parent.parent.t, | |
1033 | LTT_CHANNEL_KERNEL, | |
1034 | LTT_EVENT_SYSCALL_EXIT, | |
1035 | NULL, | |
1036 | before_syscall_exit, NULL, | |
1037 | &hooks); | |
1038 | ||
1039 | lttv_trace_find_hook(ts->parent.parent.t, | |
1040 | LTT_CHANNEL_KERNEL, | |
1041 | LTT_EVENT_TRAP_ENTRY, | |
1042 | FIELD_ARRAY(LTT_FIELD_TRAP_ID), | |
1043 | before_trap_entry, NULL, | |
1044 | &hooks); | |
1045 | ||
1046 | lttv_trace_find_hook(ts->parent.parent.t, | |
1047 | LTT_CHANNEL_KERNEL, | |
1048 | LTT_EVENT_TRAP_EXIT, | |
1049 | NULL, | |
1050 | before_trap_exit, NULL, | |
1051 | &hooks); | |
1052 | ||
1053 | lttv_trace_find_hook(ts->parent.parent.t, | |
1054 | LTT_CHANNEL_KERNEL, | |
1055 | LTT_EVENT_IRQ_ENTRY, | |
1056 | FIELD_ARRAY(LTT_FIELD_IRQ_ID), | |
1057 | before_irq_entry, NULL, | |
1058 | &hooks); | |
1059 | ||
1060 | lttv_trace_find_hook(ts->parent.parent.t, | |
1061 | LTT_CHANNEL_KERNEL, | |
1062 | LTT_EVENT_IRQ_EXIT, | |
1063 | NULL, | |
1064 | before_irq_exit, NULL, | |
1065 | &hooks); | |
1066 | ||
1067 | lttv_trace_find_hook(ts->parent.parent.t, | |
1068 | LTT_CHANNEL_KERNEL, | |
1069 | LTT_EVENT_SOFT_IRQ_ENTRY, | |
1070 | FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), | |
1071 | before_soft_irq_entry, NULL, | |
1072 | &hooks); | |
1073 | ||
1074 | lttv_trace_find_hook(ts->parent.parent.t, | |
1075 | LTT_CHANNEL_KERNEL, | |
1076 | LTT_EVENT_SOFT_IRQ_EXIT, | |
1077 | NULL, | |
1078 | before_soft_irq_exit, NULL, | |
1079 | &hooks); | |
1080 | ||
1081 | lttv_trace_find_hook(ts->parent.parent.t, | |
1082 | LTT_CHANNEL_KERNEL, | |
1083 | LTT_EVENT_SCHED_SCHEDULE, | |
1084 | FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), | |
1085 | before_schedchange, NULL, | |
1086 | &hooks); | |
1087 | ||
1088 | lttv_trace_find_hook(ts->parent.parent.t, | |
1089 | LTT_CHANNEL_USERSPACE, | |
1090 | LTT_EVENT_FUNCTION_ENTRY, | |
1091 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), | |
1092 | before_function_entry, NULL, | |
1093 | &hooks); | |
1094 | ||
1095 | lttv_trace_find_hook(ts->parent.parent.t, | |
1096 | LTT_CHANNEL_USERSPACE, | |
1097 | LTT_EVENT_FUNCTION_EXIT, | |
1098 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), | |
1099 | before_function_exit, NULL, | |
1100 | &hooks); | |
1101 | ||
1102 | /* statedump-related hooks */ | |
1103 | lttv_trace_find_hook(ts->parent.parent.t, | |
1104 | LTT_CHANNEL_TASK_STATE, | |
1105 | LTT_EVENT_PROCESS_STATE, | |
1106 | FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), | |
1107 | before_enum_process_state, NULL, | |
1108 | &hooks); | |
1109 | ||
1110 | before_hooks = hooks; | |
1111 | ||
1112 | hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 16); | |
1113 | ||
1114 | lttv_trace_find_hook(ts->parent.parent.t, | |
1115 | LTT_CHANNEL_KERNEL, | |
1116 | LTT_EVENT_SYSCALL_ENTRY, | |
1117 | FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), | |
1118 | after_syscall_entry, NULL, | |
1119 | &hooks); | |
1120 | ||
1121 | lttv_trace_find_hook(ts->parent.parent.t, | |
1122 | LTT_CHANNEL_KERNEL, | |
1123 | LTT_EVENT_SYSCALL_EXIT, | |
1124 | NULL, | |
1125 | after_syscall_exit, NULL, | |
1126 | &hooks); | |
1127 | ||
1128 | lttv_trace_find_hook(ts->parent.parent.t, | |
1129 | LTT_CHANNEL_KERNEL, | |
1130 | LTT_EVENT_TRAP_ENTRY, | |
1131 | FIELD_ARRAY(LTT_FIELD_TRAP_ID), | |
1132 | after_trap_entry, NULL, | |
1133 | &hooks); | |
1134 | ||
1135 | lttv_trace_find_hook(ts->parent.parent.t, | |
1136 | LTT_CHANNEL_KERNEL, | |
1137 | LTT_EVENT_TRAP_EXIT, | |
1138 | NULL, | |
1139 | after_trap_exit, NULL, | |
1140 | &hooks); | |
1141 | ||
1142 | lttv_trace_find_hook(ts->parent.parent.t, | |
1143 | LTT_CHANNEL_KERNEL, | |
1144 | LTT_EVENT_IRQ_ENTRY, | |
1145 | FIELD_ARRAY(LTT_FIELD_IRQ_ID), | |
1146 | after_irq_entry, NULL, | |
1147 | &hooks); | |
1148 | ||
1149 | lttv_trace_find_hook(ts->parent.parent.t, | |
1150 | LTT_CHANNEL_KERNEL, | |
1151 | LTT_EVENT_IRQ_EXIT, | |
1152 | NULL, | |
1153 | after_irq_exit, NULL, | |
1154 | &hooks); | |
1155 | ||
1156 | lttv_trace_find_hook(ts->parent.parent.t, | |
1157 | LTT_CHANNEL_KERNEL, | |
1158 | LTT_EVENT_SOFT_IRQ_ENTRY, | |
1159 | FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), | |
1160 | after_soft_irq_entry, NULL, | |
1161 | &hooks); | |
1162 | ||
1163 | lttv_trace_find_hook(ts->parent.parent.t, | |
1164 | LTT_CHANNEL_KERNEL, | |
1165 | LTT_EVENT_SOFT_IRQ_EXIT, | |
1166 | NULL, | |
1167 | after_soft_irq_exit, NULL, | |
1168 | &hooks); | |
1169 | ||
1170 | lttv_trace_find_hook(ts->parent.parent.t, | |
1171 | LTT_CHANNEL_KERNEL, | |
1172 | LTT_EVENT_SCHED_SCHEDULE, | |
1173 | FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), | |
1174 | after_schedchange, NULL, | |
1175 | &hooks); | |
1176 | ||
1177 | lttv_trace_find_hook(ts->parent.parent.t, | |
1178 | LTT_CHANNEL_KERNEL, | |
1179 | LTT_EVENT_PROCESS_FORK, | |
1180 | FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID), | |
1181 | process_fork, NULL, | |
1182 | &hooks); | |
1183 | ||
1184 | lttv_trace_find_hook(ts->parent.parent.t, | |
1185 | LTT_CHANNEL_KERNEL, | |
1186 | LTT_EVENT_PROCESS_EXIT, | |
1187 | FIELD_ARRAY(LTT_FIELD_PID), | |
1188 | process_exit, NULL, | |
1189 | &hooks); | |
1190 | ||
1191 | lttv_trace_find_hook(ts->parent.parent.t, | |
1192 | LTT_CHANNEL_KERNEL, | |
1193 | LTT_EVENT_PROCESS_FREE, | |
1194 | FIELD_ARRAY(LTT_FIELD_PID), | |
1195 | process_free, NULL, | |
1196 | &hooks); | |
1197 | ||
1198 | lttv_trace_find_hook(ts->parent.parent.t, | |
1199 | LTT_CHANNEL_USERSPACE, | |
1200 | LTT_EVENT_FUNCTION_ENTRY, | |
1201 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), | |
1202 | after_function_entry, NULL, | |
1203 | &hooks); | |
1204 | ||
1205 | lttv_trace_find_hook(ts->parent.parent.t, | |
1206 | LTT_CHANNEL_USERSPACE, | |
1207 | LTT_EVENT_FUNCTION_EXIT, | |
1208 | FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), | |
1209 | after_function_exit, NULL, | |
1210 | &hooks); | |
1211 | ||
1212 | /* statedump-related hooks */ | |
1213 | lttv_trace_find_hook(ts->parent.parent.t, | |
1214 | LTT_CHANNEL_TASK_STATE, | |
1215 | LTT_EVENT_PROCESS_STATE, | |
1216 | FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), | |
1217 | after_enum_process_state, NULL, | |
1218 | &hooks); | |
1219 | ||
1220 | lttv_trace_find_hook(ts->parent.parent.t, | |
1221 | LTT_CHANNEL_GLOBAL_STATE, | |
1222 | LTT_EVENT_STATEDUMP_END, | |
1223 | NULL, | |
1224 | after_statedump_end, NULL, | |
1225 | &hooks); | |
1226 | ||
1227 | after_hooks = hooks; | |
1228 | ||
1229 | /* Add these hooks to each event_by_id hooks list */ | |
1230 | ||
1231 | nb_tracefile = ts->parent.parent.tracefiles->len; | |
1232 | ||
1233 | for(j = 0 ; j < nb_tracefile ; j++) { | |
1234 | tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, | |
1235 | LttvTracefileContext*, j)); | |
1236 | lttv_hooks_add(tfs->parent.parent.event, every_event, NULL, | |
1237 | LTTV_PRIO_DEFAULT); | |
1238 | ||
1239 | for(k = 0 ; k < before_hooks->len ; k++) { | |
1240 | th = &g_array_index(before_hooks, LttvTraceHook, k); | |
1241 | if (th->mdata == tfs->parent.parent.tf->mdata) | |
1242 | lttv_hooks_add( | |
1243 | lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), | |
1244 | th->h, | |
1245 | th, | |
1246 | LTTV_PRIO_STATS_BEFORE_STATE); | |
1247 | } | |
1248 | for(k = 0 ; k < after_hooks->len ; k++) { | |
1249 | th = &g_array_index(after_hooks, LttvTraceHook, k); | |
1250 | if (th->mdata == tfs->parent.parent.tf->mdata) | |
1251 | lttv_hooks_add( | |
1252 | lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), | |
1253 | th->h, | |
1254 | th, | |
1255 | LTTV_PRIO_STATS_AFTER_STATE); | |
1256 | } | |
1257 | } | |
1258 | lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, | |
1259 | LTTV_POINTER, &val); | |
1260 | *(val.v_pointer) = before_hooks; | |
1261 | lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, | |
1262 | LTTV_POINTER, &val); | |
1263 | *(val.v_pointer) = after_hooks; | |
1264 | } | |
b445142a | 1265 | } |
1266 | ||
d3e01c7a | 1267 | // Hook wrapper. call_data is a traceset context. |
00e74b69 | 1268 | gboolean lttv_stats_hook_remove_event_hooks(void *hook_data, void *call_data) |
d3e01c7a | 1269 | { |
90e19f82 | 1270 | LttvTracesetStats *tss = (LttvTracesetStats*)call_data; |
d3e01c7a | 1271 | |
90e19f82 | 1272 | lttv_stats_remove_event_hooks(tss); |
d3e01c7a | 1273 | |
90e19f82 | 1274 | return 0; |
d3e01c7a | 1275 | } |
b445142a | 1276 | |
00e74b69 | 1277 | void lttv_stats_remove_event_hooks(LttvTracesetStats *self) |
b445142a | 1278 | { |
90e19f82 AM |
1279 | LttvTraceset *traceset = self->parent.parent.ts; |
1280 | ||
1281 | guint i, j, k, nb_trace, nb_tracefile; | |
b445142a | 1282 | |
90e19f82 | 1283 | LttvTraceStats *ts; |
b445142a | 1284 | |
90e19f82 | 1285 | LttvTracefileStats *tfs; |
b445142a | 1286 | |
90e19f82 | 1287 | GArray *before_hooks, *after_hooks; |
b445142a | 1288 | |
90e19f82 | 1289 | LttvTraceHook *th; |
b445142a | 1290 | |
90e19f82 | 1291 | LttvAttributeValue val; |
b445142a | 1292 | |
90e19f82 AM |
1293 | nb_trace = lttv_traceset_number(traceset); |
1294 | for(i = 0 ; i < nb_trace ; i++) { | |
1295 | ts = (LttvTraceStats*)self->parent.parent.traces[i]; | |
1296 | lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, | |
1297 | LTTV_POINTER, &val); | |
1298 | before_hooks = *(val.v_pointer); | |
1299 | lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, | |
1300 | LTTV_POINTER, &val); | |
1301 | after_hooks = *(val.v_pointer); | |
b445142a | 1302 | |
90e19f82 | 1303 | /* Remove these hooks from each event_by_id hooks list */ |
b445142a | 1304 | |
90e19f82 | 1305 | nb_tracefile = ts->parent.parent.tracefiles->len; |
b445142a | 1306 | |
90e19f82 AM |
1307 | for(j = 0 ; j < nb_tracefile ; j++) { |
1308 | tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, | |
1309 | LttvTracefileContext*, j)); | |
1310 | lttv_hooks_remove_data(tfs->parent.parent.event, every_event, | |
1311 | NULL); | |
b445142a | 1312 | |
90e19f82 AM |
1313 | for(k = 0 ; k < before_hooks->len ; k++) { |
1314 | th = &g_array_index(before_hooks, LttvTraceHook, k); | |
1315 | if (th->mdata == tfs->parent.parent.tf->mdata) | |
1316 | lttv_hooks_remove_data( | |
1317 | lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), | |
1318 | th->h, | |
1319 | th); | |
1320 | } | |
1321 | for(k = 0 ; k < after_hooks->len ; k++) { | |
1322 | th = &g_array_index(after_hooks, LttvTraceHook, k); | |
1323 | if (th->mdata == tfs->parent.parent.tf->mdata) | |
1324 | lttv_hooks_remove_data( | |
1325 | lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), | |
1326 | th->h, | |
1327 | th); | |
b445142a | 1328 | |
90e19f82 AM |
1329 | } |
1330 | } | |
1331 | g_debug("lttv_stats_remove_event_hooks()"); | |
1332 | lttv_trace_hook_remove_all(&before_hooks); | |
1333 | lttv_trace_hook_remove_all(&after_hooks); | |
1334 | g_array_free(before_hooks, TRUE); | |
1335 | g_array_free(after_hooks, TRUE); | |
1336 | } | |
9f797243 | 1337 | } |
08b1c66e | 1338 | |
1339 | ||
1340 | static void module_init() | |
1341 | { | |
90e19f82 AM |
1342 | LTTV_STATS_PROCESS_UNKNOWN = g_quark_from_string("unknown process"); |
1343 | LTTV_STATS_PROCESSES = g_quark_from_string("processes"); | |
1344 | LTTV_STATS_CPU = g_quark_from_string("cpu"); | |
1345 | LTTV_STATS_MODE_TYPES = g_quark_from_string("mode_types"); | |
1346 | LTTV_STATS_MODES = g_quark_from_string("modes"); | |
1347 | LTTV_STATS_SUBMODES = g_quark_from_string("submodes"); | |
1348 | LTTV_STATS_FUNCTIONS = g_quark_from_string("functions"); | |
1349 | LTTV_STATS_EVENT_TYPES = g_quark_from_string("event_types"); | |
1350 | LTTV_STATS_CPU_TIME = g_quark_from_string("cpu time"); | |
1351 | LTTV_STATS_CUMULATIVE_CPU_TIME = g_quark_from_string("cumulative cpu time (includes nested routines and modes)"); | |
1352 | LTTV_STATS_ELAPSED_TIME = g_quark_from_string("elapsed time (includes per process waiting time)"); | |
1353 | LTTV_STATS_EVENTS = g_quark_from_string("events"); | |
1354 | LTTV_STATS_EVENTS_COUNT = g_quark_from_string("events count"); | |
1355 | LTTV_STATS_BEFORE_HOOKS = g_quark_from_string("saved stats before hooks"); | |
1356 | LTTV_STATS_AFTER_HOOKS = g_quark_from_string("saved stats after hooks"); | |
1357 | LTTV_STATS_USE_COUNT = g_quark_from_string("stats_use_count"); | |
1358 | LTTV_STATS = g_quark_from_string("statistics"); | |
90e19f82 | 1359 | LTTV_STATS_SUMMED = g_quark_from_string("statistics summed"); |
08b1c66e | 1360 | } |
1361 | ||
1362 | static void module_destroy() | |
1363 | { | |
1364 | } | |
1365 | ||
1366 | ||
1367 | LTTV_MODULE("stats", "Compute processes statistics", \ | |
90e19f82 AM |
1368 | "Accumulate statistics for event types, processes and CPUs", \ |
1369 | module_init, module_destroy, "state"); | |
f95bc830 | 1370 | |
1371 | /* Change the places where stats are called (create/read/write stats) | |
1372 | ||
1373 | Check for options in batchtest.c to reduce writing and see what tests are | |
1374 | best candidates for performance analysis. Once OK, commit, move to main | |
1375 | and run tests. Update the gui for statistics. */ |