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.
22 #include <babeltrace/babeltrace.h>
23 #include <babeltrace/format.h>
24 #include <babeltrace/ctf/types.h>
25 #include <babeltrace/ctf/metadata.h>
26 #include <babeltrace/ctf-text/types.h>
29 int print_event(struct format
*fmt_write
, struct ctf_text_stream_pos
*sout
,
30 struct format
*fmt_read
, struct ctf_file_stream
*sin
)
32 struct ctf_stream
*stream_class
= sin
->stream
;
33 struct ctf_event
*event_class
;
37 /* Read and print event header */
38 if (stream_class
->event_header
) {
39 fmt_read
->struct_read(&sin
->pos
.parent
, stream_class
->event_header
);
42 len_index
= struct_declaration_lookup_field_index(td
->packet_header
->declaration
,
43 g_quark_from_static_string("id"));
45 struct definition_integer
*defint
;
48 field
= struct_definition_get_field_from_index(stream_class
->event_header
, len_index
);
49 assert(field
->definition
->declaration
->id
== CTF_TYPE_INTEGER
);
50 defint
= container_of(field
->definition
, struct definition_integer
, p
);
51 assert(defint
->declaration
->signedness
== FALSE
);
52 id
= defint
->value
._unsigned
; /* set id */
55 fmt_write
->struct_write(&sout
->parent
, stream_class
->event_header
);
58 /* Read and print stream-declared event context */
59 if (stream_class
->event_context
) {
60 fmt_read
->struct_read(&sin
->pos
.parent
, stream_class
->event_context
);
61 fmt_write
->struct_write(&sout
->parent
, stream_class
->event_context
);
64 if (id
>= stream_class
->events_by_id
->len
) {
65 fprintf(stdout
, "[error] Event id %" PRIu64
" is outside range.\n", id
);
68 event_class
= g_ptr_array_index(stream_class
->events_by_id
, id
);
70 fprintf(stdout
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
74 /* Read and print event-declared event context */
75 if (event_class
->context
) {
76 fmt_read
->struct_read(&sin
->pos
.parent
, event_class
->context
);
77 fmt_write
->struct_write(&sout
->parent
, event_class
->context
);
80 /* Read and print event payload */
81 if (event_class
->fields
) {
82 fmt_read
->struct_read(&sin
->pos
.parent
, event_class
->fields
);
83 fmt_write
->struct_write(&sout
->parent
, event_class
->fields
);
90 int print_stream(struct format
*fmt_write
, struct ctf_text_stream_pos
*sout
,
91 struct format
*fmt_read
, struct ctf_file_stream
*sin
)
95 /* For each event, print header, context, payload */
96 /* TODO: order events by timestamps across streams */
98 ret
= print_event(fmt_write
, sout
, fmt_read
, sin
);
102 fprintf(stdout
, "[error] Printing event failed.\n");
113 int print_trace(struct format
*fmt_write
,
114 struct trace_descriptor
*td_write
,
115 struct format
*fmt_read
,
116 struct trace_descriptor
*td_read
)
118 struct ctf_trace
*tin
= container_of(td_read
, struct ctf_trace
, parent
);
119 struct ctf_text_stream_pos
*sout
= container_of(td_write
, struct ctf_text_stream_pos
, parent
);
120 int stream_id
, filenr
;
123 /* For each stream (TODO: order events by timestamp) */
124 for (stream_id
= 0; stream_id
< tin
->streams
->len
; stream_id
++) {
125 struct ctf_stream
*stream
= g_ptr_array_index(tin
->streams
, stream_id
);
129 for (filenr
= 0; filenr
< stream
->files
->len
; filenr
++) {
130 struct ctf_file_stream
*file_stream
= g_ptr_array_index(stream
->files
, filenr
);
131 ret
= print_stream(fmt_write
, sout
, fmt_read
, file_stream
);
133 fprintf(stdout
, "[error] Printing stream %d failed.\n", stream_id
);
This page took 0.032041 seconds and 4 git commands to generate.