aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/builtin-report.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-06-03 13:59:24 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-03 14:03:32 -0400
commiteed4dcd443da7a46131ef37c7a389b444905960e (patch)
treef9dfab55e3f14c956ec1d4e3f85487d3258962ef /Documentation/perf_counter/builtin-report.c
parent44db76c8553c328f4ae02481d77bb3a88ca17645 (diff)
perf report: Add front-entry cache for lookups
Before: Performance counter stats for './perf report -i perf.data.big': 12453988058 instructions Performance counter stats for './perf report -i perf.data.big': 12379566017 instructions 0.60% reduction. Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-report.c')
-rw-r--r--Documentation/perf_counter/builtin-report.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index e837bb983dca..33b3b15fb014 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -229,6 +229,7 @@ static int thread__set_comm(struct thread *self, const char *comm)
229} 229}
230 230
231static struct rb_root threads; 231static struct rb_root threads;
232static struct thread *last_match;
232 233
233static struct thread *threads__findnew(pid_t pid) 234static struct thread *threads__findnew(pid_t pid)
234{ 235{
@@ -236,12 +237,22 @@ static struct thread *threads__findnew(pid_t pid)
236 struct rb_node *parent = NULL; 237 struct rb_node *parent = NULL;
237 struct thread *th; 238 struct thread *th;
238 239
240 /*
241 * Font-end cache - PID lookups come in blocks,
242 * so most of the time we dont have to look up
243 * the full rbtree:
244 */
245 if (last_match && last_match->pid == pid)
246 return last_match;
247
239 while (*p != NULL) { 248 while (*p != NULL) {
240 parent = *p; 249 parent = *p;
241 th = rb_entry(parent, struct thread, rb_node); 250 th = rb_entry(parent, struct thread, rb_node);
242 251
243 if (th->pid == pid) 252 if (th->pid == pid) {
253 last_match = th;
244 return th; 254 return th;
255 }
245 256
246 if (pid < th->pid) 257 if (pid < th->pid)
247 p = &(*p)->rb_left; 258 p = &(*p)->rb_left;
@@ -253,7 +264,9 @@ static struct thread *threads__findnew(pid_t pid)
253 if (th != NULL) { 264 if (th != NULL) {
254 rb_link_node(&th->rb_node, parent, p); 265 rb_link_node(&th->rb_node, parent, p);
255 rb_insert_color(&th->rb_node, &threads); 266 rb_insert_color(&th->rb_node, &threads);
267 last_match = th;
256 } 268 }
269
257 return th; 270 return th;
258} 271}
259 272