From: Simon Marchi Date: Fri, 4 Mar 2022 21:46:09 +0000 (-0500) Subject: sink.text.details: handle field classes with field locations X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=4a2156a5c3199028852af88f0a70505bd5534ed7;p=babeltrace.git sink.text.details: handle field classes with field locations Handle MIP 1 variant, option and dynamic array field classes. They have field locations instead of field paths. The format used by write_field_location is based on write_field_path. Change-Id: Ic2f6e1ed233a34ea4cc647f50eaf4027b9e5bff8 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/7500 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12691 --- diff --git a/src/plugins/text/details/details.c b/src/plugins/text/details/details.c index 0b94653e..a685e201 100644 --- a/src/plugins/text/details/details.c +++ b/src/plugins/text/details/details.c @@ -158,6 +158,7 @@ struct details_comp *create_details_comp( details_comp->log_level = bt_component_get_logging_level( bt_self_component_as_component(self_comp)); details_comp->self_comp = self_comp; + details_comp->mip_version = bt_self_component_get_graph_mip_version(self_comp); details_comp->meta = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) details_destroy_details_trace_class_meta); diff --git a/src/plugins/text/details/details.h b/src/plugins/text/details/details.h index 05f470cd..89bddad8 100644 --- a/src/plugins/text/details/details.h +++ b/src/plugins/text/details/details.h @@ -60,6 +60,7 @@ struct details_trace { struct details_comp { bt_logging_level log_level; bt_self_component *self_comp; + uint64_t mip_version; /* Component's configuration */ struct { diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index 5c9f9e75..ffc72bb4 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -762,6 +762,11 @@ void write_enum_field_class_mappings(struct details_write_ctx *ctx, g_ptr_array_free(mappings, TRUE); } +static const char *PACKET_CONTEXT_STR = "Packet context"; +static const char *EVENT_COMMON_CONTEXT_STR = "Event common context"; +static const char *EVENT_SPECIFIC_CONTEXT_STR = "Event specific context"; +static const char *EVENT_PAYLOAD_STR = "Event payload"; + static void write_field_path(struct details_write_ctx *ctx, const bt_field_path *field_path) @@ -772,16 +777,16 @@ void write_field_path(struct details_write_ctx *ctx, switch (bt_field_path_get_root_scope(field_path)) { case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT: - write_str_prop_value(ctx, "Packet context"); + write_str_prop_value(ctx, PACKET_CONTEXT_STR); break; case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT: - write_str_prop_value(ctx, "Event common context"); + write_str_prop_value(ctx, EVENT_COMMON_CONTEXT_STR); break; case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT: - write_str_prop_value(ctx, "Event specific context"); + write_str_prop_value(ctx, EVENT_SPECIFIC_CONTEXT_STR); break; case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD: - write_str_prop_value(ctx, "Event payload"); + write_str_prop_value(ctx, EVENT_PAYLOAD_STR); break; default: bt_common_abort(); @@ -813,6 +818,47 @@ void write_field_path(struct details_write_ctx *ctx, g_string_append_c(ctx->str, ']'); } +static +void write_field_location(struct details_write_ctx *ctx, + const bt_field_location *field_location) +{ + bt_field_location_scope scope = bt_field_location_get_root_scope(field_location); + uint64_t item_count = bt_field_location_get_item_count(field_location); + + g_string_append_c(ctx->str, '['); + + switch (scope) { + case BT_FIELD_LOCATION_SCOPE_PACKET_CONTEXT: + write_str_prop_value(ctx, PACKET_CONTEXT_STR); + break; + case BT_FIELD_LOCATION_SCOPE_EVENT_COMMON_CONTEXT: + write_str_prop_value(ctx, EVENT_COMMON_CONTEXT_STR); + break; + case BT_FIELD_LOCATION_SCOPE_EVENT_SPECIFIC_CONTEXT: + write_str_prop_value(ctx, EVENT_SPECIFIC_CONTEXT_STR); + break; + case BT_FIELD_LOCATION_SCOPE_EVENT_PAYLOAD: + write_str_prop_value(ctx, EVENT_PAYLOAD_STR); + break; + default: + bt_common_abort(); + } + + g_string_append(ctx->str, ": "); + + for (uint64_t idx = 0; idx < item_count; ++idx) { + const char *item = bt_field_location_get_item_by_index(field_location, idx); + + if (idx != 0) { + g_string_append(ctx->str, ", "); + } + + write_str_prop_value(ctx, item); + } + + g_string_append_c(ctx->str, ']'); +} + static void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc); @@ -1006,34 +1052,61 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc) bt_field_class_array_static_get_length(fc)); g_string_append_c(ctx->str, ')'); } else if (fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) { - const bt_field_path *length_field_path = - bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( - fc); + if (ctx->details_comp->mip_version == 0) { + const bt_field_path *length_field_path = + bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( + fc); - g_string_append(ctx->str, " (Length field path "); - write_field_path(ctx, length_field_path); - g_string_append_c(ctx->str, ')'); + g_string_append(ctx->str, " (Length field path "); + write_field_path(ctx, length_field_path); + g_string_append_c(ctx->str, ')'); + } else { + const bt_field_location *length_field_location = + bt_field_class_array_dynamic_with_length_field_borrow_length_field_location_const( + fc); + + g_string_append(ctx->str, " (Length field location "); + write_field_location(ctx, length_field_location); + g_string_append_c(ctx->str, ')'); + } } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD)) { - const bt_field_path *selector_field_path = - bt_field_class_option_with_selector_field_borrow_selector_field_path_const( - fc); + if (ctx->details_comp->mip_version == 0) { + const bt_field_path *selector_field_path = + bt_field_class_option_with_selector_field_borrow_selector_field_path_const( + fc); - g_string_append(ctx->str, " (Selector field path "); - write_field_path(ctx, selector_field_path); - g_string_append_c(ctx->str, ')'); + g_string_append(ctx->str, " (Selector field path "); + write_field_path(ctx, selector_field_path); + g_string_append_c(ctx->str, ')'); + } else { + const bt_field_location *selector_field_location = + bt_field_class_option_with_selector_field_borrow_selector_field_location_const(fc); + + g_string_append(ctx->str, " (Selector field location "); + write_field_location(ctx, selector_field_location); + g_string_append_c(ctx->str, ')'); + } } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_VARIANT)) { uint64_t option_count = bt_field_class_variant_get_option_count(fc); const bt_field_path *sel_field_path = NULL; + const bt_field_location *sel_field_loc = NULL; if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD)) { - sel_field_path = - bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( - fc); - BT_ASSERT_DBG(sel_field_path); + if (ctx->details_comp->mip_version == 0) { + sel_field_path = + bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( + fc); + BT_ASSERT_DBG(sel_field_path); + } else { + sel_field_loc = + bt_field_class_variant_with_selector_field_borrow_selector_field_location_const( + fc); + BT_ASSERT_DBG(sel_field_loc); + } } g_string_append(ctx->str, " ("); @@ -1044,6 +1117,9 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc) if (sel_field_path) { g_string_append(ctx->str, ", Selector field path "); write_field_path(ctx, sel_field_path); + } else if (sel_field_loc) { + g_string_append(ctx->str, ", Selector field location "); + write_field_location(ctx, sel_field_loc); } g_string_append_c(ctx->str, ')');