lib: add logging format specifier for bt_field_location
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 2 Nov 2023 19:58:28 +0000 (19:58 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add the `format_field_location` function, to format a bt_field_location
object in logging messages.  Add the format specifier `L`, to format
bt_field_location objects in lib-logging format strings.

Change-Id: Ia874bea6a110e051cc19a0250e5cd831888f849f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7317
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7296

CONTRIBUTING.adoc
src/common/common.h
src/lib/lib-logging.c

index 171fcb14a6b41eb991f9d3f0569738e69105aeb5..9225518b96d5f47fbe849c59a7ba9ee550776572 100644 (file)
@@ -631,6 +631,10 @@ The available format specifiers are:
 |Trace IR field path
 |`+const struct bt_field_path *+`
 
+|`L`
+|Trace IR field location
+|`+const struct bt_field_location *+`
+
 |`E`
 |Trace IR event class
 |`+const struct bt_event_class *+`
index 63b01cc9feddda198043be26d117ee3ca0e44ec5..39a4fd77ac5b8a27e164c4d31a757bd4385a5882 100644 (file)
@@ -461,7 +461,7 @@ const char *bt_common_field_class_integer_preferred_display_base_string(enum bt_
 }
 
 static inline
-const char *bt_common_scope_string(enum bt_field_path_scope scope)
+const char *bt_common_field_path_scope_string(enum bt_field_path_scope scope)
 {
        switch (scope) {
        case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
@@ -477,6 +477,23 @@ const char *bt_common_scope_string(enum bt_field_path_scope scope)
        bt_common_abort();
 }
 
+static inline
+const char *bt_common_field_location_scope_string(enum bt_field_location_scope scope)
+{
+       switch (scope) {
+       case BT_FIELD_LOCATION_SCOPE_PACKET_CONTEXT:
+               return "PACKET_CONTEXT";
+       case BT_FIELD_LOCATION_SCOPE_EVENT_COMMON_CONTEXT:
+               return "EVENT_COMMON_CONTEXT";
+       case BT_FIELD_LOCATION_SCOPE_EVENT_SPECIFIC_CONTEXT:
+               return "EVENT_SPECIFIC_CONTEXT";
+       case BT_FIELD_LOCATION_SCOPE_EVENT_PAYLOAD:
+               return "EVENT_PAYLOAD";
+       }
+
+       bt_common_abort();
+}
+
 static inline
 const char *bt_common_event_class_log_level_string(
                enum bt_event_class_log_level level)
@@ -544,6 +561,44 @@ const char *bt_common_value_type_string(enum bt_value_type type)
        bt_common_abort();
 };
 
+static inline
+GString *bt_common_field_path_string(struct bt_field_path *path)
+{
+       GString *str = g_string_new(NULL);
+       uint64_t i;
+
+       BT_ASSERT_DBG(path);
+
+       if (!str) {
+               goto end;
+       }
+
+       g_string_append_printf(str, "[%s", bt_common_field_path_scope_string(
+               bt_field_path_get_root_scope(path)));
+
+       for (i = 0; i < bt_field_path_get_item_count(path); i++) {
+               const struct bt_field_path_item *fp_item =
+                       bt_field_path_borrow_item_by_index_const(path, i);
+
+               switch (bt_field_path_item_get_type(fp_item)) {
+               case BT_FIELD_PATH_ITEM_TYPE_INDEX:
+                       g_string_append_printf(str, ", %" PRIu64,
+                               bt_field_path_item_index_get_index(fp_item));
+                       break;
+               case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT:
+                       g_string_append(str, ", <CUR>");
+                       break;
+               default:
+                       bt_common_abort();
+               }
+       }
+
+       g_string_append(str, "]");
+
+end:
+       return str;
+}
+
 static inline
 const char *bt_common_logging_level_string(
                enum bt_logging_level level)
index 6d98a0ce5e0dc38d87949f20e6559c27000dd01b..9de0780026f9bc2de87764072c165e05f85b63f4 100644 (file)
@@ -44,6 +44,7 @@
 #include "trace-ir/event.h"
 #include "trace-ir/field-class.h"
 #include "trace-ir/field.h"
+#include "trace-ir/field-location.h"
 #include "trace-ir/field-path.h"
 #include "trace-ir/packet.h"
 #include "trace-ir/stream-class.h"
@@ -108,6 +109,9 @@ static inline void format_clock_snapshot(char **buf_ch, bool extended,
 static inline void format_field_path(char **buf_ch, bool extended,
                const char *prefix, const struct bt_field_path *field_path);
 
+static inline void format_field_location(char **buf_ch, bool extended ,
+               const char *prefix, const struct bt_field_location *field_location);
+
 static inline void format_object(char **buf_ch, const char *prefix,
                const struct bt_object *obj)
 {
@@ -452,7 +456,7 @@ static inline void format_field_path(char **buf_ch, bool extended,
        }
 
        BUF_APPEND(", %spath=[%s",
-               PRFIELD(bt_common_scope_string(field_path->root)));
+               PRFIELD(bt_common_field_path_scope_string(field_path->root)));
 
        for (i = 0; i < bt_field_path_get_item_count(field_path); i++) {
                const struct bt_field_path_item *fp_item =
@@ -474,6 +478,33 @@ static inline void format_field_path(char **buf_ch, bool extended,
        BUF_APPEND("%s", "]");
 }
 
+static inline void format_field_location(char **buf_ch, bool extended,
+               const char *prefix, const struct bt_field_location *field_location)
+{
+       uint64_t i;
+
+       BT_ASSERT(field_location->items);
+
+       BUF_APPEND(", %sitem-count=%u", PRFIELD(field_location->items->len));
+
+       if (!extended) {
+               return;
+       }
+
+       BUF_APPEND(", %sloc=[%s",
+               PRFIELD(bt_common_field_location_scope_string(field_location->scope)));
+
+       for (i = 0; i < bt_field_location_get_item_count(field_location); i++) {
+               const char *item =
+                       bt_field_location_get_item_by_index (field_location, i);
+
+               BUF_APPEND(", %s", item);
+               break;
+       }
+
+       BUF_APPEND("%s", "]");
+}
+
 static inline void format_trace_class(char **buf_ch, bool extended,
                const char *prefix, const struct bt_trace_class *trace_class)
 {
@@ -1385,6 +1416,9 @@ static inline void handle_conversion_specifier_bt(
        case 'P':
                format_field_path(buf_ch, extended, prefix, obj);
                break;
+       case 'L':
+               format_field_location(buf_ch, extended, prefix, obj);
+               break;
        case 'E':
                format_event_class(buf_ch, extended, prefix, obj);
                break;
This page took 0.028446 seconds and 4 git commands to generate.