35f50719359c527f6db230bd05739b0b71727d8f
4 * Babeltrace Trace Converter Library
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
23 #include <babeltrace/babeltrace.h>
24 #include <babeltrace/format.h>
25 #include <babeltrace/ctf/types.h>
26 #include <babeltrace/ctf/metadata.h>
27 #include <babeltrace/ctf-text/types.h>
30 int convert_event(struct ctf_text_stream_pos
*sout
,
31 struct ctf_file_stream
*sin
)
33 struct ctf_stream
*stream_class
= sin
->stream
;
34 struct ctf_event
*event_class
;
39 if (sin
->pos
.offset
== EOF
)
42 /* Hide event payload struct brackets */
45 /* Read and print event header */
46 if (stream_class
->event_header
) {
47 ret
= generic_rw(&sin
->pos
.parent
, &stream_class
->event_header
->p
);
51 len_index
= struct_declaration_lookup_field_index(stream_class
->event_header_decl
,
52 g_quark_from_static_string("id"));
54 struct definition_integer
*defint
;
57 field
= struct_definition_get_field_from_index(stream_class
->event_header
, len_index
);
58 assert(field
->definition
->declaration
->id
== CTF_TYPE_INTEGER
);
59 defint
= container_of(field
->definition
, struct definition_integer
, p
);
60 assert(defint
->declaration
->signedness
== FALSE
);
61 id
= defint
->value
._unsigned
; /* set id */
64 ret
= generic_rw(&sout
->parent
, &stream_class
->event_header
->p
);
69 /* Read and print stream-declared event context */
70 if (stream_class
->event_context
) {
71 ret
= generic_rw(&sin
->pos
.parent
, &stream_class
->event_context
->p
);
74 ret
= generic_rw(&sout
->parent
, &stream_class
->event_context
->p
);
79 if (id
>= stream_class
->events_by_id
->len
) {
80 fprintf(stdout
, "[error] Event id %" PRIu64
" is outside range.\n", id
);
83 event_class
= g_ptr_array_index(stream_class
->events_by_id
, id
);
85 fprintf(stdout
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
89 /* Read and print event-declared event context */
90 if (event_class
->context
) {
91 ret
= generic_rw(&sin
->pos
.parent
, &event_class
->context
->p
);
94 ret
= generic_rw(&sout
->parent
, &event_class
->context
->p
);
99 /* Read and print event payload */
100 if (event_class
->fields
) {
101 ret
= generic_rw(&sin
->pos
.parent
, &event_class
->fields
->p
);
104 ret
= generic_rw(&sout
->parent
, &event_class
->fields
->p
);
112 fprintf(stdout
, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n");
117 int convert_stream(struct ctf_text_stream_pos
*sout
,
118 struct ctf_file_stream
*sin
)
122 /* For each event, print header, context, payload */
123 /* TODO: order events by timestamps across streams */
125 ret
= convert_event(sout
, sin
);
129 fprintf(stdout
, "[error] Printing event failed.\n");
140 int convert_trace(struct trace_descriptor
*td_write
,
141 struct trace_descriptor
*td_read
)
143 struct ctf_trace
*tin
= container_of(td_read
, struct ctf_trace
, parent
);
144 struct ctf_text_stream_pos
*sout
=
145 container_of(td_write
, struct ctf_text_stream_pos
, trace_descriptor
);
146 int stream_id
, filenr
;
149 /* For each stream (TODO: order events by timestamp) */
150 for (stream_id
= 0; stream_id
< tin
->streams
->len
; stream_id
++) {
151 struct ctf_stream
*stream
= g_ptr_array_index(tin
->streams
, stream_id
);
155 for (filenr
= 0; filenr
< stream
->files
->len
; filenr
++) {
156 struct ctf_file_stream
*file_stream
= g_ptr_array_index(stream
->files
, filenr
);
157 ret
= convert_stream(sout
, file_stream
);
159 fprintf(stdout
, "[error] Printing stream %d failed.\n", stream_id
);
This page took 0.036934 seconds and 4 git commands to generate.