Babeltrace 2 C API  2.0.0
Open-source trace manipulation framework

Detailed Description

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:

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().

Clock value vs. clock class origin

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:

If bt_clock_class_origin_is_unix_epoch() returns BT_TRUE

The Unix epoch.

The stream clocks of all the clock classes which have a Unix epoch origin, whatever the clock class UUIDs, are correlatable.

If bt_clock_class_origin_is_unix_epoch() returns BT_FALSE

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:

  1. Convert the clock class's "offset in seconds" property to cycles using its frequency.
  2. Add the value of 1., the stream clock's value, and the clock class's "offset in cycles" property.

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:

  1. Convert the clock class's "offset in cycles" property to seconds using its frequency.
  2. Convert the stream clock's value to seconds using the clock class's frequency.
  3. Add the values of 1., 2., and the clock class's "offset in seconds" property.
  4. Convert the value of 3. to nanoseconds.

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.

Properties

A clock class has the following properties:

Frequency

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 and in cycles)

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

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().

Origin is Unix epoch?

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().

Optional: Name

Name of the clock class.

Use bt_clock_class_set_name() and bt_clock_class_get_name().

Optional: Description

Description of the clock class.

Use bt_clock_class_set_description() and bt_clock_class_get_description().

Optional: UUID

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().

Optional: User attributes

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_classbt_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_valuebt_clock_class_borrow_user_attributes (bt_clock_class *clock_class)
 Borrows the user attributes of the clock class clock_class. More...
 
const bt_valuebt_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...
 

Enumeration Type Documentation

◆ bt_clock_class_set_name_status

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.

◆ bt_clock_class_set_description_status

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.

◆ bt_clock_class_cycles_to_ns_from_origin_status

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.

Macro Definition Documentation

◆ BT_CLOCK_CLASS_PUT_REF_AND_RESET

#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.

Parameters
_clock_class

Clock class of which to decrement the reference count.

Can contain NULL.

Precondition
_clock_class is an assignable expression.

◆ BT_CLOCK_CLASS_MOVE_REF

#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.

Parameters
_dst

Destination expression.

Can contain NULL.

_src

Source expression.

Can contain NULL.

Precondition
_dst is an assignable expression.
_src is an assignable expression.

Function Documentation

◆ bt_clock_class_create()

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
Parameters
[in]self_componentSelf component from which to create the default clock class.
Returns
New clock class reference, or NULL on memory error.
Precondition
self_component is not NULL.

◆ bt_clock_class_set_frequency()

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.

Parameters
[in]clock_classClock class of which to set the frequency to frequency.
[in]frequencyNew frequency of clock_class.
Precondition
clock_class is not NULL.
clock_class is not frozen.
frequency is not 0.
frequency is not UINT64_C(-1).
frequency is greater than the clock class's offset in cycles (as returned by bt_clock_class_get_offset()).
See also
bt_clock_class_get_frequency() — Returns the frequency of a clock class.

◆ bt_clock_class_get_frequency()

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.

Parameters
[in]clock_classClock class of which to get the frequency.
Returns
Frequency (Hz) of clock_class.
Precondition
clock_class is not NULL.
See also
bt_clock_class_set_frequency() — Sets the frequency of a clock class.

◆ bt_clock_class_set_offset()

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.

Parameters
[in]clock_classClock class of which to set the offset to offset_seconds and offset_cycles.
[in]offset_secondsNew offset in seconds of clock_class.
[in]offset_cyclesNew offset in cycles of clock_class.
Precondition
clock_class is not NULL.
clock_class is not frozen.
offset_cycles is less than the clock class's frequency (as returned by bt_clock_class_get_frequency()).
See also
bt_clock_class_get_offset() — Returns the offset of a clock class.

◆ bt_clock_class_get_offset()

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.

Parameters
[in]clock_classClock class of which to get the offset.
[out]offset_secondsWhen this function returns, *offset_seconds is the offset in seconds of clock_class.
[out]offset_cyclesWhen this function returns, *offset_cycles is the offset in cycles of clock_class.
Precondition
clock_class is not NULL.
offset_seconds is not NULL.
offset_cycles is not NULL.
See also
bt_clock_class_set_offset() — Sets the offset of a clock class.

◆ bt_clock_class_set_precision()

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.

Parameters
[in]clock_classClock class of which to set the precision to precision.
[in]precisionNew precision of clock_class.
Precondition
clock_class is not NULL.
clock_class is not frozen.
See also
bt_clock_class_get_precision() — Returns the precision of a clock class.

◆ bt_clock_class_get_precision()

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.

Parameters
[in]clock_classClock class of which to get the precision.
Returns
Precision (cycles) of clock_class.
Precondition
clock_class is not NULL.
See also
bt_clock_class_set_precision() — Sets the precision of a clock class.

◆ bt_clock_class_set_origin_is_unix_epoch()

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.

Parameters
[in]clock_classClock class of which to set whether or not its origin is the Unix epoch.
[in]origin_is_unix_epochBT_TRUE to make clock_class have a Unix epoch origin.
Precondition
clock_class is not NULL.
clock_class is not frozen.
See also
bt_clock_class_origin_is_unix_epoch() — Returns whether or not the origin of a clock class is the Unix epoch.

◆ bt_clock_class_origin_is_unix_epoch()

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.

Parameters
[in]clock_classClock class of which to get whether or not its origin is the Unix epoch.
Returns
BT_TRUE if the origin of clock_class is the Unix epoch.
Precondition
clock_class is not NULL.
See also
bt_clock_class_set_origin_is_unix_epoch() — Sets whether or not the origin of a clock class is the Unix epoch.

◆ bt_clock_class_set_name()

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.

Parameters
[in]clock_classClock class of which to set the name to name.
[in]nameNew name of clock_class (copied).
Return values
BT_CLOCK_CLASS_SET_NAME_STATUS_OKSuccess.
BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROROut of memory.
Precondition
clock_class is not NULL.
clock_class is not frozen.
name is not NULL.
See also
bt_clock_class_get_name() — Returns the name of a clock class.

◆ bt_clock_class_get_name()

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.

Parameters
[in]clock_classClock class of which to get the name.
Returns

Name of clock_class, or NULL if none.

The returned pointer remains valid as long as clock_class is not modified.

Precondition
clock_class is not NULL.
See also
bt_clock_class_set_name() — Sets the name of a clock class.

◆ bt_clock_class_set_description()

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.

Parameters
[in]clock_classClock class of which to set the description to description.
[in]descriptionNew description of clock_class (copied).
Return values
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OKSuccess.
BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROROut of memory.
Precondition
clock_class is not NULL.
clock_class is not frozen.
description is not NULL.
See also
bt_clock_class_get_description() — Returns the description of a clock class.

◆ bt_clock_class_get_description()

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.

Parameters
[in]clock_classClock class of which to get the description.
Returns

Description of clock_class, or NULL if none.

The returned pointer remains valid as long as clock_class is not modified.

Precondition
clock_class is not NULL.
See also
bt_clock_class_set_description() — Sets the description of a clock class.

◆ bt_clock_class_set_uuid()

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.

Parameters
[in]clock_classClock class of which to set the UUID to uuid.
[in]uuidNew UUID of clock_class (copied).
Precondition
clock_class is not NULL.
clock_class is not frozen.
uuid is not NULL.
See also
bt_clock_class_get_uuid() — Returns the UUID of a clock class.

◆ bt_clock_class_get_uuid()

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.

Parameters
[in]clock_classClock class of which to get the UUID.
Returns

UUID of clock_class, or NULL if none.

The returned pointer remains valid as long as clock_class is not modified.

Precondition
clock_class is not NULL.
See also
bt_clock_class_set_uuid() — Sets the UUID of a clock class.

◆ bt_clock_class_set_user_attributes()

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.

Note
When you create a default clock class with bt_clock_class_create(), the clock class's initial user attributes is an empty map value. Therefore you can borrow it with bt_clock_class_borrow_user_attributes() and fill it directly instead of setting a new one with this function.
Parameters
[in]clock_classClock class of which to set the user attributes to user_attributes.
[in]user_attributesNew user attributes of clock_class.
Precondition
clock_class is not NULL.
clock_class is not frozen.
user_attributes is not NULL.
user_attributes is a map value (bt_value_is_map() returns BT_TRUE).
See also
bt_clock_class_borrow_user_attributes() — Borrows the user attributes of a clock class.

◆ bt_clock_class_borrow_user_attributes()

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.

Note
When you create a default clock class with bt_clock_class_create(), the clock class's initial user attributes is an empty map value.
Parameters
[in]clock_classClock class from which to borrow the user attributes.
Returns
User attributes of clock_class (a map value).
Precondition
clock_class is not NULL.
See also
bt_clock_class_set_user_attributes() — Sets the user attributes of a clock class.
bt_clock_class_borrow_user_attributes_const()const version of this function.

◆ bt_clock_class_borrow_user_attributes_const()

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).

See bt_clock_class_borrow_user_attributes().

◆ 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.

This function:

  1. Converts the "offset in cycles" property of clock_class to seconds using its frequency.
  2. Converts the value value to seconds using the frequency of clock_class.
  3. Adds the values of 1., 2., and the "offset in seconds" property of clock_class.
  4. Converts the value of 3. to nanoseconds and sets *ns_from_origin to this result.

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.

Parameters
[in]clock_classStream clock's class.
[in]valueStream clock's value (cycles) to convert to nanoseconds from the origin of clock_class.
[out]ns_from_originOn success, *ns_from_origin is value converted to nanoseconds from the origin of clock_class.
Return values
BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OKSuccess.
BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERRORInteger overflow while computing the result.
Precondition
clock_class is not NULL.
ns_from_origin is not NULL.
See also
bt_util_clock_cycles_to_ns_from_origin() — Converts a clock value from cycles to nanoseconds from the clock's origin.

◆ bt_clock_class_get_ref()

void bt_clock_class_get_ref ( const bt_clock_class clock_class)

Increments the reference count of the clock class clock_class.

Parameters
[in]clock_class

Clock class of which to increment the reference count.

Can be NULL.

See also
bt_clock_class_put_ref() — Decrements the reference count of a clock class.

◆ bt_clock_class_put_ref()

void bt_clock_class_put_ref ( const bt_clock_class clock_class)

Decrements the reference count of the clock class clock_class.

Parameters
[in]clock_class

Clock class of which to decrement the reference count.

Can be NULL.

See also
bt_clock_class_get_ref() — Increments the reference count of a clock class.