4 * Babeltrace CTF IR - 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 #include <babeltrace/ctf-writer/clock-internal.h>
31 #include <babeltrace/ctf-ir/clock-class.h>
32 #include <babeltrace/ctf-ir/clock-class-internal.h>
33 #include <babeltrace/ctf-ir/utils.h>
34 #include <babeltrace/compat/uuid-internal.h>
35 #include <babeltrace/ref.h>
36 #include <babeltrace/object-internal.h>
37 #include <babeltrace/compiler-internal.h>
41 void bt_ctf_clock_destroy(struct bt_object
*obj
);
43 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
46 struct bt_ctf_clock
*clock
= NULL
;
47 unsigned char cc_uuid
[BABELTRACE_UUID_LEN
];
53 clock
= g_new0(struct bt_ctf_clock
, 1);
59 bt_object_init(clock
, bt_ctf_clock_destroy
);
62 /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
63 clock
->clock_class
= bt_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_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
83 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
85 const char *name
= NULL
;
88 name
= bt_clock_class_get_name(clock
->clock_class
);
94 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
96 const char *description
= NULL
;
99 description
= bt_clock_class_get_description(
106 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
111 ret
= bt_clock_class_set_description(clock
->clock_class
,
118 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
120 uint64_t freq
= -1ULL;
123 freq
= bt_clock_class_get_frequency(clock
->clock_class
);
129 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
134 ret
= bt_clock_class_set_frequency(clock
->clock_class
,
141 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
143 uint64_t precision
= -1ULL;
146 precision
= bt_clock_class_get_precision(
153 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
158 ret
= bt_clock_class_set_precision(clock
->clock_class
,
165 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
170 ret
= bt_clock_class_get_offset_s(clock
->clock_class
,
177 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
182 ret
= bt_clock_class_set_offset_s(clock
->clock_class
,
189 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
194 ret
= bt_clock_class_get_offset_cycles(clock
->clock_class
,
201 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
206 ret
= bt_clock_class_set_offset_cycles(clock
->clock_class
,
213 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
215 int is_absolute
= -1;
218 is_absolute
= bt_clock_class_is_absolute(
225 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
230 ret
= bt_clock_class_set_is_absolute(clock
->clock_class
,
237 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
239 const unsigned char *uuid
= NULL
;
242 uuid
= bt_clock_class_get_uuid(clock
->clock_class
);
248 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
253 ret
= bt_clock_class_set_uuid(clock
->clock_class
, uuid
);
259 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
269 /* Common case where cycles are actually nanoseconds */
270 if (clock
->clock_class
->frequency
== 1000000000) {
273 value
= (uint64_t) (((double) time
*
274 (double) clock
->clock_class
->frequency
) / 1e9
);
277 if (clock
->value
> value
) {
278 /* Timestamps must be strictly monotonic. */
283 clock
->value
= value
;
288 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
293 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
299 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
303 if (!clock
|| !value
) {
308 *value
= clock
->value
;
314 void bt_ctf_clock_destroy(struct bt_object
*obj
)
316 struct bt_ctf_clock
*clock
;
318 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
319 bt_put(clock
->clock_class
);
This page took 0.035737 seconds and 5 git commands to generate.