6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/babeltrace.h>
22 #include <babeltrace/babeltrace-internal.h>
23 #include <babeltrace/context.h>
24 #include <babeltrace/context-internal.h>
25 #include <babeltrace/ctf-ir/metadata.h>
26 #include <babeltrace/iterator-internal.h>
27 #include <babeltrace/ctf/events.h>
28 #include <babeltrace/ctf/events-internal.h>
29 #include <babeltrace/ctf/callbacks-internal.h>
33 struct bt_dependencies
*_babeltrace_dependencies_create(const char *first
,
37 struct bt_dependencies
*dep
;
39 dep
= g_new0(struct bt_dependencies
, 1);
41 dep
->deps
= g_array_new(FALSE
, TRUE
, sizeof(GQuark
));
44 GQuark q
= g_quark_from_string(iter
);
45 g_array_append_val(dep
->deps
, q
);
46 iter
= va_arg(ap
, const char *);
51 struct bt_dependencies
*babeltrace_dependencies_create(const char *first
, ...)
54 struct bt_dependencies
*deps
;
57 deps
= _babeltrace_dependencies_create(first
, ap
);
63 * bt_ctf_iter_add_callback: Add a callback to CTF iterator.
65 int bt_ctf_iter_add_callback(struct bt_ctf_iter
*iter
,
66 bt_intern_str event
, void *private_data
, int flags
,
67 enum bt_cb_ret (*callback
)(struct bt_ctf_event
*ctf_data
,
69 struct bt_dependencies
*depends
,
70 struct bt_dependencies
*weak_depends
,
71 struct bt_dependencies
*provides
)
74 gpointer
*event_id_ptr
;
75 unsigned long event_id
;
76 struct trace_collection
*tc
;
78 if (!iter
|| !callback
)
81 tc
= iter
->parent
.ctx
->tc
;
82 for (i
= 0; i
< tc
->array
->len
; i
++) {
83 struct ctf_trace
*tin
;
84 struct trace_descriptor
*td_read
;
86 td_read
= g_ptr_array_index(tc
->array
, i
);
87 tin
= container_of(td_read
, struct ctf_trace
, parent
);
89 for (stream_id
= 0; stream_id
< tin
->streams
->len
; stream_id
++) {
90 struct ctf_stream_declaration
*stream
;
91 struct bt_stream_callbacks
*bt_stream_cb
= NULL
;
92 struct bt_callback_chain
*bt_chain
= NULL
;
93 struct bt_callback new_callback
;
95 stream
= g_ptr_array_index(tin
->streams
, stream_id
);
97 if (stream_id
>= iter
->callbacks
->len
) {
98 g_array_set_size(iter
->callbacks
, stream
->stream_id
+ 1);
100 bt_stream_cb
= &g_array_index(iter
->callbacks
,
101 struct bt_stream_callbacks
, stream
->stream_id
);
102 if (!bt_stream_cb
->per_id_callbacks
) {
103 bt_stream_cb
->per_id_callbacks
= g_array_new(FALSE
, TRUE
,
104 sizeof(struct bt_callback_chain
));
108 /* find the event id */
109 event_id_ptr
= g_hash_table_lookup(stream
->event_quark_to_id
,
110 (gconstpointer
) (unsigned long) event
);
111 /* event not found in this stream class */
113 fprintf(stderr
, "[error] Event ID not found in stream class\n");
116 event_id
= (uint64_t)(unsigned long) *event_id_ptr
;
118 /* find or create the bt_callback_chain for this event */
119 if (event_id
>= bt_stream_cb
->per_id_callbacks
->len
) {
120 g_array_set_size(bt_stream_cb
->per_id_callbacks
, event_id
+ 1);
122 bt_chain
= &g_array_index(bt_stream_cb
->per_id_callbacks
,
123 struct bt_callback_chain
, event_id
);
124 if (!bt_chain
->callback
) {
125 bt_chain
->callback
= g_array_new(FALSE
, TRUE
,
126 sizeof(struct bt_callback
));
129 /* callback for all events */
130 if (!iter
->main_callbacks
.callback
) {
131 iter
->main_callbacks
.callback
= g_array_new(FALSE
, TRUE
,
132 sizeof(struct bt_callback
));
134 bt_chain
= &iter
->main_callbacks
;
137 new_callback
.private_data
= private_data
;
138 new_callback
.flags
= flags
;
139 new_callback
.callback
= callback
;
140 new_callback
.depends
= depends
;
141 new_callback
.weak_depends
= weak_depends
;
142 new_callback
.provides
= provides
;
144 /* TODO : take care of priority, for now just FIFO */
145 g_array_append_val(bt_chain
->callback
, new_callback
);
153 int extract_ctf_stream_event(struct ctf_stream_definition
*stream
,
154 struct bt_ctf_event
*event
)
156 struct ctf_stream_declaration
*stream_class
= stream
->stream_class
;
157 struct ctf_event_declaration
*event_class
;
158 uint64_t id
= stream
->event_id
;
160 if (id
>= stream_class
->events_by_id
->len
) {
161 fprintf(stderr
, "[error] Event id %" PRIu64
" is outside range.\n", id
);
164 event
->parent
= g_ptr_array_index(stream
->events_by_id
, id
);
165 if (!event
->parent
) {
166 fprintf(stderr
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
169 event_class
= g_ptr_array_index(stream_class
->events_by_id
, id
);
171 fprintf(stderr
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
178 void process_callbacks(struct bt_ctf_iter
*iter
,
179 struct ctf_stream_definition
*stream
)
181 struct bt_stream_callbacks
*bt_stream_cb
;
182 struct bt_callback_chain
*bt_chain
;
183 struct bt_callback
*cb
;
186 struct bt_ctf_event ctf_data
;
188 assert(iter
&& stream
);
190 ret
= extract_ctf_stream_event(stream
, &ctf_data
);
192 /* process all events callback first */
193 if (iter
->main_callbacks
.callback
) {
194 for (i
= 0; i
< iter
->main_callbacks
.callback
->len
; i
++) {
195 cb
= &g_array_index(iter
->main_callbacks
.callback
, struct bt_callback
, i
);
198 ret
= cb
->callback(&ctf_data
, cb
->private_data
);
201 case BT_CB_ERROR_STOP
:
209 /* process per event callbacks */
210 bt_stream_cb
= &g_array_index(iter
->callbacks
,
211 struct bt_stream_callbacks
, stream
->stream_id
);
212 if (!bt_stream_cb
|| !bt_stream_cb
->per_id_callbacks
)
215 if (stream
->event_id
>= bt_stream_cb
->per_id_callbacks
->len
)
217 bt_chain
= &g_array_index(bt_stream_cb
->per_id_callbacks
,
218 struct bt_callback_chain
, stream
->event_id
);
219 if (!bt_chain
|| !bt_chain
->callback
)
222 for (i
= 0; i
< bt_chain
->callback
->len
; i
++) {
223 cb
= &g_array_index(bt_chain
->callback
, struct bt_callback
, i
);
226 ret
= cb
->callback(&ctf_data
, cb
->private_data
);
229 case BT_CB_ERROR_STOP
:
This page took 0.034049 seconds and 4 git commands to generate.