perf tools: Use rb_tree for maps
PATCH 1/1 perf tools: Use rb_tree for maps
Threads can have many and kernel modules will be represented as a tree of maps as well.
Ah, and for a perf.data with 146607 samples:
Before:
[root@doppio ~]# perf stat -r 5 perf report > /dev/null
Performance counter stats for 'perf report' (5 runs):
699.823680 task-clock-msecs # 0.991 CPUs ( +- 0.454% )
74 context-switches # 0.000 M/sec ( +- 1.709% )
2 CPU-migrations # 0.000 M/sec ( +- 17.008% )
23114 page-faults # 0.033 M/sec ( +- 0.000% )
1381257019 cycles # 1973.721 M/sec ( +- 0.290% )
1456894438 instructions # 1.055 IPC ( +- 0.007% )
18779818 cache-references # 26.835 M/sec ( +- 0.380% )
641799 cache-misses # 0.917 M/sec ( +- 1.200% )0.705972729 seconds time elapsed ( +- 0.501% )
[root@doppio ~]#
After
Performance counter stats for 'perf report' (5 runs):
691.261451 task-clock-msecs # 0.993 CPUs ( +- 0.307% )
72 context-switches # 0.000 M/sec ( +- 0.829% )
6 CPU-migrations # 0.000 M/sec ( +- 18.409% )
23127 page-faults # 0.033 M/sec ( +- 0.000% )
1366395876 cycles # 1976.670 M/sec ( +- 0.153% )
1443136016 instructions # 1.056 IPC ( +- 0.012% )
17956402 cache-references # 25.976 M/sec ( +- 0.325% )
661924 cache-misses # 0.958 M/sec ( +- 1.335% )0.696127275 seconds time elapsed ( +- 0.377% )
I.e. we see some speedup too.
Cc Frédéric Weisbecker <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/Makefile | 1 + tools/perf/util/event.h | 4 +- tools/perf/util/thread.c | 129 +++++++++++++++++++++++++++++---------------- tools/perf/util/thread.h | 12 +++- 4 files changed, 95 insertions(+), 51 deletions(-)
tools/perf/Makefile +1 -0
@@ -340,6 +340,7 @@ LIB_H += util/module.h LIB_H += util/color.h LIB_H += util/values.h LIB_H += util/sort.h +LIB_H += util/thread.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
tools/perf/util/event.h +2 -2
@@ -3,7 +3,7 @@#include "../perf.h" #include "util.h" -#include <linux/list.h> +#include <linux/rbtree.h> enum {SHOW_KERNEL =1 ,
@@ -79,7 +79,7 @@ typedef union event_union { } event_t;struct map { -struct list_head node; +struct rb_node rb_node;u64 start;u64 end;u64 pgoff;
tools/perf/util/thread.c +83 -46
170 lines not on this page · raw message
tools/perf/util/thread.h +9 -3
@@ -2,13 +2,12 @@#define __PERF_THREAD_H#include <linux/rbtree.h> -#include <linux/list.h> #include <unistd.h> #include "symbol.h" struct thread {struct rb_node rb_node; -struct list_head maps; +struct rb_root maps;pid_t pid;char shortname[3 ];char *comm;
@@ -21,7 +20,14 @@ struct thread * register_idle_thread(struct rb_root *threads, struct thread **last_match);void thread__insert_map (struct thread *self,struct map *map);int thread__fork (struct thread *self,struct thread *parent); -struct map *thread__find_map (struct thread *self,u64 ip);size_t threads__fprintf (FILE *fp,struct rb_root *threads); +void maps__insert (struct rb_root *maps,struct map *map); +struct map *maps__find (struct rb_root *maps,u64 ip); + +static inline struct map *thread__find_map (struct thread *self,u64 ip) +{ +return self ?maps__find (&self->maps, ip) :NULL ; +} +#endif /* __PERF_THREAD_H */
Signature · 1 line
1.6.2.5