From c3c30b08de95f06de6ad2f12001bede5da3f7674 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 17 Nov 2016 08:20:22 -0500 Subject: [PATCH] Print other fields MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-class.c | 3 +- .../ctf/common/metadata/visitor-generate-ir.c | 85 +++++++- plugins/text/print.c | 203 +++++++++++++++++- plugins/text/text.c | 19 -- plugins/text/text.h | 18 -- 5 files changed, 282 insertions(+), 46 deletions(-) diff --git a/formats/ctf/ir/event-class.c b/formats/ctf/ir/event-class.c index 03f20a7e..3747a5cf 100644 --- a/formats/ctf/ir/event-class.c +++ b/formats/ctf/ir/event-class.c @@ -226,7 +226,8 @@ int bt_ctf_event_class_set_attribute( ret = -1; goto end; } - } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri")) { + } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri") || + !strcmp(name, "loglevel_string")) { if (!bt_value_is_string(value)) { ret = -1; goto end; diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index 6fcf5754..2e175e75 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -120,6 +120,25 @@ enum { _EVENT_FIELDS_SET = _BV(6), }; +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, + _NR_LOGLEVELS = 15, +}; + /* Prefixes of type aliases */ #define _PREFIX_ALIAS 'a' #define _PREFIX_ENUM 'e' @@ -210,6 +229,37 @@ struct ctx { GHashTable *stream_classes; }; +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 +const char *print_loglevel(int64_t value) +{ + if (value < 0) { + return NULL; + } + if (value >= _NR_LOGLEVELS) { + return "<>"; + } + return loglevel_str[value]; +} + /** * Creates a new declaration scope. * @@ -3047,7 +3097,9 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _SET(set, _EVENT_FIELDS_SET); } else if (!strcmp(left, "loglevel")) { - uint64_t loglevel; + uint64_t loglevel_value; + const char *loglevel_str; + struct bt_value *value_obj, *str_obj; if (_IS_SET(set, _EVENT_LOGLEVEL_SET)) { _PERROR_DUP_ATTR("loglevel", @@ -3057,15 +3109,38 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, } ret = get_unary_unsigned(&node->u.ctf_expression.right, - &loglevel); + &loglevel_value); if (ret) { _PERROR("%s", "unexpected unary expression for event declaration's \"loglevel\" attribute"); ret = -EINVAL; goto error; } - - // TODO: FIXME: set log level here - + value_obj = bt_value_integer_create_init(loglevel_value); + if (!value_obj) { + _PERROR("%s", "cannot allocate memory for loglevel value object"); + ret = -ENOMEM; + goto error; + } + if (bt_ctf_event_class_set_attribute(event_class, + "loglevel", value_obj) != BT_VALUE_STATUS_OK) { + _PERROR("%s", "cannot set loglevel value"); + ret = -EINVAL; + bt_put(value_obj); + goto error; + } + loglevel_str = print_loglevel(loglevel_value); + if (loglevel_str) { + str_obj = bt_value_string_create_init(loglevel_str); + if (bt_ctf_event_class_set_attribute(event_class, + "loglevel_string", str_obj) != BT_VALUE_STATUS_OK) { + _PERROR("%s", "cannot set loglevel string"); + ret = -EINVAL; + bt_put(str_obj); + goto error; + } + bt_put(str_obj); + } + bt_put(value_obj); _SET(set, _EVENT_LOGLEVEL_SET); } else if (!strcmp(left, "model.emf.uri")) { char *right; diff --git a/plugins/text/print.c b/plugins/text/print.c index a7b67409..53adab4c 100644 --- a/plugins/text/print.c +++ b/plugins/text/print.c @@ -189,7 +189,7 @@ end: static enum bt_component_status print_event_timestamp(struct text_component *text, - struct bt_ctf_event *event) + struct bt_ctf_event *event, bool *start_line) { bool print_names = text->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -219,7 +219,10 @@ enum bt_component_status print_event_timestamp(struct text_component *text, print_timestamp_wall(text, clock, event); } - fputs(print_names ? ", " : "] ", out); + if (!print_names) + fputs("] ", out); + *start_line = !print_names; + if (!text->options.print_delta_field) { goto end; } @@ -238,25 +241,219 @@ enum bt_component_status print_event_header(struct text_component *text, bool print_names = text->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_ctf_event_class *event_class = NULL; + struct bt_ctf_stream_class *stream_class = NULL; + struct bt_ctf_trace *trace_class = NULL; event_class = bt_ctf_event_get_class(event); if (!event_class) { ret = BT_COMPONENT_STATUS_ERROR; goto end; } + stream_class = bt_ctf_event_class_get_stream_class(event_class); + if (!stream_class) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } + trace_class = bt_ctf_stream_class_get_trace(stream_class); + if (!trace_class) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } if (!text->start_line) { fputs(", ", text->out); } text->start_line = false; - ret = print_event_timestamp(text, event); + ret = print_event_timestamp(text, event, &text->start_line); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } + if (text->options.print_trace_field) { + const char *name; + + name = bt_ctf_trace_get_name(trace_class); + if (name) { + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("trace = ", text->out); + } + fprintf(text->out, "%s", name); + } + } + if (text->options.print_trace_hostname_field) { + struct bt_value *hostname_str; + + hostname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, + "hostname"); + if (hostname_str) { + const char *str; + + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("trace:hostname = ", text->out); + } + if (bt_value_string_get(hostname_str, &str) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s", str); + } + bt_put(hostname_str); + } + } + if (text->options.print_trace_domain_field) { + struct bt_value *domain_str; + + domain_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, + "domain"); + if (domain_str) { + const char *str; + + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("trace:domain = ", text->out); + } + if (bt_value_string_get(domain_str, &str) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s", str); + } + bt_put(domain_str); + } + } + if (text->options.print_trace_procname_field) { + struct bt_value *procname_str; + + procname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, + "procname"); + if (procname_str) { + const char *str; + + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("trace:procname = ", text->out); + } + if (bt_value_string_get(procname_str, &str) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s", str); + } + bt_put(procname_str); + } + } + if (text->options.print_trace_vpid_field) { + struct bt_value *vpid_value; + + vpid_value = bt_ctf_trace_get_environment_field_value_by_name(trace_class, + "vpid"); + if (vpid_value) { + int64_t value; + + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("trace:vpid = ", text->out); + } + if (bt_value_integer_get(vpid_value, &value) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "(%" PRId64 ")", value); + } + bt_put(vpid_value); + } + } + if (text->options.print_loglevel_field) { + struct bt_value *loglevel_str, *loglevel_value; + + loglevel_str = bt_ctf_event_class_get_attribute_value_by_name(event_class, + "loglevel_string"); + loglevel_value = bt_ctf_event_class_get_attribute_value_by_name(event_class, + "loglevel"); + if (loglevel_str || loglevel_value) { + bool has_str = false; + + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("loglevel = ", text->out); + } + if (loglevel_str) { + const char *str; + + if (bt_value_string_get(loglevel_str, &str) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s", str); + has_str = true; + } + } + if (loglevel_value) { + int64_t value; + + if (bt_value_integer_get(loglevel_value, &value) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s(%" PRId64 ")", + has_str ? " " : "", value); + } + } + bt_put(loglevel_str); + bt_put(loglevel_value); + } + } + if (text->options.print_emf_field) { + struct bt_value *uri_str; + + uri_str = bt_ctf_event_class_get_attribute_value_by_name(event_class, + "model.emf.uri"); + if (uri_str) { + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("model.emf.uri = ", text->out); + } + if (uri_str) { + const char *str; + + if (bt_value_string_get(uri_str, &str) + == BT_VALUE_STATUS_OK) { + fprintf(text->out, "%s", str); + } + } + bt_put(uri_str); + } + } + if (text->options.print_callsite_field) { + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; + if (print_names) { + fputs("callsite = ", text->out); + } + /* TODO */ + } + if (!text->start_line) { + fputs(", ", text->out); + } + text->start_line = false; if (print_names) { fputs("name = ", text->out); } fputs(bt_ctf_event_class_get_name(event_class), text->out); end: + bt_put(trace_class); + bt_put(stream_class); bt_put(event_class); return ret; } diff --git a/plugins/text/text.c b/plugins/text/text.c index da659eeb..f9134b77 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -68,25 +68,6 @@ const char *plugin_options[] = { "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 void destroy_text_data(struct text_component *text) { diff --git a/plugins/text/text.h b/plugins/text/text.h index f1ff92df..103dc079 100644 --- a/plugins/text/text.h +++ b/plugins/text/text.h @@ -31,24 +31,6 @@ #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, -}; - enum text_default { TEXT_DEFAULT_UNSET, TEXT_DEFAULT_SHOW, -- 2.34.1