Babeltrace 2 C API
2.0.0
Open-source trace manipulation framework
|
Class of stream clocks.
A clock class is the class of stream clocks.
A clock class is a trace IR metadata object.
Stream clocks only exist conceptually in Babeltrace 2 because they are stateful objects. Messages cannot refer to stateful objects because they must not change while being transported from one component to the other.
Instead of having a stream clock object, messages have a default clock snapshot: this is a snapshot of the value of a stream's default clock (a clock class instance):
In the illustration above, notice that:
Each message (objects in blue stream rectangles) created for a given stream has a default clock snapshot (yellow star): this is a snapshot of the stream's default clock.
In other words, a default clock snapshot contains the value of the stream's default clock when this message occured.
The default clock class property of a stream class is optional: if a stream class has no default clock class, then its instances (streams) have no default clock, therefore all the messages created from this stream have no default clock snapshot.
A clock class is a shared object: get a new reference with bt_clock_class_get_ref() and put an existing reference with bt_clock_class_put_ref().
Some library functions freeze clock classes on success. The documentation of those functions indicate this postcondition.
The type of a clock class is bt_clock_class.
Create a default clock class from a self component with bt_clock_class_create().
The value of a stream clock (a conceptual instance of a clock class) is in cycles. This value is always positive and is relative to the clock's class's offset, which is relative to its origin.
A clock class's origin is one of:
The Unix epoch.
The stream clocks of all the clock classes which have a Unix epoch origin, whatever the clock class UUIDs, are correlatable.
Undefined.
In that case, two clock classes which share the same UUID, as returned by bt_clock_class_get_uuid(), including having no UUID, also share the same origin: their instances (stream clocks) are correlatable.
To compute an effective stream clock value, in cycles from its class's origin:
Because typical tracer clocks have a high frequency (often 1 GHz and more), an effective stream clock value (cycles since Unix epoch, for example) can be larger than UINT64_MAX
. This is why a clock class has two offset properties (one in seconds and one in cycles): to make it possible for a stream clock to have smaller values, relative to this offset.
The bt_clock_class_cycles_to_ns_from_origin(), bt_util_clock_cycles_to_ns_from_origin(), and bt_clock_snapshot_get_ns_from_origin() functions convert a stream clock value (cycles) to an equivalent nanoseconds from origin value using the relevant clock class properties (frequency and offset).
Those functions perform this computation:
The following illustration shows the possible scenarios:
The clock class's "offset in seconds" property can be negative. For example, considering:
Then the computed value is -7.5 seconds from origin, or -7,500,000,000 nanoseconds from origin.
A clock class has the following properties:
Frequency of the clock class's instances (stream clocks) (cycles/second).
Use bt_clock_class_set_frequency() and bt_clock_class_get_frequency().
Offset in seconds relative to the clock class's origin, and offset in cycles relative to the offset in seconds, of the clock class's instances (stream clocks).
The values of the clock class's instances are relative to the computed offset.
Use bt_clock_class_set_offset() and bt_clock_class_get_offset().
Precision of the clock class's instance (stream clocks) values (cycles).
For example, considering a precision of 7 cycles and the stream clock value 42 cycles, the real stream clock value can be anything between 35 cycles and 49 cycles.
Use bt_clock_class_set_precision() and bt_clock_class_get_precision().
Whether or not the clock class's origin is the Unix epoch.
Use bt_clock_class_set_origin_is_unix_epoch() and bt_clock_class_origin_is_unix_epoch().
Name of the clock class.
Use bt_clock_class_set_name() and bt_clock_class_get_name().
Description of the clock class.
Use bt_clock_class_set_description() and bt_clock_class_get_description().
UUID of the clock class.
The clock class's UUID uniquely identifies the clock class.
When the clock class's origin is not the Unix epoch, then the clock class's UUID determines whether or not two different clock classes have correlatable instances.
Use bt_clock_class_set_uuid() and bt_clock_class_get_uuid().
User attributes of the clock class.
User attributes are custom attributes attached to a clock class.
Use bt_clock_class_set_user_attributes(), bt_clock_class_borrow_user_attributes(), and bt_clock_class_borrow_user_attributes_const().
Type | |
typedef struct bt_clock_class | bt_clock_class |
Clock class. | |
Creation | |
bt_clock_class * | bt_clock_class_create (bt_self_component *self_component) |
Creates a default clock class from the self component self_component. More... | |
Properties | |
enum | bt_clock_class_set_name_status { BT_CLOCK_CLASS_SET_NAME_STATUS_OK, BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR } |
Status codes for bt_clock_class_set_name(). More... | |
enum | bt_clock_class_set_description_status { BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK, BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR } |
Status codes for bt_clock_class_set_description(). More... | |
typedef enum bt_clock_class_set_name_status | bt_clock_class_set_name_status |
Status codes for bt_clock_class_set_name(). | |
typedef enum bt_clock_class_set_description_status | bt_clock_class_set_description_status |
Status codes for bt_clock_class_set_description(). | |
void | bt_clock_class_set_frequency (bt_clock_class *clock_class, uint64_t frequency) |
Sets the frequency (Hz) of the clock class clock_class to frequency. More... | |
uint64_t | bt_clock_class_get_frequency (const bt_clock_class *clock_class) |
Returns the frequency (Hz) of the clock class clock_class. More... | |
void | bt_clock_class_set_offset (bt_clock_class *clock_class, int64_t offset_seconds, uint64_t offset_cycles) |
Sets the offset of the clock class clock_class to offset_seconds plus offset_cycles from its origin. More... | |
void | bt_clock_class_get_offset (const bt_clock_class *clock_class, int64_t *offset_seconds, uint64_t *offset_cycles) |
Returns the offsets in seconds and cycles of the clock class clock_class. More... | |
void | bt_clock_class_set_precision (bt_clock_class *clock_class, uint64_t precision) |
Sets the precision (cycles) of the clock class clock_class to precision. More... | |
uint64_t | bt_clock_class_get_precision (const bt_clock_class *clock_class) |
Returns the precision (cycles) of the clock class clock_class. More... | |
void | bt_clock_class_set_origin_is_unix_epoch (bt_clock_class *clock_class, bt_bool origin_is_unix_epoch) |
Sets whether or not the origin of the clock class clock_class is the Unix epoch. More... | |
bt_bool | bt_clock_class_origin_is_unix_epoch (const bt_clock_class *clock_class) |
Returns whether or not the origin of the clock class clock_class is the Unix epoch. More... | |
bt_clock_class_set_name_status | bt_clock_class_set_name (bt_clock_class *clock_class, const char *name) |
Sets the name of the clock class clock_class to a copy of name. More... | |
const char * | bt_clock_class_get_name (const bt_clock_class *clock_class) |
Returns the name of the clock class clock_class. More... | |
bt_clock_class_set_description_status | bt_clock_class_set_description (bt_clock_class *clock_class, const char *description) |
Sets the description of the clock class clock_class to a copy of description. More... | |
const char * | bt_clock_class_get_description (const bt_clock_class *clock_class) |
Returns the description of the clock class clock_class. More... | |
void | bt_clock_class_set_uuid (bt_clock_class *clock_class, bt_uuid uuid) |
Sets the UUID of the clock class clock_class to a copy of uuid. More... | |
bt_uuid | bt_clock_class_get_uuid (const bt_clock_class *clock_class) |
Returns the UUID of the clock class clock_class. More... | |
void | bt_clock_class_set_user_attributes (bt_clock_class *clock_class, const bt_value *user_attributes) |
Sets the user attributes of the clock class clock_class to user_attributes. More... | |
bt_value * | bt_clock_class_borrow_user_attributes (bt_clock_class *clock_class) |
Borrows the user attributes of the clock class clock_class. More... | |
const bt_value * | bt_clock_class_borrow_user_attributes_const (const bt_clock_class *clock_class) |
Borrows the user attributes of the clock class clock_class (const version). More... | |
Utilities | |
enum | bt_clock_class_cycles_to_ns_from_origin_status { BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK, BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR } |
Status codes for bt_clock_class_cycles_to_ns_from_origin(). More... | |
typedef enum bt_clock_class_cycles_to_ns_from_origin_status | bt_clock_class_cycles_to_ns_from_origin_status |
Status codes for bt_clock_class_cycles_to_ns_from_origin(). | |
bt_clock_class_cycles_to_ns_from_origin_status | bt_clock_class_cycles_to_ns_from_origin (const bt_clock_class *clock_class, uint64_t value, int64_t *ns_from_origin) |
Converts the stream clock value value from cycles to nanoseconds from the origin of the clock class clock_class and sets *ns_from_origin to the result. More... | |
Reference count | |
void | bt_clock_class_get_ref (const bt_clock_class *clock_class) |
Increments the reference count of the clock class clock_class. More... | |
void | bt_clock_class_put_ref (const bt_clock_class *clock_class) |
Decrements the reference count of the clock class clock_class. More... | |
#define | BT_CLOCK_CLASS_PUT_REF_AND_RESET(_clock_class) |
Decrements the reference count of the clock class _clock_class, and then sets _clock_class to NULL . More... | |
#define | BT_CLOCK_CLASS_MOVE_REF(_dst, _src) |
Decrements the reference count of the clock class _dst, sets _dst to _src, and then sets _src to NULL . More... | |
Status codes for bt_clock_class_set_name().
Enumerator | |
---|---|
BT_CLOCK_CLASS_SET_NAME_STATUS_OK | Success. |
BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR | Out of memory. |
Status codes for bt_clock_class_set_description().
Enumerator | |
---|---|
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK | Success. |
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR | Out of memory. |
Status codes for bt_clock_class_cycles_to_ns_from_origin().
Enumerator | |
---|---|
BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK | Success. |
BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR | Integer overflow while computing the result. |
#define BT_CLOCK_CLASS_PUT_REF_AND_RESET | ( | _clock_class | ) |
Decrements the reference count of the clock class _clock_class, and then sets _clock_class to NULL
.
_clock_class | Clock class of which to decrement the reference count. Can contain |
#define BT_CLOCK_CLASS_MOVE_REF | ( | _dst, | |
_src | |||
) |
Decrements the reference count of the clock class _dst, sets _dst to _src, and then sets _src to NULL
.
This macro effectively moves a clock class reference from the expression _src to the expression _dst, putting the existing _dst reference.
_dst | Destination expression. Can contain |
_src | Source expression. Can contain |
bt_clock_class* bt_clock_class_create | ( | bt_self_component * | self_component | ) |
Creates a default clock class from the self component self_component.
On success, the returned clock class has the following property values:
Property | Value |
---|---|
Frequency | 1 GHz |
Offset in seconds | 0 seconds |
Offset in cycles | 0 cycles |
Precision | 0 cycles |
Origin is Unix epoch? | Yes |
Name | None |
Description | None |
UUID | None |
User attributes | Empty map value |
[in] | self_component | Self component from which to create the default clock class. |
NULL
on memory error.NULL
. void bt_clock_class_set_frequency | ( | bt_clock_class * | clock_class, |
uint64_t | frequency | ||
) |
Sets the frequency (Hz) of the clock class clock_class to frequency.
See the frequency property.
[in] | clock_class | Clock class of which to set the frequency to frequency. |
[in] | frequency | New frequency of clock_class. |
NULL
. UINT64_C(-1)
. uint64_t bt_clock_class_get_frequency | ( | const bt_clock_class * | clock_class | ) |
Returns the frequency (Hz) of the clock class clock_class.
See the frequency property.
[in] | clock_class | Clock class of which to get the frequency. |
NULL
.void bt_clock_class_set_offset | ( | bt_clock_class * | clock_class, |
int64_t | offset_seconds, | ||
uint64_t | offset_cycles | ||
) |
Sets the offset of the clock class clock_class to offset_seconds plus offset_cycles from its origin.
See the offset property.
[in] | clock_class | Clock class of which to set the offset to offset_seconds and offset_cycles. |
[in] | offset_seconds | New offset in seconds of clock_class. |
[in] | offset_cycles | New offset in cycles of clock_class. |
NULL
. void bt_clock_class_get_offset | ( | const bt_clock_class * | clock_class, |
int64_t * | offset_seconds, | ||
uint64_t * | offset_cycles | ||
) |
Returns the offsets in seconds and cycles of the clock class clock_class.
See the offset property.
[in] | clock_class | Clock class of which to get the offset. |
[out] | offset_seconds | When this function returns, *offset_seconds is the offset in seconds of clock_class. |
[out] | offset_cycles | When this function returns, *offset_cycles is the offset in cycles of clock_class. |
NULL
. NULL
. NULL
.void bt_clock_class_set_precision | ( | bt_clock_class * | clock_class, |
uint64_t | precision | ||
) |
Sets the precision (cycles) of the clock class clock_class to precision.
See the precision property.
[in] | clock_class | Clock class of which to set the precision to precision. |
[in] | precision | New precision of clock_class. |
NULL
. uint64_t bt_clock_class_get_precision | ( | const bt_clock_class * | clock_class | ) |
Returns the precision (cycles) of the clock class clock_class.
See the precision property.
[in] | clock_class | Clock class of which to get the precision. |
NULL
.void bt_clock_class_set_origin_is_unix_epoch | ( | bt_clock_class * | clock_class, |
bt_bool | origin_is_unix_epoch | ||
) |
Sets whether or not the origin of the clock class clock_class is the Unix epoch.
See the origin is Unix epoch? property.
[in] | clock_class | Clock class of which to set whether or not its origin is the Unix epoch. |
[in] | origin_is_unix_epoch | BT_TRUE to make clock_class have a Unix epoch origin. |
NULL
. bt_bool bt_clock_class_origin_is_unix_epoch | ( | const bt_clock_class * | clock_class | ) |
Returns whether or not the origin of the clock class clock_class is the Unix epoch.
See the origin is Unix epoch? property.
[in] | clock_class | Clock class of which to get whether or not its origin is the Unix epoch. |
NULL
.bt_clock_class_set_name_status bt_clock_class_set_name | ( | bt_clock_class * | clock_class, |
const char * | name | ||
) |
Sets the name of the clock class clock_class to a copy of name.
See the name property.
[in] | clock_class | Clock class of which to set the name to name. |
[in] | name | New name of clock_class (copied). |
BT_CLOCK_CLASS_SET_NAME_STATUS_OK | Success. |
BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR | Out of memory. |
NULL
. NULL
.const char* bt_clock_class_get_name | ( | const bt_clock_class * | clock_class | ) |
Returns the name of the clock class clock_class.
See the name property.
If clock_class has no name, this function returns NULL
.
[in] | clock_class | Clock class of which to get the name. |
Name of clock_class, or NULL
if none.
The returned pointer remains valid as long as clock_class is not modified.
NULL
.bt_clock_class_set_description_status bt_clock_class_set_description | ( | bt_clock_class * | clock_class, |
const char * | description | ||
) |
Sets the description of the clock class clock_class to a copy of description.
See the description property.
[in] | clock_class | Clock class of which to set the description to description. |
[in] | description | New description of clock_class (copied). |
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK | Success. |
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR | Out of memory. |
NULL
. NULL
.const char* bt_clock_class_get_description | ( | const bt_clock_class * | clock_class | ) |
Returns the description of the clock class clock_class.
See the description property.
If clock_class has no description, this function returns NULL
.
[in] | clock_class | Clock class of which to get the description. |
Description of clock_class, or NULL
if none.
The returned pointer remains valid as long as clock_class is not modified.
NULL
.void bt_clock_class_set_uuid | ( | bt_clock_class * | clock_class, |
bt_uuid | uuid | ||
) |
Sets the UUID of the clock class clock_class to a copy of uuid.
See the UUID property.
[in] | clock_class | Clock class of which to set the UUID to uuid. |
[in] | uuid | New UUID of clock_class (copied). |
NULL
. NULL
.bt_uuid bt_clock_class_get_uuid | ( | const bt_clock_class * | clock_class | ) |
Returns the UUID of the clock class clock_class.
See the UUID property.
If clock_class has no UUID, this function returns NULL
.
[in] | clock_class | Clock class of which to get the UUID. |
UUID of clock_class, or NULL
if none.
The returned pointer remains valid as long as clock_class is not modified.
NULL
.void bt_clock_class_set_user_attributes | ( | bt_clock_class * | clock_class, |
const bt_value * | user_attributes | ||
) |
Sets the user attributes of the clock class clock_class to user_attributes.
See the user attributes property.
[in] | clock_class | Clock class of which to set the user attributes to user_attributes. |
[in] | user_attributes | New user attributes of clock_class. |
NULL
. NULL
. bt_value* bt_clock_class_borrow_user_attributes | ( | bt_clock_class * | clock_class | ) |
Borrows the user attributes of the clock class clock_class.
See the user attributes property.
[in] | clock_class | Clock class from which to borrow the user attributes. |
NULL
.const
version of this function. const bt_value* bt_clock_class_borrow_user_attributes_const | ( | const bt_clock_class * | clock_class | ) |
Borrows the user attributes of the clock class clock_class (const
version).
bt_clock_class_cycles_to_ns_from_origin_status bt_clock_class_cycles_to_ns_from_origin | ( | const bt_clock_class * | clock_class, |
uint64_t | value, | ||
int64_t * | ns_from_origin | ||
) |
Converts the stream clock value value from cycles to nanoseconds from the origin of the clock class clock_class and sets *ns_from_origin to the result.
This function:
The following illustration shows the possible scenarios:
This function can fail and return the BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR status code if any step of the computation process causes an integer overflow.
[in] | clock_class | Stream clock's class. |
[in] | value | Stream clock's value (cycles) to convert to nanoseconds from the origin of clock_class. |
[out] | ns_from_origin | On success, *ns_from_origin is value converted to nanoseconds from the origin of clock_class. |
BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK | Success. |
BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR | Integer overflow while computing the result. |
NULL
. NULL
.void bt_clock_class_get_ref | ( | const bt_clock_class * | clock_class | ) |
Increments the reference count of the clock class clock_class.
[in] | clock_class | Clock class of which to increment the reference count. Can be |
void bt_clock_class_put_ref | ( | const bt_clock_class * | clock_class | ) |
Decrements the reference count of the clock class clock_class.
[in] | clock_class | Clock class of which to decrement the reference count. Can be |