static int append_trace_metadata(struct bt_ctf_trace *trace, struct metadata_context *context) { unsigned char *uuid = trace->uuid; int ret; g_string_append(context->string, "trace {\n"); g_string_append(context->string, "\tmajor = 1;\n"); g_string_append(context->string, "\tminor = 8;\n"); g_string_append_printf(context->string, "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); g_string_append_printf(context->string, "\tbyte_order = %s;\n", get_byte_order_string(trace->byte_order)); g_string_append(context->string, "\tpacket.header := "); context->current_indentation_level++; g_string_assign(context->field_name, ""); ret = bt_ctf_field_type_serialize(trace->packet_header_type, context); if (ret) { goto end; } context->current_indentation_level--; g_string_append(context->string, ";\n};\n\n"); end: return ret; }
int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock) { int ret = 0; struct search_query query = { .value = clock, .found = 0 }; if (!writer || !clock) { ret = -1; goto end; } /* Check for duplicate clocks */ g_ptr_array_foreach(writer->clocks, value_exists, &query); if (query.found) { ret = -1; goto end; } bt_ctf_clock_get(clock); g_ptr_array_add(writer->clocks, clock); end: return ret; } BT_HIDDEN const char *get_byte_order_string(int byte_order) { const char *string; switch (byte_order) { case LITTLE_ENDIAN: string = "le"; break; case BIG_ENDIAN: string = "be"; break; default: string = "unknown"; break; } return string; } static int append_trace_metadata(struct bt_ctf_writer *writer, struct metadata_context *context) { unsigned char *uuid = writer->uuid; int ret; g_string_append(context->string, "trace {\n"); g_string_append(context->string, "\tmajor = 1;\n"); g_string_append(context->string, "\tminor = 8;\n"); g_string_append_printf(context->string, "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); g_string_append_printf(context->string, "\tbyte_order = %s;\n", get_byte_order_string(writer->byte_order)); g_string_append(context->string, "\tpacket.header := "); context->current_indentation_level++; g_string_assign(context->field_name, ""); ret = bt_ctf_field_type_serialize(writer->trace_packet_header_type, context); if (ret) { goto end; } context->current_indentation_level--; g_string_append(context->string, ";\n};\n\n"); end: return ret; }
BT_HIDDEN int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, struct metadata_context *context) { int i; int count; int ret = 0; struct bt_value *attr_value = NULL; assert(event_class); assert(context); context->current_indentation_level = 1; g_string_assign(context->field_name, ""); g_string_append(context->string, "event {\n"); count = bt_ctf_event_class_get_attribute_count(event_class); if (count < 0) { ret = -1; goto end; } for (i = 0; i < count; ++i) { const char *attr_name = NULL; attr_name = bt_ctf_event_class_get_attribute_name( event_class, i); attr_value = bt_ctf_event_class_get_attribute_value( event_class, i); if (!attr_name || !attr_value) { ret = -1; goto end; } switch (bt_value_get_type(attr_value)) { case BT_VALUE_TYPE_INTEGER: { int64_t value; ret = bt_value_integer_get(attr_value, &value); if (ret) { goto end; } g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", attr_name, value); break; } case BT_VALUE_TYPE_STRING: { const char *value; ret = bt_value_string_get(attr_value, &value); if (ret) { goto end; } g_string_append_printf(context->string, "\t%s = \"%s\";\n", attr_name, value); break; } default: /* should never happen */ assert(false); break; } BT_PUT(attr_value); } if (event_class->context) { g_string_append(context->string, "\tcontext := "); ret = bt_ctf_field_type_serialize(event_class->context, context); if (ret) { goto end; } g_string_append(context->string, ";\n"); } if (event_class->fields) { g_string_append(context->string, "\tfields := "); ret = bt_ctf_field_type_serialize(event_class->fields, context); if (ret) { goto end; } g_string_append(context->string, ";\n"); } g_string_append(context->string, "};\n\n"); end: context->current_indentation_level = 0; BT_PUT(attr_value); return ret; }