*
* CTF Text Format registration.
*
- * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
#include <babeltrace/format.h>
#include <babeltrace/ctf-text/types.h>
#include <babeltrace/ctf/metadata.h>
-#include <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
#include <inttypes.h>
#include <uuid/uuid.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+ void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+ int whence));
void ctf_text_close_trace(struct trace_descriptor *descriptor);
static
.close_trace = ctf_text_close_trace,
};
+static GQuark Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN,
+ Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END,
+ Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED,
+ Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE,
+ Q_STREAM_PACKET_CONTEXT_PACKET_SIZE;
+
+static
+void __attribute__((constructor)) init_quarks(void)
+{
+ Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN = g_quark_from_static_string("stream.packet.context.timestamp_begin");
+ Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END = g_quark_from_static_string("stream.packet.context.timestamp_end");
+ Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED = g_quark_from_static_string("stream.packet.context.events_discarded");
+ Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE = g_quark_from_static_string("stream.packet.context.content_size");
+ Q_STREAM_PACKET_CONTEXT_PACKET_SIZE = g_quark_from_static_string("stream.packet.context.packet_size");
+}
+
+int print_field(struct definition *definition)
+{
+ /* Print all fields in verbose mode */
+ if (babeltrace_verbose)
+ return 1;
+
+ /* Filter out part of the packet context */
+ if (definition->path == Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN)
+ return 0;
+ if (definition->path == Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END)
+ return 0;
+ if (definition->path == Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED)
+ return 0;
+ if (definition->path == Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE)
+ return 0;
+ if (definition->path == Q_STREAM_PACKET_CONTEXT_PACKET_SIZE)
+ return 0;
+
+ return 1;
+}
+
static
int ctf_text_write_event(struct stream_pos *ppos,
struct ctf_stream *stream)
struct ctf_text_stream_pos *pos =
container_of(ppos, struct ctf_text_stream_pos, parent);
struct ctf_stream_class *stream_class = stream->stream_class;
+ int field_nr_saved;
struct ctf_event *event_class;
- uint64_t id = 0;
- int len_index;
+ struct ctf_stream_event *event;
+ uint64_t id;
int ret;
- int field_nr = 0;
-
- /* print event header */
- if (stream_class->event_header) {
- /* lookup event id */
- len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
- g_quark_from_static_string("id"));
- if (len_index >= 0) {
- struct definition_integer *defint;
- struct definition *field;
-
- field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
- assert(field->declaration->id == CTF_TYPE_INTEGER);
- defint = container_of(field, struct definition_integer, p);
- assert(defint->declaration->signedness == FALSE);
- id = defint->value._unsigned; /* set id */
- }
- }
+
+ id = stream->event_id;
if (id >= stream_class->events_by_id->len) {
fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
return -EINVAL;
}
+ event = g_ptr_array_index(stream->events_by_id, id);
+ if (!event) {
+ fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+ return -EINVAL;
+ }
event_class = g_ptr_array_index(stream_class->events_by_id, id);
- if (!event_class) {
+ if (!event) {
fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
return -EINVAL;
}
- if (pos->print_names)
- fprintf(pos->fp, "timestamp = ");
- else
- fprintf(pos->fp, "[");
- fprintf(pos->fp, "%12" PRIu64, stream->timestamp);
- if (!pos->print_names)
- fprintf(pos->fp, "]");
+ if (stream->has_timestamp) {
+ if (pos->print_names)
+ fprintf(pos->fp, "timestamp = ");
+ else
+ fprintf(pos->fp, "[");
+ fprintf(pos->fp, "%12" PRIu64, stream->timestamp);
+ if (!pos->print_names)
+ fprintf(pos->fp, "]");
- if (pos->print_names)
- fprintf(pos->fp, ", ");
- else
- fprintf(pos->fp, " ");
+ if (pos->print_names)
+ fprintf(pos->fp, ", ");
+ else
+ fprintf(pos->fp, " ");
+ }
if (pos->print_names)
fprintf(pos->fp, "name = ");
fprintf(pos->fp, "%s", g_quark_to_string(event_class->name));
if (pos->print_names)
- field_nr++;
+ pos->field_nr++;
else
- fprintf(pos->fp, ": ");
+ fprintf(pos->fp, ":");
+
+ /* print cpuid field from packet context */
+ if (stream->stream_packet_context) {
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
+ if (pos->print_names)
+ fprintf(pos->fp, " stream.packet.context =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
+ ret = generic_rw(ppos, &stream->stream_packet_context->p);
+ if (ret)
+ goto error;
+ pos->field_nr = field_nr_saved;
+ }
/* Only show the event header in verbose mode */
- if (babeltrace_verbose && stream_class->event_header) {
- if (field_nr++ != 0)
- fprintf(pos->fp, ", ");
+ if (babeltrace_verbose && stream->stream_event_header) {
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "stream.event.header = ");
- ret = generic_rw(ppos, &stream_class->event_header->p);
+ fprintf(pos->fp, " stream.event.header =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
+ ret = generic_rw(ppos, &stream->stream_event_header->p);
if (ret)
goto error;
+ pos->field_nr = field_nr_saved;
}
/* print stream-declared event context */
- if (stream_class->event_context) {
- if (field_nr++ != 0)
- fprintf(pos->fp, ", ");
+ if (stream->stream_event_context) {
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "stream.event.context = ");
- ret = generic_rw(ppos, &stream_class->event_context->p);
+ fprintf(pos->fp, " stream.event.context =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
+ ret = generic_rw(ppos, &stream->stream_event_context->p);
if (ret)
goto error;
+ pos->field_nr = field_nr_saved;
}
/* print event-declared event context */
- if (event_class->context) {
- if (field_nr++ != 0)
- fprintf(pos->fp, ", ");
+ if (event->event_context) {
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "event.context = ");
- ret = generic_rw(ppos, &event_class->context->p);
+ fprintf(pos->fp, " event.context =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
+ ret = generic_rw(ppos, &event->event_context->p);
if (ret)
goto error;
+ pos->field_nr = field_nr_saved;
}
/* Read and print event payload */
- if (event_class->fields) {
- if (field_nr++ != 0)
- fprintf(pos->fp, ", ");
+ if (event->event_fields) {
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "event.fields = ");
- ret = generic_rw(ppos, &event_class->fields->p);
+ fprintf(pos->fp, " event.fields =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
+ ret = generic_rw(ppos, &event->event_fields->p);
if (ret)
goto error;
+ pos->field_nr = field_nr_saved;
}
+ /* newline */
fprintf(pos->fp, "\n");
+ pos->field_nr = 0;
return 0;
}
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+ void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+ int whence))
{
struct ctf_text_stream_pos *pos;
FILE *fp;