Fix: documentation: refer to bt_put()
[babeltrace.git] / plugins / text / print.c
CommitLineData
af9a82eb
JG
1/*
2 * print.c
3 *
4 * Babeltrace CTF Text Output Plugin Event Printing
5 *
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29#include <babeltrace/ctf-ir/event.h>
30#include <babeltrace/ctf-ir/event-class.h>
31#include <babeltrace/ctf-ir/stream.h>
32#include <babeltrace/ctf-ir/stream-class.h>
33#include <babeltrace/ctf-ir/clock.h>
34#include "text.h"
35
36struct timestamp {
37 int64_t real_timestamp; /* Relative to UNIX epoch. */
38 uint64_t clock_value; /* In cycles. */
39};
40
41static
42void print_timestamp_cycles(struct text_component *text,
43 struct bt_ctf_clock *clock,
44 struct bt_ctf_event *event)
45{
46 fputs("00000000000000000000", text->out);
47}
48
49static
50void print_timestamp_wall(struct text_component *text,
51 struct bt_ctf_clock *clock,
52 struct bt_ctf_event *event)
53{
54 fputs("??:??:??.?????????", text->out);
55}
56
57static
58enum bt_component_status get_event_timestamp(struct bt_ctf_event *event)
59{
60/* int ret;
61 uint64_t value, frequency;
62 int64_t offset_s, offset;
63*/
64 return BT_COMPONENT_STATUS_OK;
65}
66
67static
68enum bt_component_status print_event_timestamp(struct text_component *text,
69 struct bt_ctf_event *event)
70{
71 bool print_names = text->options.print_header_field_names;
72 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
73 struct bt_ctf_stream *stream;
74 struct bt_ctf_clock *clock = NULL;
75 FILE *out = text->out;
76 FILE *err = text->err;
77 uint64_t real_timestamp;
78
79 stream = bt_ctf_event_get_stream(event);
80 if (!stream) {
81 ret = BT_COMPONENT_STATUS_ERROR;
82 goto end;
83 }
84
85 clock = bt_ctf_event_get_clock(event);
86 if (!clock) {
87 /* Stream has no timestamp. */
88 //puts("no_timestamp!");
89 //goto end;
90 }
91
92 fputs(print_names ? "timestamp = " : "[", out);
93 if (text->options.print_timestamp_cycles) {
94 print_timestamp_cycles(text, clock, event);
95 } else {
96 print_timestamp_wall(text, clock, event);
97 }
98
99 fputs(print_names ? ", " : "] ", out);
100 if (!text->options.print_delta_field) {
101 goto end;
102 }
103end:
104 bt_put(stream);
105 bt_put(clock);
106 return ret;
107}
108
109static inline
110enum bt_component_status print_event_header(struct text_component *text,
111 struct bt_ctf_event *event)
112{
113 enum bt_component_status ret;
114 struct bt_ctf_event_class *event_class = bt_ctf_event_get_class(event);
115
116 ret = print_event_timestamp(text, event);
117 if (ret != BT_COMPONENT_STATUS_OK) {
118 goto end;
119 }
120
121 fputs(bt_ctf_event_class_get_name(event_class), text->out);
f607e11e 122 bt_put(event_class);
af9a82eb
JG
123end:
124 return ret;
125}
126
127BT_HIDDEN
128enum bt_component_status text_print_event(struct text_component *text,
129 struct bt_ctf_event *event)
130{
131 enum bt_component_status ret;
132
133 ret = print_event_header(text, event);
134 if (ret != BT_COMPONENT_STATUS_OK) {
135 goto end;
136 }
137
138 fputc('\n', text->out);
139end:
140 return ret;
141}
This page took 0.02769 seconds and 4 git commands to generate.