8fe44fbf35caa842661357b50488dd2161e36103
[babeltrace.git] / lib / babeltrace.c
1 /*
2 * babeltrace.c
3 *
4 * Babeltrace Library
5 *
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21 #include <babeltrace/babeltrace.h>
22 #include <babeltrace/ctf-text/types.h>
23 #include <stdlib.h>
24
25 int babeltrace_verbose, babeltrace_debug;
26
27 int convert_trace(struct trace_descriptor *td_write,
28 struct trace_collection *trace_collection_read)
29 {
30 struct babeltrace_iter *iter;
31 struct ctf_stream *stream;
32 struct ctf_stream_event *event;
33 struct ctf_text_stream_pos *sout;
34 struct trace_collection_pos begin_pos;
35 int ret = 0;
36
37 sout = container_of(td_write, struct ctf_text_stream_pos,
38 trace_descriptor);
39
40 begin_pos.type = BT_SEEK_BEGIN;
41 iter = babeltrace_iter_create(trace_collection_read, &begin_pos, NULL);
42 while (babeltrace_iter_read_event(iter, &stream, &event) == 0) {
43 ret = sout->parent.event_cb(&sout->parent, stream);
44 if (ret) {
45 fprintf(stdout, "[error] Writing event failed.\n");
46 goto end;
47 }
48 ret = babeltrace_iter_next(iter);
49 if (ret < 0)
50 goto end;
51 }
52 end:
53 babeltrace_iter_destroy(iter);
54 return ret;
55 }
56
57 static
58 void __attribute__((constructor)) init_babeltrace_lib(void)
59 {
60 if (getenv("BABELTRACE_VERBOSE"))
61 babeltrace_verbose = 1;
62 if (getenv("BABELTRACE_DEBUG"))
63 babeltrace_debug = 1;
64 }
This page took 0.029376 seconds and 4 git commands to generate.