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
);
61 clock
->clock_class
= bt_ctf_clock_class_create(name
);
62 if (!clock
->clock_class
) {
66 /* Automatically set clock class's UUID. */
67 ret
= bt_uuid_generate(cc_uuid
);
72 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
81 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
83 const char *name
= NULL
;
86 name
= bt_ctf_clock_class_get_name(clock
->clock_class
);
92 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
94 const char *description
= NULL
;
97 description
= bt_ctf_clock_class_get_description(
104 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
109 ret
= bt_ctf_clock_class_set_description(clock
->clock_class
,
116 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
118 uint64_t freq
= -1ULL;
121 freq
= bt_ctf_clock_class_get_frequency(clock
->clock_class
);
127 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
132 ret
= bt_ctf_clock_class_set_frequency(clock
->clock_class
,
139 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
141 uint64_t precision
= -1ULL;
144 precision
= bt_ctf_clock_class_get_precision(
151 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
156 ret
= bt_ctf_clock_class_set_precision(clock
->clock_class
,
163 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
168 ret
= bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
175 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
180 ret
= bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
187 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
192 ret
= bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
199 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
204 ret
= bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
211 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
213 int is_absolute
= -1;
216 is_absolute
= bt_ctf_clock_class_is_absolute(
223 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
228 ret
= bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
235 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
237 const unsigned char *uuid
= NULL
;
240 uuid
= bt_ctf_clock_class_get_uuid(clock
->clock_class
);
246 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
251 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
257 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
267 /* Common case where cycles are actually nanoseconds */
268 if (clock
->clock_class
->frequency
== 1000000000) {
271 value
= (uint64_t) (((double) time
*
272 (double) clock
->clock_class
->frequency
) / 1e9
);
275 if (clock
->value
> value
) {
276 /* Timestamps must be strictly monotonic. */
281 clock
->value
= value
;
286 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
291 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
297 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
301 if (!clock
|| !value
) {
306 *value
= clock
->value
;
312 void bt_ctf_clock_destroy(struct bt_object
*obj
)
314 struct bt_ctf_clock
*clock
;
316 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
317 bt_put(clock
->clock_class
);
This page took 0.047161 seconds and 4 git commands to generate.