Commit 279b7bab authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

lib/trace_parser: method for iterating over entries



Added a definition of a parsed trace entry and a function allowing for
iterating over these objects.  The difference between a parsed and a
regular trace entry is that it includes more information gathered while
processing the trace file (e.g. lcore, object statistics) and provides a
contigous buffer for trace arguments.

For now, only lcore and the pointer to the actual trace entry are
filled.  Tracepoint arguments and object statistics will be added in
subsequent patches.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I4d5e30a7abb4860a5ba9db46f64ceae8bd14646f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9433


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 6727cc38
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -102,6 +102,39 @@ const struct spdk_trace_flags *spdk_trace_parser_get_flags(const struct spdk_tra
 */
uint64_t spdk_trace_parser_get_tsc_offset(const struct spdk_trace_parser *parser);

/** Describes a parsed trace entry */
struct spdk_trace_parser_entry {
	/** Pointer to trace entry */
	struct spdk_trace_entry	*entry;
	/**
	 * Index of an object this entry is a part of.  It's only available for tracepoints with
	 * object_type != OBJECT_NONE.  If unavailable, it'll be assigned to UINT64_MAX.
	 */
	uint64_t		object_index;
	/** The tsc of when the object tied to this entry was created */
	uint64_t		object_start;
	/** Logical core number */
	uint16_t		lcore;
	/** Tracepoint arguments */
	union {
		uint64_t	integer;
		void		*pointer;
		char		string[UINT8_MAX + 1];
	} args[SPDK_TRACE_MAX_ARGS_COUNT];
};

/**
 * Return next parsed trace entry.  Once no more traces are available, this will return false and
 * entry won't be touched.
 *
 * \param parser Parser object to be used.
 * \param entry Tracepoint entry.
 *
 * \return True if a trace entry was available, false otherwise.
 */
bool spdk_trace_parser_next_entry(struct spdk_trace_parser *parser,
				  struct spdk_trace_parser_entry *entry);

#ifdef __cplusplus
}
#endif
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
	spdk_trace_parser_cleanup;
	spdk_trace_parser_get_flags;
	spdk_trace_parser_get_tsc_offset;
	spdk_trace_parser_next_entry;

	local: *;
};
+24 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ struct spdk_trace_parser {
	spdk_trace_parser &operator=(const spdk_trace_parser &) = delete;
	const spdk_trace_flags *flags() const { return &_histories->flags; }
	uint64_t tsc_offset() const { return _tsc_offset; }
	bool next_entry(spdk_trace_parser_entry *entry);
private:
	void populate_events(spdk_trace_history *history, int num_entries);
	bool init(const spdk_trace_parser_opts *opts);
@@ -78,8 +79,23 @@ private:
	int			_fd;
	uint64_t		_tsc_offset;
	entry_map		_entries;
	entry_map::iterator	_iter;
};

bool
spdk_trace_parser::next_entry(spdk_trace_parser_entry *entry)
{
	if (_iter == _entries.end()) {
		return false;
	}

	entry->entry = _iter->second;
	entry->lcore = _iter->first.lcore;

	_iter++;
	return true;
}

void
spdk_trace_parser::populate_events(spdk_trace_history *history, int num_entries)
{
@@ -212,6 +228,7 @@ spdk_trace_parser::init(const spdk_trace_parser_opts *opts)
		}
	}

	_iter = _entries.begin();
	return true;
}

@@ -271,3 +288,10 @@ spdk_trace_parser_get_tsc_offset(const struct spdk_trace_parser *parser)
{
	return parser->tsc_offset();
}

bool
spdk_trace_parser_next_entry(struct spdk_trace_parser *parser,
			     struct spdk_trace_parser_entry *entry)
{
	return parser->next_entry(entry);
}