* SOFTWARE.
*/
+#define BT_LOG_TAG "CLOCK-CLASS"
+#include <babeltrace/lib-logging-internal.h>
+
#include <babeltrace/ctf-ir/clock-class-internal.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ref.h>
-#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/types.h>
#include <inttypes.h>
+#include <babeltrace/object-internal.h>
static
void bt_ctf_clock_class_destroy(struct bt_object *obj);
BT_HIDDEN
-bool bt_ctf_clock_class_is_valid(struct bt_ctf_clock_class *clock_class)
+bt_bool bt_ctf_clock_class_is_valid(struct bt_ctf_clock_class *clock_class)
{
return clock_class && clock_class->name;
}
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
if (bt_ctf_validate_identifier(name)) {
+ BT_LOGE("Clock class's name is not a valid CTF identifier: "
+ "clock-class-addr=%p, name=\"%s\"",
+ clock_class, name);
ret = -1;
goto end;
}
} else {
clock_class->name = g_string_new(name);
if (!clock_class->name) {
+ BT_LOGE_STR("Failed to allocate a GString.");
ret = -1;
goto end;
}
}
+ BT_LOGV("Set clock class's name: clock-class-addr=%p, name=\"%s\"",
+ clock_class, name);
+
end:
return ret;
}
struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name)
{
int ret;
- struct bt_ctf_clock_class *clock_class =
- g_new0(struct bt_ctf_clock_class, 1);
+ struct bt_ctf_clock_class *clock_class;
+ BT_LOGD("Creating default clock class object: name=\"%s\"",
+ name);
+ clock_class = g_new0(struct bt_ctf_clock_class, 1);
if (!clock_class) {
+ BT_LOGE_STR("Failed to allocate one clock class.");
goto error;
}
if (name) {
ret = bt_ctf_clock_class_set_name(clock_class, name);
if (ret) {
+ BT_LOGE("Cannot set clock class's name: "
+ "clock-class-addr=%p, name=\"%s\"",
+ clock_class, name);
goto error;
}
}
ret = bt_uuid_generate(clock_class->uuid);
if (ret) {
+ BT_LOGE_STR("Failed to generate a UUID.");
goto error;
}
clock_class->uuid_set = 1;
+ BT_LOGD("Created clock class object: addr=%p", clock_class);
return clock_class;
error:
BT_PUT(clock_class);
const char *ret = NULL;
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
const char *ret = NULL;
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
{
int ret = 0;
- if (!clock_class || !desc || clock_class->frozen) {
+ if (!clock_class || !desc) {
+ BT_LOGW("Invalid parameter: clock class or description is NULL: "
+ "clock-class-addr=%p, desc-addr=%p",
+ clock_class, desc);
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->description = g_string_new(desc);
ret = clock_class->description ? 0 : -1;
+ BT_LOGV("Set clock class's description: clock-class-addr=%p, desc=\"%s\"",
+ clock_class, desc);
end:
return ret;
}
uint64_t ret = -1ULL;
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class || freq == -1ULL) {
+ BT_LOGW("Invalid parameter: clock class is NULL or frequency is invalid: "
+ "clock-class-addr=%p, freq=%" PRIu64,
+ clock_class, freq);
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->frequency = freq;
+ BT_LOGV("Set clock class's frequency: clock-class-addr=%p, freq=%" PRIu64,
+ clock_class, freq);
end:
return ret;
}
uint64_t ret = -1ULL;
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class || precision == -1ULL) {
+ BT_LOGW("Invalid parameter: clock class is NULL or precision is invalid: "
+ "clock-class-addr=%p, precision=%" PRIu64,
+ clock_class, precision);
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->precision = precision;
+ BT_LOGV("Set clock class's precision: clock-class-addr=%p, precision=%" PRIu64,
+ clock_class, precision);
end:
return ret;
}
int ret = 0;
if (!clock_class || !offset_s) {
+ BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: "
+ "clock-class-addr=%p, offset-addr=%p",
+ clock_class, offset_s);
ret = -1;
goto end;
}
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->offset_s = offset_s;
+ BT_LOGV("Set clock class's offset (seconds): clock-class-addr=%p, offset-s=%" PRId64,
+ clock_class, offset_s);
end:
return ret;
}
int ret = 0;
if (!clock_class || !offset) {
+ BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: "
+ "clock-class-addr=%p, offset-addr=%p",
+ clock_class, offset);
ret = -1;
goto end;
}
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->offset = offset;
+ BT_LOGV("Set clock class's offset (cycles): clock-class-addr=%p, offset-cycles=%" PRId64,
+ clock_class, offset);
end:
return ret;
}
-int bt_ctf_clock_class_is_absolute(struct bt_ctf_clock_class *clock_class)
+bt_bool bt_ctf_clock_class_is_absolute(struct bt_ctf_clock_class *clock_class)
{
int ret = -1;
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
}
int bt_ctf_clock_class_set_is_absolute(struct bt_ctf_clock_class *clock_class,
- int is_absolute)
+ bt_bool is_absolute)
{
int ret = 0;
- if (!clock_class || clock_class->frozen) {
+ if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
clock_class->absolute = !!is_absolute;
+ BT_LOGV("Set clock class's absolute flag: clock-class-addr=%p, is-absolute=%d",
+ clock_class, !!is_absolute);
end:
return ret;
}
{
const unsigned char *ret;
- if (!clock_class || !clock_class->uuid_set) {
+ if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
+ ret = NULL;
+ goto end;
+ }
+
+ if (!clock_class->uuid_set) {
+ BT_LOGV("Clock class's UUID is not set: clock-class-addr=%p",
+ clock_class);
ret = NULL;
goto end;
}
{
int ret = 0;
- if (!clock_class || !uuid || clock_class->frozen) {
+ if (!clock_class || !uuid) {
+ BT_LOGW("Invalid parameter: clock class or UUID is NULL: "
+ "clock-class-addr=%p, uuid-addr=%p",
+ clock_class, uuid);
+ ret = -1;
+ goto end;
+ }
+
+ if (clock_class->frozen) {
+ BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
+ clock_class);
ret = -1;
goto end;
}
memcpy(clock_class->uuid, uuid, sizeof(uuid_t));
clock_class->uuid_set = 1;
+ BT_LOGV("Set clock class's UUID: clock-class-addr=%p, "
+ "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
+ clock_class,
+ (unsigned int) uuid[0],
+ (unsigned int) uuid[1],
+ (unsigned int) uuid[2],
+ (unsigned int) uuid[3],
+ (unsigned int) uuid[4],
+ (unsigned int) uuid[5],
+ (unsigned int) uuid[6],
+ (unsigned int) uuid[7],
+ (unsigned int) uuid[8],
+ (unsigned int) uuid[9],
+ (unsigned int) uuid[10],
+ (unsigned int) uuid[11],
+ (unsigned int) uuid[12],
+ (unsigned int) uuid[13],
+ (unsigned int) uuid[14],
+ (unsigned int) uuid[15]);
end:
return ret;
}
void bt_ctf_clock_class_freeze(struct bt_ctf_clock_class *clock_class)
{
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
return;
}
- clock_class->frozen = 1;
+ if (!clock_class->frozen) {
+ BT_LOGD("Freezing clock class: addr=%p", clock_class);
+ clock_class->frozen = 1;
+ }
}
BT_HIDDEN
{
unsigned char *uuid;
+ BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
+ "metadata-context-addr=%p", clock_class, context);
+
if (!clock_class || !context) {
+ BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
+ "clock-class-addr=%p, metadata-context-addr=%p",
+ clock_class, context);
return;
}
{
struct bt_ctf_clock_class *clock_class;
+ BT_LOGD("Destroying clock class: addr=%p", obj);
clock_class = container_of(obj, struct bt_ctf_clock_class, base);
if (clock_class->name) {
g_string_free(clock_class->name, TRUE);
{
struct bt_ctf_clock_value *value;
+ BT_LOGD("Destroying clock value: addr=%p", obj);
+
if (!obj) {
return;
}
{
struct bt_ctf_clock_value *ret = NULL;
+ BT_LOGD("Creating clock value object: clock-class-addr=%p, "
+ "value=%" PRIu64, clock_class, value);
+
if (!clock_class) {
+ BT_LOGW_STR("Invalid parameter: clock class is NULL.");
goto end;
}
ret = g_new0(struct bt_ctf_clock_value, 1);
if (!ret) {
+ BT_LOGE_STR("Failed to allocate one clock value.");
goto end;
}
bt_object_init(ret, bt_ctf_clock_value_destroy);
ret->clock_class = bt_get(clock_class);
ret->value = value;
+ BT_LOGD("Created clock value object: addr=%p", ret);
end:
return ret;
}
int ret = 0;
if (!clock_value || !raw_value) {
+ BT_LOGW("Invalid parameter: clock value or raw value is NULL: "
+ "clock-value-addr=%p, raw-value-addr=%p",
+ clock_value, raw_value);
ret = -1;
goto end;
}
int64_t ns;
if (!value || !ret_value_ns) {
+ BT_LOGW("Invalid parameter: clock value or return value pointer is NULL: "
+ "clock-value-addr=%p, ret-value-addr=%p",
+ value, ret_value_ns);
ret = -1;
goto end;
}
/* Initialize nanosecond timestamp to clock's offset in seconds. */
- ns = value->clock_class->offset_s * 1000000000;
+ ns = value->clock_class->offset_s * (int64_t) 1000000000;
/* Add offset in cycles, converted to nanoseconds. */
ns += ns_from_value(value->clock_class->frequency,
struct bt_ctf_clock_class *clock_class = NULL;
if (!clock_value) {
+ BT_LOGW_STR("Invalid parameter: clock value is NULL.");
goto end;
}