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