Commit | Line | Data |
---|---|---|
8c18d80b PP |
1 | #ifndef BABELTRACE_CTF_WRITER_CLOCK_H |
2 | #define BABELTRACE_CTF_WRITER_CLOCK_H | |
3 | ||
46bd0f2b JG |
4 | /* |
5 | * BabelTrace - CTF Writer: Clock | |
6 | * | |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
46bd0f2b JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
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: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
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 | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
ac0c6bdd | 33 | #include <stdint.h> |
8c18d80b PP |
34 | |
35 | #ifdef __cplusplus | |
36 | extern "C" { | |
37 | #endif | |
38 | ||
ac0c6bdd PP |
39 | struct bt_ctf_clock; |
40 | ||
41 | /* | |
42 | * bt_ctf_clock_create: create a clock. | |
43 | * | |
44 | * Allocate a new clock setting its reference count to 1. | |
45 | * | |
46 | * @param name Name of the clock (will be copied); can be set to NULL | |
47 | * for nameless clocks. | |
48 | * | |
49 | * Returns an allocated clock on success, NULL on error. | |
50 | */ | |
51 | extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name); | |
52 | ||
53 | /* | |
54 | * bt_ctf_clock_get_name: get a clock's name. | |
55 | * | |
56 | * Get the clock's name. | |
57 | * | |
58 | * @param clock Clock instance. | |
59 | * | |
60 | * Returns the clock's name, NULL on error. | |
61 | */ | |
62 | extern const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock); | |
63 | ||
64 | /* | |
65 | * bt_ctf_clock_get_description: get a clock's description. | |
66 | * | |
67 | * Get the clock's description. | |
68 | * | |
69 | * @param clock Clock instance. | |
70 | * | |
71 | * Returns the clock's description, NULL if unset. | |
72 | */ | |
73 | extern const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock); | |
74 | ||
75 | /* | |
76 | * bt_ctf_clock_set_description: set a clock's description. | |
77 | * | |
78 | * Set the clock's description. The description appears in the clock's TSDL | |
79 | * meta-data. | |
80 | * | |
81 | * @param clock Clock instance. | |
82 | * @param desc Description of the clock. | |
83 | * | |
84 | * Returns 0 on success, a negative value on error. | |
85 | */ | |
86 | extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, | |
87 | const char *desc); | |
88 | ||
89 | /* | |
90 | * bt_ctf_clock_get_frequency: get a clock's frequency. | |
91 | * | |
92 | * Get the clock's frequency (Hz). | |
93 | * | |
94 | * @param clock Clock instance. | |
95 | * | |
96 | * Returns the clock's frequency, -1ULL on error. | |
97 | */ | |
98 | extern uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock); | |
99 | ||
100 | /* | |
101 | * bt_ctf_clock_set_frequency: set a clock's frequency. | |
102 | * | |
103 | * Set the clock's frequency (Hz). | |
104 | * | |
105 | * @param clock Clock instance. | |
106 | * @param freq Clock's frequency in Hz, defaults to 1 000 000 000 Hz (1ns). | |
107 | * | |
108 | * Returns 0 on success, a negative value on error. | |
109 | */ | |
110 | extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, | |
111 | uint64_t freq); | |
112 | ||
113 | /* | |
114 | * bt_ctf_clock_get_precision: get a clock's precision. | |
115 | * | |
116 | * Get the clock's precision (in clock ticks). | |
117 | * | |
118 | * @param clock Clock instance. | |
119 | * | |
120 | * Returns the clock's precision, -1ULL on error. | |
121 | */ | |
122 | extern uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock); | |
123 | ||
124 | /* | |
125 | * bt_ctf_clock_set_precision: set a clock's precision. | |
126 | * | |
127 | * Set the clock's precision. | |
128 | * | |
129 | * @param clock Clock instance. | |
130 | * @param precision Clock's precision in clock ticks, defaults to 1. | |
131 | * | |
132 | * Returns 0 on success, a negative value on error. | |
133 | */ | |
134 | extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, | |
135 | uint64_t precision); | |
136 | ||
137 | /* | |
138 | * bt_ctf_clock_get_offset_s: get a clock's offset in seconds. | |
139 | * | |
140 | * Get the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01. | |
141 | * | |
142 | * @param clock Clock instance. | |
143 | * @param offset_s Pointer to clock offset in seconds (output). | |
144 | * | |
145 | * Returns 0 on success, a negative value on error. | |
146 | */ | |
147 | extern int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, | |
148 | int64_t *offset_s); | |
149 | ||
150 | /* | |
151 | * bt_ctf_clock_set_offset_s: set a clock's offset in seconds. | |
152 | * | |
153 | * Set the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01, | |
154 | * defaults to 0. | |
155 | * | |
156 | * @param clock Clock instance. | |
157 | * @param offset_s Clock's offset in seconds, defaults to 0. | |
158 | * | |
159 | * Returns 0 on success, a negative value on error. | |
160 | */ | |
161 | extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, | |
162 | int64_t offset_s); | |
163 | ||
164 | /* | |
165 | * bt_ctf_clock_get_offset: get a clock's offset in ticks. | |
166 | * | |
167 | * Get the clock's offset in ticks from Epoch + offset_t. | |
168 | * | |
169 | * @param clock Clock instance. | |
170 | * @param offset Clock offset in ticks from Epoch + offset_s (output). | |
171 | * | |
172 | * Returns 0 on success, a negative value on error. | |
173 | */ | |
174 | extern int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, | |
175 | int64_t *offset); | |
176 | ||
177 | /* | |
178 | * bt_ctf_clock_set_offset: set a clock's offset in ticks. | |
179 | * | |
180 | * Set the clock's offset in ticks from Epoch + offset_s. | |
181 | * | |
182 | * @param clock Clock instance. | |
183 | * @param offset Clock's offset in ticks from Epoch + offset_s, defaults to 0. | |
184 | * | |
185 | * Returns 0 on success, a negative value on error. | |
186 | */ | |
187 | extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, | |
188 | int64_t offset); | |
189 | ||
190 | /* | |
191 | * bt_ctf_clock_get_is_absolute: get a clock's absolute attribute. | |
192 | * | |
193 | * Get the clock's absolute attribute. A clock is absolute if the clock is a | |
194 | * global reference across the trace's other clocks. | |
195 | * | |
196 | * @param clock Clock instance. | |
197 | * | |
198 | * Returns the clock's absolute attribute, a negative value on error. | |
199 | */ | |
200 | extern int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock); | |
201 | ||
202 | /* | |
203 | * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute. | |
204 | * | |
205 | * Set the clock's absolute attribute. A clock is absolute if the clock is a | |
206 | * global reference across the trace's other clocks. | |
207 | * | |
208 | * @param clock Clock instance. | |
209 | * @param is_absolute Clock's absolute attribute, defaults to FALSE. | |
210 | * | |
211 | * Returns 0 on success, a negative value on error. | |
212 | */ | |
213 | extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, | |
214 | int is_absolute); | |
215 | ||
216 | /* | |
217 | * bt_ctf_clock_get_uuid: get a clock's UUID. | |
218 | * | |
219 | * Get the clock's UUID. | |
220 | * | |
221 | * @param clock Clock instance. | |
222 | * | |
223 | * Returns a pointer to the clock's UUID (16 byte array) on success, | |
224 | * NULL on error. | |
225 | */ | |
226 | extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock); | |
227 | ||
228 | /* | |
229 | * bt_ctf_clock_set_uuid: set a clock's UUID. | |
230 | * | |
231 | * Set a clock's UUID. | |
232 | * | |
233 | * @param clock Clock instance. | |
234 | * @param uuid A 16-byte array containing a UUID. | |
235 | * | |
236 | * Returns 0 on success, a negative value on error. | |
237 | */ | |
238 | extern int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, | |
239 | const unsigned char *uuid); | |
240 | ||
64cf1d3a PP |
241 | /* |
242 | * bt_ctf_clock_set_time: set a clock's current time value. | |
243 | * | |
244 | * Set the current time in nanoseconds since the clock's origin (offset and | |
245 | * offset_s attributes). Defaults to 0. | |
246 | * | |
247 | * Returns 0 on success, a negative value on error. | |
248 | */ | |
249 | extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, | |
250 | int64_t time); | |
251 | ||
8c18d80b PP |
252 | /* |
253 | * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the | |
254 | * refcount of the clock | |
255 | * | |
256 | * You may also use bt_ctf_get() and bt_ctf_put() with clock objects. | |
257 | * | |
258 | * These functions ensure that the clock won't be destroyed when it | |
259 | * is in use. The same number of get and put (plus one extra put to | |
260 | * release the initial reference done at creation) has to be done to | |
261 | * destroy a clock. | |
262 | * | |
263 | * When the clock refcount is decremented to 0 by a bt_ctf_clock_put, | |
264 | * the clock is freed. | |
265 | * | |
266 | * @param clock Clock instance. | |
267 | */ | |
268 | extern void bt_ctf_clock_get(struct bt_ctf_clock *clock); | |
269 | extern void bt_ctf_clock_put(struct bt_ctf_clock *clock); | |
270 | ||
271 | #ifdef __cplusplus | |
272 | } | |
273 | #endif | |
274 | ||
275 | #endif /* BABELTRACE_CTF_WRITER_CLOCK_H */ |