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 #define BT_LOG_TAG "CTF-WRITER-CLOCK"
31 #include <babeltrace/lib-logging-internal.h>
33 #include <babeltrace/ctf-writer/clock-internal.h>
34 #include <babeltrace/ctf-ir/clock-class.h>
35 #include <babeltrace/ctf-ir/clock-class-internal.h>
36 #include <babeltrace/ctf-ir/utils.h>
37 #include <babeltrace/compat/uuid-internal.h>
38 #include <babeltrace/ref.h>
39 #include <babeltrace/object-internal.h>
40 #include <babeltrace/compiler-internal.h>
41 #include <babeltrace/assert-internal.h>
42 #include <babeltrace/assert-pre-internal.h>
46 void bt_ctf_clock_destroy(struct bt_object
*obj
);
48 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
51 struct bt_ctf_clock
*clock
= NULL
;
52 unsigned char cc_uuid
[BABELTRACE_UUID_LEN
];
54 BT_ASSERT_PRE_NON_NULL(name
, "Name");
55 clock
= g_new0(struct bt_ctf_clock
, 1);
60 bt_object_init(clock
, bt_ctf_clock_destroy
);
63 /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
64 clock
->clock_class
= bt_clock_class_create(name
, 1000000000);
65 if (!clock
->clock_class
) {
69 /* Automatically set clock class's UUID. */
70 ret
= bt_uuid_generate(cc_uuid
);
75 ret
= bt_clock_class_set_uuid(clock
->clock_class
, cc_uuid
);
84 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
86 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
87 return bt_clock_class_get_name(clock
->clock_class
);
90 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
92 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
93 return bt_clock_class_get_description(clock
->clock_class
);
96 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
98 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
99 return bt_clock_class_set_description(clock
->clock_class
, desc
);
102 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
104 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
105 return bt_clock_class_get_frequency(clock
->clock_class
);
108 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
110 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
111 return bt_clock_class_set_frequency(clock
->clock_class
, freq
);
114 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
116 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
117 return bt_clock_class_get_precision(clock
->clock_class
);
120 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
122 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
123 return bt_clock_class_set_precision(clock
->clock_class
, precision
);
126 int bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
, int64_t *offset_s
)
128 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
129 return bt_clock_class_get_offset_s(clock
->clock_class
, offset_s
);
132 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, int64_t offset_s
)
134 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
135 return bt_clock_class_set_offset_s(clock
->clock_class
, offset_s
);
138 int bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
, int64_t *offset
)
140 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
141 return bt_clock_class_get_offset_cycles(clock
->clock_class
, offset
);
144 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, int64_t offset
)
146 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
147 return bt_clock_class_set_offset_cycles(clock
->clock_class
, offset
);
150 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
152 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
153 return bt_clock_class_is_absolute(clock
->clock_class
);
156 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
158 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
159 return bt_clock_class_set_is_absolute(clock
->clock_class
, is_absolute
);
162 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
164 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
165 return bt_clock_class_get_uuid(clock
->clock_class
);
168 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
170 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
171 return bt_clock_class_set_uuid(clock
->clock_class
, uuid
);
174 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, int64_t time
)
178 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
180 /* Common case where cycles are actually nanoseconds */
181 if (clock
->clock_class
->frequency
== 1000000000) {
184 value
= (uint64_t) (((double) time
*
185 (double) clock
->clock_class
->frequency
) / 1e9
);
188 BT_ASSERT_PRE(clock
->value
<= value
,
189 "CTF writer clock value must be updated monotonically: "
190 "prev-value=%" PRId64
", new-value=%" PRId64
,
191 clock
->value
, value
);
192 clock
->value
= value
;
196 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
201 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
207 int bt_ctf_clock_get_value(struct bt_ctf_clock
*clock
, uint64_t *value
)
209 BT_ASSERT_PRE_NON_NULL(clock
, "CTF writer clock");
210 BT_ASSERT_PRE_NON_NULL(value
, "Value");
211 *value
= clock
->value
;
216 void bt_ctf_clock_destroy(struct bt_object
*obj
)
218 struct bt_ctf_clock
*clock
;
220 clock
= container_of(obj
, struct bt_ctf_clock
, base
);
221 bt_put(clock
->clock_class
);
This page took 0.033788 seconds and 5 git commands to generate.