Exemplo n.º 1
0
struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
		struct bt_ctf_field *field, size_t index)
{
	int ret;
	const char *field_name;
	struct bt_ctf_field_structure *structure;
	struct bt_ctf_field_type *structure_type;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_field *ret_field = NULL;

	if (!field ||
		bt_ctf_field_type_get_type_id(field->type) != CTF_TYPE_STRUCT) {
		goto end;
	}

	structure = container_of(field, struct bt_ctf_field_structure, parent);
	if (index >= structure->fields->len) {
		goto error;
	}

	ret_field = structure->fields->pdata[index];
	if (ret_field) {
		goto end;
	}

	/* Field has not been instanciated yet, create it */
	structure_type = bt_ctf_field_get_type(field);
	if (!structure_type) {
		goto error;
	}

	ret = bt_ctf_field_type_structure_get_field(structure_type,
		&field_name, &field_type, index);
	bt_ctf_field_type_put(structure_type);
	if (ret) {
		goto error;
	}

	ret_field = bt_ctf_field_create(field_type);
	if (!ret_field) {
		goto error;
	}

	structure->fields->pdata[index] = ret_field;
end:
	bt_ctf_field_get(ret_field);
error:
	if (field_type) {
		bt_ctf_field_type_put(field_type);
	}
	return ret_field;
}
Exemplo n.º 2
0
struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *field,
		uint64_t index)
{
	struct bt_ctf_field *new_field = NULL;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_field_sequence *sequence;

	if (!field || bt_ctf_field_type_get_type_id(field->type) !=
		CTF_TYPE_SEQUENCE) {
		goto end;
	}

	sequence = container_of(field, struct bt_ctf_field_sequence, parent);
	if (!sequence->elements || sequence->elements->len <= index) {
		goto end;
	}

	field_type = bt_ctf_field_type_sequence_get_element_type(field->type);
	if (sequence->elements->pdata[(size_t)index]) {
		new_field = sequence->elements->pdata[(size_t)index];
		goto end;
	}

	new_field = bt_ctf_field_create(field_type);
	bt_ctf_field_get(new_field);
	sequence->elements->pdata[(size_t)index] = new_field;
end:
	if (field_type) {
		bt_ctf_field_type_put(field_type);
	}
	return new_field;
}
Exemplo n.º 3
0
struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *field,
		uint64_t index)
{
	struct bt_ctf_field *new_field = NULL;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_field_array *array;

	if (!field || bt_ctf_field_type_get_type_id(field->type) !=
		CTF_TYPE_ARRAY) {
		goto end;
	}

	array = container_of(field, struct bt_ctf_field_array, parent);
	if (index >= array->elements->len) {
		goto end;
	}

	field_type = bt_ctf_field_type_array_get_element_type(field->type);
	if (array->elements->pdata[(size_t)index]) {
		new_field = array->elements->pdata[(size_t)index];
		goto end;
	}

	new_field = bt_ctf_field_create(field_type);
	bt_ctf_field_get(new_field);
	array->elements->pdata[(size_t)index] = new_field;
end:
	if (field_type) {
		bt_ctf_field_type_put(field_type);
	}
	return new_field;
}
Exemplo n.º 4
0
static
int bt_ctf_field_string_serialize(struct bt_ctf_field *field,
		struct ctf_stream_pos *pos)
{
	size_t i;
	int ret = 0;
	struct bt_ctf_field_string *string = container_of(field,
		struct bt_ctf_field_string, parent);
	struct bt_ctf_field_type *character_type =
		get_field_type(FIELD_TYPE_ALIAS_UINT8_T);
	struct bt_ctf_field *character = bt_ctf_field_create(character_type);

	for (i = 0; i < string->payload->len + 1; i++) {
		ret = bt_ctf_field_unsigned_integer_set_value(character,
			(uint64_t) string->payload->str[i]);
		if (ret) {
			goto end;
		}

		ret = bt_ctf_field_integer_serialize(character, pos);
		if (ret) {
			goto end;
		}
	}
end:
	bt_ctf_field_put(character);
	bt_ctf_field_type_put(character_type);
	return ret;
}
Exemplo n.º 5
0
void bt_ctf_trace_destroy(struct bt_ctf_ref *ref)
{
	struct bt_ctf_trace *trace;

	if (!ref) {
		return;
	}

	trace = container_of(ref, struct bt_ctf_trace, ref_count);
	if (trace->environment) {
		g_ptr_array_free(trace->environment, TRUE);
	}

	if (trace->clocks) {
		g_ptr_array_free(trace->clocks, TRUE);
	}

	if (trace->streams) {
		g_ptr_array_free(trace->streams, TRUE);
	}

	if (trace->stream_classes) {
		g_ptr_array_free(trace->stream_classes, TRUE);
	}

	bt_ctf_field_type_put(trace->trace_packet_header_type);
	bt_ctf_field_put(trace->trace_packet_header);
	g_free(trace);
}
Exemplo n.º 6
0
const char *bt_ctf_field_enumeration_get_mapping_name(
	struct bt_ctf_field *field)
{
	int ret;
	const char *name = NULL;
	struct bt_ctf_field *container = NULL;
	struct bt_ctf_field_type *container_type = NULL;
	struct bt_ctf_field_type_integer *integer_type = NULL;
	struct bt_ctf_field_type_enumeration *enumeration_type = NULL;

	container = bt_ctf_field_enumeration_get_container(field);
	if (!container) {
		goto end;
	}

	container_type = bt_ctf_field_get_type(container);
	if (!container_type) {
		goto error_put_container;
	}

	integer_type = container_of(container_type,
		struct bt_ctf_field_type_integer, parent);
	enumeration_type = container_of(field->type,
		struct bt_ctf_field_type_enumeration, parent);

	if (!integer_type->declaration.signedness) {
		uint64_t value;
		ret = bt_ctf_field_unsigned_integer_get_value(container,
		      &value);
		if (ret) {
			goto error_put_container_type;
		}

		name = bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
			enumeration_type, value);
	} else {
		int64_t value;
		ret = bt_ctf_field_signed_integer_get_value(container,
		      &value);
		if (ret) {
			goto error_put_container_type;
		}

		name = bt_ctf_field_type_enumeration_get_mapping_name_signed(
			enumeration_type, value);
	}

error_put_container_type:
	bt_ctf_field_type_put(container_type);
error_put_container:
	bt_ctf_field_put(container);
end:
	return name;
}
Exemplo n.º 7
0
void bt_ctf_writer_destroy(struct bt_ctf_ref *ref)
{
	struct bt_ctf_writer *writer;

	if (!ref) {
		return;
	}

	writer = container_of(ref, struct bt_ctf_writer, ref_count);
	bt_ctf_writer_flush_metadata(writer);
	if (writer->path) {
		g_string_free(writer->path, TRUE);
	}

	if (writer->trace_dir_fd > 0) {
		if (close(writer->trace_dir_fd)) {
			perror("close");
			abort();
		}
	}

	if (writer->metadata_fd > 0) {
		if (close(writer->metadata_fd)) {
			perror("close");
			abort();
		}
	}

	if (writer->environment) {
		g_ptr_array_free(writer->environment, TRUE);
	}

	if (writer->clocks) {
		g_ptr_array_free(writer->clocks, TRUE);
	}

	if (writer->streams) {
		g_ptr_array_free(writer->streams, TRUE);
	}

	if (writer->stream_classes) {
		g_ptr_array_free(writer->stream_classes, TRUE);
	}

	bt_ctf_field_type_put(writer->trace_packet_header_type);
	bt_ctf_field_put(writer->trace_packet_header);
	g_free(writer);
}
Exemplo n.º 8
0
const char *_bt_python_ctf_event_class_get_field_name(
		struct bt_ctf_event_class *event_class, size_t index)
{
	int ret;
	const char *name;
	struct bt_ctf_field_type *type;

	ret = bt_ctf_event_class_get_field(event_class, &name, &type,
		index);
	if (ret) {
		name = NULL;
		goto end;
	}

	bt_ctf_field_type_put(type);
end:
	return name;
}
Exemplo n.º 9
0
BT_HIDDEN
int bt_ctf_field_structure_set_field(struct bt_ctf_field *field,
		const char *name, struct bt_ctf_field *value)
{
	int ret = 0;
	GQuark field_quark;
	struct bt_ctf_field_structure *structure;
	struct bt_ctf_field_type *expected_field_type = NULL;
	size_t index;

	if (!field || !name || !value ||
		bt_ctf_field_type_get_type_id(field->type) !=
			CTF_TYPE_STRUCT) {
		ret = -1;
		goto end;
	}

	field_quark = g_quark_from_string(name);
	structure = container_of(field, struct bt_ctf_field_structure, parent);
	expected_field_type =
		bt_ctf_field_type_structure_get_field_type_by_name(field->type,
		name);
	if (expected_field_type != value->type) {
		ret = -1;
		goto end;
	}

	if (!g_hash_table_lookup_extended(structure->field_name_to_index,
		GUINT_TO_POINTER(field_quark), NULL, (gpointer *) &index)) {
		goto end;
	}

	if (structure->fields->pdata[index]) {
		bt_ctf_field_put(structure->fields->pdata[index]);
	}

	structure->fields->pdata[index] = value;
	bt_ctf_field_get(value);
end:
	if (expected_field_type) {
		bt_ctf_field_type_put(expected_field_type);
	}
	return ret;
}
Exemplo n.º 10
0
struct bt_ctf_field *bt_ctf_field_structure_get_field(
		struct bt_ctf_field *field, const char *name)
{
	struct bt_ctf_field *new_field = NULL;
	GQuark field_quark;
	struct bt_ctf_field_structure *structure;
	struct bt_ctf_field_type *field_type = NULL;
	size_t index;

	if (!field || !name ||
		bt_ctf_field_type_get_type_id(field->type) !=
			CTF_TYPE_STRUCT) {
		goto error;
	}

	field_quark = g_quark_from_string(name);
	structure = container_of(field, struct bt_ctf_field_structure, parent);
	field_type =
		bt_ctf_field_type_structure_get_field_type_by_name(field->type,
		name);
	if (!g_hash_table_lookup_extended(structure->field_name_to_index,
		GUINT_TO_POINTER(field_quark), NULL, (gpointer *)&index)) {
		goto error;
	}

	if (structure->fields->pdata[index]) {
		new_field = structure->fields->pdata[index];
		goto end;
	}

	new_field = bt_ctf_field_create(field_type);
	if (!new_field) {
		goto error;
	}

	structure->fields->pdata[index] = new_field;
end:
	bt_ctf_field_get(new_field);
error:
	if (field_type) {
		bt_ctf_field_type_put(field_type);
	}
	return new_field;
}
Exemplo n.º 11
0
static
void bt_ctf_field_destroy(struct bt_ctf_ref *ref)
{
	struct bt_ctf_field *field;
	struct bt_ctf_field_type *type;
	enum ctf_type_id type_id;

	if (!ref) {
		return;
	}

	field = container_of(ref, struct bt_ctf_field, ref_count);
	type = field->type;
	type_id = bt_ctf_field_type_get_type_id(type);
	if (type_id <= CTF_TYPE_UNKNOWN ||
		type_id >= NR_CTF_TYPES) {
		return;
	}

	field_destroy_funcs[type_id](field);
	if (type) {
		bt_ctf_field_type_put(type);
	}
}
Exemplo n.º 12
0
static
int init_trace_packet_header(struct bt_ctf_writer *writer)
{
	size_t i;
	int ret = 0;
	struct bt_ctf_field *trace_packet_header = NULL,
		*magic = NULL, *uuid_array = NULL;
	struct bt_ctf_field_type *_uint32_t =
		get_field_type(FIELD_TYPE_ALIAS_UINT32_T);
	struct bt_ctf_field_type *_uint8_t =
		get_field_type(FIELD_TYPE_ALIAS_UINT8_T);
	struct bt_ctf_field_type *trace_packet_header_type =
		bt_ctf_field_type_structure_create();
	struct bt_ctf_field_type *uuid_array_type =
		bt_ctf_field_type_array_create(_uint8_t, 16);

	if (!trace_packet_header_type || !uuid_array_type) {
		ret = -1;
		goto end;
	}

	ret = bt_ctf_field_type_set_byte_order(_uint32_t,
		(writer->byte_order == LITTLE_ENDIAN ?
		BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
		BT_CTF_BYTE_ORDER_BIG_ENDIAN));
	if (ret) {
		goto end;
	}

	ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
		_uint32_t, "magic");
	if (ret) {
		goto end;
	}

	ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
		uuid_array_type, "uuid");
	if (ret) {
		goto end;
	}

	ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
		_uint32_t, "stream_id");
	if (ret) {
		goto end;
	}

	trace_packet_header = bt_ctf_field_create(trace_packet_header_type);
	if (!trace_packet_header) {
		ret = -1;
		goto end;
	}

	magic = bt_ctf_field_structure_get_field(trace_packet_header, "magic");
	ret = bt_ctf_field_unsigned_integer_set_value(magic, 0xC1FC1FC1);
	if (ret) {
		goto end;
	}

	uuid_array = bt_ctf_field_structure_get_field(trace_packet_header,
		"uuid");
	for (i = 0; i < 16; i++) {
		struct bt_ctf_field *uuid_element =
			bt_ctf_field_array_get_field(uuid_array, i);
		ret = bt_ctf_field_unsigned_integer_set_value(uuid_element,
			writer->uuid[i]);
		bt_ctf_field_put(uuid_element);
		if (ret) {
			goto end;
		}
	}

	bt_ctf_field_type_put(writer->trace_packet_header_type);
	bt_ctf_field_put(writer->trace_packet_header);
	writer->trace_packet_header_type = trace_packet_header_type;
	writer->trace_packet_header = trace_packet_header;
end:
	bt_ctf_field_type_put(uuid_array_type);
	bt_ctf_field_type_put(_uint32_t);
	bt_ctf_field_type_put(_uint8_t);
	bt_ctf_field_put(magic);
	bt_ctf_field_put(uuid_array);
	if (ret) {
		bt_ctf_field_type_put(trace_packet_header_type);
		bt_ctf_field_put(trace_packet_header);
	}

	return ret;
}