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;
int ret;
- int field_nr = 0;
/* print event header */
if (stream_class->event_header) {
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, ":");
/* Only show the event header in verbose mode */
if (babeltrace_verbose && stream_class->event_header) {
- if (field_nr++ != 0)
- fprintf(pos->fp, ", ");
+ if (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "stream.event.header = ");
+ fprintf(pos->fp, " stream.event.header =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = generic_rw(ppos, &stream_class->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 (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "stream.event.context = ");
+ fprintf(pos->fp, " stream.event.context =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = generic_rw(ppos, &stream_class->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 (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "event.context = ");
+ fprintf(pos->fp, " event.context =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = generic_rw(ppos, &event_class->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 (pos->field_nr++ != 0)
+ fprintf(pos->fp, ",");
if (pos->print_names)
- fprintf(pos->fp, "event.fields = ");
+ fprintf(pos->fp, " event.fields =");
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = generic_rw(ppos, &event_class->fields->p);
if (ret)
goto error;
+ pos->field_nr = field_nr_saved;
}
+ /* newline */
fprintf(pos->fp, "\n");
+ pos->field_nr = 0;
return 0;
int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int field_nr_saved;
int ret;
if (!pos->dummy) {
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
fprintf(pos->fp, "[");
pos->depth++;
}
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = array_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
fprintf(pos->fp, " ]");
}
+ pos->field_nr = field_nr_saved;
return ret;
}
if (pos->dummy)
return 0;
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
if (pos->dummy)
return 0;
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
if (pos->dummy)
return 0;
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int field_nr_saved;
int ret;
if (!pos->dummy) {
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
fprintf(pos->fp, "[");
pos->depth++;
}
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = sequence_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
fprintf(pos->fp, " ]");
}
+ pos->field_nr = field_nr_saved;
return ret;
}
if (pos->dummy)
return 0;
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
{
+ struct declaration *declaration = definition->declaration;
+ struct declaration_struct *struct_declaration =
+ container_of(declaration, struct declaration_struct, p);
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ uint64_t len = struct_declaration_len(struct_declaration);
+ int field_nr_saved;
int ret;
if (!pos->dummy) {
if (pos->depth >= 0) {
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names && definition->name != 0)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
- fprintf(pos->fp, "{");
+ if (pos->print_names || len > 1)
+ fprintf(pos->fp, "{");
}
pos->depth++;
}
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = struct_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
- if (pos->depth >= 0) {
+ if (pos->depth >= 0 && (pos->print_names || len > 1)) {
fprintf(pos->fp, " }");
}
}
+ pos->field_nr = field_nr_saved;
return ret;
}
int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
{
struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+ int field_nr_saved;
int ret;
if (!pos->dummy) {
if (pos->depth >= 0) {
- if (definition->index != 0 && definition->index != INT_MAX)
+ if (pos->field_nr++ != 0)
fprintf(pos->fp, ",");
- if (definition->index != INT_MAX)
- fprintf(pos->fp, " ");
+ fprintf(pos->fp, " ");
if (pos->print_names)
fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
}
pos->depth++;
}
+ field_nr_saved = pos->field_nr;
+ pos->field_nr = 0;
ret = variant_rw(ppos, definition);
if (!pos->dummy) {
pos->depth--;
fprintf(pos->fp, " }");
}
}
+ pos->field_nr = field_nr_saved;
return ret;
}
int depth;
int dummy; /* disable output */
int print_names; /* print field names */
+ int field_nr;
};
static inline
struct_definition_get_field_from_index(struct definition_struct *struct_definition,
int index);
int struct_rw(struct stream_pos *pos, struct definition *definition);
+uint64_t struct_declaration_len(struct declaration_struct *struct_declaration);
/*
* The tag enumeration is validated to ensure that it contains only mappings
return NULL;
return g_ptr_array_index(_struct->fields, index);
}
+
+uint64_t struct_declaration_len(struct declaration_struct *struct_declaration)
+{
+ return struct_declaration->fields->len;
+}