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 <babeltrace2/assert-internal.h>
34 #include <babeltrace2/compat/uuid-internal.h>
35 #include <babeltrace2/compiler-internal.h>
36 #include <babeltrace2/ctf-writer/clock-class-internal.h>
37 #include <babeltrace2/ctf-writer/clock-internal.h>
38 #include <babeltrace2/ctf-writer/utils.h>
39 #include <babeltrace2/ctf-writer/writer-internal.h>
40 #include <babeltrace2/ctf-writer/object-internal.h>
41 #include <babeltrace2/ctf-writer/object.h>
45 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
);
47 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
50 struct bt_ctf_clock
*clock
= NULL
;
51 unsigned char cc_uuid
[BABELTRACE_UUID_LEN
];
53 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
54 clock
= g_new0(struct bt_ctf_clock
, 1);
59 bt_ctf_object_init_shared(&clock
->base
, bt_ctf_clock_destroy
);
62 /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
63 clock
->clock_class
= (void *) bt_ctf_clock_class_create(name
, 1000000000);
64 if (!clock
->clock_class
) {
68 /* Automatically set clock class's UUID. */
69 ret
= bt_uuid_generate(cc_uuid
);
74 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
79 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
83 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
85 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
86 return bt_ctf_clock_class_get_name(clock
->clock_class
);
89 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
91 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
92 return bt_ctf_clock_class_get_description(clock
->clock_class
);
95 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
97 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
98 return bt_ctf_clock_class_set_description(clock
->clock_class
,
102 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
104 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
105 return bt_ctf_clock_class_get_frequency(clock
->clock_class
);
108 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
110 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
111 return bt_ctf_clock_class_set_frequency(clock
->clock_class
,
115 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
117 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
118 return bt_ctf_clock_class_get_precision(clock
->clock_class
);
121 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
123 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
124 return bt_ctf_clock_class_set_precision(clock
->clock_class
,
128 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
130 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
131 return bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
135 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
137 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
138 return bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
142 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
144 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
145 return bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
149 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
151 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
152 return bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
156 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
158 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
159 return bt_ctf_clock_class_is_absolute(clock
->clock_class
);
162 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
164 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
165 return bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
169 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
171 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
172 return bt_ctf_clock_class_get_uuid(clock
->clock_class
);
175 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
177 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
178 return bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
181 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
184 struct bt_ctf_clock_class
*cc
;
186 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
187 cc
= clock
->clock_class
;
189 /* Common case where cycles are actually nanoseconds */
190 if (cc
->frequency
== 1000000000) {
193 value
= (uint64_t) (((double) time
*
194 (double) cc
->frequency
) / 1e9
);
197 BT_CTF_ASSERT_PRE(clock
->value
<= value
,
198 "CTF writer clock value must be updated monotonically: "
199 "prev-value=%" PRId64
", new-value=%" PRId64
,
200 clock
->value
, value
);
201 clock
->value
= value
;
206 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
208 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
209 BT_CTF_ASSERT_PRE_NON_NULL(value
, "Value");
210 *value
= clock
->value
;
215 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
)
217 struct bt_ctf_clock
*clock
;
219 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
220 bt_ctf_object_put_ref(clock
->clock_class
);
225 void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class
*clock_class
,
226 struct metadata_context
*context
)
230 BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
231 "name=\"%s\", metadata-context-addr=%p", clock_class
,
232 bt_ctf_clock_class_get_name(clock_class
),
235 if (!clock_class
|| !context
) {
236 BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
237 "clock-class-addr=%p, name=\"%s\", metadata-context-addr=%p",
239 bt_ctf_clock_class_get_name(clock_class
),
244 uuid
= clock_class
->uuid
;
245 g_string_append(context
->string
, "clock {\n");
246 g_string_append_printf(context
->string
, "\tname = %s;\n",
247 clock_class
->name
->str
);
249 if (clock_class
->uuid_set
) {
250 g_string_append_printf(context
->string
,
251 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
252 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
253 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
254 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
255 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
258 if (clock_class
->description
) {
259 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
260 clock_class
->description
->str
);
263 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
264 clock_class
->frequency
);
265 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
266 clock_class
->precision
);
267 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
268 clock_class
->offset_s
);
269 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
270 clock_class
->offset
);
271 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
272 clock_class
->absolute
? "true" : "false");
273 g_string_append(context
->string
, "};\n\n");
This page took 0.036327 seconds and 4 git commands to generate.