fix API : deal with the optional underscore
authorJulien Desfossez <julien.desfossez@efficios.com>
Thu, 1 Mar 2012 16:14:44 +0000 (11:14 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 16:14:44 +0000 (11:14 -0500)
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 <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/events.c
include/babeltrace/ctf-text/types.h
include/babeltrace/types.h

index eea58cfd796ffeec39d13c381d4216dcb4128c14..b35f54a8ecba9cee1f5000323b47b3c082462c7a 100644 (file)
@@ -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;
 }
 
index 101873a9d5af801bff4508bef1183728ff75e329..3db8a1069ef97625a667cf28eb5dd26bfc243ae5 100644 (file)
@@ -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 */
index cfc74a2f6206c72cfb3805bf139b81dbd0dba719..dd116f10ed49be0f42f32ccfcece918d20731502 100644 (file)
@@ -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 */
This page took 0.026258 seconds and 4 git commands to generate.