Add missing text plugin files
[babeltrace.git] / plugins / text / print.c
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
36 struct timestamp {
37 int64_t real_timestamp; /* Relative to UNIX epoch. */
38 uint64_t clock_value; /* In cycles. */
39 };
40
41 static
42 void 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
49 static
50 void 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
57 static
58 enum 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
67 static
68 enum 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 }
103 end:
104 bt_put(stream);
105 bt_put(clock);
106 return ret;
107 }
108
109 static inline
110 enum 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);
122 end:
123 return ret;
124 }
125
126 BT_HIDDEN
127 enum bt_component_status text_print_event(struct text_component *text,
128 struct bt_ctf_event *event)
129 {
130 enum bt_component_status ret;
131
132 ret = print_event_header(text, event);
133 if (ret != BT_COMPONENT_STATUS_OK) {
134 goto end;
135 }
136
137 fputc('\n', text->out);
138 end:
139 return ret;
140 }
This page took 0.038111 seconds and 4 git commands to generate.