* SOFTWARE.
*/
-#define BT_LOG_TAG "PLUGIN-TEXT-DETAILS-SINK-WRITE"
-#include "logging.h"
-
#include <babeltrace2/babeltrace.h>
+#include <stdio.h>
+#include <string.h>
#include "common/assert.h"
#include "common/common.h"
void write_trace_class(struct details_write_ctx *ctx, const bt_trace_class *tc)
{
GPtrArray *stream_classes = g_ptr_array_new();
- GPtrArray *env_names = g_ptr_array_new();
- uint64_t env_count;
uint64_t i;
bool printed_prop = false;
write_indent(ctx);
write_obj_type_name(ctx, "Trace class");
- /* Write name */
- if (ctx->details_comp->cfg.with_trace_class_name) {
- const char *name = bt_trace_class_get_name(tc);
-
- if (name) {
- g_string_append(ctx->str, " `");
- write_str_prop_value(ctx, name);
- g_string_append(ctx->str, "`");
- }
- }
-
- /* Write properties */
- incr_indent(ctx);
-
- if (ctx->details_comp->cfg.with_uuid) {
- bt_uuid uuid = bt_trace_class_get_uuid(tc);
-
- if (uuid) {
- if (!printed_prop) {
- g_string_append(ctx->str, ":\n");
- printed_prop = true;
- }
-
- write_uuid_prop_line(ctx, "UUID", uuid);
- }
- }
-
- /* Write environment */
- env_count = bt_trace_class_get_environment_entry_count(tc);
- if (env_count > 0) {
- if (!printed_prop) {
- g_string_append(ctx->str, ":\n");
- printed_prop = true;
- }
-
- write_indent(ctx);
- write_prop_name(ctx, "Environment");
- g_string_append(ctx->str, " (");
- write_uint_prop_value(ctx, env_count);
- g_string_append_printf(ctx->str, " entr%s):",
- env_count == 1 ? "y" : "ies");
- write_nl(ctx);
- incr_indent(ctx);
-
- for (i = 0; i < env_count; i++) {
- const char *name;
- const bt_value *value;
-
- bt_trace_class_borrow_environment_entry_by_index_const(
- tc, i, &name, &value);
- g_ptr_array_add(env_names, (gpointer) name);
- }
-
- g_ptr_array_sort(env_names, (GCompareFunc) compare_strings);
-
- for (i = 0; i < env_names->len; i++) {
- const char *name = env_names->pdata[i];
- const bt_value *value =
- bt_trace_class_borrow_environment_entry_value_by_name_const(
- tc, name);
-
- BT_ASSERT(value);
- write_compound_member_name(ctx, name);
- write_sp(ctx);
-
- if (bt_value_get_type(value) ==
- BT_VALUE_TYPE_SIGNED_INTEGER) {
- write_int_prop_value(ctx,
- bt_value_signed_integer_get(value));
- } else if (bt_value_get_type(value) ==
- BT_VALUE_TYPE_STRING) {
- write_str_prop_value(ctx,
- bt_value_string_get(value));
- } else {
- abort();
- }
-
- write_nl(ctx);
- }
-
- decr_indent(ctx);
- }
-
for (i = 0; i < bt_trace_class_get_stream_class_count(tc); i++) {
g_ptr_array_add(stream_classes,
(gpointer) bt_trace_class_borrow_stream_class_by_index_const(
}
}
+ incr_indent(ctx);
+
for (i = 0; i < stream_classes->len; i++) {
write_stream_class(ctx, stream_classes->pdata[i]);
}
- decr_indent(ctx);
-
if (!printed_prop) {
write_nl(ctx);
}
+ decr_indent(ctx);
g_ptr_array_free(stream_classes, TRUE);
- g_ptr_array_free(env_names, TRUE);
}
static
static
void write_time(struct details_write_ctx *ctx, const bt_clock_snapshot *cs)
{
- bt_clock_snapshot_status status;
+ bt_clock_snapshot_get_ns_from_origin_status cs_status;
int64_t ns_from_origin;
char buf[32];
color_bold(ctx), color_fg_blue(ctx), buf,
color_reset(ctx),
ctx->details_comp->cfg.compact ? "" : " cycles");
- status = bt_clock_snapshot_get_ns_from_origin(cs, &ns_from_origin);
- if (status == BT_CLOCK_SNAPSHOT_STATUS_OK) {
+ cs_status = bt_clock_snapshot_get_ns_from_origin(cs, &ns_from_origin);
+ if (cs_status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OK) {
format_int(buf, ns_from_origin, 10);
g_string_append_printf(ctx->str, "%s %s%s%s%s%s",
ctx->details_comp->cfg.compact ? "" : ",",
void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
{
const char *name;
- const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
GPtrArray *streams = g_ptr_array_new();
uint64_t i;
bool printed_prop = false;
+ GPtrArray *env_names = g_ptr_array_new();
+ uint64_t env_count;
write_indent(ctx);
write_obj_type_name(ctx, "Trace");
/* Write properties */
incr_indent(ctx);
- if (ctx->details_comp->cfg.with_trace_class_name) {
- name = bt_trace_class_get_name(tc);
- if (name) {
+ /* Write UUID */
+ if (ctx->details_comp->cfg.with_uuid) {
+ bt_uuid uuid = bt_trace_get_uuid(trace);
+
+ if (uuid) {
if (!printed_prop) {
g_string_append(ctx->str, ":\n");
printed_prop = true;
}
- write_str_prop_line(ctx, "Class name", name);
+ write_uuid_prop_line(ctx, "UUID", uuid);
}
}
- if (ctx->details_comp->cfg.with_uuid) {
- bt_uuid uuid = bt_trace_class_get_uuid(tc);
+ /* Write environment */
+ env_count = bt_trace_get_environment_entry_count(trace);
+ if (env_count > 0) {
+ if (!printed_prop) {
+ g_string_append(ctx->str, ":\n");
+ printed_prop = true;
+ }
- if (uuid) {
- if (!printed_prop) {
- g_string_append(ctx->str, ":\n");
- printed_prop = true;
+ write_indent(ctx);
+ write_prop_name(ctx, "Environment");
+ g_string_append(ctx->str, " (");
+ write_uint_prop_value(ctx, env_count);
+ g_string_append_printf(ctx->str, " entr%s):",
+ env_count == 1 ? "y" : "ies");
+ write_nl(ctx);
+ incr_indent(ctx);
+
+ for (i = 0; i < env_count; i++) {
+ const char *name;
+ const bt_value *value;
+
+ bt_trace_borrow_environment_entry_by_index_const(
+ trace, i, &name, &value);
+ g_ptr_array_add(env_names, (gpointer) name);
+ }
+
+ g_ptr_array_sort(env_names, (GCompareFunc) compare_strings);
+
+ for (i = 0; i < env_names->len; i++) {
+ const char *name = env_names->pdata[i];
+ const bt_value *value =
+ bt_trace_borrow_environment_entry_value_by_name_const(
+ trace, name);
+
+ BT_ASSERT(value);
+ write_compound_member_name(ctx, name);
+ write_sp(ctx);
+
+ if (bt_value_get_type(value) ==
+ BT_VALUE_TYPE_SIGNED_INTEGER) {
+ write_int_prop_value(ctx,
+ bt_value_signed_integer_get(value));
+ } else if (bt_value_get_type(value) ==
+ BT_VALUE_TYPE_STRING) {
+ write_str_prop_value(ctx,
+ bt_value_string_get(value));
+ } else {
+ abort();
}
- write_uuid_prop_line(ctx, "Class UUID", uuid);
+ write_nl(ctx);
}
+
+ decr_indent(ctx);
}
for (i = 0; i < bt_trace_get_stream_count(trace); i++) {
}
g_ptr_array_free(streams, TRUE);
+ g_ptr_array_free(env_names, TRUE);
}
static
bt_message_stream_beginning_borrow_stream_const(msg);
const bt_trace *trace = bt_stream_borrow_trace_const(stream);
const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
+ const bt_clock_class *cc = bt_stream_class_borrow_default_clock_class_const(sc);
const bt_trace_class *tc = bt_stream_class_borrow_trace_class_const(sc);
const char *name;
goto end;
}
+ /* Write time */
+ if (cc) {
+ const bt_clock_snapshot *cs;
+ bt_message_stream_clock_snapshot_state cs_state =
+ bt_message_stream_beginning_borrow_default_clock_snapshot_const(msg, &cs);
+
+ if (cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
+ write_time(ctx, cs);
+ } else {
+ write_time_str(ctx, "Unknown");
+ }
+ }
+
/* Write follow tag for message */
ret = write_message_follow_tag(ctx, stream);
if (ret) {
int ret = 0;
const bt_stream *stream =
bt_message_stream_end_borrow_stream_const(msg);
-
- /* Write follow tag for message */
- ret = write_message_follow_tag(ctx, stream);
- if (ret) {
- goto end;
- }
-
- /* Write stream properties */
- write_obj_type_name(ctx, "Stream end\n");
-
-end:
- return ret;
-}
-
-static
-int write_stream_activity_beginning_message(struct details_write_ctx *ctx,
- const bt_message *msg)
-{
- int ret = 0;
- const bt_stream *stream =
- bt_message_stream_activity_beginning_borrow_stream_const(msg);
- bt_message_stream_activity_clock_snapshot_state cs_state;
- const bt_clock_snapshot *cs = NULL;
+ const bt_stream_class *sc =
+ bt_stream_borrow_class_const(stream);
+ const bt_clock_class *cc =
+ bt_stream_class_borrow_default_clock_class_const(sc);
/* Write time */
- cs_state = bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
- msg, &cs);
- switch (cs_state) {
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN:
- BT_ASSERT(cs);
- write_time(ctx, cs);
- break;
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN:
- write_time_str(ctx, "Unknown");
- break;
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE:
- write_time_str(ctx, "-Infinity");
- break;
- default:
- abort();
- }
-
- /* Write follow tag for message */
- ret = write_message_follow_tag(ctx, stream);
- if (ret) {
- goto end;
- }
+ if (cc) {
+ const bt_clock_snapshot *cs;
+ bt_message_stream_clock_snapshot_state cs_state =
+ bt_message_stream_end_borrow_default_clock_snapshot_const(msg, &cs);
- write_obj_type_name(ctx, "Stream activity beginning");
- write_nl(ctx);
-
-end:
- return ret;
-}
-
-static
-int write_stream_activity_end_message(struct details_write_ctx *ctx,
- const bt_message *msg)
-{
- int ret = 0;
- const bt_stream *stream =
- bt_message_stream_activity_end_borrow_stream_const(msg);
- bt_message_stream_activity_clock_snapshot_state cs_state;
- const bt_clock_snapshot *cs = NULL;
-
- /* Write time */
- cs_state = bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
- msg, &cs);
- switch (cs_state) {
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN:
- BT_ASSERT(cs);
- write_time(ctx, cs);
- break;
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN:
- write_time_str(ctx, "Unknown");
- break;
- case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE:
- write_time_str(ctx, "+Infinity");
- break;
- default:
- abort();
+ if (cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
+ write_time(ctx, cs);
+ } else {
+ write_time_str(ctx, "Unknown");
+ }
}
/* Write follow tag for message */
goto end;
}
- write_obj_type_name(ctx, "Stream activity end");
- write_nl(ctx);
+ /* Write stream properties */
+ write_obj_type_name(ctx, "Stream end\n");
end:
return ret;
case BT_MESSAGE_TYPE_PACKET_END:
ret = write_packet_end_message(&ctx, msg);
break;
- case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
- ret = write_stream_activity_beginning_message(&ctx, msg);
- break;
- case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
- ret = write_stream_activity_end_message(&ctx, msg);
- break;
case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
ret = write_discarded_events_message(&ctx, msg);
break;