X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Flibctfcopytrace%2Fclock-fields.c;h=5d312a81125730c800d3d37163933d5f93baaf06;hb=f01de2aee1992a782fe57109c100d4a36b79ebf2;hp=300540216019ccdd7a046d818bfff30f41bc1b6f;hpb=7b4717447467c0767abebe2d8ed359f733c8abbe;p=babeltrace.git diff --git a/plugins/libctfcopytrace/clock-fields.c b/plugins/libctfcopytrace/clock-fields.c index 30054021..5d312a81 100644 --- a/plugins/libctfcopytrace/clock-fields.c +++ b/plugins/libctfcopytrace/clock-fields.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-CTFCOPYTRACE-LIB-CLOCK-FIELDS" +#include "logging.h" + #include #include #include @@ -100,16 +103,14 @@ int update_header_clock_int_field_type(FILE *err, struct bt_ctf_field_type *type ret = bt_ctf_field_type_integer_set_size(type, 64); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to set integer size to 64."); goto end; } ret = bt_ctf_field_type_integer_set_mapped_clock_class(type, writer_clock_class); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to map integer to clock_class."); goto end; } @@ -166,15 +167,14 @@ int find_update_variant_clock_fields(FILE *err, struct bt_ctf_field_type *type, ret = bt_ctf_field_type_variant_get_field(type, &entry_name, &entry_type, i); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to get variant field."); goto error; } + ret = find_update_clock_fields(err, entry_type, writer_clock_class); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields."); goto error; } BT_PUT(entry_type); @@ -204,15 +204,14 @@ int find_update_struct_clock_fields(FILE *err, struct bt_ctf_field_type *type, ret = bt_ctf_field_type_structure_get_field(type, &entry_name, &entry_type, i); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to get struct field."); goto error; } + ret = find_update_clock_fields(err, entry_type, writer_clock_class); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields."); goto error; } BT_PUT(entry_type); @@ -235,16 +234,12 @@ int find_update_sequence_clock_fields(FILE *err, struct bt_ctf_field_type *type, struct bt_ctf_field_type *entry_type = NULL; entry_type = bt_ctf_field_type_sequence_get_element_type(type); - if (!entry_type) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } + assert(entry_type); + ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields."); goto error; } @@ -261,29 +256,20 @@ static int find_update_array_clock_fields(FILE *err, struct bt_ctf_field_type *type, struct bt_ctf_clock_class *writer_clock_class) { - int ret; + int ret = 0; struct bt_ctf_field_type *entry_type = NULL; entry_type = bt_ctf_field_type_array_get_element_type(type); - if (!entry_type) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } + assert(entry_type); + ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields."); ret = -1; goto end; } - ret = 0; - goto end; - -error: - ret = -1; end: return ret; } @@ -296,16 +282,12 @@ int find_update_enum_clock_fields(FILE *err, struct bt_ctf_field_type *type, struct bt_ctf_field_type *entry_type = NULL; entry_type = bt_ctf_field_type_enumeration_get_container_type(type); - if (!entry_type) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } + assert(entry_type); + ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields."); goto error; } @@ -329,28 +311,23 @@ struct bt_ctf_field_type *override_header_type(FILE *err, /* FIXME multi-clock? */ writer_clock_class = bt_ctf_trace_get_clock_class_by_index(writer_trace, 0); - if (!writer_clock_class) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); - goto error; - } + assert(writer_clock_class); new_type = bt_ctf_field_type_copy(type); if (!new_type) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to copy field type."); goto error; } if (bt_ctf_field_type_get_type_id(new_type) != BT_CTF_FIELD_TYPE_ID_STRUCT) { - fprintf(err, "[error] Unexpected header field type\n"); + BT_LOGE("Expected header field type to be struct: type=%d", + bt_ctf_field_type_get_type_id(new_type)); goto error; } ret = find_update_struct_clock_fields(err, new_type, writer_clock_class); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to find clock fields in struct."); goto error; } BT_PUT(writer_clock_class); @@ -374,21 +351,22 @@ int copy_float_field(FILE *err, struct bt_ctf_field *field, ret = bt_ctf_field_floating_point_get_value(field, &value); if (ret) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto end; + BT_LOGE_STR("Failed to get value."); + goto error; } + ret = bt_ctf_field_floating_point_set_value(copy_field, value); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); + BT_LOGE_STR("Failed to set floating point value."); goto end; } ret = 0; + goto end; +error: + ret = -1; end: return ret; } @@ -403,21 +381,22 @@ int copy_string_field(FILE *err, struct bt_ctf_field *field, value = bt_ctf_field_string_get_value(field); if (!value) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto end; + BT_LOGE_STR("Failed to get value."); + goto error; } + ret = bt_ctf_field_string_set_value(copy_field, value); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); + BT_LOGE_STR("Failed to set string value."); goto end; } ret = 0; + goto end; +error: + ret = -1; end: return ret; } @@ -428,15 +407,10 @@ int copy_override_field(FILE *err, struct bt_ctf_event *event, struct bt_ctf_field *copy_field) { struct bt_ctf_field_type *type = NULL; - int ret; + int ret = 0; type = bt_ctf_field_get_type(field); - if (!type) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto end; - } + assert(type); switch (bt_ctf_field_type_get_type_id(type)) { case BT_CTF_FIELD_TYPE_ID_INTEGER: @@ -475,10 +449,8 @@ int copy_override_field(FILE *err, struct bt_ctf_event *event, break; } - ret = 0; BT_PUT(type); -end: return ret; } @@ -491,27 +463,16 @@ int copy_find_clock_enum_field(FILE *err, struct bt_ctf_event *event, struct bt_ctf_field *container = NULL, *copy_container = NULL; container = bt_ctf_field_enumeration_get_container(field); - if (!container) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto end; - } + assert(container); copy_container = bt_ctf_field_enumeration_get_container(copy_field); - if (!copy_container) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(copy_container); ret = copy_override_field(err, event, writer_event, container, copy_container); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to override enum field."); goto error; } @@ -536,31 +497,21 @@ int copy_find_clock_variant_field(FILE *err, struct bt_ctf_event *event, struct bt_ctf_field *variant_field = NULL, *copy_variant_field = NULL; tag = bt_ctf_field_variant_get_tag(field); - if (!tag) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(tag); variant_field = bt_ctf_field_variant_get_field(field, tag); if (!variant_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to get variant field."); goto error; } copy_variant_field = bt_ctf_field_variant_get_field(copy_field, tag); - if (!copy_variant_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(copy_variant_field); ret = copy_override_field(err, event, writer_event, variant_field, copy_variant_field); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to override variant field."); goto error; } @@ -588,23 +539,17 @@ int copy_find_clock_sequence_field(FILE *err, struct bt_ctf_field *entry_field = NULL, *entry_copy = NULL; length_field = bt_ctf_field_sequence_get_length(field); - if (!length_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(length_field); ret = bt_ctf_field_unsigned_integer_get_value(length_field, &count); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE("Failed to get value."); goto error; } ret = bt_ctf_field_sequence_set_length(copy_field, length_field); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to set sequence length."); goto error; } BT_PUT(length_field); @@ -612,23 +557,17 @@ int copy_find_clock_sequence_field(FILE *err, for (i = 0; i < count; i++) { entry_field = bt_ctf_field_sequence_get_field(field, i); if (!entry_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to get sequence field."); goto error; } entry_copy = bt_ctf_field_sequence_get_field(copy_field, i); - if (!entry_copy) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Faield to override field in sequence."); goto error; } BT_PUT(entry_field); @@ -660,24 +599,19 @@ int copy_find_clock_array_field(FILE *err, for (i = 0; i < count; i++) { entry_field = bt_ctf_field_array_get_field(field, i); if (!entry_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + ret = -1; + BT_LOGE_STR("Failed to get array field."); goto error; } entry_copy = bt_ctf_field_array_get_field(copy_field, i); - if (!entry_copy) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to override field in array."); goto error; } BT_PUT(entry_field); @@ -711,31 +645,24 @@ int copy_find_clock_struct_field(FILE *err, entry_field = bt_ctf_field_structure_get_field_by_index(field, i); if (!entry_field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to get struct field."); goto error; } ret = bt_ctf_field_type_structure_get_field(type, &entry_name, &entry_type, i); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", - __func__, __FILE__, __LINE__); + BT_LOGE_STR("Failed to get struct field."); goto error; } entry_copy = bt_ctf_field_structure_get_field_by_index(copy_field, i); - if (!entry_copy) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to override field in struct."); goto error; } BT_PUT(entry_copy); @@ -767,37 +694,36 @@ int set_int_value(FILE *err, struct bt_ctf_field *field, if (bt_ctf_field_type_integer_get_signed(type)) { ret = bt_ctf_field_signed_integer_get_value(field, &value); if (ret) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto end; + BT_LOGE("Failed to get value."); + goto error; } + ret = bt_ctf_field_signed_integer_set_value(copy_field, value); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); + BT_LOGE_STR("Failed to set signed integer value."); goto end; } } else { ret = bt_ctf_field_unsigned_integer_get_value(field, &uvalue); if (ret) { - ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto end; + BT_LOGE("Failed to get value."); + goto error; } + ret = bt_ctf_field_unsigned_integer_set_value(copy_field, uvalue); if (ret) { ret = -1; - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); + BT_LOGE_STR("Failed to set unsigned integer value."); goto end; } } ret = 0; + goto end; +error: + ret = -1; end: return ret; } @@ -809,17 +735,13 @@ struct bt_ctf_clock_class *stream_class_get_clock_class(FILE *err, struct bt_ctf_clock_class *clock_class = NULL; trace = bt_ctf_stream_class_get_trace(stream_class); - if (!trace) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto end; - } + assert(trace); /* FIXME multi-clock? */ clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0); bt_put(trace); -end: + return clock_class; } @@ -830,24 +752,15 @@ struct bt_ctf_clock_class *event_get_clock_class(FILE *err, struct bt_ctf_event struct bt_ctf_clock_class *clock_class = NULL; event_class = bt_ctf_event_get_class(event); - if (!event_class) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto end; - } + assert(event_class); stream_class = bt_ctf_event_class_get_stream_class(event_class); BT_PUT(event_class); - if (!stream_class) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto end; - } + assert(stream_class); clock_class = stream_class_get_clock_class(err, stream_class); bt_put(stream_class); -end: return clock_class; } @@ -869,47 +782,35 @@ int copy_find_clock_int_field(FILE *err, clock_value = bt_ctf_event_get_clock_value(event, clock_class); BT_PUT(clock_class); - if (!clock_value) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(clock_value); ret = bt_ctf_clock_value_get_value(clock_value, &value); BT_PUT(clock_value); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE("Failed to get clock value."); goto error; } ret = bt_ctf_field_unsigned_integer_set_value(copy_field, value); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to set unsigned integer value."); goto error; } writer_clock_class = event_get_clock_class(err, writer_event); - if (!writer_clock_class) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; - } + assert(writer_clock_class); writer_clock_value = bt_ctf_clock_value_create(writer_clock_class, value); BT_PUT(writer_clock_class); if (!writer_clock_value) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to create clock value."); goto error; } ret = bt_ctf_event_set_clock_value(writer_event, writer_clock_value); BT_PUT(writer_clock_value); if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); + BT_LOGE_STR("Failed to set clock value."); goto error; }