2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
8 #include <babeltrace2-ctf-writer/writer.h>
9 #include <babeltrace2-ctf-writer/clock.h>
10 #include <babeltrace2-ctf-writer/clock-class.h>
11 #include <babeltrace2-ctf-writer/stream.h>
12 #include <babeltrace2-ctf-writer/event.h>
13 #include <babeltrace2-ctf-writer/event-types.h>
14 #include <babeltrace2-ctf-writer/event-fields.h>
15 #include <babeltrace2-ctf-writer/stream-class.h>
16 #include <babeltrace2-ctf-writer/trace.h>
18 #include "common/assert.h"
21 struct bt_ctf_writer
*writer
;
22 struct bt_ctf_trace
*trace
;
23 struct bt_ctf_clock
*clock
;
24 struct bt_ctf_stream_class
*sc
;
25 struct bt_ctf_stream
*stream
;
26 struct bt_ctf_event_class
*ec
;
30 void fini_config(struct config
*cfg
)
32 bt_ctf_object_put_ref(cfg
->stream
);
33 bt_ctf_object_put_ref(cfg
->sc
);
34 bt_ctf_object_put_ref(cfg
->ec
);
35 bt_ctf_object_put_ref(cfg
->clock
);
36 bt_ctf_object_put_ref(cfg
->trace
);
37 bt_ctf_object_put_ref(cfg
->writer
);
41 void configure_writer(struct config
*cfg
, const char *path
)
43 struct bt_ctf_field_type
*ft
;
46 cfg
->writer
= bt_ctf_writer_create(path
);
47 BT_ASSERT(cfg
->writer
);
48 cfg
->trace
= bt_ctf_writer_get_trace(cfg
->writer
);
49 BT_ASSERT(cfg
->trace
);
50 cfg
->clock
= bt_ctf_clock_create("default");
51 BT_ASSERT(cfg
->clock
);
52 ret
= bt_ctf_writer_add_clock(cfg
->writer
, cfg
->clock
);
54 ret
= bt_ctf_writer_set_byte_order(cfg
->writer
,
55 BT_CTF_BYTE_ORDER_BIG_ENDIAN
);
57 cfg
->sc
= bt_ctf_stream_class_create("hello");
59 ret
= bt_ctf_stream_class_set_clock(cfg
->sc
, cfg
->clock
);
61 cfg
->ec
= bt_ctf_event_class_create("ev");
63 ft
= bt_ctf_field_type_floating_point_create();
65 ret
= bt_ctf_field_type_floating_point_set_exponent_digits(ft
, 11);
67 ret
= bt_ctf_field_type_floating_point_set_mantissa_digits(ft
, 53);
69 ret
= bt_ctf_event_class_add_field(cfg
->ec
, ft
, "dbl");
71 bt_ctf_object_put_ref(ft
);
72 ret
= bt_ctf_stream_class_add_event_class(cfg
->sc
, cfg
->ec
);
74 cfg
->stream
= bt_ctf_writer_create_stream(cfg
->writer
, cfg
->sc
);
75 BT_ASSERT(cfg
->stream
);
79 void write_stream(struct config
*cfg
)
81 struct bt_ctf_event
*ev
;
82 struct bt_ctf_field
*field
;
85 /* Create event and fill fields */
86 ev
= bt_ctf_event_create(cfg
->ec
);
88 field
= bt_ctf_event_get_payload(ev
, "dbl");
90 ret
= bt_ctf_field_floating_point_set_value(field
, 17283.3881);
92 bt_ctf_object_put_ref(field
);
93 ret
= bt_ctf_clock_set_time(cfg
->clock
, 0);
97 ret
= bt_ctf_stream_append_event(cfg
->stream
, ev
);
99 bt_ctf_object_put_ref(ev
);
102 ret
= bt_ctf_stream_flush(cfg
->stream
);
106 int main(int argc
, char **argv
)
108 struct config cfg
= {0};
110 BT_ASSERT(argc
>= 2);
111 configure_writer(&cfg
, argv
[1]);