bd0e11e1dd795d3da0a8d9f8b10abba9ebeb0c2a
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
;
38 if (sin
->pos
.offset
== -EOF
)
41 /* Hide event payload struct brackets */
44 /* Read and print event header */
45 if (stream_class
->event_header
) {
46 generic_rw(&sin
->pos
.parent
, &stream_class
->event_header
->p
);
49 len_index
= struct_declaration_lookup_field_index(stream_class
->event_header_decl
,
50 g_quark_from_static_string("id"));
52 struct definition_integer
*defint
;
55 field
= struct_definition_get_field_from_index(stream_class
->event_header
, len_index
);
56 assert(field
->definition
->declaration
->id
== CTF_TYPE_INTEGER
);
57 defint
= container_of(field
->definition
, struct definition_integer
, p
);
58 assert(defint
->declaration
->signedness
== FALSE
);
59 id
= defint
->value
._unsigned
; /* set id */
62 generic_rw(&sout
->parent
, &stream_class
->event_header
->p
);
65 /* Read and print stream-declared event context */
66 if (stream_class
->event_context
) {
67 generic_rw(&sin
->pos
.parent
, &stream_class
->event_context
->p
);
68 generic_rw(&sout
->parent
, &stream_class
->event_context
->p
);
71 if (id
>= stream_class
->events_by_id
->len
) {
72 fprintf(stdout
, "[error] Event id %" PRIu64
" is outside range.\n", id
);
75 event_class
= g_ptr_array_index(stream_class
->events_by_id
, id
);
77 fprintf(stdout
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
81 /* Read and print event-declared event context */
82 if (event_class
->context
) {
83 generic_rw(&sin
->pos
.parent
, &event_class
->context
->p
);
84 generic_rw(&sout
->parent
, &event_class
->context
->p
);
87 /* Read and print event payload */
88 if (event_class
->fields
) {
89 generic_rw(&sin
->pos
.parent
, &event_class
->fields
->p
);
90 generic_rw(&sout
->parent
, &event_class
->fields
->p
);
97 int convert_stream(struct ctf_text_stream_pos
*sout
,
98 struct ctf_file_stream
*sin
)
102 /* For each event, print header, context, payload */
103 /* TODO: order events by timestamps across streams */
105 ret
= convert_event(sout
, sin
);
109 fprintf(stdout
, "[error] Printing event failed.\n");
120 int convert_trace(struct trace_descriptor
*td_write
,
121 struct trace_descriptor
*td_read
)
123 struct ctf_trace
*tin
= container_of(td_read
, struct ctf_trace
, parent
);
124 struct ctf_text_stream_pos
*sout
=
125 container_of(td_write
, struct ctf_text_stream_pos
, trace_descriptor
);
126 int stream_id
, filenr
;
129 /* For each stream (TODO: order events by timestamp) */
130 for (stream_id
= 0; stream_id
< tin
->streams
->len
; stream_id
++) {
131 struct ctf_stream
*stream
= g_ptr_array_index(tin
->streams
, stream_id
);
135 for (filenr
= 0; filenr
< stream
->files
->len
; filenr
++) {
136 struct ctf_file_stream
*file_stream
= g_ptr_array_index(stream
->files
, filenr
);
137 ret
= convert_stream(sout
, file_stream
);
139 fprintf(stdout
, "[error] Printing stream %d failed.\n", stream_id
);
This page took 0.032038 seconds and 3 git commands to generate.