Commit 7137ff50 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Arnaldo Carvalho de Melo
Browse files

perf symbols: Use cached rbtrees



At the cost of an extra pointer, we can avoid the O(logN) cost of
finding the first element in the tree (smallest node).

Signed-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20181206191819.30182-6-dave@stgolabs.net


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ca227029
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
		 * the DSO?
		 */
		if (al->sym != NULL) {
			rb_erase(&al->sym->rb_node,
			rb_erase_cached(&al->sym->rb_node,
				 &al->map->dso->symbols);
			symbol__delete(al->sym);
			dso__reset_find_symbol_cache(al->map->dso);
+2 −2
Original line number Diff line number Diff line
@@ -1197,7 +1197,7 @@ struct dso *dso__new(const char *name)
		strcpy(dso->name, name);
		dso__set_long_name(dso, dso->name, false);
		dso__set_short_name(dso, dso->name, false);
		dso->symbols = dso->symbol_names = RB_ROOT;
		dso->symbols = dso->symbol_names = RB_ROOT_CACHED;
		dso->data.cache = RB_ROOT;
		dso->inlined_nodes = RB_ROOT_CACHED;
		dso->srclines = RB_ROOT_CACHED;
@@ -1469,7 +1469,7 @@ size_t dso__fprintf(struct dso *dso, FILE *fp)
	ret += fprintf(fp, "%sloaded, ", dso__loaded(dso) ? "" : "NOT ");
	ret += dso__fprintf_buildid(dso, fp);
	ret += fprintf(fp, ")\n");
	for (nd = rb_first(&dso->symbols); nd; nd = rb_next(nd)) {
	for (nd = rb_first_cached(&dso->symbols); nd; nd = rb_next(nd)) {
		struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
		ret += symbol__fprintf(pos, fp);
	}
+3 −3
Original line number Diff line number Diff line
@@ -141,8 +141,8 @@ struct dso {
	struct list_head node;
	struct rb_node	 rb_node;	/* rbtree node sorted by long name */
	struct rb_root	 *root;		/* root of rbtree that rb_node is in */
	struct rb_root	 symbols;
	struct rb_root	 symbol_names;
	struct rb_root_cached symbols;
	struct rb_root_cached symbol_names;
	struct rb_root_cached inlined_nodes;
	struct rb_root_cached srclines;
	struct {
@@ -236,7 +236,7 @@ bool dso__loaded(const struct dso *dso);

static inline bool dso__has_symbols(const struct dso *dso)
{
	return !RB_EMPTY_ROOT(&dso->symbols);
	return !RB_EMPTY_ROOT(&dso->symbols.rb_root);
}

bool dso__sorted_by_name(const struct dso *dso);
+4 −4
Original line number Diff line number Diff line
@@ -286,8 +286,8 @@ void map__put(struct map *map)

void map__fixup_start(struct map *map)
{
	struct rb_root *symbols = &map->dso->symbols;
	struct rb_node *nd = rb_first(symbols);
	struct rb_root_cached *symbols = &map->dso->symbols;
	struct rb_node *nd = rb_first_cached(symbols);
	if (nd != NULL) {
		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
		map->start = sym->start;
@@ -296,8 +296,8 @@ void map__fixup_start(struct map *map)

void map__fixup_end(struct map *map)
{
	struct rb_root *symbols = &map->dso->symbols;
	struct rb_node *nd = rb_last(symbols);
	struct rb_root_cached *symbols = &map->dso->symbols;
	struct rb_node *nd = rb_last(&symbols->rb_root);
	if (nd != NULL) {
		struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
		map->end = sym->end;
+2 −1
Original line number Diff line number Diff line
@@ -3529,7 +3529,8 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
	/* Show all (filtered) symbols */
	setup_pager();

	for (nd = rb_first(&map->dso->symbol_names); nd; nd = rb_next(nd)) {
	for (nd = rb_first_cached(&map->dso->symbol_names); nd;
	     nd = rb_next(nd)) {
		struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);

		if (strfilter__compare(_filter, pos->sym.name))
Loading