Esempio n. 1
0
struct bt_ctf_trace *bt_ctf_trace_create(void)
{
	struct bt_ctf_trace *trace = NULL;

	trace = g_new0(struct bt_ctf_trace, 1);
	if (!trace) {
		goto error;
	}

	bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE);
	bt_object_init(trace, bt_ctf_trace_destroy);
	trace->clocks = g_ptr_array_new_with_free_func(
		(GDestroyNotify) bt_put);
	trace->streams = g_ptr_array_new_with_free_func(
		(GDestroyNotify) bt_put);
	trace->stream_classes = g_ptr_array_new_with_free_func(
		(GDestroyNotify) put_stream_class);
	if (!trace->clocks || !trace->stream_classes || !trace->streams) {
		goto error;
	}

	/* Generate a trace UUID */
	uuid_generate(trace->uuid);
	if (init_trace_packet_header(trace)) {
		goto error;
	}

	/* Create the environment array object */
	trace->environment = bt_ctf_attributes_create();
	if (!trace->environment) {
		goto error;
	}

	return trace;

error:
	BT_PUT(trace);
	return trace;
}
Esempio n. 2
0
struct bt_ctf_trace *bt_ctf_trace_create(void)
{
	struct bt_ctf_trace *trace = NULL;

	trace = g_new0(struct bt_ctf_trace, 1);
	if (!trace) {
		goto error;
	}

	bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE);
	bt_ctf_ref_init(&trace->ref_count);
	trace->environment = g_ptr_array_new_with_free_func(
		(GDestroyNotify)environment_variable_destroy);
	trace->clocks = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_clock_put);
	trace->streams = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_stream_put);
	trace->stream_classes = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_stream_class_put);
	if (!trace->environment || !trace->clocks ||
		!trace->stream_classes || !trace->streams) {
		goto error_destroy;
	}

	/* Generate a trace UUID */
	uuid_generate(trace->uuid);
	if (init_trace_packet_header(trace)) {
		goto error_destroy;
	}

	return trace;

error_destroy:
	bt_ctf_trace_destroy(&trace->ref_count);
	trace = NULL;
error:
	return trace;
}
Esempio n. 3
0
int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
		enum bt_ctf_byte_order byte_order)
{
	int ret = 0;
	int internal_byte_order;

	if (!writer || writer->frozen) {
		ret = -1;
		goto end;
	}

	switch (byte_order) {
	case BT_CTF_BYTE_ORDER_NATIVE:
		internal_byte_order =  (G_BYTE_ORDER == G_LITTLE_ENDIAN) ?
			LITTLE_ENDIAN : BIG_ENDIAN;
		break;
	case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
		internal_byte_order = LITTLE_ENDIAN;
		break;
	case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
	case BT_CTF_BYTE_ORDER_NETWORK:
		internal_byte_order = BIG_ENDIAN;
		break;
	default:
		ret = -1;
		goto end;
	}

	writer->byte_order = internal_byte_order;
	if (writer->trace_packet_header_type ||
		writer->trace_packet_header) {
		init_trace_packet_header(writer);
	}
end:
	return ret;
}
Esempio n. 4
0
struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
{
	struct bt_ctf_writer *writer = NULL;

	if (!path) {
		goto error;
	}

	writer = g_new0(struct bt_ctf_writer, 1);
	if (!writer) {
		goto error;
	}

	bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE);
	bt_ctf_ref_init(&writer->ref_count);
	writer->path = g_string_new(path);
	if (!writer->path) {
		goto error_destroy;
	}

	/* Create trace directory if necessary and open a metadata file */
	if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) {
		perror("g_mkdir_with_parents");
		goto error_destroy;
	}

	writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG);
	if (writer->trace_dir_fd < 0) {
		perror("open");
		goto error_destroy;
	}

	writer->metadata_fd = openat(writer->trace_dir_fd, "metadata",
		O_WRONLY | O_CREAT | O_TRUNC,
		S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
	writer->environment = g_ptr_array_new_with_free_func(
		(GDestroyNotify)environment_variable_destroy);
	writer->clocks = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_clock_put);
	writer->streams = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_stream_put);
	writer->stream_classes = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_stream_class_put);
	if (!writer->environment || !writer->clocks ||
		!writer->stream_classes || !writer->streams) {
		goto error_destroy;
	}

	/* Generate a trace UUID */
	uuid_generate(writer->uuid);
	if (init_trace_packet_header(writer)) {
		goto error_destroy;
	}

	return writer;
error_destroy:
	unlinkat(writer->trace_dir_fd, "metadata", 0);
	bt_ctf_writer_destroy(&writer->ref_count);
	writer = NULL;
error:
	return writer;
}