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