bd9b4c56ced34df1879e92cb77c8eb4ec8b34d82
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 "common/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
;
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 bt_uuid_generate(cc_uuid
);
72 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
73 BT_ASSERT_DBG(ret
== 0);
77 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
81 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
83 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
84 return bt_ctf_clock_class_get_name(clock
->clock_class
);
87 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
89 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
90 return bt_ctf_clock_class_get_description(clock
->clock_class
);
93 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
95 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
96 return bt_ctf_clock_class_set_description(clock
->clock_class
,
100 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
102 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
103 return bt_ctf_clock_class_get_frequency(clock
->clock_class
);
106 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
108 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
109 return bt_ctf_clock_class_set_frequency(clock
->clock_class
,
113 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
115 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
116 return bt_ctf_clock_class_get_precision(clock
->clock_class
);
119 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
121 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
122 return bt_ctf_clock_class_set_precision(clock
->clock_class
,
126 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
128 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
129 return bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
133 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
135 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
136 return bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
140 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
142 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
143 return bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
147 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
149 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
150 return bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
154 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
156 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
157 return bt_ctf_clock_class_is_absolute(clock
->clock_class
);
160 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
162 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
163 return bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
167 const uint8_t *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
169 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
170 return bt_ctf_clock_class_get_uuid(clock
->clock_class
);
173 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const uint8_t *uuid
)
175 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
176 return bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
179 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
182 struct bt_ctf_clock_class
*cc
;
184 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
185 cc
= clock
->clock_class
;
187 /* Common case where cycles are actually nanoseconds */
188 if (cc
->frequency
== 1000000000) {
191 value
= (uint64_t) (((double) time
*
192 (double) cc
->frequency
) / 1e9
);
195 BT_CTF_ASSERT_PRE(clock
->value
<= value
,
196 "CTF writer clock value must be updated monotonically: "
197 "prev-value=%" PRId64
", new-value=%" PRId64
,
198 clock
->value
, value
);
199 clock
->value
= value
;
204 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
206 BT_CTF_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
207 BT_CTF_ASSERT_PRE_NON_NULL(value
, "Value");
208 *value
= clock
->value
;
213 void bt_ctf_clock_destroy(struct bt_ctf_object
*obj
)
215 struct bt_ctf_clock
*clock
;
217 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
218 bt_ctf_object_put_ref(clock
->clock_class
);
223 void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class
*clock_class
,
224 struct metadata_context
*context
)
228 BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
229 "name=\"%s\", metadata-context-addr=%p", clock_class
,
230 bt_ctf_clock_class_get_name(clock_class
),
233 if (!clock_class
|| !context
) {
234 BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
235 "clock-class-addr=%p, name=\"%s\", metadata-context-addr=%p",
237 bt_ctf_clock_class_get_name(clock_class
),
242 uuid
= clock_class
->uuid
;
243 g_string_append(context
->string
, "clock {\n");
244 g_string_append_printf(context
->string
, "\tname = %s;\n",
245 clock_class
->name
->str
);
247 if (clock_class
->uuid_set
) {
248 g_string_append_printf(context
->string
,
249 "\tuuid = \"" BT_UUID_FMT
"\";\n",
250 BT_UUID_FMT_VALUES(uuid
));
253 if (clock_class
->description
) {
254 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
255 clock_class
->description
->str
);
258 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
259 clock_class
->frequency
);
260 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
261 clock_class
->precision
);
262 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
263 clock_class
->offset_s
);
264 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
265 clock_class
->offset
);
266 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
267 clock_class
->absolute
? "true" : "false");
268 g_string_append(context
->string
, "};\n\n");
This page took 0.034152 seconds and 4 git commands to generate.