4 * Babeltrace Debug Info Plug-in
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@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.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/graph/notification-iterator.h>
30 #include <babeltrace/graph/private-notification-iterator.h>
31 #include <babeltrace/graph/connection.h>
32 #include <babeltrace/graph/notification.h>
33 #include <babeltrace/graph/notification-event.h>
34 #include <babeltrace/graph/notification-stream.h>
35 #include <babeltrace/graph/notification-packet.h>
36 #include <babeltrace/graph/component-filter.h>
37 #include <babeltrace/graph/private-component-filter.h>
38 #include <babeltrace/graph/private-port.h>
39 #include <babeltrace/graph/private-connection.h>
40 #include <babeltrace/graph/private-component.h>
41 #include <babeltrace/plugin/plugin-dev.h>
42 #include <plugins-common.h>
44 #include "debug-info.h"
48 void destroy_debug_info_data(struct debug_info_component
*debug_info
)
50 free(debug_info
->arg_debug_info_field_name
);
55 void destroy_debug_info_component(struct bt_private_component
*component
)
57 void *data
= bt_private_component_get_user_data(component
);
58 destroy_debug_info_data(data
);
62 struct debug_info_component
*create_debug_info_component_data(void)
64 struct debug_info_component
*debug_info
;
66 debug_info
= g_new0(struct debug_info_component
, 1);
70 debug_info
->err
= stderr
;
77 void unref_trace(struct debug_info_trace
*di_trace
)
79 bt_put(di_trace
->trace
);
83 void debug_info_iterator_destroy(struct bt_private_notification_iterator
*it
)
85 struct debug_info_iterator
*it_data
;
87 it_data
= bt_private_notification_iterator_get_user_data(it
);
90 if (it_data
->input_iterator_group
) {
91 g_ptr_array_free(it_data
->input_iterator_group
, TRUE
);
93 bt_put(it_data
->current_notification
);
94 bt_put(it_data
->input_iterator
);
95 g_hash_table_destroy(it_data
->trace_map
);
98 g_hash_table_destroy(it_data->stream_map);
99 g_hash_table_destroy(it_data->stream_class_map);
100 g_hash_table_destroy(it_data->packet_map);
101 g_hash_table_destroy(it_data->trace_debug_map);
107 struct bt_notification
*handle_notification(FILE *err
,
108 struct debug_info_iterator
*debug_it
,
109 struct bt_notification
*notification
)
111 struct bt_notification
*new_notification
= NULL
;
113 switch (bt_notification_get_type(notification
)) {
114 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
116 struct bt_ctf_packet
*packet
=
117 bt_notification_packet_begin_get_packet(notification
);
118 struct bt_ctf_packet
*writer_packet
;
124 writer_packet
= debug_info_new_packet(debug_it
, packet
);
125 assert(writer_packet
);
126 new_notification
= bt_notification_packet_begin_create(
128 assert(new_notification
);
132 case BT_NOTIFICATION_TYPE_PACKET_END
:
134 struct bt_ctf_packet
*packet
=
135 bt_notification_packet_end_get_packet(notification
);
136 struct bt_ctf_packet
*writer_packet
;
142 writer_packet
= debug_info_close_packet(debug_it
, packet
);
143 assert(writer_packet
);
144 new_notification
= bt_notification_packet_end_create(
146 assert(new_notification
);
150 case BT_NOTIFICATION_TYPE_EVENT
:
152 struct bt_ctf_event
*event
= bt_notification_event_get_event(
154 struct bt_ctf_event
*writer_event
;
155 struct bt_clock_class_priority_map
*cc_prio_map
=
156 bt_notification_event_get_clock_class_priority_map(
162 writer_event
= debug_info_output_event(debug_it
, event
);
163 assert(writer_event
);
164 new_notification
= bt_notification_event_create(writer_event
,
167 assert(new_notification
);
169 bt_put(writer_event
);
172 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
174 struct bt_ctf_stream
*stream
=
175 bt_notification_stream_begin_get_stream(notification
);
176 struct bt_ctf_stream
*writer_stream
;
182 writer_stream
= debug_info_stream_begin(debug_it
, stream
);
183 assert(writer_stream
);
184 new_notification
= bt_notification_stream_begin_create(
186 assert(new_notification
);
188 bt_put(writer_stream
);
191 case BT_NOTIFICATION_TYPE_STREAM_END
:
193 struct bt_ctf_stream
*stream
=
194 bt_notification_stream_end_get_stream(notification
);
195 struct bt_ctf_stream
*writer_stream
;
201 writer_stream
= debug_info_stream_end(debug_it
, stream
);
202 assert(writer_stream
);
203 new_notification
= bt_notification_stream_end_create(
205 assert(new_notification
);
207 bt_put(writer_stream
);
210 case BT_NOTIFICATION_TYPE_INACTIVITY
:
212 new_notification
= bt_get(notification
);
216 puts("Unhandled notification type");
220 return new_notification
;
224 struct bt_notification_iterator_next_return
debug_info_iterator_next(
225 struct bt_private_notification_iterator
*iterator
)
227 struct debug_info_iterator
*debug_it
= NULL
;
228 struct bt_private_component
*component
= NULL
;
229 struct debug_info_component
*debug_info
= NULL
;
230 struct bt_notification_iterator
*source_it
= NULL
;
231 struct bt_notification
*notification
;
232 struct bt_notification_iterator_next_return ret
= {
233 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
234 .notification
= NULL
,
237 debug_it
= bt_private_notification_iterator_get_user_data(iterator
);
240 component
= bt_private_notification_iterator_get_private_component(iterator
);
242 debug_info
= bt_private_component_get_user_data(component
);
245 source_it
= debug_it
->input_iterator
;
247 ret
.status
= bt_notification_iterator_next(source_it
);
248 if (ret
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
252 notification
= bt_notification_iterator_get_notification(
255 ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
259 ret
.notification
= handle_notification(debug_info
->err
, debug_it
,
261 assert(ret
.notification
);
262 bt_put(notification
);
270 enum bt_notification_iterator_status
debug_info_iterator_init(
271 struct bt_private_notification_iterator
*iterator
,
272 struct bt_private_port
*port
)
274 enum bt_notification_iterator_status ret
=
275 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
276 enum bt_notification_iterator_status it_ret
;
277 enum bt_connection_status conn_status
;
278 struct bt_private_connection
*connection
= NULL
;
279 struct bt_private_component
*component
=
280 bt_private_notification_iterator_get_private_component(iterator
);
281 struct debug_info_iterator
*it_data
= g_new0(struct debug_info_iterator
, 1);
282 struct bt_private_port
*input_port
;
283 static const enum bt_notification_type notif_types
[] = {
284 BT_NOTIFICATION_TYPE_EVENT
,
285 BT_NOTIFICATION_TYPE_STREAM_BEGIN
,
286 BT_NOTIFICATION_TYPE_STREAM_END
,
287 BT_NOTIFICATION_TYPE_PACKET_BEGIN
,
288 BT_NOTIFICATION_TYPE_PACKET_END
,
289 BT_NOTIFICATION_TYPE_SENTINEL
,
293 ret
= BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
;
297 input_port
= bt_private_component_filter_get_input_private_port_by_name(
300 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
304 connection
= bt_private_port_get_private_connection(input_port
);
307 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
311 conn_status
= bt_private_connection_create_notification_iterator(
312 connection
, notif_types
, &it_data
->input_iterator
);
313 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
314 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
318 it_data
->debug_info_component
= (struct debug_info_component
*)
319 bt_private_component_get_user_data(component
);
320 it_data
->err
= it_data
->debug_info_component
->err
;
321 it_data
->trace_map
= g_hash_table_new_full(g_direct_hash
,
322 g_direct_equal
, NULL
, (GDestroyNotify
) unref_trace
);
324 it_ret
= bt_private_notification_iterator_set_user_data(iterator
, it_data
);
336 enum bt_component_status
init_from_params(
337 struct debug_info_component
*debug_info_component
,
338 struct bt_value
*params
)
340 struct bt_value
*value
= NULL
;
341 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
345 value
= bt_value_map_get(params
, "debug-info-field-name");
347 enum bt_value_status value_ret
;
350 value_ret
= bt_value_string_get(value
, &tmp
);
352 ret
= BT_COMPONENT_STATUS_INVALID
;
353 printf_error("Failed to retrieve debug-info-field-name value. "
354 "Expecting a string");
356 strcpy(debug_info_component
->arg_debug_info_field_name
, tmp
);
359 debug_info_component
->arg_debug_info_field_name
=
360 malloc(strlen("debug_info") + 1);
361 if (!debug_info_component
->arg_debug_info_field_name
) {
362 ret
= BT_COMPONENT_STATUS_NOMEM
;
365 sprintf(debug_info_component
->arg_debug_info_field_name
,
368 if (ret
!= BT_COMPONENT_STATUS_OK
) {
372 value
= bt_value_map_get(params
, "debug-dir");
374 enum bt_value_status value_ret
;
376 value_ret
= bt_value_string_get(value
,
377 &debug_info_component
->arg_debug_dir
);
379 ret
= BT_COMPONENT_STATUS_INVALID
;
380 printf_error("Failed to retrieve debug-dir value. "
381 "Expecting a string");
385 if (ret
!= BT_COMPONENT_STATUS_OK
) {
389 value
= bt_value_map_get(params
, "target-prefix");
391 enum bt_value_status value_ret
;
393 value_ret
= bt_value_string_get(value
,
394 &debug_info_component
->arg_target_prefix
);
396 ret
= BT_COMPONENT_STATUS_INVALID
;
397 printf_error("Failed to retrieve target-prefix value. "
398 "Expecting a string");
402 if (ret
!= BT_COMPONENT_STATUS_OK
) {
406 value
= bt_value_map_get(params
, "full-path");
408 enum bt_value_status value_ret
;
411 value_ret
= bt_value_bool_get(value
,
414 ret
= BT_COMPONENT_STATUS_INVALID
;
415 printf_error("Failed to retrieve full-path value. "
416 "Expecting a boolean");
419 debug_info_component
->arg_full_path
= bool_val
;
422 if (ret
!= BT_COMPONENT_STATUS_OK
) {
430 enum bt_component_status
debug_info_component_init(
431 struct bt_private_component
*component
, struct bt_value
*params
,
432 UNUSED_VAR
void *init_method_data
)
434 enum bt_component_status ret
;
435 struct debug_info_component
*debug_info
= create_debug_info_component_data();
438 ret
= BT_COMPONENT_STATUS_NOMEM
;
442 ret
= bt_private_component_set_user_data(component
, debug_info
);
443 if (ret
!= BT_COMPONENT_STATUS_OK
) {
447 ret
= bt_private_component_filter_add_input_private_port(
448 component
, "in", NULL
, NULL
);
449 if (ret
!= BT_COMPONENT_STATUS_OK
) {
453 ret
= bt_private_component_filter_add_output_private_port(
454 component
, "out", NULL
, NULL
);
455 if (ret
!= BT_COMPONENT_STATUS_OK
) {
459 ret
= init_from_params(debug_info
, params
);
463 destroy_debug_info_data(debug_info
);
467 /* Initialize plug-in entry points. */
468 BT_PLUGIN_WITH_ID(lttng_utils
, "lttng-utils");
469 BT_PLUGIN_DESCRIPTION_WITH_ID(lttng_utils
, "LTTng utilities");
470 BT_PLUGIN_AUTHOR_WITH_ID(lttng_utils
, "Julien Desfossez");
471 BT_PLUGIN_LICENSE_WITH_ID(lttng_utils
, "MIT");
473 BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(lttng_utils
, debug_info
, "debug-info",
474 debug_info_iterator_next
);
475 BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(lttng_utils
, debug_info
,
476 "Augment compatible events with debugging information.");
477 BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(lttng_utils
,
478 debug_info
, debug_info_component_init
);
479 BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(lttng_utils
,
480 debug_info
, destroy_debug_info_component
);
481 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(
482 lttng_utils
, debug_info
, debug_info_iterator_init
);
483 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(
484 lttng_utils
, debug_info
, debug_info_iterator_destroy
);