From af9a82ebc462fbc376143d656ca184cfd31ebdc7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 11 Oct 2016 10:44:38 -0400 Subject: [PATCH] Add missing text plugin files MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- plugins/text/print.c | 140 +++++++++++++++++++++++++++++++++++++++++++ plugins/text/text.h | 79 ++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 plugins/text/print.c create mode 100644 plugins/text/text.h diff --git a/plugins/text/print.c b/plugins/text/print.c new file mode 100644 index 00000000..4183b8e0 --- /dev/null +++ b/plugins/text/print.c @@ -0,0 +1,140 @@ +/* + * print.c + * + * Babeltrace CTF Text Output Plugin Event Printing + * + * Copyright 2016 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include "text.h" + +struct timestamp { + int64_t real_timestamp; /* Relative to UNIX epoch. */ + uint64_t clock_value; /* In cycles. */ +}; + +static +void print_timestamp_cycles(struct text_component *text, + struct bt_ctf_clock *clock, + struct bt_ctf_event *event) +{ + fputs("00000000000000000000", text->out); +} + +static +void print_timestamp_wall(struct text_component *text, + struct bt_ctf_clock *clock, + struct bt_ctf_event *event) +{ + fputs("??:??:??.?????????", text->out); +} + +static +enum bt_component_status get_event_timestamp(struct bt_ctf_event *event) +{ +/* int ret; + uint64_t value, frequency; + int64_t offset_s, offset; +*/ + return BT_COMPONENT_STATUS_OK; +} + +static +enum bt_component_status print_event_timestamp(struct text_component *text, + struct bt_ctf_event *event) +{ + bool print_names = text->options.print_header_field_names; + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct bt_ctf_stream *stream; + struct bt_ctf_clock *clock = NULL; + FILE *out = text->out; + FILE *err = text->err; + uint64_t real_timestamp; + + stream = bt_ctf_event_get_stream(event); + if (!stream) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } + + clock = bt_ctf_event_get_clock(event); + if (!clock) { + /* Stream has no timestamp. */ + //puts("no_timestamp!"); + //goto end; + } + + fputs(print_names ? "timestamp = " : "[", out); + if (text->options.print_timestamp_cycles) { + print_timestamp_cycles(text, clock, event); + } else { + print_timestamp_wall(text, clock, event); + } + + fputs(print_names ? ", " : "] ", out); + if (!text->options.print_delta_field) { + goto end; + } +end: + bt_put(stream); + bt_put(clock); + return ret; +} + +static inline +enum bt_component_status print_event_header(struct text_component *text, + struct bt_ctf_event *event) +{ + enum bt_component_status ret; + struct bt_ctf_event_class *event_class = bt_ctf_event_get_class(event); + + ret = print_event_timestamp(text, event); + if (ret != BT_COMPONENT_STATUS_OK) { + goto end; + } + + fputs(bt_ctf_event_class_get_name(event_class), text->out); +end: + return ret; +} + +BT_HIDDEN +enum bt_component_status text_print_event(struct text_component *text, + struct bt_ctf_event *event) +{ + enum bt_component_status ret; + + ret = print_event_header(text, event); + if (ret != BT_COMPONENT_STATUS_OK) { + goto end; + } + + fputc('\n', text->out); +end: + return ret; +} diff --git a/plugins/text/text.h b/plugins/text/text.h new file mode 100644 index 00000000..5ae994e2 --- /dev/null +++ b/plugins/text/text.h @@ -0,0 +1,79 @@ +#ifndef BABELTRACE_PLUGIN_TEXT_H +#define BABELTRACE_PLUGIN_TEXT_H + +/* + * BabelTrace - CTF Text Output Plug-in + * + * Copyright 2016 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +enum loglevel { + LOGLEVEL_EMERG = 0, + LOGLEVEL_ALERT = 1, + LOGLEVEL_CRIT = 2, + LOGLEVEL_ERR = 3, + LOGLEVEL_WARNING = 4, + LOGLEVEL_NOTICE = 5, + LOGLEVEL_INFO = 6, + LOGLEVEL_DEBUG_SYSTEM = 7, + LOGLEVEL_DEBUG_PROGRAM = 8, + LOGLEVEL_DEBUG_PROCESS = 9, + LOGLEVEL_DEBUG_MODULE = 10, + LOGLEVEL_DEBUG_UNIT = 11, + LOGLEVEL_DEBUG_FUNCTION = 12, + LOGLEVEL_DEBUG_LINE = 13, + LOGLEVEL_DEBUG = 14, +}; + +struct text_options { + bool print_scope_field_names : 1; + bool print_header_field_names : 1; + bool print_context_field_names : 1; + bool print_payload_field_names : 1; + bool print_delta_field : 1; + bool print_loglevel_field : 1; + bool print_trace_field : 1; + bool print_trace_domain_field : 1; + bool print_trace_procname_field : 1; + bool print_trace_vpid_field : 1; + bool print_trace_hostname_field : 1; + bool print_timestamp_cycles : 1; + bool no_size_limit : 1; +}; + +struct text_component { + struct text_options options; + FILE *out, *err; + bool processed_first_event; + uint64_t last_real_timestamp; +}; + +BT_HIDDEN +enum bt_component_status text_print_event(struct text_component *text, + struct bt_ctf_event *event); + +#endif /* BABELTRACE_PLUGIN_TEXT_H */ -- 2.34.1