1 /* This file is part of the Linux Trace Toolkit Graphic User Interface
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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;
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.
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,
19 /* This file is the API used to launch any background computation on a trace */
21 /* Here is the implementation of the API */
24 #include <ltt/trace.h>
26 #include <lttv/lttv.h>
27 #include <lttv/traceset.h>
28 #include <lttv/attribute.h>
29 #include <lttv/tracecontext.h>
30 #include <lttvwindow/lttvwindowtraces.h>
33 typedef struct _BackgroundRequest
{
34 LttvAttributeName module_name
; /* Hook path in global attributes,
35 where all standard hooks under computation/.
37 LttvTrace
*trace
; /* trace concerned */
40 typedef struct _BackgroundNotify
{
42 LttvTrace
*trace
; /* trace */
44 LttvTracesetContextPosition
*notify_position
;
45 LttvHooks
*notify
; /* Hook to call when the notify is
46 passed, or at the end of trace */
51 /* Get a trace by its path name.
53 * @param path path of the trace on the virtual file system.
54 * @return Pointer to trace if found
55 * NULL is returned if the trace is not present
58 LttvTrace
*lttvwindowtraces_get_trace_by_name(gchar
*path
)
60 LttvAttribute
*attribute
= lttv_global_attributes();
63 for(i
=0;i
<lttvwindowtraces_get_number();i
++) {
64 LttvTrace
*trace_v
= lttvwindowtraces_get_trace(i
);
68 g_assert(trace_v
!= NULL
);
70 trace
= lttv_trace(trace_v
);
71 g_assert(trace
!= NULL
);
72 name
= ltt_trace_name(trace
);
74 if(strcmp(name
, path
) == 0) {
83 /* Get a trace by its number identifier */
85 LttvTrace
*lttvwindowtraces_get_trace(guint num
)
87 LttvAttribute
*g_attribute
= lttv_global_attributes();
88 LttvAttribute
*attribute
;
89 LttvAttributeType type
;
90 LttvAttributeName name
;
91 LttvAttributeValue value
;
94 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute
),
97 type
= lttv_iattribute_get(LTTV_IATTRIBUTE(attribute
), num
, &name
, &value
);
99 if(type
== LTTV_POINTER
) {
100 return (LttvTrace
*)*(value
.v_pointer
);
106 /* Total number of traces */
108 guint
lttvwindowtraces_get_number()
110 LttvAttribute
*g_attribute
= lttv_global_attributes();
111 LttvAttribute
*attribute
;
112 LttvAttributeValue value
;
115 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute
),
118 return ( lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute
)) );
121 /* Add a trace to the global attributes */
123 void lttvwindowtraces_add_trace(LttvTrace
*trace
)
125 LttvAttribute
*g_attribute
= lttv_global_attributes();
126 LttvAttribute
*attribute
;
127 LttvAttributeValue value
;
131 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute
),
133 num
= lttv_attribute_get_number(attribute
);
135 value
= lttv_attribute_add(attribute
,
139 *(value
.v_pointer
) = (gpointer
)trace
;
142 /* Remove a trace from the global attributes */
144 void lttvwindowtraces_remove_trace(LttvTrace
*trace
)
146 LttvAttribute
*g_attribute
= lttv_global_attributes();
147 LttvAttribute
*attribute
;
148 LttvAttributeValue value
;
152 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute
),
155 for(i
=0;i
<lttvwindowtraces_get_number();i
++) {
156 LttvTrace
*trace_v
= lttvwindowtraces_get_trace(i
);
158 g_assert(trace_v
!= NULL
);
160 if(trace_v
== trace
) {
162 lttv_attribute_remove(attribute
, i
);
170 * Function to request data from a specific trace
172 * The memory allocated for the request will be managed by the API.
174 * @param trace the trace to compute
175 * @param module_name the name of the module which registered global computation
179 void lttvwindowtraces_background_request_queue
180 (LttvTrace
*trace
, gchar
*module_name
)
182 BackgroundRequest
*bg_req
;
183 LttvAttribute
*attribute
= lttv_trace_attribute(trace
);
184 LttvAttributeValue value
;
188 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
192 slist
= (GSList
**)(value
.v_pointer
);
194 bg_req
= g_new(BackgroundRequest
,1);
195 bg_req
->module_name
= g_quark_from_string(module_name
);
196 bg_req
->trace
= trace
;
198 *slist
= g_slist_append(*slist
, bg_req
);
202 * Remove a background request from a trace.
204 * This should ONLY be used by the modules which registered the global hooks
205 * (module_name). If this is called by the viewers, it may lead to incomplete
206 * and incoherent background processing information.
208 * Even if the module which deals with the hooks removes the background
209 * requests, it may cause a problem if the module gets loaded again in the
210 * session : the data will be partially calculated. The calculation function
211 * must deal with this case correctly.
213 * @param trace the trace to compute
214 * @param module_name the name of the module which registered global computation
218 void lttvwindowtraces_background_request_remove
219 (LttvTrace
*trace
, gchar
*module_name
)
221 LttvAttribute
*attribute
= lttv_trace_attribute(trace
);
222 LttvAttributeValue value
;
226 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
230 slist
= (GSList
**)(value
.v_pointer
);
232 for(iter
=*slist
;iter
!=NULL
;) {
233 BackgroundRequest
*bg_req
=
234 (BackgroundRequest
*)iter
->data
;
236 if(bg_req
->module_name
== g_quark_from_string(module_name
)) {
237 GSList
*rem_iter
= iter
;
238 iter
=g_slist_next(iter
);
240 *slist
= g_slist_delete_link(*slist
, rem_iter
);
242 iter
=g_slist_next(iter
);
249 * Register a callback to be called when requested data is passed in the next
250 * queued background processing.
252 * @param owner owner of the background notification
253 * @param trace the trace computed
254 * @param notify_time time when notification hooks must be called
255 * @param notify_position position when notification hooks must be called
256 * @param notify Hook to call when the notify position is passed
259 void lttvwindowtraces_background_notify_queue
263 const LttvTracesetContextPosition
*notify_position
,
264 const LttvHooks
*notify
)
266 BackgroundNotify
*bg_notify
;
267 LttvAttribute
*attribute
= lttv_trace_attribute(trace
);
268 LttvAttributeValue value
;
271 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
275 slist
= (GSList
**)(value
.v_pointer
);
278 bg_notify
= g_new(BackgroundNotify
,1);
280 bg_notify
->owner
= owner
;
281 bg_notify
->trace
= trace
;
282 bg_notify
->notify_time
= notify_time
;
283 bg_notify
->notify_position
= ltt_traceset_context_position_new();
284 lttv_traceset_context_position_copy(bg_notify
->notify_position
,
286 bg_notify
->notify
= lttv_hooks_new();
287 lttv_hooks_add_list(bg_notify
->notify
, notify
);
289 *slist
= g_slist_append(*slist
, bg_notify
);
293 * Register a callback to be called when requested data is passed in the current
294 * background processing.
296 * @param owner owner of the background notification
297 * @param trace the trace computed
298 * @param notify_time time when notification hooks must be called
299 * @param notify_position position when notification hooks must be called
300 * @param notify Hook to call when the notify position is passed
303 void lttvwindowtraces_background_notify_current
307 const LttvTracesetContextPosition
*notify_position
,
308 const LttvHooks
*notify
)
310 BackgroundNotify
*bg_notify
;
311 LttvAttribute
*attribute
= lttv_trace_attribute(trace
);
312 LttvAttributeValue value
;
315 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
319 slist
= (GSList
**)(value
.v_pointer
);
321 bg_notify
= g_new(BackgroundNotify
,1);
323 bg_notify
->owner
= owner
;
324 bg_notify
->trace
= trace
;
325 bg_notify
->notify_time
= notify_time
;
326 bg_notify
->notify_position
= ltt_traceset_context_position_new();
327 lttv_traceset_context_position_copy(bg_notify
->notify_position
,
329 bg_notify
->notify
= lttv_hooks_new();
330 lttv_hooks_add_list(bg_notify
->notify
, notify
);
332 *slist
= g_slist_append(*slist
, bg_notify
);
336 * Removes all the notifications requests from a specific viewer.
338 * @param owner owner of the background notification
341 void lttvwindowtraces_background_notify_remove(gpointer owner
)
345 for(i
=0;i
<lttvwindowtraces_get_number();i
++) {
346 LttvAttribute
*attribute
;
347 LttvAttributeValue value
;
348 LttvTrace
*trace_v
= lttvwindowtraces_get_trace(i
);
352 g_assert(trace_v
!= NULL
);
354 LttvAttribute
*t_a
= lttv_trace_attribute(trace_v
);
356 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
360 slist
= (GSList
**)(value
.v_pointer
);
362 for(iter
=*slist
;iter
!=NULL
;) {
364 BackgroundNotify
*bg_notify
= (BackgroundNotify
*)iter
->data
;
366 if(bg_notify
->owner
== owner
) {
367 GSList
*rem_iter
= iter
;
368 iter
=g_slist_next(iter
);
369 lttv_traceset_context_position_destroy(
370 bg_notify
->notify_position
);
371 lttv_hooks_destroy(bg_notify
->notify
);
373 g_slist_remove_link(*slist
, rem_iter
);
375 iter
=g_slist_next(iter
);
379 g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute
),
383 slist
= (GSList
**)(value
.v_pointer
);
385 for(iter
=*slist
;iter
!=NULL
;) {
387 BackgroundNotify
*bg_notify
= (BackgroundNotify
*)iter
->data
;
389 if(bg_notify
->owner
== owner
) {
390 GSList
*rem_iter
= iter
;
391 iter
=g_slist_next(iter
);
392 lttv_traceset_context_position_destroy(
393 bg_notify
->notify_position
);
394 lttv_hooks_destroy(bg_notify
->notify
);
396 g_slist_remove_link(*slist
, rem_iter
);
398 iter
=g_slist_next(iter
);