cb5592655f6616af607d1124b46115f0b2853ced
4 * Babeltrace CTF writer - Clock
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #define BT_LOG_TAG "CTF-WRITER-CLOCK"
33 #include "common/assert.h"
34 #include "compat/uuid.h"
35 #include "compat/compiler.h"
36 #include <babeltrace2/ctf-writer/utils.h>
37 #include <babeltrace2/ctf-writer/object.h>
40 #include "clock-class.h"
46 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
);
48 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
51 struct bt_ctf_clock
*clock
= NULL
;
52 unsigned char cc_uuid
[BABELTRACE_UUID_LEN
];
54 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
55 clock
= g_new0(struct bt_ctf_clock
, 1);
60 bt_ctf_object_init_shared(&clock
->base
, bt_ctf_clock_destroy
);
63 /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
64 clock
->clock_class
= (void *) bt_ctf_clock_class_create(name
, 1000000000);
65 if (!clock
->clock_class
) {
69 /* Automatically set clock class's UUID. */
70 ret
= bt_uuid_generate(cc_uuid
);
75 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
80 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
84 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
86 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
87 return bt_ctf_clock_class_get_name(clock
->clock_class
);
90 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
92 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
93 return bt_ctf_clock_class_get_description(clock
->clock_class
);
96 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
98 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
99 return bt_ctf_clock_class_set_description(clock
->clock_class
,
103 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
105 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
106 return bt_ctf_clock_class_get_frequency(clock
->clock_class
);
109 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
111 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
112 return bt_ctf_clock_class_set_frequency(clock
->clock_class
,
116 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
118 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
119 return bt_ctf_clock_class_get_precision(clock
->clock_class
);
122 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
124 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
125 return bt_ctf_clock_class_set_precision(clock
->clock_class
,
129 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
131 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
132 return bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
136 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
138 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
139 return bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
143 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
145 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
146 return bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
150 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
152 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
153 return bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
157 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
159 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
160 return bt_ctf_clock_class_is_absolute(clock
->clock_class
);
163 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
165 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
166 return bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
170 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
172 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
173 return bt_ctf_clock_class_get_uuid(clock
->clock_class
);
176 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
178 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
179 return bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
182 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
185 struct bt_ctf_clock_class
*cc
;
187 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
188 cc
= clock
->clock_class
;
190 /* Common case where cycles are actually nanoseconds */
191 if (cc
->frequency
== 1000000000) {
194 value
= (uint64_t) (((double) time
*
195 (double) cc
->frequency
) / 1e9
);
198 BT_CTF_ASSERT_PRE(clock
->value
<= value
,
199 "CTF writer clock value must be updated monotonically: "
200 "prev-value=%" PRId64
", new-value=%" PRId64
,
201 clock
->value
, value
);
202 clock
->value
= value
;
207 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
209 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
210 BT_CTF_ASSERT_PRE_NON_NULL(value
, "Value");
211 *value
= clock
->value
;
216 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
)
218 struct bt_ctf_clock
*clock
;
220 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
221 bt_ctf_object_put_ref(clock
->clock_class
);
226 void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class
*clock_class
,
227 struct metadata_context
*context
)
231 BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
232 "name=\"%s\", metadata-context-addr=%p", clock_class
,
233 bt_ctf_clock_class_get_name(clock_class
),
236 if (!clock_class
|| !context
) {
237 BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
238 "clock-class-addr=%p, name=\"%s\", metadata-context-addr=%p",
240 bt_ctf_clock_class_get_name(clock_class
),
245 uuid
= clock_class
->uuid
;
246 g_string_append(context
->string
, "clock {\n");
247 g_string_append_printf(context
->string
, "\tname = %s;\n",
248 clock_class
->name
->str
);
250 if (clock_class
->uuid_set
) {
251 g_string_append_printf(context
->string
,
252 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
253 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
254 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
255 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
256 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
259 if (clock_class
->description
) {
260 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
261 clock_class
->description
->str
);
264 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
265 clock_class
->frequency
);
266 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
267 clock_class
->precision
);
268 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
269 clock_class
->offset_s
);
270 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
271 clock_class
->offset
);
272 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
273 clock_class
->absolute
? "true" : "false");
274 g_string_append(context
->string
, "};\n\n");
This page took 0.035379 seconds and 4 git commands to generate.