From: tip-bot for Arnaldo Carvalho de Melo <acme@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, acme@redhat.com, hpa@zytor.com,
mingo@redhat.com, tglx@linutronix.de, mingo@elte.hu
Subject: [tip:perfcounters/core] strlist: Introduce strlist__entry and strlist__nr_entries methods
Date: Sat, 11 Jul 2009 17:25:06 GMT [thread overview]
Message-ID: <tip-27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a@git.kernel.org> (raw)
In-Reply-To: <1247325517-12272-2-git-send-email-acme@redhat.com>
Commit-ID: 27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a
Gitweb: http://git.kernel.org/tip/27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Sat, 11 Jul 2009 12:18:34 -0300
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Sat, 11 Jul 2009 19:20:25 +0200
strlist: Introduce strlist__entry and strlist__nr_entries methods
The strlist__entry method allows accessing strlists like an
array, will be used in the 'perf report' to access the first
entry.
We now keep the nr_entries so that we can check if we have just
one entry, will be used in 'perf report' to improve the output
by showing just at the top when we have just, say, one DSO.
While at it use nr_entries to optimize strlist__is_empty by not
using the far more costly rb_first based implementation.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-2-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/util/strlist.c | 20 ++++++++++++++++++--
tools/perf/util/strlist.h | 11 +++++++++--
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 025a78e..7ad3817 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -64,6 +64,7 @@ int strlist__add(struct strlist *self, const char *new_entry)
rb_link_node(&sn->rb_node, parent, p);
rb_insert_color(&sn->rb_node, &self->entries);
+ ++self->nr_entries;
return 0;
}
@@ -155,8 +156,9 @@ struct strlist *strlist__new(bool dupstr, const char *slist)
struct strlist *self = malloc(sizeof(*self));
if (self != NULL) {
- self->entries = RB_ROOT;
- self->dupstr = dupstr;
+ self->entries = RB_ROOT;
+ self->dupstr = dupstr;
+ self->nr_entries = 0;
if (slist && strlist__parse_list(self, slist) != 0)
goto out_error;
}
@@ -182,3 +184,17 @@ void strlist__delete(struct strlist *self)
free(self);
}
}
+
+struct str_node *strlist__entry(const struct strlist *self, unsigned int idx)
+{
+ struct rb_node *nd;
+
+ for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
+ struct str_node *pos = rb_entry(nd, struct str_node, rb_node);
+
+ if (!idx--)
+ return pos;
+ }
+
+ return NULL;
+}
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index 2fdcfee..921818e 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -11,7 +11,8 @@ struct str_node {
struct strlist {
struct rb_root entries;
- bool dupstr;
+ unsigned int nr_entries;
+ bool dupstr;
};
struct strlist *strlist__new(bool dupstr, const char *slist);
@@ -21,11 +22,17 @@ void strlist__remove(struct strlist *self, struct str_node *sn);
int strlist__load(struct strlist *self, const char *filename);
int strlist__add(struct strlist *self, const char *str);
+struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
bool strlist__has_entry(struct strlist *self, const char *entry);
static inline bool strlist__empty(const struct strlist *self)
{
- return rb_first(&self->entries) == NULL;
+ return self->nr_entries == 0;
+}
+
+static inline unsigned int strlist__nr_entries(const struct strlist *self)
+{
+ return self->nr_entries;
}
int strlist__parse_list(struct strlist *self, const char *s);
next prev parent reply other threads:[~2009-07-11 17:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-11 15:18 [PATCH tip 1/5] perf report: Tidy up reporting of symbols not found Arnaldo Carvalho de Melo
2009-07-11 15:18 ` [PATCH tip 2/5] strlist: Introduce strlist__entry and strlist__nr_entries methods Arnaldo Carvalho de Melo
2009-07-11 15:18 ` [PATCH tip 3/5] perf report: Make the output more compact Arnaldo Carvalho de Melo
2009-07-11 15:18 ` [PATCH tip 4/5] perf_counter tools: PLT info is stripped in -debuginfo packages Arnaldo Carvalho de Melo
2009-07-11 15:18 ` [PATCH tip 5/5] perf report: Introduce -n/--show-nr-samples Arnaldo Carvalho de Melo
2009-07-11 17:25 ` [tip:perfcounters/core] " tip-bot for Arnaldo Carvalho de Melo
2009-07-11 17:25 ` [tip:perfcounters/core] perf_counter tools: PLT info is stripped in -debuginfo packages tip-bot for Arnaldo Carvalho de Melo
2009-07-11 15:31 ` [PATCH tip 3/5] perf report: Make the output more compact Arnaldo Carvalho de Melo
2009-07-11 17:25 ` [tip:perfcounters/core] " tip-bot for Arnaldo Carvalho de Melo
2009-07-11 17:25 ` tip-bot for Arnaldo Carvalho de Melo [this message]
2009-07-11 17:24 ` [tip:perfcounters/core] perf report: Tidy up reporting of symbols not found tip-bot for Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-27d0fd410c3cee00ece2e55f4354a7a9ec1a6a6a@git.kernel.org \
--to=acme@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox