Exemplo n.º 1
0
/*
 * seek_ctf_trace_by_timestamp : for each file stream, seek to the event with
 * the corresponding timestamp
 *
 * Return 0 on success.
 * If the timestamp is not part of any file stream, return EOF to inform the
 * user the timestamp is out of the scope.
 * On other errors, return positive value.
 */
static int seek_ctf_trace_by_timestamp(struct ctf_trace *tin,
		uint64_t timestamp, struct ptr_heap *stream_heap)
{
	int i, j, ret;
	int found = 0;
	struct bt_trace_descriptor *td = &tin->parent;

	if (td->interval_set) {
		/*
		 * If this trace has an interval selected, don't allow seeks
		 * before the selected interval. We seek to the start of the
		 * interval, thereby presenting a shorter "virtual" trace.
		 */
		timestamp = max(timestamp, td->interval_real.timestamp_begin);
	}

	/* for each stream_class */
	for (i = 0; i < tin->streams->len; i++) {
		struct ctf_stream_declaration *stream_class;

		stream_class = g_ptr_array_index(tin->streams, i);
		if (!stream_class)
			continue;
		/* for each file_stream */
		for (j = 0; j < stream_class->streams->len; j++) {
			struct ctf_stream_definition *stream;
			struct ctf_file_stream *cfs;

			stream = g_ptr_array_index(stream_class->streams, j);
			if (!stream)
				continue;
			cfs = container_of(stream, struct ctf_file_stream,
					parent);
			ret = seek_file_stream_by_timestamp(cfs, timestamp);
			if (ret == 0) {
				/* Add to heap */
				ret = bt_heap_insert(stream_heap, cfs);
				if (ret) {
					/* Return positive error. */
					return -ret;
				}
				found = 1;
			} else if (ret > 0) {
				/*
				 * Error in seek (not EOF), failure.
				 */
				return ret;
			}
			/* on EOF just do not put stream into heap. */
		}
	}

	return found ? 0 : EOF;
}
Exemplo n.º 2
0
/*
 * seek_last_ctf_trace_collection: seek trace collection to last event.
 *
 * Return 0 if OK, EOF if no events were found, or positive error value
 * on error.
 */
static int seek_last_ctf_trace_collection(struct trace_collection *tc,
		struct ctf_file_stream **cfsp)
{
	int i, j, ret;
	int found = 0;
	uint64_t max_timestamp = 0;

	if (!tc)
		return 1;

	/* For each trace in the trace_collection */
	for (i = 0; i < tc->array->len; i++) {
		struct ctf_trace *tin;
		struct bt_trace_descriptor *td_read;

		td_read = g_ptr_array_index(tc->array, i);
		if (!td_read)
			continue;
		tin = container_of(td_read, struct ctf_trace, parent);
		/* For each stream_class in the trace */
		for (j = 0; j < tin->streams->len; j++) {
			struct ctf_stream_declaration *stream_class;

			stream_class = g_ptr_array_index(tin->streams, j);
			if (!stream_class)
				continue;
			ret = find_max_timestamp_ctf_stream_class(stream_class,
					cfsp, &max_timestamp);
			if (ret > 0)
				goto end;
			if (ret == 0)
				found = 1;
			assert(ret == EOF || ret == 0);
		}
	}
	/*
	 * Now we know in which file stream the last event is located,
	 * and we know its timestamp.
	 */
	if (!found) {
		ret = EOF;
	} else {
		ret = seek_file_stream_by_timestamp(*cfsp, max_timestamp);
		assert(ret == 0);
	}
end:
	return ret;
}
Exemplo n.º 3
0
/*
 * seek_ctf_trace_by_timestamp : for each file stream, seek to the event with
 * the corresponding timestamp
 *
 * Return 0 on success.
 * If the timestamp is not part of any file stream, return EOF to inform the
 * user the timestamp is out of the scope.
 * On other errors, return positive value.
 */
static int seek_ctf_trace_by_timestamp(struct ctf_trace *tin,
		uint64_t timestamp, struct ptr_heap *stream_heap)
{
	int i, j, ret;
	int found = 0;

	/* for each stream_class */
	for (i = 0; i < tin->streams->len; i++) {
		struct ctf_stream_declaration *stream_class;

		stream_class = g_ptr_array_index(tin->streams, i);
		if (!stream_class)
			continue;
		/* for each file_stream */
		for (j = 0; j < stream_class->streams->len; j++) {
			struct ctf_stream_definition *stream;
			struct ctf_file_stream *cfs;

			stream = g_ptr_array_index(stream_class->streams, j);
			if (!stream)
				continue;
			cfs = container_of(stream, struct ctf_file_stream,
					parent);
			ret = seek_file_stream_by_timestamp(cfs, timestamp);
			if (ret == 0) {
				/* Add to heap */
				ret = bt_heap_insert(stream_heap, cfs);
				if (ret) {
					/* Return positive error. */
					return -ret;
				}
				found = 1;
			} else if (ret > 0) {
				/*
				 * Error in seek (not EOF), failure.
				 */
				return ret;
			}
			/* on EOF just do not put stream into heap. */
		}
	}

	return found ? 0 : EOF;
}