summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
199b9d9)
The frequency of a clock class is a mandatory property: CTF 1.8
indicates that it's 1 GHz by default, but it is expected that there's no
default frequency in CTF 2. To allow this immediately, add a mandatory
frequency parameter to bt_ctf_clock_class_create() so that the user's
frequency is set at creation time.
To maintain backward compatibility with pre-2.0.0 CTF writer,
bt_ctf_clock_create() sets its clock class's frequency to 1 GHz, and so
do other parts of the code base.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
struct bt_ctf_clock_class;
struct bt_ctf_clock_value;
struct bt_ctf_clock_class;
struct bt_ctf_clock_value;
-extern struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name);
+extern struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name,
+ uint64_t freq);
extern const char *bt_ctf_clock_class_get_name(
struct bt_ctf_clock_class *clock_class);
extern int bt_ctf_clock_class_set_name(struct bt_ctf_clock_class *clock_class,
extern const char *bt_ctf_clock_class_get_name(
struct bt_ctf_clock_class *clock_class);
extern int bt_ctf_clock_class_set_name(struct bt_ctf_clock_class *clock_class,
-struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name)
+static
+bool validate_freq(struct bt_ctf_clock_class *clock_class,
+ const char *name, uint64_t freq)
+{
+ bool is_valid = true;
+
+ if (freq == -1ULL || freq == 0) {
+ BT_LOGW("Invalid parameter: frequency is invalid: "
+ "addr=%p, name=\"%s\", freq=%" PRIu64,
+ clock_class, name, freq);
+ is_valid = false;
+ goto end;
+ }
+
+end:
+ return is_valid;
+}
+
+struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name,
+ uint64_t freq)
- struct bt_ctf_clock_class *clock_class;
+ struct bt_ctf_clock_class *clock_class = NULL;
BT_LOGD("Creating default clock class object: name=\"%s\"",
name);
BT_LOGD("Creating default clock class object: name=\"%s\"",
name);
+
+ if (!validate_freq(NULL, name, freq)) {
+ /* validate_freq() logs errors */
+ goto error;
+ }
+
clock_class = g_new0(struct bt_ctf_clock_class, 1);
if (!clock_class) {
BT_LOGE_STR("Failed to allocate one clock class.");
clock_class = g_new0(struct bt_ctf_clock_class, 1);
if (!clock_class) {
BT_LOGE_STR("Failed to allocate one clock class.");
}
clock_class->precision = 1;
}
clock_class->precision = 1;
- clock_class->frequency = 1000000000;
+ clock_class->frequency = freq;
bt_object_init(clock_class, bt_ctf_clock_class_destroy);
if (name) {
bt_object_init(clock_class, bt_ctf_clock_class_destroy);
if (name) {
- if (!clock_class || freq == -1ULL) {
BT_LOGW("Invalid parameter: clock class is NULL or frequency is invalid: "
BT_LOGW("Invalid parameter: clock class is NULL or frequency is invalid: "
- "addr=%p, name=\"%s\", freq=%" PRIu64,
- clock_class, bt_ctf_clock_class_get_name(clock_class),
- freq);
+ "addr=%p, name=\"%s\"",
+ clock_class, bt_ctf_clock_class_get_name(clock_class));
+ if (!validate_freq(clock_class, bt_ctf_clock_class_get_name(clock_class),
+ freq)) {
+ /* validate_freq() logs errors */
+ goto end;
+ }
+
if (clock_class->frozen) {
BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"",
clock_class, bt_ctf_clock_class_get_name(clock_class));
if (clock_class->frozen) {
BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"",
clock_class, bt_ctf_clock_class_get_name(clock_class));
bt_object_init(clock, bt_ctf_clock_destroy);
clock->value = 0;
bt_object_init(clock, bt_ctf_clock_destroy);
clock->value = 0;
- clock->clock_class = bt_ctf_clock_class_create(name);
+
+ /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
+ clock->clock_class = bt_ctf_clock_class_create(name, 1000000000);
if (!clock->clock_class) {
goto error;
}
if (!clock->clock_class) {
goto error;
}
* point. Create an implicit one at 1 GHz,
* named `default`, and use this clock class.
*/
* point. Create an implicit one at 1 GHz,
* named `default`, and use this clock class.
*/
- clock_class_to_map_to = bt_ctf_clock_class_create("default");
+ clock_class_to_map_to = bt_ctf_clock_class_create("default",
+ 1000000000);
if (!clock_class_to_map_to) {
BT_LOGE_STR("Cannot create a clock class.");
ret = -1;
goto end;
}
if (!clock_class_to_map_to) {
BT_LOGE_STR("Cannot create a clock class.");
ret = -1;
goto end;
}
- ret = bt_ctf_clock_class_set_frequency(clock_class_to_map_to,
- 1000000000);
- assert(ret == 0);
-
ret = bt_ctf_trace_add_clock_class(ctx->trace,
clock_class_to_map_to);
if (ret) {
ret = bt_ctf_trace_add_clock_class(ctx->trace,
clock_class_to_map_to);
if (ret) {
}
clock_node->visited = TRUE;
}
clock_node->visited = TRUE;
- clock = bt_ctf_clock_class_create(NULL);
+
+ /* CTF 1.8's default frequency for a clock class is 1 GHz */
+ clock = bt_ctf_clock_class_create(NULL, 1000000000);
if (!clock) {
_BT_LOGE_NODE(clock_node,
"Cannot create default clock class.");
if (!clock) {
_BT_LOGE_NODE(clock_node,
"Cannot create default clock class.");
- writer_clock_class = bt_ctf_clock_class_create(name);
+ writer_clock_class = bt_ctf_clock_class_create(name,
+ bt_ctf_clock_class_get_frequency(clock_class));
if (!writer_clock_class) {
fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
__LINE__);
if (!writer_clock_class) {
fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
__LINE__);
- u64_ret = bt_ctf_clock_class_get_frequency(clock_class);
- if (u64_ret == -1ULL) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end_destroy;
- }
- int_ret = bt_ctf_clock_class_set_frequency(writer_clock_class, u64_ret);
- if (int_ret != 0) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end_destroy;
- }
-
u64_ret = bt_ctf_clock_class_get_precision(clock_class);
if (u64_ret == -1ULL) {
fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
u64_ret = bt_ctf_clock_class_get_precision(clock_class);
if (u64_ret == -1ULL) {
fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
cc_prio_map = bt_clock_class_priority_map_create();
ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds");
cc_prio_map = bt_clock_class_priority_map_create();
ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds");
- cc1 = bt_ctf_clock_class_create("cc1");
+ cc1 = bt_ctf_clock_class_create("cc1", 1);
- cc2 = bt_ctf_clock_class_create("cc2");
+ cc2 = bt_ctf_clock_class_create("cc2", 2);
- cc3 = bt_ctf_clock_class_create("cc3");
+ cc3 = bt_ctf_clock_class_create("cc3", 3);
assert(cc3);
ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL),
"bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL");
assert(cc3);
ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL),
"bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL");
non_writer_stream = bt_ctf_stream_create(non_writer_sc, NULL);
assert(non_writer_stream);
non_writer_clock_class =
non_writer_stream = bt_ctf_stream_create(non_writer_sc, NULL);
assert(non_writer_stream);
non_writer_clock_class =
- bt_ctf_clock_class_create("non_writer_clock_class");
+ bt_ctf_clock_class_create("non_writer_clock_class",
+ 1000000000);
assert(non_writer_clock_class);
ret = bt_ctf_trace_add_clock_class(non_writer_trace,
non_writer_clock_class);
assert(non_writer_clock_class);
ret = bt_ctf_trace_add_clock_class(non_writer_trace,
non_writer_clock_class);
"bt_ctf_trace_set_is_static() succeeds");
ok(bt_ctf_trace_is_static(trace),
"bt_ctf_trace_is_static() returns the expected value");
"bt_ctf_trace_set_is_static() succeeds");
ok(bt_ctf_trace_is_static(trace),
"bt_ctf_trace_is_static() returns the expected value");
- clock_class = bt_ctf_clock_class_create("yes");
+ clock_class = bt_ctf_clock_class_create("yes", 1000000000);
assert(clock_class);
stream_class2 = bt_ctf_stream_class_create(NULL);
assert(stream_class2);
assert(clock_class);
stream_class2 = bt_ctf_stream_class_create(NULL);
assert(stream_class2);
assert(ret == 0);
ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft);
assert(ret == 0);
assert(ret == 0);
ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft);
assert(ret == 0);
- src_clock_class = bt_ctf_clock_class_create("my-clock");
+ src_clock_class = bt_ctf_clock_class_create("my-clock", 1000000000);
assert(src_clock_class);
ret = bt_ctf_clock_class_set_is_absolute(src_clock_class, 1);
assert(ret == 0);
assert(src_clock_class);
ret = bt_ctf_clock_class_set_is_absolute(src_clock_class, 1);
assert(ret == 0);