aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-08-12 04:03:49 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2009-08-12 06:02:38 -0400
commitcd84c2ac6d6425dd4d1b80a2231e534b9b03df18 (patch)
tree943332327f02f7a056dc87c64e72e340c484ede6
parent9f8666971185b86615a074bcac67c90fdf8af8bc (diff)
perf tools: Factorize high level dso helpers
Factorize multiple definitions of high level dso helpers into the symbol source file. The side effect is a general export of the verbose and eprintf debugging helpers into a new file dedicated to debugging purposes. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Brice Goglin <Brice.Goglin@inria.fr>
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/builtin-annotate.c96
-rw-r--r--tools/perf/builtin-record.c1
-rw-r--r--tools/perf/builtin-report.c97
-rw-r--r--tools/perf/builtin-stat.c1
-rw-r--r--tools/perf/builtin-top.c4
-rw-r--r--tools/perf/builtin.h1
-rw-r--r--tools/perf/perf.h1
-rw-r--r--tools/perf/util/debug.c22
-rw-r--r--tools/perf/util/debug.h5
-rw-r--r--tools/perf/util/symbol.c97
-rw-r--r--tools/perf/util/symbol.h11
12 files changed, 138 insertions, 199 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index de7beac1095e..2aee21baf785 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -339,6 +339,7 @@ LIB_OBJS += util/pager.o
339LIB_OBJS += util/header.o 339LIB_OBJS += util/header.o
340LIB_OBJS += util/callchain.o 340LIB_OBJS += util/callchain.o
341LIB_OBJS += util/values.o 341LIB_OBJS += util/values.o
342LIB_OBJS += util/debug.o
342 343
343BUILTIN_OBJS += builtin-annotate.o 344BUILTIN_OBJS += builtin-annotate.o
344BUILTIN_OBJS += builtin-help.o 345BUILTIN_OBJS += builtin-help.o
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 1dba568e1941..1a792990031a 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -26,7 +26,6 @@
26#define SHOW_HV 4 26#define SHOW_HV 4
27 27
28static char const *input_name = "perf.data"; 28static char const *input_name = "perf.data";
29static char *vmlinux = "vmlinux";
30 29
31static char default_sort_order[] = "comm,symbol"; 30static char default_sort_order[] = "comm,symbol";
32static char *sort_order = default_sort_order; 31static char *sort_order = default_sort_order;
@@ -37,9 +36,6 @@ static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
37static int dump_trace = 0; 36static int dump_trace = 0;
38#define dprintf(x...) do { if (dump_trace) printf(x); } while (0) 37#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
39 38
40static int verbose;
41
42static int modules;
43 39
44static int full_paths; 40static int full_paths;
45 41
@@ -89,98 +85,6 @@ struct sym_ext {
89 char *path; 85 char *path;
90}; 86};
91 87
92static LIST_HEAD(dsos);
93static struct dso *kernel_dso;
94static struct dso *vdso;
95
96
97static void dsos__add(struct dso *dso)
98{
99 list_add_tail(&dso->node, &dsos);
100}
101
102static struct dso *dsos__find(const char *name)
103{
104 struct dso *pos;
105
106 list_for_each_entry(pos, &dsos, node)
107 if (strcmp(pos->name, name) == 0)
108 return pos;
109 return NULL;
110}
111
112static struct dso *dsos__findnew(const char *name)
113{
114 struct dso *dso = dsos__find(name);
115 int nr;
116
117 if (dso)
118 return dso;
119
120 dso = dso__new(name, 0);
121 if (!dso)
122 goto out_delete_dso;
123
124 nr = dso__load(dso, NULL, verbose);
125 if (nr < 0) {
126 if (verbose)
127 fprintf(stderr, "Failed to open: %s\n", name);
128 goto out_delete_dso;
129 }
130 if (!nr && verbose) {
131 fprintf(stderr,
132 "No symbols found in: %s, maybe install a debug package?\n",
133 name);
134 }
135
136 dsos__add(dso);
137
138 return dso;
139
140out_delete_dso:
141 dso__delete(dso);
142 return NULL;
143}
144
145static void dsos__fprintf(FILE *fp)
146{
147 struct dso *pos;
148
149 list_for_each_entry(pos, &dsos, node)
150 dso__fprintf(pos, fp);
151}
152
153static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
154{
155 return dso__find_symbol(dso, ip);
156}
157
158static int load_kernel(void)
159{
160 int err;
161
162 kernel_dso = dso__new("[kernel]", 0);
163 if (!kernel_dso)
164 return -1;
165
166 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
167 if (err <= 0) {
168 dso__delete(kernel_dso);
169 kernel_dso = NULL;
170 } else
171 dsos__add(kernel_dso);
172
173 vdso = dso__new("[vdso]", 0);
174 if (!vdso)
175 return -1;
176
177 vdso->find_symbol = vdso__find_symbol;
178
179 dsos__add(vdso);
180
181 return err;
182}
183
184struct map { 88struct map {
185 struct list_head node; 89 struct list_head node;
186 u64 start; 90 u64 start;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0345aad8eba5..afae3873b47c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -40,7 +40,6 @@ static int inherit = 1;
40static int force = 0; 40static int force = 0;
41static int append_file = 0; 41static int append_file = 0;
42static int call_graph = 0; 42static int call_graph = 0;
43static int verbose = 0;
44static int inherit_stat = 0; 43static int inherit_stat = 0;
45static int no_samples = 0; 44static int no_samples = 0;
46static int sample_address = 0; 45static int sample_address = 0;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 2357c66fb91d..827eab2edf4b 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -30,7 +30,6 @@
30#define SHOW_HV 4 30#define SHOW_HV 4
31 31
32static char const *input_name = "perf.data"; 32static char const *input_name = "perf.data";
33static char *vmlinux = NULL;
34 33
35static char default_sort_order[] = "comm,dso,symbol"; 34static char default_sort_order[] = "comm,dso,symbol";
36static char *sort_order = default_sort_order; 35static char *sort_order = default_sort_order;
@@ -46,11 +45,6 @@ static int dump_trace = 0;
46#define dprintf(x...) do { if (dump_trace) printf(x); } while (0) 45#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
47#define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0) 46#define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0)
48 47
49static int verbose;
50#define eprintf(x...) do { if (verbose) fprintf(stderr, x); } while (0)
51
52static int modules;
53
54static int full_paths; 48static int full_paths;
55static int show_nr_samples; 49static int show_nr_samples;
56 50
@@ -161,98 +155,7 @@ static int repsep_fprintf(FILE *fp, const char *fmt, ...)
161 return n; 155 return n;
162} 156}
163 157
164static LIST_HEAD(dsos);
165static struct dso *kernel_dso;
166static struct dso *vdso;
167static struct dso *hypervisor_dso;
168
169static void dsos__add(struct dso *dso)
170{
171 list_add_tail(&dso->node, &dsos);
172}
173
174static struct dso *dsos__find(const char *name)
175{
176 struct dso *pos;
177
178 list_for_each_entry(pos, &dsos, node)
179 if (strcmp(pos->name, name) == 0)
180 return pos;
181 return NULL;
182}
183
184static struct dso *dsos__findnew(const char *name)
185{
186 struct dso *dso = dsos__find(name);
187 int nr;
188
189 if (dso)
190 return dso;
191
192 dso = dso__new(name, 0);
193 if (!dso)
194 goto out_delete_dso;
195
196 nr = dso__load(dso, NULL, verbose);
197 if (nr < 0) {
198 eprintf("Failed to open: %s\n", name);
199 goto out_delete_dso;
200 }
201 if (!nr)
202 eprintf("No symbols found in: %s, maybe install a debug package?\n", name);
203
204 dsos__add(dso);
205
206 return dso;
207
208out_delete_dso:
209 dso__delete(dso);
210 return NULL;
211}
212
213static void dsos__fprintf(FILE *fp)
214{
215 struct dso *pos;
216
217 list_for_each_entry(pos, &dsos, node)
218 dso__fprintf(pos, fp);
219}
220
221static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
222{
223 return dso__find_symbol(dso, ip);
224}
225
226static int load_kernel(void)
227{
228 int err;
229
230 kernel_dso = dso__new("[kernel]", 0);
231 if (!kernel_dso)
232 return -1;
233
234 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
235 if (err <= 0) {
236 dso__delete(kernel_dso);
237 kernel_dso = NULL;
238 } else
239 dsos__add(kernel_dso);
240
241 vdso = dso__new("[vdso]", 0);
242 if (!vdso)
243 return -1;
244 158
245 vdso->find_symbol = vdso__find_symbol;
246
247 dsos__add(vdso);
248
249 hypervisor_dso = dso__new("[hypervisor]", 0);
250 if (!hypervisor_dso)
251 return -1;
252 dsos__add(hypervisor_dso);
253
254 return err;
255}
256 159
257static char __cwd[PATH_MAX]; 160static char __cwd[PATH_MAX];
258static char *cwd = __cwd; 161static char *cwd = __cwd;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b4b06c7903e1..4b9dd4af61a6 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -63,7 +63,6 @@ static struct perf_counter_attr default_attrs[] = {
63#define MAX_RUN 100 63#define MAX_RUN 100
64 64
65static int system_wide = 0; 65static int system_wide = 0;
66static int verbose = 0;
67static unsigned int nr_cpus = 0; 66static unsigned int nr_cpus = 0;
68static int run_idx = 0; 67static int run_idx = 0;
69 68
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7de28ce9ca26..0aa567371bd3 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -68,8 +68,6 @@ static int group = 0;
68static unsigned int page_size; 68static unsigned int page_size;
69static unsigned int mmap_pages = 16; 69static unsigned int mmap_pages = 16;
70static int freq = 0; 70static int freq = 0;
71static int verbose = 0;
72static char *vmlinux = NULL;
73 71
74static int delay_secs = 2; 72static int delay_secs = 2;
75static int zero; 73static int zero;
@@ -338,8 +336,6 @@ static void show_details(struct sym_entry *syme)
338 printf("%d lines not displayed, maybe increase display entries [e]\n", more); 336 printf("%d lines not displayed, maybe increase display entries [e]\n", more);
339} 337}
340 338
341struct dso *kernel_dso;
342
343/* 339/*
344 * Symbols will be added here in record_ip and will get out 340 * Symbols will be added here in record_ip and will get out
345 * after decayed. 341 * after decayed.
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 51d168230ee7..3a63e41fb44e 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -22,5 +22,6 @@ extern int cmd_stat(int argc, const char **argv, const char *prefix);
22extern int cmd_top(int argc, const char **argv, const char *prefix); 22extern int cmd_top(int argc, const char **argv, const char *prefix);
23extern int cmd_version(int argc, const char **argv, const char *prefix); 23extern int cmd_version(int argc, const char **argv, const char *prefix);
24extern int cmd_list(int argc, const char **argv, const char *prefix); 24extern int cmd_list(int argc, const char **argv, const char *prefix);
25extern int cmd_trace(int argc, const char **argv, const char *prefix);
25 26
26#endif 27#endif
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index e5148e2b6134..f5509213f030 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -48,6 +48,7 @@
48 48
49#include "../../include/linux/perf_counter.h" 49#include "../../include/linux/perf_counter.h"
50#include "util/types.h" 50#include "util/types.h"
51#include "util/debug.h"
51 52
52/* 53/*
53 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all 54 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
new file mode 100644
index 000000000000..7cb8464abe61
--- /dev/null
+++ b/tools/perf/util/debug.c
@@ -0,0 +1,22 @@
1/* For general debugging purposes */
2
3#include "../perf.h"
4#include <string.h>
5#include <stdarg.h>
6#include <stdio.h>
7
8int verbose = 0;
9
10int eprintf(const char *fmt, ...)
11{
12 va_list args;
13 int ret = 0;
14
15 if (verbose) {
16 va_start(args, fmt);
17 ret = vfprintf(stderr, fmt, args);
18 va_end(args);
19 }
20
21 return ret;
22}
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
new file mode 100644
index 000000000000..2ae9090108d3
--- /dev/null
+++ b/tools/perf/util/debug.h
@@ -0,0 +1,5 @@
1/* For debugging general purposes */
2
3extern int verbose;
4
5int eprintf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index f1dcede14307..e9b13b414955 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -937,6 +937,103 @@ int dso__load_kernel(struct dso *self, const char *vmlinux,
937 return err; 937 return err;
938} 938}
939 939
940LIST_HEAD(dsos);
941struct dso *kernel_dso;
942struct dso *vdso;
943struct dso *hypervisor_dso;
944
945char *vmlinux = "vmlinux";
946int modules;
947
948static void dsos__add(struct dso *dso)
949{
950 list_add_tail(&dso->node, &dsos);
951}
952
953static struct dso *dsos__find(const char *name)
954{
955 struct dso *pos;
956
957 list_for_each_entry(pos, &dsos, node)
958 if (strcmp(pos->name, name) == 0)
959 return pos;
960 return NULL;
961}
962
963struct dso *dsos__findnew(const char *name)
964{
965 struct dso *dso = dsos__find(name);
966 int nr;
967
968 if (dso)
969 return dso;
970
971 dso = dso__new(name, 0);
972 if (!dso)
973 goto out_delete_dso;
974
975 nr = dso__load(dso, NULL, verbose);
976 if (nr < 0) {
977 eprintf("Failed to open: %s\n", name);
978 goto out_delete_dso;
979 }
980 if (!nr)
981 eprintf("No symbols found in: %s, maybe install a debug package?\n", name);
982
983 dsos__add(dso);
984
985 return dso;
986
987out_delete_dso:
988 dso__delete(dso);
989 return NULL;
990}
991
992void dsos__fprintf(FILE *fp)
993{
994 struct dso *pos;
995
996 list_for_each_entry(pos, &dsos, node)
997 dso__fprintf(pos, fp);
998}
999
1000static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
1001{
1002 return dso__find_symbol(dso, ip);
1003}
1004
1005int load_kernel(void)
1006{
1007 int err;
1008
1009 kernel_dso = dso__new("[kernel]", 0);
1010 if (!kernel_dso)
1011 return -1;
1012
1013 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
1014 if (err <= 0) {
1015 dso__delete(kernel_dso);
1016 kernel_dso = NULL;
1017 } else
1018 dsos__add(kernel_dso);
1019
1020 vdso = dso__new("[vdso]", 0);
1021 if (!vdso)
1022 return -1;
1023
1024 vdso->find_symbol = vdso__find_symbol;
1025
1026 dsos__add(vdso);
1027
1028 hypervisor_dso = dso__new("[hypervisor]", 0);
1029 if (!hypervisor_dso)
1030 return -1;
1031 dsos__add(hypervisor_dso);
1032
1033 return err;
1034}
1035
1036
940void symbol__init(void) 1037void symbol__init(void)
941{ 1038{
942 elf_version(EV_CURRENT); 1039 elf_version(EV_CURRENT);
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 1e003ec2f4b1..f3490fcd40ee 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -48,9 +48,20 @@ int dso__load_kernel(struct dso *self, const char *vmlinux,
48 symbol_filter_t filter, int verbose, int modules); 48 symbol_filter_t filter, int verbose, int modules);
49int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose); 49int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose);
50int dso__load(struct dso *self, symbol_filter_t filter, int verbose); 50int dso__load(struct dso *self, symbol_filter_t filter, int verbose);
51struct dso *dsos__findnew(const char *name);
52void dsos__fprintf(FILE *fp);
51 53
52size_t dso__fprintf(struct dso *self, FILE *fp); 54size_t dso__fprintf(struct dso *self, FILE *fp);
53char dso__symtab_origin(const struct dso *self); 55char dso__symtab_origin(const struct dso *self);
54 56
57int load_kernel(void);
58
55void symbol__init(void); 59void symbol__init(void);
60
61extern struct list_head dsos;
62extern struct dso *kernel_dso;
63extern struct dso *vdso;
64extern struct dso *hypervisor_dso;
65extern char *vmlinux;
66extern int modules;
56#endif /* _PERF_SYMBOL_ */ 67#endif /* _PERF_SYMBOL_ */