Esempio n. 1
0
struct bt_clock_value *bt_event_get_clock_value(
		struct bt_event *event, struct bt_clock_class *clock_class)
{
	struct bt_clock_value *clock_value = NULL;

	if (!event || !clock_class) {
		BT_LOGW("Invalid parameter: event or clock class is NULL: "
			"event-addr=%p, clock-class-addr=%p",
			event, clock_class);
		goto end;
	}

	clock_value = g_hash_table_lookup(event->clock_values, clock_class);
	if (!clock_value) {
		BT_LOGV("No clock value associated to the given clock class: "
			"event-addr=%p, event-class-name=\"%s\", "
			"event-class-id=%" PRId64 ", clock-class-addr=%p, "
			"clock-class-name=\"%s\"", event,
			bt_event_class_get_name(event->event_class),
			bt_event_class_get_id(event->event_class),
			clock_class, bt_clock_class_get_name(clock_class));
		goto end;
	}

	bt_get(clock_value);
end:
	return clock_value;
}
Esempio n. 2
0
void *bt_get(void *ptr)
{
	struct bt_object *obj = ptr;

	if (unlikely(!obj)) {
		goto end;
	}

	if (unlikely(!obj->ref_count.release)) {
		goto end;
	}

	if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) {
		BT_LOGV("Incrementing object's parent's reference count: "
			"addr=%p, parent-addr=%p", ptr, obj->parent);
		bt_get(obj->parent);
	}
	BT_LOGV("Incrementing object's reference count: %lu -> %lu: "
		"addr=%p, cur-count=%lu, new-count=%lu",
		obj->ref_count.count, obj->ref_count.count + 1,
		ptr,
		obj->ref_count.count, obj->ref_count.count + 1);
	bt_ref_get(&obj->ref_count);

end:
	return obj;
}
Esempio n. 3
0
static
int stack_push(struct stack *stack, struct bt_field_type *base_type,
	size_t base_len)
{
	int ret = 0;
	struct stack_entry *entry;

	assert(stack);
	assert(base_type);

	BT_LOGV("Pushing field type on stack: stack-addr=%p, "
		"ft-addr=%p, ft-id=%s, base-length=%zu, "
		"stack-size-before=%u, stack-size-after=%u",
		stack, base_type, bt_field_type_id_string(
			bt_field_type_get_type_id(base_type)),
		base_len, stack->entries->len, stack->entries->len + 1);
	entry = g_new0(struct stack_entry, 1);
	if (!entry) {
		BT_LOGE("Failed to allocate one stack entry: stack-addr=%p",
			stack);
		ret = BT_BTR_STATUS_ERROR;
		goto end;
	}

	entry->base_type = base_type;
	bt_get(entry->base_type);
	entry->base_len = base_len;
	g_ptr_array_add(stack->entries, entry);

end:
	return ret;
}
Esempio n. 4
0
BT_HIDDEN
int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type;

	if (!stream || !field || stream->pos.fd < 0) {
		ret = -1;
		goto end;
	}

	field_type = bt_ctf_field_get_type(field);
	if (bt_ctf_field_type_compare(field_type,
			stream->stream_class->packet_context_type)) {
		ret = -1;
		goto end;
	}

	bt_put(field_type);
	bt_get(field);
	bt_put(stream->packet_context);
	stream->packet_context = field;
end:
	return ret;
}
Esempio n. 5
0
BT_HIDDEN
int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_trace *trace = NULL;
	struct bt_ctf_field_type *field_type = NULL;

	if (!stream || !field || stream->pos.fd < 0) {
		ret = -1;
		goto end;
	}

	trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
	field_type = bt_ctf_field_get_type(field);
	if (bt_ctf_field_type_compare(field_type, trace->packet_header_type)) {
		ret = -1;
		goto end;
	}

	bt_get(field);
	bt_put(stream->packet_header);
	stream->packet_header = field;
end:
	BT_PUT(trace);
	bt_put(field_type);
	return ret;
}
Esempio n. 6
0
struct bt_stream *bt_event_get_stream(struct bt_event *event)
{
	struct bt_stream *stream = NULL;

	if (!event) {
		BT_LOGW_STR("Invalid parameter: event is NULL.");
		goto end;
	}

	/*
	 * If the event has a parent, then this is its (writer) stream.
	 * If the event has no parent, then if it has a packet, this
	 * is its (non-writer) stream.
	 */
	if (event->base.parent) {
		stream = (struct bt_stream *) bt_object_get_parent(event);
	} else {
		if (event->packet) {
			stream = bt_get(event->packet->stream);
		}
	}

end:
	return stream;
}
Esempio n. 7
0
struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name(
		struct bt_ctf_trace *trace, const char *name)
{
	size_t i;
	struct bt_ctf_clock *clock = NULL;

	if (!trace || !name) {
		goto end;
	}

	for (i = 0; i < trace->clocks->len; ++i) {
		struct bt_ctf_clock *cur_clk =
			g_ptr_array_index(trace->clocks, i);
		const char *cur_clk_name = bt_ctf_clock_get_name(cur_clk);

		if (!cur_clk_name) {
			goto end;
		}

		if (!strcmp(cur_clk_name, name)) {
			clock = cur_clk;
			bt_get(clock);
			goto end;
		}
	}

end:
	return clock;
}
Esempio n. 8
0
struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id(
		struct bt_ctf_trace *trace, uint32_t id)
{
	int i;
	struct bt_ctf_stream_class *stream_class = NULL;

	if (!trace) {
		goto end;
	}

	for (i = 0; i < trace->stream_classes->len; ++i) {
		struct bt_ctf_stream_class *stream_class_candidate;

		stream_class_candidate =
			g_ptr_array_index(trace->stream_classes, i);

		if (bt_ctf_stream_class_get_id(stream_class_candidate) ==
				(int64_t) id) {
			stream_class = stream_class_candidate;
			bt_get(stream_class);
			goto end;
		}
	}

end:
	return stream_class;
}
Esempio n. 9
0
BT_HIDDEN
int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
		struct bt_ctf_field *stream_event_context)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_stream_class *stream_class = NULL;

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

	stream_class = bt_ctf_event_class_get_stream_class(event->event_class);
	/*
	 * We should not have been able to create the event without associating
	 * the event class to a stream class.
	 */
	assert(stream_class);

	field_type = bt_ctf_field_get_type(stream_event_context);
	if (bt_ctf_field_type_compare(field_type,
			stream_class->event_context_type)) {
		ret = -1;
		goto end;
	}

	bt_get(stream_event_context);
	BT_MOVE(event->stream_event_context, stream_event_context);
end:
	BT_PUT(stream_class);
	bt_put(field_type);
	return ret;
}
Esempio n. 10
0
BT_HIDDEN
int bt_ctf_event_set_header(struct bt_ctf_event *event,
		struct bt_ctf_field *header)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_stream_class *stream_class = NULL;

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

	stream_class = (struct bt_ctf_stream_class *) bt_object_get_parent(
		event->event_class);
	/*
	 * Ensure the provided header's type matches the one registered to the
	 * stream class.
	 */
	field_type = bt_ctf_field_get_type(header);
	if (bt_ctf_field_type_compare(field_type,
			stream_class->event_header_type)) {
		ret = -1;
		goto end;
	}

	bt_get(header);
	bt_put(event->event_header);
	event->event_header = header;
end:
	bt_put(stream_class);
	bt_put(field_type);
	return ret;
}
Esempio n. 11
0
BT_HIDDEN
int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
		struct bt_ctf_field *context)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;

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

	field_type = bt_ctf_field_get_type(context);
	if (bt_ctf_field_type_compare(field_type,
			event->event_class->context)) {
		ret = -1;
		goto end;
	}

	bt_get(context);
	bt_put(event->context_payload);
	event->context_payload = context;
end:
	bt_put(field_type);
	return ret;
}
Esempio n. 12
0
BT_HIDDEN
int bt_ctf_event_set_payload_field(struct bt_ctf_event *event,
		struct bt_ctf_field *payload)
{
	int ret = 0;
	struct bt_ctf_field_type *payload_type = NULL;

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

	payload_type = bt_ctf_field_get_type(payload);
	if (!payload_type) {
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_get_type_id(payload_type) !=
			CTF_TYPE_STRUCT) {
		ret = -1;
		goto end;
	}

	bt_get(payload);
	bt_put(event->fields_payload);
	event->fields_payload = payload;

end:
	bt_put(payload_type);
	return ret;
}
Esempio n. 13
0
int bt_ctf_event_set_payload(struct bt_ctf_event *event,
		const char *name,
		struct bt_ctf_field *payload)
{
	int ret = 0;

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

	if (name) {
		ret = bt_ctf_field_structure_set_field(event->fields_payload,
			name, payload);
	} else {
		struct bt_ctf_field_type *payload_type;

		payload_type = bt_ctf_field_get_type(payload);

		if (bt_ctf_field_type_compare(payload_type,
				event->event_class->fields) == 0) {
			bt_put(event->fields_payload);
			bt_get(payload);
			event->fields_payload = payload;
		} else {
			ret = -1;
		}

		bt_put(payload_type);
	}
end:
	return ret;
}
Esempio n. 14
0
BT_HIDDEN
struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event)
{
	struct bt_ctf_stream *stream = NULL;

	if (!event) {
		goto end;
	}

	/*
	 * If the event has a parent, then this is its (writer) stream.
	 * If the event has no parent, then if it has a packet, this
	 * is its (non-writer) stream.
	 */
	if (event->base.parent) {
		stream = (struct bt_ctf_stream *) bt_object_get_parent(event);
	} else {
		if (event->packet) {
			stream = bt_get(event->packet->stream);
		}
	}

end:
	return stream;
}
Esempio n. 15
0
BT_HIDDEN
struct bt_ctf_packet *trimmer_new_packet(
		struct trimmer_iterator *trim_it,
		struct bt_ctf_packet *packet)
{
	struct bt_ctf_stream *stream = NULL;
	struct bt_ctf_field *writer_packet_context = NULL;
	struct bt_ctf_packet *writer_packet = NULL;
	int int_ret;

	stream = bt_ctf_packet_get_stream(packet);
	if (!stream) {
		fprintf(trim_it->err, "[error] %s in %s:%d\n",
				__func__, __FILE__, __LINE__);
		goto error;
	}

	/*
	 * If a packet was already opened, close it and remove it from
	 * the HT.
	 */
	writer_packet = lookup_packet(trim_it, packet);
	if (writer_packet) {
		g_hash_table_remove(trim_it->packet_map, packet);
		BT_PUT(writer_packet);
	}

	writer_packet = insert_new_packet(trim_it, packet, stream);
	if (!writer_packet) {
		fprintf(trim_it->err, "[error] %s in %s:%d\n",
				__func__, __FILE__, __LINE__);
		goto error;
	}
	bt_get(writer_packet);

	writer_packet_context = ctf_copy_packet_context(trim_it->err, packet,
			stream);
	if (!writer_packet_context) {
		fprintf(trim_it->err, "[error] %s in %s:%d\n",
				__func__, __FILE__, __LINE__);
		goto error;
	}

	int_ret = bt_ctf_packet_set_context(writer_packet, writer_packet_context);
	if (int_ret) {
		fprintf(trim_it->err, "[error] %s in %s:%d\n",
				__func__, __FILE__, __LINE__);
		goto error;
	}

	goto end;

error:
	BT_PUT(writer_packet);
end:
	bt_put(writer_packet_context);
	bt_put(stream);
	return writer_packet;
}
Esempio n. 16
0
int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
		struct bt_ctf_event *event)
{
	int ret = 0;
	struct bt_ctf_field *event_context_copy = NULL;

	if (!stream || !event) {
		ret = -1;
		goto end;
	}

	ret = bt_ctf_event_set_stream(event, stream);
	if (ret) {
		/* Event was already associated to a stream */
		ret = -1;
		goto end;
	}

	ret = bt_ctf_event_populate_event_header(event);
	if (ret) {
		goto end;
	}

	/* Make sure the event's payload is set */
	ret = bt_ctf_event_validate(event);
	if (ret) {
		goto end;
	}

	/* Sample the current stream event context by copying it */
	if (stream->event_context) {
		/* Make sure the event context's payload is set */
		ret = bt_ctf_field_validate(stream->event_context);
		if (ret) {
			goto end;
		}

		event_context_copy = bt_ctf_field_copy(stream->event_context);
		if (!event_context_copy) {
			ret = -1;
			goto end;
		}
	}

	bt_get(event);
	/* Save the new event along with its associated stream event context */
	g_ptr_array_add(stream->events, event);
	if (event_context_copy) {
		g_ptr_array_add(stream->event_contexts, event_context_copy);
	}
end:
	if (ret) {
		(void) bt_ctf_event_set_stream(event, NULL);
	}
	return ret;
}
Esempio n. 17
0
struct bt_event_class *bt_event_get_class(struct bt_event *event)
{
	struct bt_event_class *event_class = NULL;

	if (!event) {
		BT_LOGW_STR("Invalid parameter: event is NULL.");
		goto end;
	}

	event_class = bt_get(bt_event_borrow_event_class(event));
end:
	return event_class;
}
Esempio n. 18
0
struct bt_ctf_clock *bt_ctf_trace_get_clock(struct bt_ctf_trace *trace,
		int index)
{
	struct bt_ctf_clock *clock = NULL;

	if (!trace || index < 0 || index >= trace->clocks->len) {
		goto end;
	}

	clock = g_ptr_array_index(trace->clocks, index);
	bt_get(clock);
end:
	return clock;
}
Esempio n. 19
0
BT_HIDDEN
struct bt_ctf_field *bt_ctf_event_get_payload_field(struct bt_ctf_event *event)
{
	struct bt_ctf_field *payload = NULL;

	if (!event || !event->fields_payload) {
		goto end;
	}

	payload = event->fields_payload;
	bt_get(payload);
end:
	return payload;
}
Esempio n. 20
0
BT_HIDDEN
struct bt_ctf_field *bt_ctf_event_get_stream_event_context(
		struct bt_ctf_event *event)
{
	struct bt_ctf_field *stream_event_context = NULL;

	if (!event || !event->stream_event_context) {
		goto end;
	}

	stream_event_context = event->stream_event_context;
end:
	return bt_get(stream_event_context);
}
Esempio n. 21
0
struct bt_ctf_stream_class *bt_ctf_stream_get_class(
		struct bt_ctf_stream *stream)
{
	struct bt_ctf_stream_class *stream_class = NULL;

	if (!stream) {
		goto end;
	}

	stream_class = stream->stream_class;
	bt_get(stream_class);
end:
	return stream_class;
}
Esempio n. 22
0
struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class(
		struct bt_ctf_trace *trace, int index)
{
	struct bt_ctf_stream_class *stream_class = NULL;

	if (!trace || index < 0 || index >= trace->stream_classes->len) {
		goto end;
	}

	stream_class = g_ptr_array_index(trace->stream_classes, index);
	bt_get(stream_class);
end:
	return stream_class;
}
Esempio n. 23
0
BT_HIDDEN
struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event)
{
	struct bt_ctf_event_class *event_class = NULL;

	if (!event) {
		goto end;
	}

	event_class = event->event_class;
	bt_get(event_class);
end:
	return event_class;
}
Esempio n. 24
0
struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type(
		struct bt_ctf_trace *trace)
{
	struct bt_ctf_field_type *field_type = NULL;

	if (!trace) {
		goto end;
	}

	bt_get(trace->packet_header_type);
	field_type = trace->packet_header_type;
end:
	return field_type;
}
Esempio n. 25
0
struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event,
		struct bt_clock_class_priority_map *cc_prio_map)
{
	struct bt_notification_event *notification = NULL;

	if (!event || !cc_prio_map) {
		goto error;
	}

	if (!bt_ctf_event_borrow_packet(event)) {
		goto error;
	}

	if (!event_has_trace(event)) {
		goto error;
	}

	notification = g_new0(struct bt_notification_event, 1);
	if (!notification) {
		goto error;
	}
	bt_notification_init(&notification->parent,
			BT_NOTIFICATION_TYPE_EVENT,
			bt_notification_event_destroy);
	notification->event = bt_get(event);
	notification->cc_prio_map = bt_get(cc_prio_map);
	if (!validate_clock_classes(notification)) {
		goto error;
	}

	bt_ctf_event_freeze(notification->event);
	bt_clock_class_priority_map_freeze(notification->cc_prio_map);
	return &notification->parent;
error:
	bt_put(notification);
	return NULL;
}
Esempio n. 26
0
BT_HIDDEN
int bt_ctf_event_set_packet(struct bt_ctf_event *event,
		struct bt_ctf_packet *packet)
{
	struct bt_ctf_stream_class *event_stream_class = NULL;
	struct bt_ctf_stream_class *packet_stream_class = NULL;
	struct bt_ctf_stream *stream = NULL;
	int ret = 0;

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

	/*
	 * Make sure the new packet was created by this event's
	 * stream, if it is set.
	 */
	stream = bt_ctf_event_get_stream(event);
	if (stream) {
		if (packet->stream != stream) {
			ret = -1;
			goto end;
		}
	} else {
		event_stream_class =
			bt_ctf_event_class_get_stream_class(event->event_class);
		packet_stream_class =
			bt_ctf_stream_get_class(packet->stream);

		assert(event_stream_class);
		assert(packet_stream_class);

		if (event_stream_class != packet_stream_class) {
			ret = -1;
			goto end;
		}
	}

	bt_get(packet);
	BT_MOVE(event->packet, packet);

end:
	BT_PUT(stream);
	BT_PUT(event_stream_class);
	BT_PUT(packet_stream_class);

	return ret;
}
Esempio n. 27
0
static
void release_event(struct bt_ctf_event *event)
{
	if (bt_object_get_ref_count(event)) {
		/*
		 * The event is being orphaned, but it must guarantee the
		 * existence of its event class for the duration of its
		 * lifetime.
		 */
		bt_get(event->event_class);
		BT_PUT(event->base.parent);
	} else {
		bt_object_release(event);
	}
}
Esempio n. 28
0
void *bt_get(void *ptr)
{
	struct bt_object *obj = ptr;

	if (!obj) {
		goto end;
	}

	if (obj->parent && bt_object_get_ref_count(obj) == 0) {
		bt_get(obj->parent);
	}
	bt_ref_get(&obj->ref_count);
end:
	return obj;
}
Esempio n. 29
0
BT_HIDDEN
struct bt_ctf_field_type *bt_ctf_event_class_get_payload_type(
		struct bt_ctf_event_class *event_class)
{
	struct bt_ctf_field_type *payload = NULL;

	if (!event_class) {
		goto end;
	}

	bt_get(event_class->fields);
	payload = event_class->fields;
end:
	return payload;
}
Esempio n. 30
0
BT_HIDDEN
struct bt_ctf_field_type *bt_ctf_event_class_get_context_type(
		struct bt_ctf_event_class *event_class)
{
	struct bt_ctf_field_type *context_type = NULL;

	if (!event_class || !event_class->context) {
		goto end;
	}

	bt_get(event_class->context);
	context_type = event_class->context;
end:
	return context_type;
}