Commit 2eb3d689 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Arnaldo Carvalho de Melo
Browse files

perf hist: 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), which is
something heavily required for histograms. Specifically, the following
are converted to rb_root_cached, and users accordingly:

hist::entries_in_array
hist::entries_in
hist::entries
hist::entries_collapsed
hist_entry::hroot_in
hist_entry::hroot_out

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-7-dave@stgolabs.net


[ Added some missing conversions to rb_first_cached() ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7137ff50
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ static void hists__find_annotations(struct hists *hists,
				    struct perf_evsel *evsel,
				    struct perf_annotate *ann)
{
	struct rb_node *nd = rb_first(&hists->entries), *next;
	struct rb_node *nd = rb_first_cached(&hists->entries), *next;
	int key = K_RIGHT;

	while (nd) {
+3 −3
Original line number Diff line number Diff line
@@ -2088,7 +2088,7 @@ static int resort_hitm_cb(struct hist_entry *he)

static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
{
	struct rb_node *next = rb_first(&hists->entries);
	struct rb_node *next = rb_first_cached(&hists->entries);
	int ret = 0;

	while (next) {
@@ -2215,7 +2215,7 @@ static void print_pareto(FILE *out)
	if (WARN_ONCE(ret, "failed to setup sort entries\n"))
		return;

	nd = rb_first(&c2c.hists.hists.entries);
	nd = rb_first_cached(&c2c.hists.hists.entries);

	for (; nd; nd = rb_next(nd)) {
		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
@@ -2283,7 +2283,7 @@ static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)
static void c2c_browser__update_nr_entries(struct hist_browser *hb)
{
	u64 nr_entries = 0;
	struct rb_node *nd = rb_first(&hb->hists->entries);
	struct rb_node *nd = rb_first_cached(&hb->hists->entries);

	while (nd) {
		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
+5 −5
Original line number Diff line number Diff line
@@ -429,7 +429,7 @@ get_pair_fmt(struct hist_entry *he, struct diff_hpp_fmt *dfmt)

static void hists__baseline_only(struct hists *hists)
{
	struct rb_root *root;
	struct rb_root_cached *root;
	struct rb_node *next;

	if (hists__has(hists, need_collapse))
@@ -437,13 +437,13 @@ static void hists__baseline_only(struct hists *hists)
	else
		root = hists->entries_in;

	next = rb_first(root);
	next = rb_first_cached(root);
	while (next != NULL) {
		struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in);

		next = rb_next(&he->rb_node_in);
		if (!hist_entry__next_pair(he)) {
			rb_erase(&he->rb_node_in, root);
			rb_erase_cached(&he->rb_node_in, root);
			hist_entry__delete(he);
		}
	}
@@ -451,7 +451,7 @@ static void hists__baseline_only(struct hists *hists)

static void hists__precompute(struct hists *hists)
{
	struct rb_root *root;
	struct rb_root_cached *root;
	struct rb_node *next;

	if (hists__has(hists, need_collapse))
@@ -459,7 +459,7 @@ static void hists__precompute(struct hists *hists)
	else
		root = hists->entries_in;

	next = rb_first(root);
	next = rb_first_cached(root);
	while (next != NULL) {
		struct hist_entry *he, *pair;
		struct data__file *d;
+1 −1
Original line number Diff line number Diff line
@@ -367,7 +367,7 @@ static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)
	if (p)
		*p = 0;

	next = rb_first(&hists->entries);
	next = rb_first_cached(&hists->entries);
	while (next) {
		n = rb_entry(next, struct hist_entry, rb_node);
		if (n->ms.sym && !strcmp(buf, n->ms.sym->name)) {
+4 −4
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ out:
void print_hists_in(struct hists *hists)
{
	int i = 0;
	struct rb_root *root;
	struct rb_root_cached *root;
	struct rb_node *node;

	if (hists__has(hists, need_collapse))
@@ -170,7 +170,7 @@ void print_hists_in(struct hists *hists)
		root = hists->entries_in;

	pr_info("----- %s --------\n", __func__);
	node = rb_first(root);
	node = rb_first_cached(root);
	while (node) {
		struct hist_entry *he;

@@ -191,13 +191,13 @@ void print_hists_in(struct hists *hists)
void print_hists_out(struct hists *hists)
{
	int i = 0;
	struct rb_root *root;
	struct rb_root_cached *root;
	struct rb_node *node;

	root = &hists->entries;

	pr_info("----- %s --------\n", __func__);
	node = rb_first(root);
	node = rb_first_cached(root);
	while (node) {
		struct hist_entry *he;

Loading