84125f2229bd6e4ef6100a9f1c69a7d10f906458
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/ref.h>
35 #include <babeltrace/object-internal.h>
36 #include <babeltrace/compiler.h>
40 void bt_ctf_clock_destroy(struct bt_object
*obj
);
42 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
44 struct bt_ctf_clock
*clock
= NULL
;
50 clock
= g_new0(struct bt_ctf_clock
, 1);
56 bt_object_init(clock
, bt_ctf_clock_destroy
);
58 clock
->clock_class
= bt_ctf_clock_class_create(name
);
59 if (!clock
->clock_class
) {
69 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
71 const char *name
= NULL
;
74 name
= bt_ctf_clock_class_get_name(clock
->clock_class
);
80 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
82 const char *description
= NULL
;
85 description
= bt_ctf_clock_class_get_description(
92 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
97 ret
= bt_ctf_clock_class_set_description(clock
->clock_class
,
104 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
106 uint64_t freq
= -1ULL;
109 freq
= bt_ctf_clock_class_get_frequency(clock
->clock_class
);
115 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
120 ret
= bt_ctf_clock_class_set_frequency(clock
->clock_class
,
127 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
129 uint64_t precision
= -1ULL;
132 precision
= bt_ctf_clock_class_get_precision(
139 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
144 ret
= bt_ctf_clock_class_set_precision(clock
->clock_class
,
151 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
156 ret
= bt_ctf_clock_class_get_offset_s(clock
->clock_class
,
163 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
168 ret
= bt_ctf_clock_class_set_offset_s(clock
->clock_class
,
175 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
180 ret
= bt_ctf_clock_class_get_offset_cycles(clock
->clock_class
,
187 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
192 ret
= bt_ctf_clock_class_set_offset_cycles(clock
->clock_class
,
199 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
201 int is_absolute
= -1;
204 is_absolute
= bt_ctf_clock_class_get_is_absolute(
211 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
216 ret
= bt_ctf_clock_class_set_is_absolute(clock
->clock_class
,
223 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
225 const unsigned char *uuid
= NULL
;
228 uuid
= bt_ctf_clock_class_get_uuid(clock
->clock_class
);
234 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
239 ret
= bt_ctf_clock_class_set_uuid(clock
->clock_class
, uuid
);
245 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
255 /* Common case where cycles are actually nanoseconds */
256 if (clock
->clock_class
->frequency
== 1000000000) {
259 value
= (uint64_t) (((double) time
*
260 (double) clock
->clock_class
->frequency
) / 1e9
);
263 if (clock
->value
> value
) {
264 /* Timestamps must be strictly monotonic. */
269 clock
->value
= value
;
274 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
279 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
285 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
289 if (!clock
|| !value
) {
294 *value
= clock
->value
;
300 void bt_ctf_clock_destroy(struct bt_object
*obj
)
302 struct bt_ctf_clock
*clock
;
304 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
305 bt_put(clock
->clock_class
);
This page took 0.034467 seconds and 4 git commands to generate.