Update FSF address
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindowtraces.c
CommitLineData
a1a2b649 1/* This file is part of the Linux Trace Toolkit Graphic User Interface
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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
b9ce0bad
YB
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
a1a2b649 17 */
18
19/* This file is the API used to launch any background computation on a trace */
20
21/* Here is the implementation of the API */
22
4e4d11b3 23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
0fdb8bb0 27#include <sys/types.h>
28#include <sys/stat.h>
29#include <unistd.h>
2eef04b5 30#include <string.h>
43ed82b5 31#include <inttypes.h>
0fdb8bb0 32
a1a2b649 33#include <glib.h>
34#include <lttv/lttv.h>
35#include <lttv/traceset.h>
36#include <lttv/attribute.h>
a1a2b649 37#include <lttvwindow/lttvwindowtraces.h>
8bc02ec8 38#include <lttvwindow/lttvwindow.h> // for CHUNK_NUM_EVENTS
b5e17af5 39#include <lttvwindow/mainwindow-private.h> /* for main window structure */
a1a2b649 40
b5e17af5 41extern GSList * g_main_window_list;
a1a2b649 42
43typedef struct _BackgroundRequest {
44 LttvAttributeName module_name; /* Hook path in global attributes,
45 where all standard hooks under computation/.
46 i.e. modulename */
47 LttvTrace *trace; /* trace concerned */
93ac601b 48 GtkWidget *dialog; /* Dialog linked with the request, may be NULL */
b5e17af5 49 GtkWidget *parent_window; /* Parent window the dialog must be transient for */
a1a2b649 50} BackgroundRequest;
51
52typedef struct _BackgroundNotify {
53 gpointer owner;
54 LttvTrace *trace; /* trace */
55 LttTime notify_time;
451aaf27 56 LttvTracesetPosition *notify_position;
a1a2b649 57 LttvHooks *notify; /* Hook to call when the notify is
58 passed, or at the end of trace */
59} BackgroundNotify;
60
61
62
313bd6fc 63/* Prototypes */
64gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace);
65
a1a2b649 66/* Get a trace by its path name.
67 *
68 * @param path path of the trace on the virtual file system.
69 * @return Pointer to trace if found
70 * NULL is returned if the trace is not present
71 */
72
f9240312 73__EXPORT LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path)
a1a2b649 74{
451aaf27 75#ifdef BABEL_CLEANUP
a1a2b649 76 guint i;
77
78 for(i=0;i<lttvwindowtraces_get_number();i++) {
79 LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
80 LttTrace *trace;
43ed82b5 81 const gchar *name;
a1a2b649 82 g_assert(trace_v != NULL);
83
84 trace = lttv_trace(trace_v);
85 g_assert(trace != NULL);
d27948a3 86 name = g_quark_to_string(ltt_trace_name(trace));
a1a2b649 87
88 if(strcmp(name, path) == 0) {
89 /* Found */
90 return trace_v;
91 }
92 }
451aaf27 93#endif
a1a2b649 94 return NULL;
95}
96
97/* Get a trace by its number identifier */
98
f9240312 99__EXPORT LttvTrace *lttvwindowtraces_get_trace(guint num)
a1a2b649 100{
101 LttvAttribute *g_attribute = lttv_global_attributes();
102 LttvAttribute *attribute;
103 LttvAttributeType type;
104 LttvAttributeName name;
105 LttvAttributeValue value;
c0cb4d12 106 gboolean is_named;
a1a2b649 107
96c9eb79 108 attribute =
a1a2b649 109 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 110 LTTV_TRACES));
111 g_assert(attribute);
a1a2b649 112
c0cb4d12 113 type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), num, &name, &value,
114 &is_named);
a1a2b649 115
116 if(type == LTTV_POINTER) {
117 return (LttvTrace *)*(value.v_pointer);
118 }
119
120 return NULL;
121}
122
123/* Total number of traces */
124
f9240312 125__EXPORT guint lttvwindowtraces_get_number()
a1a2b649 126{
127 LttvAttribute *g_attribute = lttv_global_attributes();
128 LttvAttribute *attribute;
a1a2b649 129
96c9eb79 130 attribute =
a1a2b649 131 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 132 LTTV_TRACES));
133 g_assert(attribute);
a1a2b649 134
135 return ( lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute)) );
136}
137
138/* Add a trace to the global attributes */
139
140void lttvwindowtraces_add_trace(LttvTrace *trace)
141{
26ea84eb 142#ifdef BABEL_CLEANUP
b22f4f42
YB
143 LttvAttribute *attribute;
144
26ea84eb
YB
145
146 LttvAttribute *g_attribute = lttv_global_attributes();
0fdb8bb0 147 struct stat buf;
148 gchar attribute_path[PATH_MAX];
96c9eb79 149 int result;
150 gboolean result_b;
23bb9b6b 151 if(stat(g_quark_to_string(ltt_trace_name(lttv_trace(trace))), &buf)) {
0fdb8bb0 152 g_warning("lttvwindowtraces_add_trace: Trace %s not found",
23bb9b6b 153 g_quark_to_string(ltt_trace_name(lttv_trace(trace))));
0fdb8bb0 154 return;
155 }
43ed82b5 156 result = snprintf(attribute_path, PATH_MAX, "%" PRIu64 ":%" PRIu64,
157 buf.st_dev, buf.st_ino);
96c9eb79 158 g_assert(result >= 0);
0fdb8bb0 159
96c9eb79 160 attribute =
a1a2b649 161 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 162 LTTV_TRACES));
163 g_assert(attribute);
0fdb8bb0 164
a1a2b649 165 value = lttv_attribute_add(attribute,
0fdb8bb0 166 g_quark_from_string(attribute_path),
a1a2b649 167 LTTV_POINTER);
168
169 *(value.v_pointer) = (gpointer)trace;
8bc02ec8 170
171 /* create new traceset and tracesetcontext */
172 LttvTraceset *ts;
313bd6fc 173 LttvTracesetStats *tss;
088f6772 174 //LttvTracesetContextPosition *sync_position;
8bc02ec8 175
176 attribute = lttv_trace_attribute(trace);
96c9eb79 177 result_b = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
8bc02ec8 178 LTTV_COMPUTATION_TRACESET,
179 LTTV_POINTER,
96c9eb79 180 &value);
181 g_assert(result_b);
182
8bc02ec8 183 ts = lttv_traceset_new();
184 *(value.v_pointer) = ts;
185
186 lttv_traceset_add(ts,trace);
187
96c9eb79 188 result_b = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
8bc02ec8 189 LTTV_COMPUTATION_TRACESET_CONTEXT,
190 LTTV_POINTER,
96c9eb79 191 &value);
192 g_assert(result_b);
193
313bd6fc 194 tss = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
195 *(value.v_pointer) = tss;
8bc02ec8 196
313bd6fc 197 lttv_context_init(LTTV_TRACESET_CONTEXT(tss), ts);
b22f4f42 198
088f6772 199#if 0
96c9eb79 200 result_b = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
79257ba5 201 LTTV_COMPUTATION_SYNC_POSITION,
202 LTTV_POINTER,
96c9eb79 203 &value);
204 g_assert(result_b);
79257ba5 205
206 sync_position = lttv_traceset_context_position_new();
207 *(value.v_pointer) = sync_position;
088f6772 208#endif //0
26ea84eb 209 lttv_attribute_add(attribute,
8bc02ec8 210 LTTV_REQUESTS_QUEUE,
211 LTTV_POINTER);
212
26ea84eb 213 lttv_attribute_add(attribute,
8bc02ec8 214 LTTV_REQUESTS_CURRENT,
215 LTTV_POINTER);
216
26ea84eb 217 lttv_attribute_add(attribute,
8bc02ec8 218 LTTV_NOTIFY_QUEUE,
219 LTTV_POINTER);
220
26ea84eb 221 lttv_attribute_add(attribute,
8bc02ec8 222 LTTV_NOTIFY_CURRENT,
223 LTTV_POINTER);
b22f4f42 224#endif
a1a2b649 225}
226
227/* Remove a trace from the global attributes */
228
229void lttvwindowtraces_remove_trace(LttvTrace *trace)
230{
231 LttvAttribute *g_attribute = lttv_global_attributes();
232 LttvAttribute *attribute;
233 LttvAttributeValue value;
234 guint i;
96c9eb79 235 gboolean result;
a1a2b649 236
96c9eb79 237 attribute =
a1a2b649 238 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 239 LTTV_TRACES));
240 g_assert(attribute);
a1a2b649 241
242 for(i=0;i<lttvwindowtraces_get_number();i++) {
243 LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
244
245 g_assert(trace_v != NULL);
246
b052368a 247 /* Remove and background computation that could be in progress */
248 g_idle_remove_by_data(trace_v);
249
a1a2b649 250 if(trace_v == trace) {
251 /* Found */
8bc02ec8 252 LttvAttribute *l_attribute;
253
23bb9b6b 254 /* destroy traceset and tracesetcontext */
8bc02ec8 255 LttvTraceset *ts;
088f6772 256 //LttvTracesetContextPosition *sync_position;
8bc02ec8 257
258 l_attribute = lttv_trace_attribute(trace);
259
260
261 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
262 LTTV_REQUESTS_QUEUE);
263
264 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
265 LTTV_REQUESTS_CURRENT);
266
267 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
268 LTTV_NOTIFY_QUEUE);
269
270 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
271 LTTV_NOTIFY_CURRENT);
272
96c9eb79 273 result = lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute),
8bc02ec8 274 LTTV_COMPUTATION_TRACESET,
275 LTTV_POINTER,
96c9eb79 276 &value);
277 g_assert(result);
278
8bc02ec8 279 ts = (LttvTraceset*)*(value.v_pointer);
088f6772 280#if 0
96c9eb79 281 result = lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute),
79257ba5 282 LTTV_COMPUTATION_SYNC_POSITION,
283 LTTV_POINTER,
96c9eb79 284 &value);
285 g_assert(result);
286
79257ba5 287 sync_position = (LttvTracesetContextPosition*)*(value.v_pointer);
79257ba5 288 lttv_traceset_context_position_destroy(sync_position);
289
290 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
291 LTTV_COMPUTATION_SYNC_POSITION);
292
088f6772 293#endif //0
96c9eb79 294 result = lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute),
8bc02ec8 295 LTTV_COMPUTATION_TRACESET_CONTEXT,
296 LTTV_POINTER,
96c9eb79 297 &value);
298 g_assert(result);
451aaf27 299#ifdef BABEL_CLEANUP
313bd6fc 300 tss = (LttvTracesetStats*)*(value.v_pointer);
8bc02ec8 301
313bd6fc 302 lttv_context_fini(LTTV_TRACESET_CONTEXT(tss));
303 g_object_unref(tss);
451aaf27 304#endif /* BABEL_CLEANUP */
8bc02ec8 305 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
306 LTTV_COMPUTATION_TRACESET_CONTEXT);
8bc02ec8 307 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
308 LTTV_COMPUTATION_TRACESET);
1ba187d3 309 /* Destroy the traceset and the trace also */
310 lttv_traceset_destroy(ts);
8bc02ec8 311
312 /* finally, remove the global attribute */
a1a2b649 313 lttv_attribute_remove(attribute, i);
8bc02ec8 314
a1a2b649 315 return;
316 }
317 }
318}
319
93ac601b 320static void destroy_dialog(BackgroundRequest *bg_req)
321{
322 gtk_widget_destroy(bg_req->dialog);
323 bg_req->dialog = NULL;
324}
325
a1a2b649 326
327/**
328 * Function to request data from a specific trace
329 *
330 * The memory allocated for the request will be managed by the API.
331 *
b5e17af5 332 * @param widget the current Window
a1a2b649 333 * @param trace the trace to compute
334 * @param module_name the name of the module which registered global computation
335 * hooks.
336 */
337
f9240312 338__EXPORT void lttvwindowtraces_background_request_queue
b5e17af5 339 (GtkWidget *widget, LttvTrace *trace, gchar *module_name)
a1a2b649 340{
341 BackgroundRequest *bg_req;
342 LttvAttribute *attribute = lttv_trace_attribute(trace);
91fd6881 343 LttvAttribute *g_attribute = lttv_global_attributes();
344 LttvAttribute *module_attribute;
a1a2b649 345 LttvAttributeValue value;
91fd6881 346 LttvAttributeType type;
a1a2b649 347 GSList **slist;
96c9eb79 348 gboolean result;
a1a2b649 349
eaac6798 350 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 351 LTTV_REQUESTS_QUEUE,
352 LTTV_POINTER,
96c9eb79 353 &value);
354 g_assert(result);
355
a1a2b649 356 slist = (GSList**)(value.v_pointer);
91fd6881 357
358 /* Verify that the calculator is loaded */
96c9eb79 359 module_attribute =
91fd6881 360 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 361 LTTV_COMPUTATION));
362 g_assert(module_attribute);
91fd6881 363
364 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
365 g_quark_from_string(module_name),
366 &value);
367 if(type == LTTV_NONE) {
368 g_critical("Missing background calculator %s", module_name);
369 return;
370 }
371
a1a2b649 372 bg_req = g_new(BackgroundRequest,1);
373 bg_req->module_name = g_quark_from_string(module_name);
374 bg_req->trace = trace;
375
376 *slist = g_slist_append(*slist, bg_req);
313bd6fc 377
378 /* Priority lower than live servicing */
379 g_idle_remove_by_data(trace);
380 g_idle_add_full((G_PRIORITY_HIGH_IDLE + 23),
381 (GSourceFunc)lttvwindowtraces_process_pending_requests,
382 trace,
383 NULL);
b052368a 384 /* FIXME : show message in status bar, need context and message id */
93ac601b 385 g_info("Background computation for %s started for trace %p", module_name,
386 trace);
387 GtkWidget *dialog =
b5e17af5 388 gtk_message_dialog_new(
389 GTK_WINDOW(widget),
390 GTK_DIALOG_DESTROY_WITH_PARENT,
391 GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
93ac601b 392 "Background computation for %s started for trace %s",
393 module_name,
451aaf27 394 trace->traceset->filename);
b5e17af5 395 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(widget));
93ac601b 396 g_signal_connect_swapped (dialog, "response",
397 G_CALLBACK (destroy_dialog),
398 bg_req);
399 bg_req->dialog = dialog;
b5e17af5 400 /* the parent window might vanish : only use this pointer for a
401 * comparison with existing windows */
402 bg_req->parent_window = gtk_widget_get_toplevel(widget);
93ac601b 403 gtk_widget_show(dialog);
a1a2b649 404}
405
406/**
407 * Remove a background request from a trace.
408 *
409 * This should ONLY be used by the modules which registered the global hooks
410 * (module_name). If this is called by the viewers, it may lead to incomplete
411 * and incoherent background processing information.
412 *
413 * Even if the module which deals with the hooks removes the background
414 * requests, it may cause a problem if the module gets loaded again in the
415 * session : the data will be partially calculated. The calculation function
416 * must deal with this case correctly.
417 *
418 * @param trace the trace to compute
419 * @param module_name the name of the module which registered global computation
420 * hooks.
421 */
422
423void lttvwindowtraces_background_request_remove
424 (LttvTrace *trace, gchar *module_name)
425{
426 LttvAttribute *attribute = lttv_trace_attribute(trace);
427 LttvAttributeValue value;
428 GSList *iter = NULL;
429 GSList **slist;
96c9eb79 430 gboolean result;
a1a2b649 431
eaac6798 432 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 433 LTTV_REQUESTS_QUEUE,
434 LTTV_POINTER,
96c9eb79 435 &value);
436 g_assert(result);
437
a1a2b649 438 slist = (GSList**)(value.v_pointer);
439
440 for(iter=*slist;iter!=NULL;) {
441 BackgroundRequest *bg_req =
442 (BackgroundRequest *)iter->data;
443
444 if(bg_req->module_name == g_quark_from_string(module_name)) {
445 GSList *rem_iter = iter;
446 iter=g_slist_next(iter);
447 g_free(bg_req);
448 *slist = g_slist_delete_link(*slist, rem_iter);
449 } else {
450 iter=g_slist_next(iter);
451 }
452 }
453}
454
93ac601b 455/**
456 * Find a background request in a trace
457 *
458 */
459
f9240312 460__EXPORT gboolean lttvwindowtraces_background_request_find
93ac601b 461 (LttvTrace *trace, gchar *module_name)
462{
463 LttvAttribute *attribute = lttv_trace_attribute(trace);
464 LttvAttributeValue value;
465 GSList *iter = NULL;
466 GSList **slist;
96c9eb79 467 gboolean result;
93ac601b 468
96c9eb79 469 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
93ac601b 470 LTTV_REQUESTS_QUEUE,
471 LTTV_POINTER,
96c9eb79 472 &value);
473 g_assert(result);
474
93ac601b 475 slist = (GSList**)(value.v_pointer);
476
477 for(iter=*slist;iter!=NULL;) {
478 BackgroundRequest *bg_req =
479 (BackgroundRequest *)iter->data;
480
481 if(bg_req->module_name == g_quark_from_string(module_name)) {
482 return TRUE;
483 } else {
484 iter=g_slist_next(iter);
485 }
486 }
487 return FALSE;
488}
a1a2b649 489
490/**
491 * Register a callback to be called when requested data is passed in the next
492 * queued background processing.
493 *
494 * @param owner owner of the background notification
495 * @param trace the trace computed
496 * @param notify_time time when notification hooks must be called
497 * @param notify_position position when notification hooks must be called
498 * @param notify Hook to call when the notify position is passed
499 */
500
f9240312 501__EXPORT void lttvwindowtraces_background_notify_queue
a1a2b649 502 (gpointer owner,
503 LttvTrace *trace,
504 LttTime notify_time,
451aaf27 505 const LttvTracesetPosition *notify_position,
a1a2b649 506 const LttvHooks *notify)
507{
451aaf27 508 #ifdef BABEL_CLEANUP
a1a2b649 509 BackgroundNotify *bg_notify;
510 LttvAttribute *attribute = lttv_trace_attribute(trace);
511 LttvAttributeValue value;
512 GSList **slist;
96c9eb79 513 gboolean result;
a1a2b649 514
96c9eb79 515 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 516 LTTV_NOTIFY_QUEUE,
517 LTTV_POINTER,
96c9eb79 518 &value);
519 g_assert(result);
520
a1a2b649 521 slist = (GSList**)(value.v_pointer);
522
96c9eb79 523 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
8e680509 524 LTTV_COMPUTATION_TRACESET_CONTEXT,
525 LTTV_POINTER,
96c9eb79 526 &value);
527 g_assert(result);
528
451aaf27 529 LttvTraceset *ts = (LttvTraceset)(value.v_pointer);
a1a2b649 530
531 bg_notify = g_new(BackgroundNotify,1);
532
533 bg_notify->owner = owner;
534 bg_notify->trace = trace;
535 bg_notify->notify_time = notify_time;
313bd6fc 536 if(notify_position != NULL) {
8e680509 537 bg_notify->notify_position = lttv_traceset_context_position_new(tsc);
313bd6fc 538 lttv_traceset_context_position_copy(bg_notify->notify_position,
539 notify_position);
540 } else {
541 bg_notify->notify_position = NULL;
542 }
543
a1a2b649 544 bg_notify->notify = lttv_hooks_new();
545 lttv_hooks_add_list(bg_notify->notify, notify);
546
547 *slist = g_slist_append(*slist, bg_notify);
451aaf27 548#endif /* BABEL_CLEANUP*/
a1a2b649 549}
550
551/**
552 * Register a callback to be called when requested data is passed in the current
553 * background processing.
554 *
555 * @param owner owner of the background notification
556 * @param trace the trace computed
557 * @param notify_time time when notification hooks must be called
558 * @param notify_position position when notification hooks must be called
559 * @param notify Hook to call when the notify position is passed
560 */
561
f9240312 562__EXPORT void lttvwindowtraces_background_notify_current
a1a2b649 563 (gpointer owner,
564 LttvTrace *trace,
565 LttTime notify_time,
451aaf27 566 const LttvTracesetPosition *notify_position,
a1a2b649 567 const LttvHooks *notify)
568{
451aaf27 569 #ifdef BABEL_CLEANUP
a1a2b649 570 BackgroundNotify *bg_notify;
571 LttvAttribute *attribute = lttv_trace_attribute(trace);
572 LttvAttributeValue value;
573 GSList **slist;
96c9eb79 574 gboolean result;
a1a2b649 575
96c9eb79 576 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 577 LTTV_NOTIFY_CURRENT,
578 LTTV_POINTER,
96c9eb79 579 &value);
580 g_assert(result);
581
a1a2b649 582 slist = (GSList**)(value.v_pointer);
583
96c9eb79 584 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
8e680509 585 LTTV_COMPUTATION_TRACESET_CONTEXT,
586 LTTV_POINTER,
96c9eb79 587 &value);
588 g_assert(result);
589
8e680509 590 LttvTracesetContext *tsc = (LttvTracesetContext*)(value.v_pointer);
591
592
a1a2b649 593 bg_notify = g_new(BackgroundNotify,1);
594
595 bg_notify->owner = owner;
596 bg_notify->trace = trace;
597 bg_notify->notify_time = notify_time;
313bd6fc 598 if(notify_position!= NULL) {
8e680509 599 bg_notify->notify_position = lttv_traceset_context_position_new(tsc);
313bd6fc 600 lttv_traceset_context_position_copy(bg_notify->notify_position,
601 notify_position);
602 } else {
603 bg_notify->notify_position = NULL;
604 }
a1a2b649 605 bg_notify->notify = lttv_hooks_new();
606 lttv_hooks_add_list(bg_notify->notify, notify);
607
608 *slist = g_slist_append(*slist, bg_notify);
451aaf27 609 #endif /* BABEL_CLEANUP */
a1a2b649 610}
611
b052368a 612
613static void notify_request_free(BackgroundNotify *notify_req)
614{
451aaf27 615 #ifdef BABEL_CLEANUP
b052368a 616 if(notify_req == NULL) return;
617
618 if(notify_req->notify_position != NULL)
619 lttv_traceset_context_position_destroy(notify_req->notify_position);
620 if(notify_req->notify != NULL)
621 lttv_hooks_destroy(notify_req->notify);
622 g_free(notify_req);
451aaf27 623 #endif /* BABEL_CLEANUP */
b052368a 624}
625
a1a2b649 626/**
627 * Removes all the notifications requests from a specific viewer.
628 *
629 * @param owner owner of the background notification
630 */
631
f9240312 632__EXPORT void lttvwindowtraces_background_notify_remove(gpointer owner)
a1a2b649 633{
634 guint i;
635
636 for(i=0;i<lttvwindowtraces_get_number();i++) {
637 LttvAttribute *attribute;
638 LttvAttributeValue value;
639 LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
640 GSList **slist;
641 GSList *iter = NULL;
96c9eb79 642 gboolean result;
a1a2b649 643
644 g_assert(trace_v != NULL);
645
b052368a 646 attribute = lttv_trace_attribute(trace_v);
a1a2b649 647
96c9eb79 648 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 649 LTTV_NOTIFY_QUEUE,
650 LTTV_POINTER,
96c9eb79 651 &value);
652 g_assert(result);
653
a1a2b649 654 slist = (GSList**)(value.v_pointer);
655
656 for(iter=*slist;iter!=NULL;) {
657
658 BackgroundNotify *bg_notify = (BackgroundNotify*)iter->data;
659
660 if(bg_notify->owner == owner) {
661 GSList *rem_iter = iter;
662 iter=g_slist_next(iter);
b052368a 663 notify_request_free(bg_notify);
664 *slist = g_slist_remove_link(*slist, rem_iter);
a1a2b649 665 } else {
666 iter=g_slist_next(iter);
667 }
668 }
669
96c9eb79 670 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
a1a2b649 671 LTTV_NOTIFY_CURRENT,
672 LTTV_POINTER,
96c9eb79 673 &value);
674 g_assert(result);
675
a1a2b649 676 slist = (GSList**)(value.v_pointer);
677
678 for(iter=*slist;iter!=NULL;) {
679
680 BackgroundNotify *bg_notify = (BackgroundNotify*)iter->data;
681
682 if(bg_notify->owner == owner) {
683 GSList *rem_iter = iter;
684 iter=g_slist_next(iter);
b052368a 685 notify_request_free(bg_notify);
686 *slist = g_slist_remove_link(*slist, rem_iter);
a1a2b649 687 } else {
688 iter=g_slist_next(iter);
689 }
690 }
691 }
692}
693
8bc02ec8 694
695/* Background processing helper functions */
696
697void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name,
451aaf27 698 LttvTraceset *ts,
1ce324c6 699 LttvHooks *hook_adder)
8bc02ec8 700{
451aaf27 701 #ifdef BABEL_CLEANUP
8bc02ec8 702 LttvAttribute *g_attribute = lttv_global_attributes();
703 LttvAttribute *module_attribute;
704 LttvAttributeType type;
705 LttvAttributeValue value;
088f6772 706
707
96c9eb79 708 module_attribute =
088f6772 709 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 710 LTTV_COMPUTATION));
711 g_assert(module_attribute);
088f6772 712
96c9eb79 713 module_attribute =
088f6772 714 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
715 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 716 module_name));
717 g_assert(module_attribute);
088f6772 718
719 /* Call the module's hook adder */
720 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
721 LTTV_HOOK_ADDER,
722 &value);
723 if(type == LTTV_POINTER) {
724 //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
725 if(hook_adder != NULL)
726 lttv_hooks_add_list(hook_adder, (LttvHooks*)*(value.v_pointer));
727 }
451aaf27 728#endif /* BABEL_CLEANUP */
088f6772 729}
730
731void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name,
451aaf27 732 LttvTraceset *ts,
088f6772 733 LttvHooks *hook_remover)
734{
451aaf27 735 #ifdef BABEL_CLEANUP
088f6772 736 LttvAttribute *g_attribute = lttv_global_attributes();
737 LttvAttribute *module_attribute;
738 LttvAttributeType type;
739 LttvAttributeValue value;
740
96c9eb79 741 module_attribute =
088f6772 742 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 743 LTTV_COMPUTATION));
744 g_assert(module_attribute);
088f6772 745
96c9eb79 746 module_attribute =
088f6772 747 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
748 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 749 module_name));
750 g_assert(module_attribute);
088f6772 751
752 /* Call the module's hook remover */
753 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
754 LTTV_HOOK_REMOVER,
755 &value);
756 if(type == LTTV_POINTER) {
757 //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
758 if(hook_remover != NULL)
759 lttv_hooks_add_list(hook_remover, (LttvHooks*)*(value.v_pointer));
760 }
451aaf27 761 #endif /* BABEL_CLEANUP */
088f6772 762}
763
764void lttvwindowtraces_call_before_chunk(LttvAttributeName module_name,
451aaf27 765 LttvTraceset *ts)
088f6772 766{
451aaf27 767 #ifdef BABEL_CLEANUP
088f6772 768 LttvAttribute *g_attribute = lttv_global_attributes();
769 LttvAttribute *module_attribute;
770 LttvAttributeType type;
771 LttvAttributeValue value;
8bc02ec8 772 LttvHooks *before_chunk_traceset=NULL;
773 LttvHooks *before_chunk_trace=NULL;
774 LttvHooks *before_chunk_tracefile=NULL;
775 LttvHooks *event_hook=NULL;
750eb11a 776 LttvHooksByIdChannelArray *event_hook_by_id_channel=NULL;
8bc02ec8 777
778
96c9eb79 779 module_attribute =
8bc02ec8 780 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 781 LTTV_COMPUTATION));
782 g_assert(module_attribute);
8bc02ec8 783
96c9eb79 784 module_attribute =
8bc02ec8 785 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
786 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 787 module_name));
788 g_assert(module_attribute);
8bc02ec8 789
790 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
791 LTTV_BEFORE_CHUNK_TRACESET,
792 &value);
793 if(type == LTTV_POINTER) {
794 before_chunk_traceset = (LttvHooks*)*(value.v_pointer);
795 }
796
797 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
798 LTTV_BEFORE_CHUNK_TRACE,
799 &value);
800 if(type == LTTV_POINTER) {
801 before_chunk_trace = (LttvHooks*)*(value.v_pointer);
802 }
803
804 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
805 LTTV_BEFORE_CHUNK_TRACEFILE,
806 &value);
807 if(type == LTTV_POINTER) {
808 before_chunk_tracefile = (LttvHooks*)*(value.v_pointer);
809 }
810
811 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
812 LTTV_EVENT_HOOK,
813 &value);
814 if(type == LTTV_POINTER) {
815 event_hook = (LttvHooks*)*(value.v_pointer);
816 }
817
818 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
750eb11a 819 LTTV_EVENT_HOOK_BY_ID_CHANNEL,
8bc02ec8 820 &value);
821 if(type == LTTV_POINTER) {
43ed82b5 822 event_hook_by_id_channel = (LttvHooksByIdChannelArray*)*(value.v_pointer);
8bc02ec8 823 }
824
8bc02ec8 825 lttv_process_traceset_begin(tsc,
826 before_chunk_traceset,
827 before_chunk_trace,
828 before_chunk_tracefile,
829 event_hook,
750eb11a 830 event_hook_by_id_channel);
451aaf27 831#endif /* BABEL_CLEANUP */
8bc02ec8 832}
088f6772 833
834
835
836void lttvwindowtraces_call_after_chunk(LttvAttributeName module_name,
451aaf27 837 LttvTraceset *ts)
8bc02ec8 838{
b22f4f42
YB
839#warning "lttvwindowtraces_call_after_chunk does nothing"
840#ifdef BABEL_CLEANUP
8bc02ec8 841 LttvAttribute *g_attribute = lttv_global_attributes();
842 LttvAttribute *module_attribute;
843 LttvAttributeType type;
844 LttvAttributeValue value;
845 LttvHooks *after_chunk_traceset=NULL;
846 LttvHooks *after_chunk_trace=NULL;
847 LttvHooks *after_chunk_tracefile=NULL;
848 LttvHooks *event_hook=NULL;
8bc02ec8 849
96c9eb79 850 module_attribute =
8bc02ec8 851 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 852 LTTV_COMPUTATION));
853 g_assert(module_attribute);
8bc02ec8 854
96c9eb79 855 module_attribute =
8bc02ec8 856 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
857 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 858 module_name));
859 g_assert(module_attribute);
8bc02ec8 860
861 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
862 LTTV_AFTER_CHUNK_TRACESET,
863 &value);
864 if(type == LTTV_POINTER) {
865 after_chunk_traceset = (LttvHooks*)*(value.v_pointer);
866 }
867
868 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
869 LTTV_AFTER_CHUNK_TRACE,
870 &value);
871 if(type == LTTV_POINTER) {
872 after_chunk_trace = (LttvHooks*)*(value.v_pointer);
873 }
874
875 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
876 LTTV_AFTER_CHUNK_TRACEFILE,
877 &value);
878 if(type == LTTV_POINTER) {
879 after_chunk_tracefile = (LttvHooks*)*(value.v_pointer);
880 }
881
882 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
883 LTTV_EVENT_HOOK,
884 &value);
885 if(type == LTTV_POINTER) {
886 event_hook = (LttvHooks*)*(value.v_pointer);
887 }
888
889 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
750eb11a 890 LTTV_EVENT_HOOK_BY_ID_CHANNEL,
8bc02ec8 891 &value);
8bc02ec8 892 lttv_process_traceset_end(tsc,
893 after_chunk_traceset,
894 after_chunk_trace,
895 after_chunk_tracefile,
451aaf27
FD
896 event_hook);
897#endif /* BABEL_CLEANUP*/
313bd6fc 898
8bc02ec8 899}
900
901
902void lttvwindowtraces_set_in_progress(LttvAttributeName module_name,
903 LttvTrace *trace)
904{
905 LttvAttribute *attribute = lttv_trace_attribute(trace);
8bc02ec8 906
96c9eb79 907 attribute =
8bc02ec8 908 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 909 module_name));
910 g_assert(attribute);
8bc02ec8 911
e865422c
YB
912 lttv_iattribute_add(LTTV_IATTRIBUTE(attribute),
913 LTTV_IN_PROGRESS,
914 LTTV_INT);
8bc02ec8 915 /* the value is left unset. The only presence of the attribute is necessary.
916 */
917}
918
919void lttvwindowtraces_unset_in_progress(LttvAttributeName module_name,
920 LttvTrace *trace)
921{
922 LttvAttribute *attribute = lttv_trace_attribute(trace);
923
96c9eb79 924 attribute =
8bc02ec8 925 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 926 module_name));
927 g_assert(attribute);
8bc02ec8 928
313bd6fc 929 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
8bc02ec8 930 LTTV_IN_PROGRESS);
931}
932
f9240312 933__EXPORT gboolean lttvwindowtraces_get_in_progress(LttvAttributeName module_name,
8bc02ec8 934 LttvTrace *trace)
935{
936 LttvAttribute *attribute = lttv_trace_attribute(trace);
937 LttvAttributeType type;
938 LttvAttributeValue value;
939
96c9eb79 940 attribute =
8bc02ec8 941 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 942 module_name));
943 g_assert(attribute);
8bc02ec8 944
945 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
946 LTTV_IN_PROGRESS,
947 &value);
948 /* The only presence of the attribute is necessary. */
949 if(type == LTTV_NONE)
950 return FALSE;
951 else
952 return TRUE;
953}
954
955void lttvwindowtraces_set_ready(LttvAttributeName module_name,
956 LttvTrace *trace)
957{
958 LttvAttribute *attribute = lttv_trace_attribute(trace);
8bc02ec8 959
96c9eb79 960 attribute =
8bc02ec8 961 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 962 module_name));
963 g_assert(attribute);
8bc02ec8 964
e865422c
YB
965 lttv_iattribute_add(LTTV_IATTRIBUTE(attribute),
966 LTTV_READY,
967 LTTV_INT);
8bc02ec8 968 /* the value is left unset. The only presence of the attribute is necessary.
969 */
970}
971
972void lttvwindowtraces_unset_ready(LttvAttributeName module_name,
973 LttvTrace *trace)
974{
975 LttvAttribute *attribute = lttv_trace_attribute(trace);
976
96c9eb79 977 attribute =
8bc02ec8 978 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 979 module_name));
980 g_assert(attribute);
8bc02ec8 981
313bd6fc 982 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
8bc02ec8 983 LTTV_READY);
984}
985
f9240312 986__EXPORT gboolean lttvwindowtraces_get_ready(LttvAttributeName module_name,
8bc02ec8 987 LttvTrace *trace)
988{
989 LttvAttribute *attribute = lttv_trace_attribute(trace);
990 LttvAttributeType type;
991 LttvAttributeValue value;
992
96c9eb79 993 attribute =
8bc02ec8 994 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 995 module_name));
996 g_assert(attribute);
8bc02ec8 997
998 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
999 LTTV_READY,
1000 &value);
1001 /* The only presence of the attribute is necessary. */
1002 if(type == LTTV_NONE)
1003 return FALSE;
1004 else
1005 return TRUE;
1006}
26ea84eb 1007#ifdef BABEL_CLEANUP
b5e17af5 1008static gint find_window_widget(MainWindow *a, GtkWidget *b)
1009{
1010 if(a->mwindow == b) return 0;
1011 else return -1;
1012}
26ea84eb 1013#endif
8bc02ec8 1014
8bc02ec8 1015/* lttvwindowtraces_process_pending_requests
d389bc8d 1016 *
1017 * Process the pending background computation requests
8bc02ec8 1018 *
1019 * This internal function gets called by g_idle, taking care of the pending
1020 * requests.
1021 *
1022 */
1023
1024
1025gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
1026{
b22f4f42
YB
1027 gboolean ret_val = FALSE;
1028#ifdef BABEL_CLEANUP
8bc02ec8 1029 LttvAttribute *attribute;
91fd6881 1030 LttvAttribute *g_attribute = lttv_global_attributes();
313bd6fc 1031 GSList **list_out, **list_in, **notify_in, **notify_out;
8bc02ec8 1032 LttvAttributeValue value;
1033 LttvAttributeType type;
b22f4f42 1034
8bc02ec8 1035
313bd6fc 1036 if(trace == NULL)
8bc02ec8 1037 return FALSE;
3c456a8a 1038
1039 if(lttvwindow_preempt_count > 0) return TRUE;
8bc02ec8 1040
1041 attribute = lttv_trace_attribute(trace);
1042
1043 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1044 LTTV_REQUESTS_QUEUE,
1045 &value);
1046 g_assert(type == LTTV_POINTER);
313bd6fc 1047 list_out = (GSList**)(value.v_pointer);
8bc02ec8 1048
1049 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1050 LTTV_REQUESTS_CURRENT,
1051 &value);
1052 g_assert(type == LTTV_POINTER);
313bd6fc 1053 list_in = (GSList**)(value.v_pointer);
8bc02ec8 1054
1055 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1056 LTTV_NOTIFY_QUEUE,
1057 &value);
1058 g_assert(type == LTTV_POINTER);
313bd6fc 1059 notify_out = (GSList**)(value.v_pointer);
8bc02ec8 1060
1061 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1062 LTTV_NOTIFY_CURRENT,
1063 &value);
1064 g_assert(type == LTTV_POINTER);
313bd6fc 1065 notify_in = (GSList**)(value.v_pointer);
8bc02ec8 1066
1067 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1068 LTTV_COMPUTATION_TRACESET,
1069 &value);
1070 g_assert(type == LTTV_POINTER);
26ea84eb 1071#ifdef BABEL_CLEANUP
8bc02ec8 1072 ts = (LttvTraceset*)*(value.v_pointer);
26ea84eb 1073#endif
088f6772 1074#if 0
79257ba5 1075 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1076 LTTV_COMPUTATION_SYNC_POSITION,
1077 &value);
1078 g_assert(type == LTTV_POINTER);
1079 sync_position = (LttvTracesetContextPosition*)*(value.v_pointer);
088f6772 1080#endif //0
b22f4f42 1081//#ifdef BABEL_CLEANUP moved at the beginning of the function
8bc02ec8 1082 /* There is no events requests pending : we should never have been called! */
313bd6fc 1083 g_assert(g_slist_length(*list_out) != 0 || g_slist_length(*list_in) != 0);
b052368a 1084 /* 0.1 Lock traces */
1085 {
1086 guint iter_trace=0;
1087
1088 for(iter_trace=0;
451aaf27 1089 iter_trace<lttv_traceset_number(ts->ts);
b052368a 1090 iter_trace++) {
451aaf27 1091 LttvTrace *trace_v = lttv_traceset_get(ts->ts,iter_trace);
b052368a 1092
1093 if(lttvwindowtraces_lock(trace_v) != 0)
1094 return TRUE; /* Cannot get trace lock, try later */
8bc02ec8 1095
b052368a 1096 }
1097 }
1098 /* 0.2 Sync tracefiles */
088f6772 1099 //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
1100 lttv_process_traceset_synchronize_tracefiles(tsc);
8bc02ec8 1101 /* 1. Before processing */
1102 {
1103 /* if list_in is empty */
313bd6fc 1104 if(g_slist_length(*list_in) == 0) {
8bc02ec8 1105
1106 {
1107 /* - Add all requests in list_out to list_in, empty list_out */
313bd6fc 1108 GSList *iter = *list_out;
8bc02ec8 1109
1110 while(iter != NULL) {
1111 gboolean remove = FALSE;
1112 gboolean free_data = FALSE;
1113
1114 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1115
1116 remove = TRUE;
1117 free_data = FALSE;
313bd6fc 1118 *list_in = g_slist_append(*list_in, bg_req);
8bc02ec8 1119
1120 /* Go to next */
1121 if(remove)
1122 {
1123 GSList *remove_iter = iter;
1124
1125 iter = g_slist_next(iter);
1126 if(free_data) g_free(remove_iter->data);
313bd6fc 1127 *list_out = g_slist_remove_link(*list_out, remove_iter);
8bc02ec8 1128 } else { // not remove
1129 iter = g_slist_next(iter);
1130 }
1131 }
1132 }
1133
1134 {
313bd6fc 1135 GSList *iter = *list_in;
8bc02ec8 1136 /* - for each request in list_in */
1137 while(iter != NULL) {
1138
1139 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
91fd6881 1140 /* - set hooks'in_progress flag to TRUE */
8bc02ec8 1141 lttvwindowtraces_set_in_progress(bg_req->module_name,
1142 bg_req->trace);
91fd6881 1143
1144 /* - call before request hook */
1145 /* Get before request hook */
1146 LttvAttribute *module_attribute;
1147
96c9eb79 1148 module_attribute =
91fd6881 1149 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
1150 LTTV_IATTRIBUTE(g_attribute),
96c9eb79 1151 LTTV_COMPUTATION));
1152 g_assert(module_attribute);
91fd6881 1153
96c9eb79 1154 module_attribute =
91fd6881 1155 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
1156 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 1157 bg_req->module_name));
1158 g_assert(module_attribute);
91fd6881 1159
1160 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
1161 LTTV_BEFORE_REQUEST,
1162 &value);
1163 g_assert(type == LTTV_POINTER);
1164 LttvHooks *before_request = (LttvHooks*)*(value.v_pointer);
91fd6881 1165
1166 if(before_request != NULL) lttv_hooks_call(before_request, tsc);
8bc02ec8 1167
1168 iter = g_slist_next(iter);
1169 }
1170 }
1171
1172 /* - seek trace to start */
1173 {
1174 LttTime start = { 0, 0};
1175 lttv_process_traceset_seek_time(tsc, start);
1176 }
1177
1178 /* - Move all notifications from notify_out to notify_in. */
1179 {
313bd6fc 1180 GSList *iter = *notify_out;
1181 g_assert(g_slist_length(*notify_in) == 0);
8bc02ec8 1182
1183 while(iter != NULL) {
1184 gboolean remove = FALSE;
1185 gboolean free_data = FALSE;
1186
1187 BackgroundNotify *notify_req = (BackgroundNotify*)iter->data;
1188
1189 remove = TRUE;
1190 free_data = FALSE;
313bd6fc 1191 *notify_in = g_slist_append(*notify_in, notify_req);
8bc02ec8 1192
1193 /* Go to next */
1194 if(remove)
1195 {
1196 GSList *remove_iter = iter;
1197
1198 iter = g_slist_next(iter);
b052368a 1199 if(free_data)
1200 notify_request_free((BackgroundNotify*)remove_iter->data);
313bd6fc 1201 *notify_out = g_slist_remove_link(*notify_out, remove_iter);
8bc02ec8 1202 } else { // not remove
1203 iter = g_slist_next(iter);
1204 }
1205 }
1206 }
088f6772 1207 {
1208 GSList *iter = *list_in;
1209 LttvHooks *hook_adder = lttv_hooks_new();
1210 /* - for each request in list_in */
1211 while(iter != NULL) {
1212
1213 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1214 /*- add hooks to context*/
1215 lttvwindowtraces_add_computation_hooks(bg_req->module_name,
1216 tsc,
1217 hook_adder);
1218 iter = g_slist_next(iter);
1219 }
1220 lttv_hooks_call(hook_adder,tsc);
1221 lttv_hooks_destroy(hook_adder);
1222 }
1223
1224
8bc02ec8 1225 }
1226
1227 {
313bd6fc 1228 GSList *iter = *list_in;
8bc02ec8 1229 /* - for each request in list_in */
1230 while(iter != NULL) {
1231
1232 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1233 /*- Call before chunk hooks for list_in*/
088f6772 1234 lttvwindowtraces_call_before_chunk(bg_req->module_name,
1235 tsc);
8bc02ec8 1236 iter = g_slist_next(iter);
1237 }
1238 }
8bc02ec8 1239
088f6772 1240 }
8bc02ec8 1241 /* 2. call process traceset middle for a chunk */
1242 {
1243 /*(assert list_in is not empty! : should not even be called in that case)*/
0aa6c3a1 1244 LttTime end = ltt_time_infinite;
313bd6fc 1245 g_assert(g_slist_length(*list_in) != 0);
8bc02ec8 1246
1247 lttv_process_traceset_middle(tsc, end, CHUNK_NUM_EVENTS, NULL);
1248 }
1249
1250 /* 3. After the chunk */
1251 {
1252 /* 3.1 call after_chunk hooks for list_in */
1253 {
313bd6fc 1254 GSList *iter = *list_in;
8bc02ec8 1255 /* - for each request in list_in */
1256 while(iter != NULL) {
1257
1258 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1259 /* - Call after chunk hooks for list_in */
088f6772 1260 lttvwindowtraces_call_after_chunk(bg_req->module_name,
1261 tsc);
8bc02ec8 1262 iter = g_slist_next(iter);
1263 }
1264 }
1265
1266 /* 3.2 for each notify_in */
1267 {
313bd6fc 1268 GSList *iter = *notify_in;
8bc02ec8 1269 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
1270
1271 while(iter != NULL) {
1272 gboolean remove = FALSE;
1273 gboolean free_data = FALSE;
1274
1275 BackgroundNotify *notify_req = (BackgroundNotify*)iter->data;
1276
1277 /* - if current time >= notify time, call notify and remove from
1278 * notify_in.
1279 * - if current position >= notify position, call notify and remove
1280 * from notify_in.
1281 */
1282 if( (tfc != NULL &&
313bd6fc 1283 ltt_time_compare(notify_req->notify_time, tfc->timestamp) <= 0)
8bc02ec8 1284 ||
313bd6fc 1285 (notify_req->notify_position != NULL &&
1286 lttv_traceset_context_ctx_pos_compare(tsc,
1287 notify_req->notify_position) >= 0)
8bc02ec8 1288 ) {
1289
1290 lttv_hooks_call(notify_req->notify, notify_req);
1291
1292 remove = TRUE;
1293 free_data = TRUE;
1294 }
1295
1296 /* Go to next */
1297 if(remove)
1298 {
1299 GSList *remove_iter = iter;
1300
1301 iter = g_slist_next(iter);
b052368a 1302 if(free_data)
1303 notify_request_free((BackgroundNotify*)remove_iter->data);
313bd6fc 1304 *notify_in = g_slist_remove_link(*notify_in, remove_iter);
8bc02ec8 1305 } else { // not remove
1306 iter = g_slist_next(iter);
1307 }
1308 }
1309 }
1310
1311 {
1312 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
1313 /* 3.3 if end of trace reached */
313bd6fc 1314 if(tfc != NULL)
1315 g_debug("Current time : %lu sec, %lu nsec",
1316 tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec);
8bc02ec8 1317 if(tfc == NULL || ltt_time_compare(tfc->timestamp,
1318 tsc->time_span.end_time) > 0) {
088f6772 1319
1320 {
1321 GSList *iter = *list_in;
1322 LttvHooks *hook_remover = lttv_hooks_new();
1323 /* - for each request in list_in */
1324 while(iter != NULL) {
1325
1326 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1327 /* - remove hooks from context */
1328 lttvwindowtraces_remove_computation_hooks(bg_req->module_name,
1329 tsc,
1330 hook_remover);
1331 iter = g_slist_next(iter);
1332 }
1333 lttv_hooks_call(hook_remover,tsc);
1334 lttv_hooks_destroy(hook_remover);
1335 }
1336
8bc02ec8 1337 /* - for each request in list_in */
1338 {
313bd6fc 1339 GSList *iter = *list_in;
8bc02ec8 1340
1341 while(iter != NULL) {
1342 gboolean remove = FALSE;
1343 gboolean free_data = FALSE;
1344
1345 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1346
1347 /* - set hooks'in_progress flag to FALSE */
1348 lttvwindowtraces_unset_in_progress(bg_req->module_name,
1349 bg_req->trace);
1350 /* - set hooks'ready flag to TRUE */
1351 lttvwindowtraces_set_ready(bg_req->module_name,
1352 bg_req->trace);
91fd6881 1353 /* - call after request hook */
1354 /* Get after request hook */
1355 LttvAttribute *module_attribute;
1356
96c9eb79 1357 module_attribute =
91fd6881 1358 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
1359 LTTV_IATTRIBUTE(g_attribute),
96c9eb79 1360 LTTV_COMPUTATION));
1361 g_assert(module_attribute);
91fd6881 1362
96c9eb79 1363 module_attribute =
91fd6881 1364 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
1365 LTTV_IATTRIBUTE(module_attribute),
96c9eb79 1366 bg_req->module_name));
1367 g_assert(module_attribute);
91fd6881 1368
1369 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(module_attribute),
1370 LTTV_AFTER_REQUEST,
1371 &value);
1372 g_assert(type == LTTV_POINTER);
1373 LttvHooks *after_request = (LttvHooks*)*(value.v_pointer);
b91e751b 1374 {
1375 struct sum_traceset_closure t_closure;
1376 t_closure.tss = (LttvTracesetStats*)tsc;
1377 t_closure.current_time = ltt_time_infinite;
1378 if(after_request != NULL) lttv_hooks_call(after_request,
1379 &t_closure);
1380 }
93ac601b 1381
1382 if(bg_req->dialog != NULL)
1383 gtk_widget_destroy(bg_req->dialog);
b5e17af5 1384 GtkWidget *parent_window;
1385 if(g_slist_find_custom(g_main_window_list,
1386 bg_req->parent_window,
1387 (GCompareFunc)find_window_widget))
1388 parent_window = GTK_WIDGET(bg_req->parent_window);
1389 else
1390 parent_window = NULL;
1391
93ac601b 1392 GtkWidget *dialog =
b5e17af5 1393 gtk_message_dialog_new(GTK_WINDOW(parent_window),
1394 GTK_DIALOG_DESTROY_WITH_PARENT,
1395 GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
93ac601b 1396 "Background computation %s finished for trace %s",
1397 g_quark_to_string(bg_req->module_name),
1398 g_quark_to_string(ltt_trace_name(lttv_trace(bg_req->trace))));
b5e17af5 1399 if(parent_window != NULL)
1400 gtk_window_set_transient_for(GTK_WINDOW(dialog),
1401 GTK_WINDOW(parent_window));
93ac601b 1402 g_signal_connect_swapped (dialog, "response",
1403 G_CALLBACK (gtk_widget_destroy),
1404 dialog);
1405 gtk_widget_show(dialog);
1406
8bc02ec8 1407 /* - remove request */
1408 remove = TRUE;
1409 free_data = TRUE;
1410
1411 /* Go to next */
1412 if(remove)
1413 {
1414 GSList *remove_iter = iter;
1415
1416 iter = g_slist_next(iter);
1417 if(free_data) g_free(remove_iter->data);
313bd6fc 1418 *list_in = g_slist_remove_link(*list_in, remove_iter);
8bc02ec8 1419 } else { // not remove
1420 iter = g_slist_next(iter);
1421 }
1422 }
1423 }
1424
1425 /* - for each notifications in notify_in */
1426 {
313bd6fc 1427 GSList *iter = *notify_in;
8bc02ec8 1428
1429 while(iter != NULL) {
1430 gboolean remove = FALSE;
1431 gboolean free_data = FALSE;
1432
1433 BackgroundNotify *notify_req = (BackgroundNotify*)iter->data;
1434
1435 /* - call notify and remove from notify_in */
1436 lttv_hooks_call(notify_req->notify, notify_req);
1437 remove = TRUE;
1438 free_data = TRUE;
1439
1440 /* Go to next */
1441 if(remove)
1442 {
1443 GSList *remove_iter = iter;
1444
1445 iter = g_slist_next(iter);
b052368a 1446 if(free_data)
1447 notify_request_free((BackgroundNotify*)remove_iter->data);
313bd6fc 1448 *notify_in = g_slist_remove_link(*notify_in, remove_iter);
8bc02ec8 1449 } else { // not remove
1450 iter = g_slist_next(iter);
1451 }
1452 }
1453 }
1ce324c6 1454 {
1455 /* - reset the context */
1456 LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->fini(tsc);
1457 LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->init(tsc,ts);
1458 }
3710295e 1459 /* - if list_out is empty */
1460 if(g_slist_length(*list_out) == 0) {
1461 /* - return FALSE (scheduler stopped) */
1462 g_debug("Background computation scheduler stopped");
1463 g_info("Background computation finished for trace %p", trace);
1464 /* FIXME : remove status bar info, need context id and message id */
93ac601b 1465
3710295e 1466 ret_val = FALSE;
1467 } else {
1468 ret_val = TRUE;
1469 }
8bc02ec8 1470 } else {
1471 /* 3.4 else, end of trace not reached */
1472 /* - return TRUE (scheduler still registered) */
313bd6fc 1473 g_debug("Background computation left");
b052368a 1474 ret_val = TRUE;
8bc02ec8 1475 }
1476 }
1477 }
b052368a 1478 /* 4. Unlock traces */
1479 {
088f6772 1480 lttv_process_traceset_get_sync_data(tsc);
1481 //lttv_traceset_context_position_save(tsc, sync_position);
b052368a 1482 guint iter_trace;
1483
1484 for(iter_trace=0;
1485 iter_trace<lttv_traceset_number(tsc->ts);
1486 iter_trace++) {
1487 LttvTrace *trace_v = lttv_traceset_get(tsc->ts, iter_trace);
1488
1489 lttvwindowtraces_unlock(trace_v);
1490 }
1491 }
451aaf27 1492 #endif /* BABEL_CLEANUP */
b052368a 1493 return ret_val;
8bc02ec8 1494}
e62a7964 1495
1496
1497
1498/**
1499 * Register the background computation hooks for a specific module. It adds the
313bd6fc 1500 * computation hooks to the global attrubutes, under "computation/module name".
e62a7964 1501 *
1502 * @param module_name A GQuark : the name of the module which computes the
1503 * information.
1504 */
1505void lttvwindowtraces_register_computation_hooks(LttvAttributeName module_name,
750eb11a 1506 LttvHooks *before_chunk_traceset,
1507 LttvHooks *before_chunk_trace,
1508 LttvHooks *before_chunk_tracefile,
1509 LttvHooks *after_chunk_traceset,
1510 LttvHooks *after_chunk_trace,
1511 LttvHooks *after_chunk_tracefile,
1512 LttvHooks *before_request,
1513 LttvHooks *after_request,
1514 LttvHooks *event_hook,
750eb11a 1515 LttvHooks *hook_adder,
1516 LttvHooks *hook_remover)
e62a7964 1517{
1518 LttvAttribute *g_attribute = lttv_global_attributes();
1519 LttvAttribute *attribute;
1520 LttvAttributeValue value;
96c9eb79 1521 gboolean result;
e62a7964 1522
96c9eb79 1523 attribute =
e62a7964 1524 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 1525 LTTV_COMPUTATION));
1526 g_assert(attribute);
e62a7964 1527
96c9eb79 1528 attribute =
e62a7964 1529 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
96c9eb79 1530 module_name));
1531 g_assert(attribute);
e62a7964 1532
96c9eb79 1533 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1534 LTTV_BEFORE_CHUNK_TRACESET,
1535 LTTV_POINTER,
96c9eb79 1536 &value);
1537 g_assert(result);
1538
e62a7964 1539 *(value.v_pointer) = before_chunk_traceset;
1540
96c9eb79 1541 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1542 LTTV_BEFORE_CHUNK_TRACE,
1543 LTTV_POINTER,
96c9eb79 1544 &value);
1545 g_assert(result);
e62a7964 1546 *(value.v_pointer) = before_chunk_trace;
1547
96c9eb79 1548 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1549 LTTV_BEFORE_CHUNK_TRACEFILE,
1550 LTTV_POINTER,
96c9eb79 1551 &value);
1552 g_assert(result);
e62a7964 1553 *(value.v_pointer) = before_chunk_tracefile;
1554
96c9eb79 1555 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1556 LTTV_AFTER_CHUNK_TRACESET,
1557 LTTV_POINTER,
96c9eb79 1558 &value);
1559 g_assert(result);
e62a7964 1560 *(value.v_pointer) = after_chunk_traceset;
1561
96c9eb79 1562 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1563 LTTV_AFTER_CHUNK_TRACE,
1564 LTTV_POINTER,
96c9eb79 1565 &value);
1566 g_assert(result);
e62a7964 1567 *(value.v_pointer) = after_chunk_trace;
1568
96c9eb79 1569 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1570 LTTV_AFTER_CHUNK_TRACEFILE,
1571 LTTV_POINTER,
96c9eb79 1572 &value);
1573 g_assert(result);
e62a7964 1574 *(value.v_pointer) = after_chunk_tracefile;
1575
96c9eb79 1576 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1577 LTTV_BEFORE_REQUEST,
1578 LTTV_POINTER,
96c9eb79 1579 &value);
1580 g_assert(result);
e62a7964 1581 *(value.v_pointer) = before_request;
1582
96c9eb79 1583 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1584 LTTV_AFTER_REQUEST,
1585 LTTV_POINTER,
96c9eb79 1586 &value);
1587 g_assert(result);
e62a7964 1588 *(value.v_pointer) = after_request;
1589
96c9eb79 1590 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1591 LTTV_EVENT_HOOK,
1592 LTTV_POINTER,
96c9eb79 1593 &value);
1594 g_assert(result);
e62a7964 1595 *(value.v_pointer) = event_hook;
1596
96c9eb79 1597 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
313bd6fc 1598 LTTV_HOOK_ADDER,
1599 LTTV_POINTER,
96c9eb79 1600 &value);
1601 g_assert(result);
313bd6fc 1602 *(value.v_pointer) = hook_adder;
1603
96c9eb79 1604 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
313bd6fc 1605 LTTV_HOOK_REMOVER,
1606 LTTV_POINTER,
96c9eb79 1607 &value);
1608 g_assert(result);
313bd6fc 1609 *(value.v_pointer) = hook_remover;
1610
e62a7964 1611}
1612
1613
1614/**
d389bc8d 1615 * It removes all the requests that can be currently processed by the
e62a7964 1616 * background computation algorithm for all the traces (list_in and list_out).
1617 *
1618 * Leaves the flag to in_progress or none.. depending if current or queue
1619 *
1620 * @param module_name A GQuark : the name of the module which computes the
1621 * information.
1622 */
1623void lttvwindowtraces_unregister_requests(LttvAttributeName module_name)
1624{
1625 guint i;
96c9eb79 1626 gboolean result;
e62a7964 1627
1628 for(i=0;i<lttvwindowtraces_get_number();i++) {
1629 LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
1630 g_assert(trace_v != NULL);
e62a7964 1631 LttvAttribute *attribute = lttv_trace_attribute(trace_v);
1632 LttvAttributeValue value;
313bd6fc 1633 GSList **queue, **current;
e62a7964 1634 GSList *iter;
1635
96c9eb79 1636 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1637 LTTV_REQUESTS_QUEUE,
1638 LTTV_POINTER,
96c9eb79 1639 &value);
1640 g_assert(result);
1641
313bd6fc 1642 queue = (GSList**)(value.v_pointer);
e62a7964 1643
313bd6fc 1644 iter = *queue;
e62a7964 1645 while(iter != NULL) {
1646 gboolean remove = FALSE;
1647 gboolean free_data = FALSE;
1648
1649 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1650
1651 if(bg_req->module_name == module_name) {
1652 remove = TRUE;
1653 free_data = TRUE;
1654 }
1655
1656 /* Go to next */
1657 if(remove)
1658 {
1659 GSList *remove_iter = iter;
1660
1661 iter = g_slist_next(iter);
1662 if(free_data) g_free(remove_iter->data);
313bd6fc 1663 *queue = g_slist_remove_link(*queue, remove_iter);
e62a7964 1664 } else { // not remove
1665 iter = g_slist_next(iter);
1666 }
1667 }
1668
1669
96c9eb79 1670 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
e62a7964 1671 LTTV_REQUESTS_CURRENT,
1672 LTTV_POINTER,
96c9eb79 1673 &value);
1674 g_assert(result);
1675
313bd6fc 1676 current = (GSList**)(value.v_pointer);
e62a7964 1677
313bd6fc 1678 iter = *current;
e62a7964 1679 while(iter != NULL) {
1680 gboolean remove = FALSE;
1681 gboolean free_data = FALSE;
1682
1683 BackgroundRequest *bg_req = (BackgroundRequest*)iter->data;
1684
1685 if(bg_req->module_name == module_name) {
1686 remove = TRUE;
1687 free_data = TRUE;
1688 }
1689
1690 /* Go to next */
1691 if(remove)
1692 {
1693 GSList *remove_iter = iter;
1694
1695 iter = g_slist_next(iter);
1696 if(free_data) g_free(remove_iter->data);
313bd6fc 1697 *current = g_slist_remove_link(*current, remove_iter);
e62a7964 1698 } else { // not remove
1699 iter = g_slist_next(iter);
1700 }
1701 }
1702 }
1703}
1704
1705
1706/**
1707 * Unregister the background computation hooks for a specific module.
1708 *
d389bc8d 1709 * It also removes all the requests that can be currently processed by the
e62a7964 1710 * background computation algorithm for all the traces (list_in and list_out).
1711 *
1712 * @param module_name A GQuark : the name of the module which computes the
1713 * information.
1714 */
1715
1716void lttvwindowtraces_unregister_computation_hooks
1717 (LttvAttributeName module_name)
1718{
1719 LttvAttribute *g_attribute = lttv_global_attributes();
1720 LttvAttribute *attribute;
91fd6881 1721 LttvAttributeValue value;
96c9eb79 1722 gboolean result;
e62a7964 1723
96c9eb79 1724 attribute =
e62a7964 1725 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 1726 LTTV_COMPUTATION));
1727 g_assert(attribute);
e62a7964 1728
96c9eb79 1729 attribute =
1730 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(attribute),
1731 module_name));
1732 g_assert(attribute);
e62a7964 1733
96c9eb79 1734 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1735 LTTV_BEFORE_CHUNK_TRACESET,
1736 LTTV_POINTER,
96c9eb79 1737 &value);
1738 g_assert(result);
1739
91fd6881 1740 LttvHooks *before_chunk_traceset = (LttvHooks*)*(value.v_pointer);
1741 if(before_chunk_traceset != NULL)
1742 lttv_hooks_destroy(before_chunk_traceset);
1743
96c9eb79 1744 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1745 LTTV_BEFORE_CHUNK_TRACE,
1746 LTTV_POINTER,
96c9eb79 1747 &value);
1748 g_assert(result);
1749
91fd6881 1750 LttvHooks *before_chunk_trace = (LttvHooks*)*(value.v_pointer);
1751 if(before_chunk_trace != NULL)
1752 lttv_hooks_destroy(before_chunk_trace);
1753
96c9eb79 1754 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1755 LTTV_BEFORE_CHUNK_TRACEFILE,
1756 LTTV_POINTER,
96c9eb79 1757 &value);
1758 g_assert(result);
1759
91fd6881 1760 LttvHooks *before_chunk_tracefile = (LttvHooks*)*(value.v_pointer);
1761 if(before_chunk_tracefile != NULL)
1762 lttv_hooks_destroy(before_chunk_tracefile);
1763
96c9eb79 1764 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1765 LTTV_AFTER_CHUNK_TRACESET,
1766 LTTV_POINTER,
96c9eb79 1767 &value);
1768 g_assert(result);
1769
91fd6881 1770 LttvHooks *after_chunk_traceset = (LttvHooks*)*(value.v_pointer);
1771 if(after_chunk_traceset != NULL)
1772 lttv_hooks_destroy(after_chunk_traceset);
1773
96c9eb79 1774 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1775 LTTV_AFTER_CHUNK_TRACE,
1776 LTTV_POINTER,
96c9eb79 1777 &value);
1778 g_assert(result);
1779
91fd6881 1780 LttvHooks *after_chunk_trace = (LttvHooks*)*(value.v_pointer);
1781 if(after_chunk_trace != NULL)
1782 lttv_hooks_destroy(after_chunk_trace);
1783
96c9eb79 1784 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1785 LTTV_AFTER_CHUNK_TRACEFILE,
1786 LTTV_POINTER,
96c9eb79 1787 &value);
1788 g_assert(result);
1789
91fd6881 1790 LttvHooks *after_chunk_tracefile = (LttvHooks*)*(value.v_pointer);
1791 if(after_chunk_tracefile != NULL)
1792 lttv_hooks_destroy(after_chunk_tracefile);
1793
96c9eb79 1794 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1795 LTTV_BEFORE_REQUEST,
1796 LTTV_POINTER,
96c9eb79 1797 &value);
1798 g_assert(result);
1799
91fd6881 1800 LttvHooks *before_request = (LttvHooks*)*(value.v_pointer);
1801 if(before_request != NULL)
1802 lttv_hooks_destroy(before_request);
1803
96c9eb79 1804 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1805 LTTV_AFTER_REQUEST,
1806 LTTV_POINTER,
96c9eb79 1807 &value);
1808 g_assert(result);
1809
91fd6881 1810 LttvHooks *after_request = (LttvHooks*)*(value.v_pointer);
1811 if(after_request != NULL)
1812 lttv_hooks_destroy(after_request);
1813
96c9eb79 1814 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1815 LTTV_EVENT_HOOK,
1816 LTTV_POINTER,
96c9eb79 1817 &value);
1818 g_assert(result);
1819
91fd6881 1820 LttvHooks *event_hook = (LttvHooks*)*(value.v_pointer);
1821 if(event_hook != NULL)
1822 lttv_hooks_destroy(event_hook);
1823
96c9eb79 1824 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
750eb11a 1825 LTTV_EVENT_HOOK_BY_ID_CHANNEL,
91fd6881 1826 LTTV_POINTER,
96c9eb79 1827 &value);
1828 g_assert(result);
1829
96c9eb79 1830 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1831 LTTV_HOOK_ADDER,
1832 LTTV_POINTER,
96c9eb79 1833 &value);
1834 g_assert(result);
1835
91fd6881 1836 LttvHooks *hook_adder = (LttvHooks*)*(value.v_pointer);
1837 if(hook_adder != NULL)
1838 lttv_hooks_destroy(hook_adder);
1839
96c9eb79 1840 result = lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
91fd6881 1841 LTTV_HOOK_REMOVER,
1842 LTTV_POINTER,
96c9eb79 1843 &value);
1844 g_assert(result);
1845
91fd6881 1846 LttvHooks *hook_remover = (LttvHooks*)*(value.v_pointer);
1847 if(hook_remover != NULL)
1848 lttv_hooks_destroy(hook_remover);
1849
1850
e62a7964 1851 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
750eb11a 1852 LTTV_EVENT_HOOK_BY_ID_CHANNEL);
e62a7964 1853 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1854 LTTV_EVENT_HOOK);
1855
1856 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1857 LTTV_AFTER_REQUEST);
1858 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1859 LTTV_BEFORE_REQUEST);
1860
1861 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1862 LTTV_AFTER_CHUNK_TRACEFILE);
1863 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1864 LTTV_AFTER_CHUNK_TRACE);
1865 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1866 LTTV_AFTER_CHUNK_TRACESET);
1867
1868 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1869 LTTV_BEFORE_CHUNK_TRACEFILE);
1870 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1871 LTTV_BEFORE_CHUNK_TRACE);
1872 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1873 LTTV_BEFORE_CHUNK_TRACESET);
313bd6fc 1874 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1875 LTTV_HOOK_ADDER);
1876 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1877 LTTV_HOOK_REMOVER);
1878
e62a7964 1879 /* finally, remove module name */
96c9eb79 1880 attribute =
e62a7964 1881 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
96c9eb79 1882 LTTV_COMPUTATION));
1883 g_assert(attribute);
e62a7964 1884 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1885 module_name);
1886
1887}
1888
b052368a 1889/**
1890 * Lock a trace so no other instance can use it.
1891 *
1892 * @param trace The trace to lock.
1893 * @return 0 on success, -1 if cannot get lock.
1894 */
1895gint lttvwindowtraces_lock(LttvTrace *trace)
1896{
1897 LttvAttribute *attribute = lttv_trace_attribute(trace);
1898 LttvAttributeValue value;
1899 LttvAttributeType type;
1900
1901 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1902 LTTV_LOCK,
1903 &value);
1904 /* Verify the absence of the lock. */
1905 if(type != LTTV_NONE) {
1906 g_critical("Cannot take trace lock");
1907 return -1;
1908 }
1909
1910 value = lttv_iattribute_add(LTTV_IATTRIBUTE(attribute),
1911 LTTV_LOCK,
1912 LTTV_INT);
1913 /* the value is left unset. The only presence of the attribute is necessary.
1914 */
1915
1916 return 0;
1917}
1918
1919/**
1920 * Unlock a trace.
1921 *
1922 * @param trace The trace to unlock.
1923 * @return 0 on success, -1 if cannot unlock (not locked ?).
1924 */
1925gint lttvwindowtraces_unlock(LttvTrace *trace)
1926{
1927 LttvAttribute *attribute = lttv_trace_attribute(trace);
1928 LttvAttributeType type;
1929 LttvAttributeValue value;
1930
1931 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1932 LTTV_LOCK,
1933 &value);
1934 /* Verify the presence of the lock. */
1935 if(type == LTTV_NONE) {
1936 g_critical("Cannot release trace lock");
1937 return -1;
1938 }
1939
1940 lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
1941 LTTV_LOCK);
1942
1943 return 0;
1944}
1945
1946/**
1947 * Verify if a trace is locked.
1948 *
1949 * @param trace The trace to verify.
1950 * @return TRUE if locked, FALSE is unlocked.
1951 */
1952gint lttvwindowtraces_get_lock_state(LttvTrace *trace)
1953{
1954 LttvAttribute *attribute = lttv_trace_attribute(trace);
1955 LttvAttributeType type;
1956 LttvAttributeValue value;
1957
1958 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
1959 LTTV_LOCK,
1960 &value);
1961 /* The only presence of the attribute is necessary. */
1962 if(type == LTTV_NONE)
1963 return FALSE;
1964 else
1965 return TRUE;
1966}
e62a7964 1967
This page took 0.248713 seconds and 4 git commands to generate.