5d7211922e8f214f2e09446c7282054e0f4ec654
2 * SPDX-License-Identifier: MIT
4 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
7 * Babeltrace CTF writer - Clock
10 #define BT_LOG_TAG "CTF-WRITER/CLOCK"
13 #include "common/assert.h"
14 #include "common/uuid.h"
15 #include "compat/compiler.h"
16 #include <babeltrace2-ctf-writer/utils.h>
17 #include <babeltrace2-ctf-writer/object.h>
20 #include "clock-class.h"
26 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
);
29 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
32 struct bt_ctf_clock
*clock
= NULL
;
35 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
36 clock
= g_new0(struct bt_ctf_clock
, 1);
41 bt_ctf_object_init_shared(&clock
->base
, bt_ctf_clock_destroy
);
44 /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
45 clock
->clock_class
= (void *) bt_ctf_clock_class_create(name
, 1000000000);
46 if (!clock
->clock_class
) {
50 /* Automatically set clock class's UUID. */
51 bt_uuid_generate(cc_uuid
);
53 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
54 BT_ASSERT_DBG(ret
== 0);
58 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
63 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
65 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
66 return bt_ctf_clock_class_get_name(clock
->clock_class
);
70 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
72 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
73 return bt_ctf_clock_class_get_description(clock
->clock_class
);
77 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
79 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
80 return bt_ctf_clock_class_set_description(clock
->clock_class
,
85 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
87 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
88 return bt_ctf_clock_class_get_frequency(clock
->clock_class
);
92 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
94 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
95 return bt_ctf_clock_class_set_frequency(clock
->clock_class
,
100 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
102 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
103 return bt_ctf_clock_class_get_precision(clock
->clock_class
);
107 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
109 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
110 return bt_ctf_clock_class_set_precision(clock
->clock_class
,
115 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
117 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
118 return bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
123 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
125 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
126 return bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
131 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
133 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
134 return bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
139 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
141 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
142 return bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
147 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
149 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
150 return bt_ctf_clock_class_is_absolute(clock
->clock_class
);
154 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
156 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
157 return bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
162 const uint8_t *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
164 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
165 return bt_ctf_clock_class_get_uuid(clock
->clock_class
);
169 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const uint8_t *uuid
)
171 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
172 return bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
176 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
179 struct bt_ctf_clock_class
*cc
;
181 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
182 cc
= clock
->clock_class
;
184 /* Common case where cycles are actually nanoseconds */
185 if (cc
->frequency
== 1000000000) {
188 value
= (uint64_t) (((double) time
*
189 (double) cc
->frequency
) / 1e9
);
192 BT_CTF_ASSERT_PRE(clock
->value
<= value
,
193 "CTF writer clock value must be updated monotonically: "
194 "prev-value=%" PRId64
", new-value=%" PRId64
,
195 clock
->value
, value
);
196 clock
->value
= value
;
200 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
202 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
203 BT_CTF_ASSERT_PRE_NON_NULL(value
, "Value");
204 *value
= clock
->value
;
209 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
)
211 struct bt_ctf_clock
*clock
;
213 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
214 bt_ctf_object_put_ref(clock
->clock_class
);
218 void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class
*clock_class
,
219 struct metadata_context
*context
)
223 BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
224 "name=\"%s\", metadata-context-addr=%p", clock_class
,
225 bt_ctf_clock_class_get_name(clock_class
),
228 if (!clock_class
|| !context
) {
229 BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
230 "clock-class-addr=%p, name=\"%s\", metadata-context-addr=%p",
232 bt_ctf_clock_class_get_name(clock_class
),
237 uuid
= clock_class
->uuid
;
238 g_string_append(context
->string
, "clock {\n");
239 g_string_append_printf(context
->string
, "\tname = %s;\n",
240 clock_class
->name
->str
);
242 if (clock_class
->uuid_set
) {
243 g_string_append_printf(context
->string
,
244 "\tuuid = \"" BT_UUID_FMT
"\";\n",
245 BT_UUID_FMT_VALUES(uuid
));
248 if (clock_class
->description
) {
249 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
250 clock_class
->description
->str
);
253 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
254 clock_class
->frequency
);
255 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
256 clock_class
->precision
);
257 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
258 clock_class
->offset_s
);
259 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
260 clock_class
->offset
);
261 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
262 clock_class
->absolute
? "true" : "false");
263 g_string_append(context
->string
, "};\n\n");
This page took 0.033513 seconds and 4 git commands to generate.