| 1 | |
| 2 | #include <lttv/processTrace.h> |
| 3 | #include <ltt/event.h> |
| 4 | #include <ltt/facility.h> |
| 5 | |
| 6 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts) |
| 7 | { |
| 8 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts); |
| 9 | } |
| 10 | |
| 11 | |
| 12 | void lttv_context_fini(LttvTracesetContext *self) |
| 13 | { |
| 14 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self); |
| 15 | } |
| 16 | |
| 17 | |
| 18 | LttvTracesetContext * |
| 19 | lttv_context_new_traceset_context(LttvTracesetContext *self) |
| 20 | { |
| 21 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | LttvTraceContext * |
| 28 | lttv_context_new_trace_context(LttvTracesetContext *self) |
| 29 | { |
| 30 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | LttvTracefileContext * |
| 35 | lttv_context_new_tracefile_context(LttvTracesetContext *self) |
| 36 | { |
| 37 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
| 38 | } |
| 39 | |
| 40 | /**************************************************************************** |
| 41 | * lttv_traceset_context_compute_time_span |
| 42 | * |
| 43 | * Keep the Time_Span is sync with on the fly addition and removal of traces |
| 44 | * in a trace set. It must be called each time a trace is added/removed from |
| 45 | * the traceset. It could be more efficient to call it only once a bunch |
| 46 | * of traces are loaded, but the calculation is not long, so it's not |
| 47 | * critical. |
| 48 | * |
| 49 | * Author : Xang Xiu Yang |
| 50 | * Imported from gtkTraceSet.c by Mathieu Desnoyers |
| 51 | ***************************************************************************/ |
| 52 | static void lttv_traceset_context_compute_time_span( |
| 53 | LttvTracesetContext *self, |
| 54 | TimeInterval *Time_Span) |
| 55 | { |
| 56 | LttvTraceset * traceset = self->ts; |
| 57 | int numTraces = lttv_traceset_number(traceset); |
| 58 | int i; |
| 59 | LttTime s, e; |
| 60 | LttvTraceContext *tc; |
| 61 | LttTrace * trace; |
| 62 | |
| 63 | for(i=0; i<numTraces;i++){ |
| 64 | tc = self->traces[i]; |
| 65 | trace = tc->t; |
| 66 | |
| 67 | ltt_trace_time_span_get(trace, &s, &e); |
| 68 | |
| 69 | if(i==0){ |
| 70 | Time_Span->startTime = s; |
| 71 | Time_Span->endTime = e; |
| 72 | }else{ |
| 73 | if(s.tv_sec < Time_Span->startTime.tv_sec || |
| 74 | (s.tv_sec == Time_Span->startTime.tv_sec |
| 75 | && s.tv_nsec < Time_Span->startTime.tv_nsec)) |
| 76 | Time_Span->startTime = s; |
| 77 | if(e.tv_sec > Time_Span->endTime.tv_sec || |
| 78 | (e.tv_sec == Time_Span->endTime.tv_sec && |
| 79 | e.tv_nsec > Time_Span->endTime.tv_nsec)) |
| 80 | Time_Span->endTime = e; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | static void |
| 87 | init(LttvTracesetContext *self, LttvTraceset *ts) |
| 88 | { |
| 89 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
| 90 | |
| 91 | LttvTraceContext *tc; |
| 92 | |
| 93 | LttvTracefileContext *tfc; |
| 94 | |
| 95 | nb_trace = lttv_traceset_number(ts); |
| 96 | self->ts = ts; |
| 97 | self->traces = g_new(LttvTraceContext *, nb_trace); |
| 98 | self->before = lttv_hooks_new(); |
| 99 | self->after = lttv_hooks_new(); |
| 100 | self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
| 101 | for(i = 0 ; i < nb_trace ; i++) { |
| 102 | tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
| 103 | self->traces[i] = tc; |
| 104 | |
| 105 | tc->ts_context = self; |
| 106 | tc->index = i; |
| 107 | tc->t = lttv_traceset_get(ts, i); |
| 108 | tc->check = lttv_hooks_new(); |
| 109 | tc->before = lttv_hooks_new(); |
| 110 | tc->after = lttv_hooks_new(); |
| 111 | tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
| 112 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
| 113 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
| 114 | nb_tracefile = nb_control + nb_per_cpu; |
| 115 | tc->control_tracefiles = g_new(LttvTracefileContext *, nb_control); |
| 116 | tc->per_cpu_tracefiles = g_new(LttvTracefileContext *, nb_per_cpu); |
| 117 | |
| 118 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 119 | tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
| 120 | if(j < nb_control) { |
| 121 | tc->control_tracefiles[j] = tfc; |
| 122 | tfc->control = TRUE; |
| 123 | tfc->index = j; |
| 124 | tfc->tf = ltt_trace_control_tracefile_get(tc->t, j); |
| 125 | } |
| 126 | else { |
| 127 | tc->per_cpu_tracefiles[j - nb_control] = tfc; |
| 128 | tfc->control = FALSE; |
| 129 | tfc->index = j - nb_control; |
| 130 | tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control); |
| 131 | } |
| 132 | tfc->t_context = tc; |
| 133 | tfc->check = lttv_hooks_new(); |
| 134 | tfc->before = lttv_hooks_new(); |
| 135 | tfc->after = lttv_hooks_new(); |
| 136 | tfc->check_event = lttv_hooks_new(); |
| 137 | tfc->before_event = lttv_hooks_new(); |
| 138 | tfc->before_event_by_id = lttv_hooks_by_id_new(); |
| 139 | tfc->after_event = lttv_hooks_new(); |
| 140 | tfc->after_event_by_id = lttv_hooks_by_id_new(); |
| 141 | tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
| 142 | } |
| 143 | } |
| 144 | self->Time_Span = g_new(TimeInterval,1); |
| 145 | lttv_traceset_context_compute_time_span(self, self->Time_Span); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | void fini(LttvTracesetContext *self) |
| 150 | { |
| 151 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
| 152 | |
| 153 | LttvTraceContext *tc; |
| 154 | |
| 155 | LttvTracefileContext *tfc; |
| 156 | |
| 157 | LttvTraceset *ts = self->ts; |
| 158 | |
| 159 | g_free(self->Time_Span); |
| 160 | |
| 161 | lttv_hooks_destroy(self->before); |
| 162 | lttv_hooks_destroy(self->after); |
| 163 | //FIXME : segfault |
| 164 | // g_object_unref(self->a); |
| 165 | |
| 166 | nb_trace = lttv_traceset_number(ts); |
| 167 | |
| 168 | for(i = 0 ; i < nb_trace ; i++) { |
| 169 | tc = self->traces[i]; |
| 170 | |
| 171 | lttv_hooks_destroy(tc->check); |
| 172 | lttv_hooks_destroy(tc->before); |
| 173 | lttv_hooks_destroy(tc->after); |
| 174 | g_object_unref(tc->a); |
| 175 | |
| 176 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
| 177 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
| 178 | nb_tracefile = nb_control + nb_per_cpu; |
| 179 | |
| 180 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 181 | if(j < nb_control) tfc = tc->control_tracefiles[j]; |
| 182 | else tfc = tc->per_cpu_tracefiles[j - nb_control]; |
| 183 | |
| 184 | lttv_hooks_destroy(tfc->check); |
| 185 | lttv_hooks_destroy(tfc->before); |
| 186 | lttv_hooks_destroy(tfc->after); |
| 187 | lttv_hooks_destroy(tfc->check_event); |
| 188 | lttv_hooks_destroy(tfc->before_event); |
| 189 | lttv_hooks_by_id_destroy(tfc->before_event_by_id); |
| 190 | lttv_hooks_destroy(tfc->after_event); |
| 191 | lttv_hooks_by_id_destroy(tfc->after_event_by_id); |
| 192 | g_object_unref(tfc->a); |
| 193 | g_object_unref(tfc); |
| 194 | } |
| 195 | g_free(tc->control_tracefiles); |
| 196 | g_free(tc->per_cpu_tracefiles); |
| 197 | g_object_unref(tc); |
| 198 | } |
| 199 | g_free(self->traces); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
| 204 | LttvHooks *before_traceset, |
| 205 | LttvHooks *after_traceset, |
| 206 | LttvHooks *check_trace, |
| 207 | LttvHooks *before_trace, |
| 208 | LttvHooks *after_trace, |
| 209 | LttvHooks *check_tracefile, |
| 210 | LttvHooks *before_tracefile, |
| 211 | LttvHooks *after_tracefile, |
| 212 | LttvHooks *check_event, |
| 213 | LttvHooks *before_event, |
| 214 | LttvHooks *after_event) |
| 215 | { |
| 216 | LttvTraceset *ts = self->ts; |
| 217 | |
| 218 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
| 219 | |
| 220 | LttvTraceContext *tc; |
| 221 | |
| 222 | LttvTracefileContext *tfc; |
| 223 | |
| 224 | void *hook_data; |
| 225 | |
| 226 | lttv_hooks_add_list(self->before, before_traceset); |
| 227 | lttv_hooks_add_list(self->after, after_traceset); |
| 228 | nb_trace = lttv_traceset_number(ts); |
| 229 | |
| 230 | for(i = 0 ; i < nb_trace ; i++) { |
| 231 | tc = self->traces[i]; |
| 232 | lttv_hooks_add_list(tc->check, check_trace); |
| 233 | lttv_hooks_add_list(tc->before, before_trace); |
| 234 | lttv_hooks_add_list(tc->after, after_trace); |
| 235 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
| 236 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
| 237 | nb_tracefile = nb_control + nb_per_cpu; |
| 238 | |
| 239 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 240 | if(j < nb_control) { |
| 241 | tfc = tc->control_tracefiles[j]; |
| 242 | } |
| 243 | else { |
| 244 | tfc = tc->per_cpu_tracefiles[j-nb_control]; |
| 245 | } |
| 246 | lttv_hooks_add_list(tfc->check, check_tracefile); |
| 247 | lttv_hooks_add_list(tfc->before, before_tracefile); |
| 248 | lttv_hooks_add_list(tfc->after, after_tracefile); |
| 249 | lttv_hooks_add_list(tfc->check_event, check_event); |
| 250 | lttv_hooks_add_list(tfc->before_event, before_event); |
| 251 | lttv_hooks_add_list(tfc->after_event, after_event); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | |
| 257 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
| 258 | LttvHooks *before_traceset, |
| 259 | LttvHooks *after_traceset, |
| 260 | LttvHooks *check_trace, |
| 261 | LttvHooks *before_trace, |
| 262 | LttvHooks *after_trace, |
| 263 | LttvHooks *check_tracefile, |
| 264 | LttvHooks *before_tracefile, |
| 265 | LttvHooks *after_tracefile, |
| 266 | LttvHooks *check_event, |
| 267 | LttvHooks *before_event, |
| 268 | LttvHooks *after_event) |
| 269 | { |
| 270 | LttvTraceset *ts = self->ts; |
| 271 | |
| 272 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
| 273 | |
| 274 | LttvTraceContext *tc; |
| 275 | |
| 276 | LttvTracefileContext *tfc; |
| 277 | |
| 278 | void *hook_data; |
| 279 | |
| 280 | lttv_hooks_remove_list(self->before, before_traceset); |
| 281 | lttv_hooks_remove_list(self->after, after_traceset); |
| 282 | nb_trace = lttv_traceset_number(ts); |
| 283 | |
| 284 | for(i = 0 ; i < nb_trace ; i++) { |
| 285 | tc = self->traces[i]; |
| 286 | lttv_hooks_remove_list(tc->check, check_trace); |
| 287 | lttv_hooks_remove_list(tc->before, before_trace); |
| 288 | lttv_hooks_remove_list(tc->after, after_trace); |
| 289 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
| 290 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
| 291 | nb_tracefile = nb_control + nb_per_cpu; |
| 292 | |
| 293 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 294 | if(j < nb_control) { |
| 295 | tfc = tc->control_tracefiles[j]; |
| 296 | } |
| 297 | else { |
| 298 | tfc = tc->per_cpu_tracefiles[j-nb_control]; |
| 299 | } |
| 300 | lttv_hooks_remove_list(tfc->check, check_tracefile); |
| 301 | lttv_hooks_remove_list(tfc->before, before_tracefile); |
| 302 | lttv_hooks_remove_list(tfc->after, after_tracefile); |
| 303 | lttv_hooks_remove_list(tfc->check_event, check_event); |
| 304 | lttv_hooks_remove_list(tfc->before_event, before_event); |
| 305 | lttv_hooks_remove_list(tfc->after_event, after_event); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | static LttvTracesetContext * |
| 312 | new_traceset_context(LttvTracesetContext *self) |
| 313 | { |
| 314 | return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | static LttvTraceContext * |
| 319 | new_trace_context(LttvTracesetContext *self) |
| 320 | { |
| 321 | return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | static LttvTracefileContext * |
| 326 | new_tracefile_context(LttvTracesetContext *self) |
| 327 | { |
| 328 | return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | static void |
| 333 | traceset_context_instance_init (GTypeInstance *instance, gpointer g_class) |
| 334 | { |
| 335 | /* Be careful of anything which would not work well with shallow copies */ |
| 336 | } |
| 337 | |
| 338 | |
| 339 | static void |
| 340 | traceset_context_finalize (LttvTracesetContext *self) |
| 341 | { |
| 342 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE))) |
| 343 | ->finalize(G_OBJECT(self)); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | static void |
| 348 | traceset_context_class_init (LttvTracesetContextClass *klass) |
| 349 | { |
| 350 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
| 351 | |
| 352 | gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize; |
| 353 | klass->init = init; |
| 354 | klass->fini = fini; |
| 355 | klass->new_traceset_context = new_traceset_context; |
| 356 | klass->new_trace_context = new_trace_context; |
| 357 | klass->new_tracefile_context = new_tracefile_context; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | GType |
| 362 | lttv_traceset_context_get_type(void) |
| 363 | { |
| 364 | static GType type = 0; |
| 365 | if (type == 0) { |
| 366 | static const GTypeInfo info = { |
| 367 | sizeof (LttvTracesetContextClass), |
| 368 | NULL, /* base_init */ |
| 369 | NULL, /* base_finalize */ |
| 370 | (GClassInitFunc) traceset_context_class_init, /* class_init */ |
| 371 | NULL, /* class_finalize */ |
| 372 | NULL, /* class_data */ |
| 373 | sizeof (LttvTracesetContext), |
| 374 | 0, /* n_preallocs */ |
| 375 | (GInstanceInitFunc) traceset_context_instance_init /* instance_init */ |
| 376 | }; |
| 377 | |
| 378 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", |
| 379 | &info, 0); |
| 380 | } |
| 381 | return type; |
| 382 | } |
| 383 | |
| 384 | |
| 385 | static void |
| 386 | trace_context_instance_init (GTypeInstance *instance, gpointer g_class) |
| 387 | { |
| 388 | /* Be careful of anything which would not work well with shallow copies */ |
| 389 | } |
| 390 | |
| 391 | |
| 392 | static void |
| 393 | trace_context_finalize (LttvTraceContext *self) |
| 394 | { |
| 395 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))-> |
| 396 | finalize(G_OBJECT(self)); |
| 397 | } |
| 398 | |
| 399 | |
| 400 | static void |
| 401 | trace_context_class_init (LttvTraceContextClass *klass) |
| 402 | { |
| 403 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
| 404 | |
| 405 | gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize; |
| 406 | } |
| 407 | |
| 408 | |
| 409 | GType |
| 410 | lttv_trace_context_get_type(void) |
| 411 | { |
| 412 | static GType type = 0; |
| 413 | if (type == 0) { |
| 414 | static const GTypeInfo info = { |
| 415 | sizeof (LttvTraceContextClass), |
| 416 | NULL, /* base_init */ |
| 417 | NULL, /* base_finalize */ |
| 418 | (GClassInitFunc) trace_context_class_init, /* class_init */ |
| 419 | NULL, /* class_finalize */ |
| 420 | NULL, /* class_data */ |
| 421 | sizeof (LttvTraceContext), |
| 422 | 0, /* n_preallocs */ |
| 423 | (GInstanceInitFunc) trace_context_instance_init /* instance_init */ |
| 424 | }; |
| 425 | |
| 426 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", |
| 427 | &info, 0); |
| 428 | } |
| 429 | return type; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | static void |
| 434 | tracefile_context_instance_init (GTypeInstance *instance, gpointer g_class) |
| 435 | { |
| 436 | /* Be careful of anything which would not work well with shallow copies */ |
| 437 | } |
| 438 | |
| 439 | |
| 440 | static void |
| 441 | tracefile_context_finalize (LttvTracefileContext *self) |
| 442 | { |
| 443 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE))) |
| 444 | ->finalize(G_OBJECT(self)); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | static void |
| 449 | tracefile_context_class_init (LttvTracefileContextClass *klass) |
| 450 | { |
| 451 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
| 452 | |
| 453 | gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | GType |
| 458 | lttv_tracefile_context_get_type(void) |
| 459 | { |
| 460 | static GType type = 0; |
| 461 | if (type == 0) { |
| 462 | static const GTypeInfo info = { |
| 463 | sizeof (LttvTracefileContextClass), |
| 464 | NULL, /* base_init */ |
| 465 | NULL, /* base_finalize */ |
| 466 | (GClassInitFunc) tracefile_context_class_init, /* class_init */ |
| 467 | NULL, /* class_finalize */ |
| 468 | NULL, /* class_data */ |
| 469 | sizeof (LttvTracefileContext), |
| 470 | 0, /* n_preallocs */ |
| 471 | (GInstanceInitFunc) tracefile_context_instance_init /* instance_init */ |
| 472 | }; |
| 473 | |
| 474 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", |
| 475 | &info, 0); |
| 476 | } |
| 477 | return type; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | gint compare_tracefile(gconstpointer a, gconstpointer b) |
| 482 | { |
| 483 | if(((LttvTime *)a)->tv_sec > ((LttvTime *)b)->tv_sec) return 1; |
| 484 | if(((LttvTime *)a)->tv_sec < ((LttvTime *)b)->tv_sec) return -1; |
| 485 | if(((LttvTime *)a)->tv_nsec > ((LttvTime *)b)->tv_nsec) return 1; |
| 486 | if(((LttvTime *)a)->tv_nsec < ((LttvTime *)b)->tv_nsec) return -1; |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | gboolean get_first(gpointer key, gpointer value, gpointer user_data) { |
| 492 | *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; |
| 493 | return TRUE; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | void lttv_process_trace(LttTime start, LttTime end, LttvTraceset *traceset, |
| 498 | LttvTracesetContext *context, unsigned maxNumEvents) |
| 499 | { |
| 500 | GPtrArray *traces = g_ptr_array_new(); |
| 501 | |
| 502 | GPtrArray *tracefiles = g_ptr_array_new(); |
| 503 | |
| 504 | GTree *pqueue = g_tree_new(compare_tracefile); |
| 505 | |
| 506 | guint i, j, nbi, nbj, id, nb_control, nb_cpu; |
| 507 | |
| 508 | LttTrace *trace; |
| 509 | |
| 510 | LttvTraceContext *tc; |
| 511 | |
| 512 | LttTracefile *tracefile; |
| 513 | |
| 514 | LttvTracefileContext *tfc; |
| 515 | |
| 516 | LttEvent *event; |
| 517 | unsigned count = 0; |
| 518 | LttTime preTimestamp; |
| 519 | |
| 520 | /* Call all before_traceset, before_trace, and before_tracefile hooks. |
| 521 | For all qualifying tracefiles, seek to the start time, create a context, |
| 522 | read one event and insert in the pqueue based on the event time. */ |
| 523 | |
| 524 | lttv_hooks_call(context->before, context); |
| 525 | nbi = lttv_traceset_number(traceset); |
| 526 | // nbi = ltt_trace_set_number(traceset); |
| 527 | |
| 528 | for(i = 0 ; i < nbi ; i++) { |
| 529 | tc = context->traces[i]; |
| 530 | trace = tc->t; |
| 531 | |
| 532 | if(!lttv_hooks_call_check(tc->check, tc)) { |
| 533 | g_ptr_array_add(traces, tc); |
| 534 | lttv_hooks_call(tc->before, tc); |
| 535 | nb_control = ltt_trace_control_tracefile_number(trace); |
| 536 | nb_cpu = ltt_trace_per_cpu_tracefile_number(trace); |
| 537 | nbj = nb_control + nb_cpu; |
| 538 | |
| 539 | for(j = 0 ; j < nbj ; j++) { |
| 540 | if(j < nb_control) { |
| 541 | tfc = tc->control_tracefiles[j]; |
| 542 | } |
| 543 | else { |
| 544 | tfc = tc->per_cpu_tracefiles[j - nb_control]; |
| 545 | } |
| 546 | |
| 547 | tracefile = tfc->tf; |
| 548 | |
| 549 | if(!lttv_hooks_call_check(tfc->check, tfc)) { |
| 550 | g_ptr_array_add(tracefiles, tfc); |
| 551 | lttv_hooks_call(tfc->before, tfc); |
| 552 | |
| 553 | ltt_tracefile_seek_time(tracefile, start); |
| 554 | event = ltt_tracefile_read(tracefile); |
| 555 | tfc->e = event; |
| 556 | |
| 557 | if(event != NULL) { |
| 558 | tfc->timestamp = ltt_event_time(event); |
| 559 | g_tree_insert(pqueue, &(tfc->timestamp), tfc); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | /* Get the next event from the pqueue, call its hooks, |
| 567 | reinsert in the pqueue the following event from the same tracefile |
| 568 | unless the tracefile is finished or the event is later than the |
| 569 | start time. */ |
| 570 | |
| 571 | while(TRUE) { |
| 572 | tfc = NULL; |
| 573 | g_tree_foreach(pqueue, get_first, &tfc); |
| 574 | if(tfc == NULL) break; |
| 575 | |
| 576 | /* Get the tracefile with an event for the smallest time found. If two |
| 577 | or more tracefiles have events for the same time, hope that lookup |
| 578 | and remove are consistent. */ |
| 579 | |
| 580 | count++; |
| 581 | if(count > maxNumEvents){ |
| 582 | if(tfc->timestamp.tv_sec == preTimestamp.tv_sec && |
| 583 | tfc->timestamp.tv_nsec == preTimestamp.tv_nsec) { |
| 584 | count--; |
| 585 | }else{ |
| 586 | while(TRUE){ |
| 587 | tfc = NULL; |
| 588 | g_tree_foreach(pqueue, get_first, &tfc); |
| 589 | if(tfc == NULL) break; |
| 590 | g_tree_remove(pqueue, &(tfc->timestamp)); |
| 591 | } |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | preTimestamp = tfc->timestamp; |
| 596 | |
| 597 | tfc = g_tree_lookup(pqueue, &(tfc->timestamp)); |
| 598 | g_tree_remove(pqueue, &(tfc->timestamp)); |
| 599 | |
| 600 | if(!lttv_hooks_call(tfc->check_event, tfc)) { |
| 601 | id = ltt_event_eventtype_id(tfc->e); |
| 602 | lttv_hooks_call(tfc->before_event, tfc); |
| 603 | lttv_hooks_call(lttv_hooks_by_id_get(tfc->before_event_by_id, id), tfc); |
| 604 | lttv_hooks_call(tfc->after_event, tfc); |
| 605 | lttv_hooks_call(lttv_hooks_by_id_get(tfc->after_event_by_id, id), tfc); |
| 606 | } |
| 607 | |
| 608 | event = ltt_tracefile_read(tfc->tf); |
| 609 | if(event != NULL) { |
| 610 | tfc->e = event; |
| 611 | tfc->timestamp = ltt_event_time(event); |
| 612 | if(tfc->timestamp.tv_sec < end.tv_sec || |
| 613 | (tfc->timestamp.tv_sec == end.tv_sec && tfc->timestamp.tv_nsec <= end.tv_nsec)) |
| 614 | g_tree_insert(pqueue, &(tfc->timestamp), tfc); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /* Call all the after_tracefile, after_trace and after_traceset hooks. */ |
| 619 | |
| 620 | for(i = 0, j = 0 ; i < traces->len ; i++) { |
| 621 | tc = traces->pdata[i]; |
| 622 | while(j < tracefiles->len) { |
| 623 | tfc = tracefiles->pdata[j]; |
| 624 | |
| 625 | if(tfc->t_context == tc) { |
| 626 | lttv_hooks_call(tfc->after, tfc); |
| 627 | j++; |
| 628 | } |
| 629 | else break; |
| 630 | } |
| 631 | lttv_hooks_call(tc->after, tc); |
| 632 | } |
| 633 | |
| 634 | g_assert(j == tracefiles->len); |
| 635 | lttv_hooks_call(context->after, context); |
| 636 | |
| 637 | /* Free the traces, tracefiles and pqueue */ |
| 638 | |
| 639 | g_ptr_array_free(tracefiles, TRUE); |
| 640 | g_ptr_array_free(traces, TRUE); |
| 641 | g_tree_destroy(pqueue); |
| 642 | } |
| 643 | |
| 644 | static LttField * |
| 645 | find_field(LttEventType *et, const char *field) |
| 646 | { |
| 647 | LttType *t; |
| 648 | |
| 649 | LttField *f; |
| 650 | |
| 651 | guint i, nb; |
| 652 | |
| 653 | char *name; |
| 654 | |
| 655 | if(field == NULL) return NULL; |
| 656 | |
| 657 | f = ltt_eventtype_field(et); |
| 658 | t = ltt_eventtype_type(et); |
| 659 | g_assert(ltt_type_class(t) == LTT_STRUCT); |
| 660 | nb = ltt_type_member_number(t); |
| 661 | for(i = 0 ; i < nb ; i++) { |
| 662 | ltt_type_member_type(t, i, &name); |
| 663 | if(strcmp(name, field) == 0) break; |
| 664 | } |
| 665 | g_assert(i < nb); |
| 666 | return ltt_field_member(f, i); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | void |
| 671 | lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, |
| 672 | char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th) |
| 673 | { |
| 674 | LttFacility *f; |
| 675 | |
| 676 | LttEventType *et; |
| 677 | |
| 678 | guint nb, pos, i; |
| 679 | |
| 680 | char *name; |
| 681 | |
| 682 | nb = ltt_trace_facility_find(t, facility, &pos); |
| 683 | if(nb < 1) g_error("No %s facility", facility); |
| 684 | f = ltt_trace_facility_get(t, pos); |
| 685 | et = ltt_facility_eventtype_get_by_name(f, event_type); |
| 686 | if(et == NULL) g_error("Event %s does not exist", event_type); |
| 687 | |
| 688 | th->h = h; |
| 689 | th->id = ltt_eventtype_id(et); |
| 690 | th->f1 = find_field(et, field1); |
| 691 | th->f2 = find_field(et, field2); |
| 692 | th->f3 = find_field(et, field3); |
| 693 | } |
| 694 | |
| 695 | |