* Babeltrace CTF Text Output Plugin
*
* Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* SOFTWARE.
*/
-#include <babeltrace/plugin/plugin-macros.h>
-#include <babeltrace/plugin/component.h>
-#include <babeltrace/plugin/sink.h>
-#include <babeltrace/plugin/notification/notification.h>
-#include <babeltrace/plugin/notification/iterator.h>
-#include <babeltrace/plugin/notification/event.h>
+#include <babeltrace/plugin/plugin-dev.h>
+#include <babeltrace/component/component.h>
+#include <babeltrace/component/component-sink.h>
+#include <babeltrace/component/notification/notification.h>
+#include <babeltrace/component/notification/iterator.h>
+#include <babeltrace/component/notification/event.h>
#include <babeltrace/values.h>
#include <babeltrace/compiler.h>
#include <stdio.h>
#include <glib.h>
#include "text.h"
-#define PLUGIN_NAME "text"
-
static
const char *plugin_options[] = {
"output-path",
"field-trace:vpid",
"field-loglevel",
"field-emf",
- "field-callsite",
-};
-
-static
-const char *loglevel_str [] = {
- [LOGLEVEL_EMERG] = "TRACE_EMERG",
- [LOGLEVEL_ALERT] = "TRACE_ALERT",
- [LOGLEVEL_CRIT] = "TRACE_CRIT",
- [LOGLEVEL_ERR] = "TRACE_ERR",
- [LOGLEVEL_WARNING] = "TRACE_WARNING",
- [LOGLEVEL_NOTICE] = "TRACE_NOTICE",
- [LOGLEVEL_INFO] = "TRACE_INFO",
- [LOGLEVEL_DEBUG_SYSTEM] = "TRACE_DEBUG_SYSTEM",
- [LOGLEVEL_DEBUG_PROGRAM] = "TRACE_DEBUG_PROGRAM",
- [LOGLEVEL_DEBUG_PROCESS] = "TRACE_DEBUG_PROCESS",
- [LOGLEVEL_DEBUG_MODULE] = "TRACE_DEBUG_MODULE",
- [LOGLEVEL_DEBUG_UNIT] = "TRACE_DEBUG_UNIT",
- [LOGLEVEL_DEBUG_FUNCTION] = "TRACE_DEBUG_FUNCTION",
- [LOGLEVEL_DEBUG_LINE] = "TRACE_DEBUG_LINE",
- [LOGLEVEL_DEBUG] = "TRACE_DEBUG",
};
static
}
switch (bt_notification_get_type(notification)) {
- case BT_NOTIFICATION_TYPE_PACKET_START:
+ case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
puts("<packet>");
break;
case BT_NOTIFICATION_TYPE_PACKET_END:
goto end;
}
- if (!text->processed_first_event) {
- ret = bt_notification_iterator_next(it);
- if (ret != BT_COMPONENT_STATUS_OK) {
+ if (likely(text->processed_first_event)) {
+ enum bt_notification_iterator_status it_ret;
+
+ it_ret = bt_notification_iterator_next(it);
+ switch (it_ret) {
+ case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ case BT_NOTIFICATION_ITERATOR_STATUS_END:
+ ret = BT_COMPONENT_STATUS_END;
goto end;
+ default:
+ break;
}
- } else {
- text->processed_first_event = true;
}
-
notification = bt_notification_iterator_get_notification(it);
if (!notification) {
ret = BT_COMPONENT_STATUS_ERROR;
}
ret = handle_notification(text, notification);
+ text->processed_first_event = true;
end:
bt_put(it);
bt_put(notification);
if (!bt_value_map_get(plugin_opt_map, key)) {
fprintf(text->err,
- "[warning] Parameter \"%s\" unknown to \"%s\" plugin\n",
- key, PLUGIN_NAME);
+ "[warning] Parameter \"%s\" unknown to \"text\" plugin\n", key);
}
return true;
}
text->options.print_loglevel_field = false;
text->options.print_emf_field = false;
text->options.print_emf_field = false;
- text->options.print_callsite_field = false;
break;
case TEXT_DEFAULT_SHOW:
text->options.print_trace_field = true;
text->options.print_loglevel_field = true;
text->options.print_emf_field = true;
text->options.print_emf_field = true;
- text->options.print_callsite_field = true;
break;
case TEXT_DEFAULT_HIDE:
text->options.print_trace_field = false;
text->options.print_loglevel_field = false;
text->options.print_emf_field = false;
text->options.print_emf_field = false;
- text->options.print_callsite_field = false;
break;
default:
ret = BT_COMPONENT_STATUS_ERROR;
text->options.print_emf_field = value;
}
- value = false;
- found = false;
- ret = apply_one_bool("field-callsite", params, &value, &found);
- if (ret != BT_COMPONENT_STATUS_OK) {
- goto end;
- }
- if (found) {
- text->options.print_callsite_field = value;
- }
end:
bt_put(text->plugin_opt_map);
text->plugin_opt_map = NULL;
text->out = stdout;
text->err = stderr;
- ret = apply_params(text, params);
- if (ret != BT_COMPONENT_STATUS_OK) {
- goto error;
- }
+ text->delta_cycles = -1ULL;
+ text->last_cycles_timestamp = -1ULL;
- ret = bt_component_set_destroy_cb(component,
- destroy_text);
- if (ret != BT_COMPONENT_STATUS_OK) {
- goto error;
- }
+ text->delta_real_timestamp = -1ULL;
+ text->last_real_timestamp = -1ULL;
- ret = bt_component_set_private_data(component, text);
+ ret = apply_params(text, params);
if (ret != BT_COMPONENT_STATUS_OK) {
goto error;
}
- ret = bt_component_sink_set_consume_cb(component,
- run);
+ ret = bt_component_set_private_data(component, text);
if (ret != BT_COMPONENT_STATUS_OK) {
goto error;
}
}
/* Initialize plug-in entry points. */
-BT_PLUGIN_NAME("text");
+BT_PLUGIN(text);
BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in.");
BT_PLUGIN_AUTHOR("Jérémie Galarneau");
BT_PLUGIN_LICENSE("MIT");
+BT_PLUGIN_SINK_COMPONENT_CLASS(text, run);
+BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(text, destroy_text);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text,
+ "Formats CTF-IR to text. Formerly known as ctf-text.");
-BT_PLUGIN_COMPONENT_CLASSES_BEGIN
-BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(PLUGIN_NAME,
- "Formats CTF-IR to text. Formerly known as ctf-text.",
- text_component_init)
-BT_PLUGIN_COMPONENT_CLASSES_END