From 300d317acaa3bd38afafe0a440946e6c73e6fd73 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Thu, 1 Mar 2012 11:14:44 -0500 Subject: [PATCH] fix API : deal with the optional underscore A field can be prefixed by an underscore internally by the tracer. This provides the abilility for the user to specify the underscore or not (depending if he read the metadata or the tracepoint event definition). This is a fallback mechanism, so if the request fails, we prefix an underscore to the field name and request it again. Also, the bt_ctf_field_name function now removes the optional underscore. A quick benchmark shows that calling the bt_ctf_get_field without the underscore on a field that requires an underscore adds around 151 nanoseconds to the call on a core 2 duo (tested in a loop of 1000000 iterations). Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- formats/ctf/events.c | 14 +++++++++++++- include/babeltrace/ctf-text/types.h | 9 --------- include/babeltrace/types.h | 9 +++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/formats/ctf/events.c b/formats/ctf/events.c index eea58cfd..b35f54a8 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -172,9 +172,21 @@ struct definition *bt_ctf_get_field(struct bt_ctf_event *event, const char *field) { struct definition *def; + char *field_underscore; if (scope) { def = lookup_definition(scope, field); + /* + * optionally a field can have an underscore prefix, try + * to lookup the field with this prefix if it failed + */ + if (!def) { + field_underscore = g_new(char, strlen(field) + 2); + field_underscore[0] = '_'; + strcpy(&field_underscore[1], field); + def = lookup_definition(scope, field_underscore); + g_free(field_underscore); + } if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) { struct definition_variant *variant_definition; variant_definition = container_of(def, @@ -222,7 +234,7 @@ const char *bt_ctf_event_name(struct bt_ctf_event *event) const char *bt_ctf_field_name(const struct definition *def) { if (def) - return g_quark_to_string(def->name); + return rem_(g_quark_to_string(def->name)); return NULL; } diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 101873a9..3db8a106 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -75,13 +75,4 @@ void print_pos_tabs(struct ctf_text_stream_pos *pos) */ int print_field(struct definition *definition); -static inline -const char *rem_(const char *str) -{ - if (str[0] == '_') - return &str[1]; - else - return str; -} - #endif /* _BABELTRACE_CTF_TEXT_TYPES_H */ diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index cfc74a2f..dd116f10 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -518,4 +518,13 @@ struct definition_enum *lookup_enum(struct definition *definition, struct definition *lookup_variant(struct definition *definition, const char *field_name); +static inline +const char *rem_(const char *str) +{ + if (str[0] == '_') + return &str[1]; + else + return str; +} + #endif /* _BABELTRACE_TYPES_H */ -- 2.34.1