* SOFTWARE.
*/
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock-class.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/babeltrace.h>
#include <babeltrace/bitfield-internal.h>
#include <babeltrace/common-internal.h>
+#include <babeltrace/compat/time-internal.h>
#include <inttypes.h>
#include <ctype.h>
#include "pretty.h"
#define NSEC_PER_SEC 1000000000LL
-#define COLOR_NAME BT_COMMON_COLOR_BOLD
-#define COLOR_FIELD_NAME BT_COMMON_COLOR_FG_CYAN
-#define COLOR_RST BT_COMMON_COLOR_RESET
-#define COLOR_STRING_VALUE BT_COMMON_COLOR_BOLD
-#define COLOR_NUMBER_VALUE BT_COMMON_COLOR_BOLD
-#define COLOR_ENUM_MAPPING_NAME BT_COMMON_COLOR_BOLD
-#define COLOR_UNKNOWN BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
-#define COLOR_EVENT_NAME BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
-#define COLOR_TIMESTAMP BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW
-
-static inline
-const char *rem_(const char *str)
-{
- if (str[0] == '_')
- return &str[1];
- else
- return str;
-}
+#define COLOR_NAME BT_COMMON_COLOR_BOLD
+#define COLOR_FIELD_NAME BT_COMMON_COLOR_FG_CYAN
+#define COLOR_RST BT_COMMON_COLOR_RESET
+#define COLOR_STRING_VALUE BT_COMMON_COLOR_BOLD
+#define COLOR_NUMBER_VALUE BT_COMMON_COLOR_BOLD
+#define COLOR_ENUM_MAPPING_NAME BT_COMMON_COLOR_BOLD
+#define COLOR_UNKNOWN BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
+#define COLOR_EVENT_NAME BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
+#define COLOR_TIMESTAMP BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW
struct timestamp {
int64_t real_timestamp; /* Relative to UNIX epoch. */
void print_name_equal(struct pretty_component *pretty, const char *name)
{
if (pretty->use_colors) {
- fprintf(pretty->out, "%s%s%s = ", COLOR_NAME, name, COLOR_RST);
+ g_string_append_printf(pretty->string, "%s%s%s = ", COLOR_NAME,
+ name, COLOR_RST);
} else {
- fprintf(pretty->out, "%s = ", name);
+ g_string_append_printf(pretty->string, "%s = ", name);
}
}
void print_field_name_equal(struct pretty_component *pretty, const char *name)
{
if (pretty->use_colors) {
- fprintf(pretty->out, "%s%s%s = ", COLOR_FIELD_NAME, name,
- COLOR_RST);
+ g_string_append_printf(pretty->string, "%s%s%s = ",
+ COLOR_FIELD_NAME, name, COLOR_RST);
} else {
- fprintf(pretty->out, "%s = ", name);
+ g_string_append_printf(pretty->string, "%s = ", name);
}
}
clock_value = bt_ctf_event_get_clock_value(event, clock_class);
if (!clock_value) {
- fputs("????????????????????", pretty->out);
+ g_string_append(pretty->string, "????????????????????");
return;
}
ret = bt_ctf_clock_value_get_value(clock_value, &cycles);
bt_put(clock_value);
if (ret) {
- fprintf(pretty->out, "Error");
+ // TODO: log, this is unexpected
+ g_string_append(pretty->string, "Error");
return;
}
- fprintf(pretty->out, "%020" PRIu64, cycles);
+
+ g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
if (pretty->last_cycles_timestamp != -1ULL) {
pretty->delta_cycles = cycles - pretty->last_cycles_timestamp;
static
void print_timestamp_wall(struct pretty_component *pretty,
- struct bt_ctf_clock_class *clock_class,
- struct bt_ctf_event *event)
+ struct bt_ctf_clock_value *clock_value)
{
int ret;
- struct bt_ctf_clock_value *clock_value;
int64_t ts_nsec = 0; /* add configurable offset */
int64_t ts_sec = 0; /* add configurable offset */
uint64_t ts_sec_abs, ts_nsec_abs;
bool is_negative;
- clock_value = bt_ctf_event_get_clock_value(event, clock_class);
if (!clock_value) {
- fputs("??:??:??.?????????", pretty->out);
+ g_string_append(pretty->string, "??:??:??.?????????");
return;
}
ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, &ts_nsec);
- bt_put(clock_value);
if (ret) {
- fprintf(pretty->out, "Error");
+ // TODO: log, this is unexpected
+ g_string_append(pretty->string, "Error");
return;
}
if (pretty->last_real_timestamp != -1ULL) {
pretty->delta_real_timestamp = ts_nsec - pretty->last_real_timestamp;
}
- pretty->last_real_timestamp = ts_nsec;
+ pretty->last_real_timestamp = ts_nsec;
ts_sec += ts_nsec / NSEC_PER_SEC;
ts_nsec = ts_nsec % NSEC_PER_SEC;
+
if (ts_sec >= 0 && ts_nsec >= 0) {
is_negative = false;
ts_sec_abs = ts_sec;
struct tm tm;
time_t time_s = (time_t) ts_sec_abs;
- if (is_negative) {
+ if (is_negative && !pretty->negative_timestamp_warning_done) {
+ // TODO: log instead
fprintf(stderr, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
+ pretty->negative_timestamp_warning_done = true;
goto seconds;
}
if (!pretty->options.clock_gmt) {
struct tm *res;
- res = localtime_r(&time_s, &tm);
+ res = bt_localtime_r(&time_s, &tm);
if (!res) {
+ // TODO: log instead
fprintf(stderr, "[warning] Unable to get localtime.\n");
goto seconds;
}
} else {
struct tm *res;
- res = gmtime_r(&time_s, &tm);
+ res = bt_gmtime_r(&time_s, &tm);
if (!res) {
+ // TODO: log instead
fprintf(stderr, "[warning] Unable to get gmtime.\n");
goto seconds;
}
/* Print date and time */
res = strftime(timestr, sizeof(timestr),
- "%F ", &tm);
+ "%Y-%m-%d ", &tm);
if (!res) {
+ // TODO: log instead
fprintf(stderr, "[warning] Unable to print ascii time.\n");
goto seconds;
}
- fprintf(pretty->out, "%s", timestr);
+
+ g_string_append(pretty->string, timestr);
}
+
/* Print time in HH:MM:SS.ns */
- fprintf(pretty->out, "%02d:%02d:%02d.%09" PRIu64,
- tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec_abs);
+ g_string_append_printf(pretty->string,
+ "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min,
+ tm.tm_sec, ts_nsec_abs);
goto end;
}
seconds:
- fprintf(pretty->out, "%s%" PRId64 ".%09" PRIu64,
- is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs);
+ g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64,
+ is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs);
end:
return;
}
struct bt_ctf_stream_class *stream_class = NULL;
struct bt_ctf_trace *trace = NULL;
struct bt_ctf_clock_class *clock_class = NULL;
- FILE *out = pretty->out;
stream = bt_ctf_event_get_stream(event);
if (!stream) {
if (print_names) {
print_name_equal(pretty, "timestamp");
} else {
- fputs("[", out);
+ g_string_append(pretty->string, "[");
}
if (pretty->use_colors) {
- fputs(COLOR_TIMESTAMP, pretty->out);
+ g_string_append(pretty->string, COLOR_TIMESTAMP);
}
if (pretty->options.print_timestamp_cycles) {
print_timestamp_cycles(pretty, clock_class, event);
} else {
- print_timestamp_wall(pretty, clock_class, event);
+ struct bt_ctf_clock_value *clock_value =
+ bt_ctf_event_get_clock_value(event, clock_class);
+
+ print_timestamp_wall(pretty, clock_value);
+ bt_put(clock_value);
}
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
if (!print_names)
- fputs("] ", out);
+ g_string_append(pretty->string, "] ");
if (pretty->options.print_delta_field) {
if (print_names) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
print_name_equal(pretty, "delta");
} else {
- fputs("(", pretty->out);
+ g_string_append(pretty->string, "(");
}
if (pretty->options.print_timestamp_cycles) {
if (pretty->delta_cycles == -1ULL) {
- fputs("+??????????\?\?) ", pretty->out); /* Not a trigraph. */
+ g_string_append(pretty->string,
+ "+??????????\?\?) "); /* Not a trigraph. */
} else {
- fprintf(pretty->out, "+%012" PRIu64, pretty->delta_cycles);
+ g_string_append_printf(pretty->string,
+ "+%012" PRIu64, pretty->delta_cycles);
}
} else {
if (pretty->delta_real_timestamp != -1ULL) {
delta = pretty->delta_real_timestamp;
delta_sec = delta / NSEC_PER_SEC;
delta_nsec = delta % NSEC_PER_SEC;
- fprintf(pretty->out, "+%" PRIu64 ".%09" PRIu64,
+ g_string_append_printf(pretty->string,
+ "+%" PRIu64 ".%09" PRIu64,
delta_sec, delta_nsec);
} else {
- fputs("+?.?????????", pretty->out);
+ g_string_append(pretty->string, "+?.?????????");
}
}
if (!print_names) {
- fputs(") ", pretty->out);
+ g_string_append(pretty->string, ") ");
}
}
*start_line = !print_names;
name = bt_ctf_trace_get_name(trace_class);
if (name) {
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "trace");
}
- fprintf(pretty->out, "%s", name);
+
+ g_string_append(pretty->string, name);
+
if (!print_names) {
- fprintf(pretty->out, " ");
+ g_string_append(pretty->string, " ");
}
}
}
const char *str;
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "trace:hostname");
}
if (bt_value_string_get(hostname_str, &str)
== BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s", str);
+ g_string_append(pretty->string, str);
}
bt_put(hostname_str);
dom_print = 1;
const char *str;
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "trace:domain");
} else if (dom_print) {
- fputs(":", pretty->out);
+ g_string_append(pretty->string, ":");
}
if (bt_value_string_get(domain_str, &str)
== BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s", str);
+ g_string_append(pretty->string, str);
}
bt_put(domain_str);
dom_print = 1;
const char *str;
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "trace:procname");
} else if (dom_print) {
- fputs(":", pretty->out);
+ g_string_append(pretty->string, ":");
}
if (bt_value_string_get(procname_str, &str)
== BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s", str);
+ g_string_append(pretty->string, str);
}
bt_put(procname_str);
dom_print = 1;
int64_t value;
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "trace:vpid");
} else if (dom_print) {
- fputs(":", pretty->out);
+ g_string_append(pretty->string, ":");
}
if (bt_value_integer_get(vpid_value, &value)
== BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "(%" PRId64 ")", value);
+ g_string_append_printf(pretty->string, "(%" PRId64 ")", value);
}
bt_put(vpid_value);
dom_print = 1;
}
}
if (pretty->options.print_loglevel_field) {
- struct bt_value *loglevel_str, *loglevel_value;
-
- loglevel_str = bt_ctf_event_class_get_attribute_value_by_name(event_class,
- "loglevel_string");
- loglevel_value = bt_ctf_event_class_get_attribute_value_by_name(event_class,
- "loglevel");
- if (loglevel_str || loglevel_value) {
- bool has_str = false;
+ static const char *log_level_names[] = {
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY ] = "TRACE_EMERG",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT ] = "TRACE_ALERT",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL ] = "TRACE_CRIT",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR ] = "TRACE_ERR",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING ] = "TRACE_WARNING",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE ] = "TRACE_NOTICE",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO ] = "TRACE_INFO",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE",
+ [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG ] = "TRACE_DEBUG",
+ };
+ enum bt_ctf_event_class_log_level log_level;
+ const char *log_level_str = NULL;
+
+ log_level = bt_ctf_event_class_get_log_level(event_class);
+ assert(log_level != BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN);
+ if (log_level != BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) {
+ log_level_str = log_level_names[log_level];
+ }
+ if (log_level_str) {
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "loglevel");
} else if (dom_print) {
- fputs(":", pretty->out);
- }
- if (loglevel_str) {
- const char *str;
-
- if (bt_value_string_get(loglevel_str, &str)
- == BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s", str);
- has_str = true;
- }
- }
- if (loglevel_value) {
- int64_t value;
-
- if (bt_value_integer_get(loglevel_value, &value)
- == BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s(%" PRId64 ")",
- has_str ? " " : "", value);
- }
+ g_string_append(pretty->string, ":");
}
- bt_put(loglevel_str);
- bt_put(loglevel_value);
+
+ g_string_append(pretty->string, log_level_str);
+ g_string_append_printf(
+ pretty->string, " (%d)", (int) log_level);
dom_print = 1;
}
}
if (pretty->options.print_emf_field) {
- struct bt_value *uri_str;
+ const char *uri_str;
- uri_str = bt_ctf_event_class_get_attribute_value_by_name(event_class,
- "model.emf.uri");
+ uri_str = bt_ctf_event_class_get_emf_uri(event_class);
if (uri_str) {
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
if (print_names) {
print_name_equal(pretty, "model.emf.uri");
} else if (dom_print) {
- fputs(":", pretty->out);
+ g_string_append(pretty->string, ":");
}
- if (uri_str) {
- const char *str;
- if (bt_value_string_get(uri_str, &str)
- == BT_VALUE_STATUS_OK) {
- fprintf(pretty->out, "%s", str);
- }
- }
- bt_put(uri_str);
+ g_string_append(pretty->string, uri_str);
dom_print = 1;
}
}
if (dom_print && !print_names) {
- fputs(" ", pretty->out);
+ g_string_append(pretty->string, " ");
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = true;
if (print_names) {
print_name_equal(pretty, "name");
}
if (pretty->use_colors) {
- fputs(COLOR_EVENT_NAME, pretty->out);
+ g_string_append(pretty->string, COLOR_EVENT_NAME);
}
- fputs(bt_ctf_event_class_get_name(event_class), pretty->out);
+ g_string_append(pretty->string, bt_ctf_event_class_get_name(event_class));
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
if (!print_names) {
- fputs(": ", pretty->out);
+ g_string_append(pretty->string, ": ");
} else {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
end:
bt_put(trace_class);
switch (encoding) {
case BT_CTF_STRING_ENCODING_UTF8:
case BT_CTF_STRING_ENCODING_ASCII:
- g_string_append_c(pretty->string, (int) v.u);
+ g_string_append_c(pretty->tmp_string, (int) v.u);
goto end;
case BT_CTF_STRING_ENCODING_NONE:
case BT_CTF_STRING_ENCODING_UNKNOWN:
}
if (pretty->use_colors) {
- fputs(COLOR_NUMBER_VALUE, pretty->out);
+ g_string_append(pretty->string, COLOR_NUMBER_VALUE);
rst_color = true;
}
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- fprintf(pretty->out, "0b");
+ g_string_append(pretty->string, "0b");
v.u = _bt_piecewise_lshift(v.u, 64 - len);
for (bitnr = 0; bitnr < len; bitnr++) {
- fprintf(pretty->out, "%u", (v.u & (1ULL << 63)) ? 1 : 0);
+ g_string_append_printf(pretty->string, "%u", (v.u & (1ULL << 63)) ? 1 : 0);
v.u = _bt_piecewise_lshift(v.u, 1);
}
break;
}
}
- fprintf(pretty->out, "0%" PRIo64, v.u);
+ g_string_append_printf(pretty->string, "0%" PRIo64, v.u);
break;
}
case BT_CTF_INTEGER_BASE_DECIMAL:
+ case BT_CTF_INTEGER_BASE_UNSPECIFIED:
if (!signedness) {
- fprintf(pretty->out, "%" PRIu64, v.u);
+ g_string_append_printf(pretty->string, "%" PRIu64, v.u);
} else {
- fprintf(pretty->out, "%" PRId64, v.s);
+ g_string_append_printf(pretty->string, "%" PRId64, v.s);
}
break;
case BT_CTF_INTEGER_BASE_HEXADECIMAL:
v.u &= ((uint64_t) 1 << rounded_len) - 1;
}
- fprintf(pretty->out, "0x%" PRIX64, v.u);
+ g_string_append_printf(pretty->string, "0x%" PRIX64, v.u);
break;
}
default:
}
end:
if (rst_color) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
bt_put(field_type);
return ret;
{
int i;
- fputc('"', pretty->out);
+ g_string_append_c(pretty->string, '"');
+
for (i = 0; i < strlen(str); i++) {
/* Escape sequences not recognized by iscntrl(). */
switch (str[i]) {
case '\\':
- fputs("\\\\", pretty->out);
+ g_string_append(pretty->string, "\\\\");
continue;
case '\'':
- fputs("\\\'", pretty->out);
+ g_string_append(pretty->string, "\\\'");
continue;
case '\"':
- fputs("\\\"", pretty->out);
+ g_string_append(pretty->string, "\\\"");
continue;
case '\?':
- fputs("\\\?", pretty->out);
+ g_string_append(pretty->string, "\\\?");
continue;
}
/* Standard characters. */
if (!iscntrl(str[i])) {
- fputc(str[i], pretty->out);
+ g_string_append_c(pretty->string, str[i]);
continue;
}
switch (str[i]) {
case '\0':
- fputs("\\0", pretty->out);
+ g_string_append(pretty->string, "\\0");
break;
case '\a':
- fputs("\\a", pretty->out);
+ g_string_append(pretty->string, "\\a");
break;
case '\b':
- fputs("\\b", pretty->out);
+ g_string_append(pretty->string, "\\b");
break;
case '\e':
- fputs("\\e", pretty->out);
+ g_string_append(pretty->string, "\\e");
break;
case '\f':
- fputs("\\f", pretty->out);
+ g_string_append(pretty->string, "\\f");
break;
case '\n':
- fputs("\\n", pretty->out);
+ g_string_append(pretty->string, "\\n");
break;
case '\r':
- fputs("\\r", pretty->out);
+ g_string_append(pretty->string, "\\r");
break;
case '\t':
- fputs("\\t", pretty->out);
+ g_string_append(pretty->string, "\\t");
break;
case '\v':
- fputs("\\v", pretty->out);
+ g_string_append(pretty->string, "\\v");
break;
default:
/* Unhandled control-sequence, print as hex. */
- fprintf(pretty->out, "\\x%02x", str[i]);
+ g_string_append_printf(pretty->string, "\\x%02x", str[i]);
break;
}
}
- fputc('"', pretty->out);
+
+ g_string_append_c(pretty->string, '"');
}
static
iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
enumeration_field_type, value);
}
- if (!iter) {
- ret = BT_COMPONENT_STATUS_ERROR;
- goto end;
+ g_string_append(pretty->string, "( ");
+ ret = bt_ctf_field_type_enumeration_mapping_iterator_next(iter);
+ if (ret) {
+ if (pretty->use_colors) {
+ g_string_append(pretty->string, COLOR_UNKNOWN);
+ }
+ g_string_append(pretty->string, "<unknown>");
+ if (pretty->use_colors) {
+ g_string_append(pretty->string, COLOR_RST);
+ }
+ goto skip_loop;
}
- fprintf(pretty->out, "( ");
for (;;) {
const char *mapping_name;
goto end;
}
if (nr_mappings++)
- fprintf(pretty->out, ", ");
+ g_string_append(pretty->string, ", ");
if (pretty->use_colors) {
- fputs(COLOR_ENUM_MAPPING_NAME, pretty->out);
+ g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME);
}
print_escape_string(pretty, mapping_name);
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter) < 0) {
break;
}
}
- if (!nr_mappings) {
- if (pretty->use_colors) {
- fputs(COLOR_UNKNOWN, pretty->out);
- }
- fprintf(pretty->out, "<unknown>");
- if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
- }
- }
- fprintf(pretty->out, " : container = ");
+skip_loop:
+ g_string_append(pretty->string, " : container = ");
ret = print_integer(pretty, container_field);
if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- fprintf(pretty->out, " )");
+ g_string_append(pretty->string, " )");
end:
bt_put(iter);
bt_put(container_field_type);
}
if (*nr_printed_fields > 0) {
- fprintf(pretty->out, ", ");
+ g_string_append(pretty->string, ", ");
} else {
- fprintf(pretty->out, " ");
+ g_string_append(pretty->string, " ");
}
if (print_names) {
- print_field_name_equal(pretty, rem_(field_name));
+ print_field_name_equal(pretty, field_name);
}
ret = print_field(pretty, field, print_names, NULL, 0);
*nr_printed_fields += 1;
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- fprintf(pretty->out, "{");
+ g_string_append(pretty->string, "{");
pretty->depth++;
nr_printed_fields = 0;
for (i = 0; i < nr_fields; i++) {
}
}
pretty->depth--;
- fprintf(pretty->out, " }");
+ g_string_append(pretty->string, " }");
end:
bt_put(struct_type);
return ret;
if (!is_string) {
if (i != 0) {
- fprintf(pretty->out, ", ");
+ g_string_append(pretty->string, ", ");
} else {
- fprintf(pretty->out, " ");
+ g_string_append(pretty->string, " ");
}
if (print_names) {
- fprintf(pretty->out, "[%" PRIu64 "] = ", i);
+ g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
}
}
field = bt_ctf_field_array_get_field(array, i);
}
if (is_string) {
- g_string_assign(pretty->string, "");
+ g_string_assign(pretty->tmp_string, "");
} else {
- fprintf(pretty->out, "[");
+ g_string_append(pretty->string, "[");
}
pretty->depth++;
if (is_string) {
if (pretty->use_colors) {
- fputs(COLOR_STRING_VALUE, pretty->out);
+ g_string_append(pretty->string, COLOR_STRING_VALUE);
}
- print_escape_string(pretty, pretty->string->str);
+ print_escape_string(pretty, pretty->tmp_string->str);
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
} else {
- fprintf(pretty->out, " ]");
+ g_string_append(pretty->string, " ]");
}
end:
bt_put(field_type);
if (!is_string) {
if (i != 0) {
- fprintf(pretty->out, ", ");
+ g_string_append(pretty->string, ", ");
} else {
- fprintf(pretty->out, " ");
+ g_string_append(pretty->string, " ");
}
if (print_names) {
- fprintf(pretty->out, "[%" PRIu64 "] = ", i);
+ g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
}
}
field = bt_ctf_field_sequence_get_field(seq, i);
}
if (is_string) {
- g_string_assign(pretty->string, "");
+ g_string_assign(pretty->tmp_string, "");
} else {
- fprintf(pretty->out, "[");
+ g_string_append(pretty->string, "[");
}
pretty->depth++;
if (is_string) {
if (pretty->use_colors) {
- fputs(COLOR_STRING_VALUE, pretty->out);
+ g_string_append(pretty->string, COLOR_STRING_VALUE);
}
- print_escape_string(pretty, pretty->string->str);
+ print_escape_string(pretty, pretty->tmp_string->str);
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
} else {
- fprintf(pretty->out, " ]");
+ g_string_append(pretty->string, " ]");
}
end:
bt_put(length_field);
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- fprintf(pretty->out, "{ ");
+ g_string_append(pretty->string, "{ ");
pretty->depth++;
if (print_names) {
int iter_ret;
}
iter = bt_ctf_field_enumeration_get_mappings(tag_field);
- if (!iter) {
+ iter_ret = bt_ctf_field_type_enumeration_mapping_iterator_next(
+ iter);
+ if (!iter || ret) {
bt_put(tag_field);
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- print_field_name_equal(pretty, rem_(tag_choice));
+ print_field_name_equal(pretty, tag_choice);
bt_put(tag_field);
bt_put(iter);
}
goto end;
}
pretty->depth--;
- fprintf(pretty->out, " }");
+ g_string_append(pretty->string, " }");
end:
bt_put(field);
return ret;
return BT_COMPONENT_STATUS_ERROR;
}
if (pretty->use_colors) {
- fputs(COLOR_NUMBER_VALUE, pretty->out);
+ g_string_append(pretty->string, COLOR_NUMBER_VALUE);
}
- fprintf(pretty->out, "%g", v);
+ g_string_append_printf(pretty->string, "%g", v);
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
return BT_COMPONENT_STATUS_OK;
}
case CTF_TYPE_ENUM:
return print_enum(pretty, field);
case CTF_TYPE_STRING:
+ {
+ const char *str;
+
+ str = bt_ctf_field_string_get_value(field);
+ if (!str) {
+ return BT_COMPONENT_STATUS_ERROR;
+ }
+
if (pretty->use_colors) {
- fputs(COLOR_STRING_VALUE, pretty->out);
+ g_string_append(pretty->string, COLOR_STRING_VALUE);
}
- print_escape_string(pretty, bt_ctf_field_string_get_value(field));
+ print_escape_string(pretty, str);
if (pretty->use_colors) {
- fputs(COLOR_RST, pretty->out);
+ g_string_append(pretty->string, COLOR_RST);
}
return BT_COMPONENT_STATUS_OK;
+ }
case CTF_TYPE_STRUCT:
return print_struct(pretty, field, print_names, filter_fields,
filter_array_len);
- case CTF_TYPE_UNTAGGED_VARIANT:
case CTF_TYPE_VARIANT:
return print_variant(pretty, field, print_names);
case CTF_TYPE_ARRAY:
case CTF_TYPE_SEQUENCE:
return print_sequence(pretty, field, print_names);
default:
+ // TODO: log instead
fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) type_id);
return BT_COMPONENT_STATUS_ERROR;
}
goto end;
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = false;
if (pretty->options.print_scope_field_names) {
goto end;
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = false;
if (pretty->options.print_scope_field_names) {
goto end;
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = false;
if (pretty->options.print_scope_field_names) {
goto end;
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = false;
if (pretty->options.print_scope_field_names) {
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
struct bt_ctf_field *main_field = NULL;
- main_field = bt_ctf_event_get_payload_field(event);
+ main_field = bt_ctf_event_get_event_payload(event);
if (!main_field) {
goto end;
}
if (!pretty->start_line) {
- fputs(", ", pretty->out);
+ g_string_append(pretty->string, ", ");
}
pretty->start_line = false;
if (pretty->options.print_scope_field_names) {
return ret;
}
+static
+int flush_buf(struct pretty_component *pretty)
+{
+ int ret = 0;
+
+ if (pretty->string->len == 0) {
+ goto end;
+ }
+
+ if (fwrite(pretty->string->str, pretty->string->len, 1, pretty->out) != 1) {
+ ret = -1;
+ }
+
+end:
+ return ret;
+}
+
BT_HIDDEN
enum bt_component_status pretty_print_event(struct pretty_component *pretty,
struct bt_notification *event_notif)
assert(event);
assert(cc_prio_map);
pretty->start_line = true;
+ g_string_assign(pretty->string, "");
ret = print_event_header(pretty, event, cc_prio_map);
if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
goto end;
}
- fputc('\n', pretty->out);
+ g_string_append_c(pretty->string, '\n');
+ if (flush_buf(pretty)) {
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+
end:
bt_put(event);
bt_put(cc_prio_map);
return ret;
}
+
+BT_HIDDEN
+enum bt_component_status pretty_print_discarded_elements(
+ struct pretty_component *pretty,
+ struct bt_notification *notif)
+{
+ enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+ struct bt_ctf_stream *stream = NULL;
+ struct bt_ctf_stream_class *stream_class = NULL;
+ struct bt_ctf_trace *trace = NULL;
+ const char *stream_name;
+ const char *trace_name;
+ const unsigned char *trace_uuid;
+ int64_t stream_class_id;
+ int64_t stream_id;
+ bool is_discarded_events;
+ int64_t count;
+ struct bt_ctf_clock_value *clock_value = NULL;
+
+ /* Stream name */
+ switch (bt_notification_get_type(notif)) {
+ case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
+ stream = bt_notification_discarded_events_get_stream(notif);
+ count = bt_notification_discarded_events_get_count(notif);
+ is_discarded_events = true;
+ break;
+ case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
+ stream = bt_notification_discarded_packets_get_stream(notif);
+ count = bt_notification_discarded_packets_get_count(notif);
+ is_discarded_events = false;
+ break;
+ default:
+ abort();
+ }
+
+ assert(stream);
+ stream_name = bt_ctf_stream_get_name(stream);
+
+ /* Stream class ID */
+ stream_class = bt_ctf_stream_get_class(stream);
+ assert(stream_class);
+ stream_class_id = bt_ctf_stream_class_get_id(stream_class);
+
+ /* Stream ID */
+ stream_id = bt_ctf_stream_get_id(stream);
+
+ /* Trace path */
+ trace = bt_ctf_stream_class_get_trace(stream_class);
+ assert(trace);
+ trace_name = bt_ctf_trace_get_name(trace);
+ if (!trace_name) {
+ trace_name = "(unknown)";
+ }
+
+ /* Trace UUID */
+ trace_uuid = bt_ctf_trace_get_uuid(trace);
+
+ /*
+ * Print to standard error stream to remain backward compatible
+ * with Babeltrace 1.
+ */
+ fprintf(stderr,
+ "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s between [",
+ bt_common_color_fg_yellow(),
+ bt_common_color_bold(),
+ bt_common_color_reset(),
+ bt_common_color_fg_yellow(),
+ count, is_discarded_events ? "event" : "packet",
+ count == 1 ? "" : "s");
+ g_string_assign(pretty->string, "");
+ clock_value = is_discarded_events ?
+ bt_notification_discarded_events_get_begin_clock_value(notif) :
+ bt_notification_discarded_packets_get_begin_clock_value(notif);
+ print_timestamp_wall(pretty, clock_value);
+ BT_PUT(clock_value);
+ fprintf(stderr, "%s] and [", pretty->string->str);
+ g_string_assign(pretty->string, "");
+ clock_value = is_discarded_events ?
+ bt_notification_discarded_events_get_end_clock_value(notif) :
+ bt_notification_discarded_packets_get_end_clock_value(notif);
+ print_timestamp_wall(pretty, clock_value);
+ BT_PUT(clock_value);
+ fprintf(stderr, "%s] in trace \"%s\" ",
+ pretty->string->str, trace_name);
+
+ if (trace_uuid) {
+ fprintf(stderr,
+ "(UUID: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x) ",
+ trace_uuid[0],
+ trace_uuid[1],
+ trace_uuid[2],
+ trace_uuid[3],
+ trace_uuid[4],
+ trace_uuid[5],
+ trace_uuid[6],
+ trace_uuid[7],
+ trace_uuid[8],
+ trace_uuid[9],
+ trace_uuid[10],
+ trace_uuid[11],
+ trace_uuid[12],
+ trace_uuid[13],
+ trace_uuid[14],
+ trace_uuid[15]);
+ } else {
+ fprintf(stderr, "(no UUID) ");
+ }
+
+ fprintf(stderr, "within stream \"%s\" (stream class ID: %" PRId64 ", ",
+ stream_name, stream_class_id);
+
+ if (stream_id >= 0) {
+ fprintf(stderr, "stream ID: %" PRId64, stream_id);
+ } else {
+ fprintf(stderr, "no stream ID");
+ }
+
+ fprintf(stderr, ").%s\n", bt_common_color_reset());
+ bt_put(stream);
+ bt_put(stream_class);
+ bt_put(trace);
+ bt_put(clock_value);
+ return ret;
+}