aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2013-11-06 00:28:23 -0500
committerIngo Molnar <mingo@kernel.org>2013-11-06 00:28:23 -0500
commit83bf9702c876a54e4e4d1735f9c8680a72421fbe (patch)
treeba664f98d92563544aa63dfb63ae4b49c27929c6 /tools/perf
parent87968f94fbea47df334502a0db645833ce8a848b (diff)
parent316c7136f8bad924609163b9b115f68d59a68c82 (diff)
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: * Check maximum frequency rate for record/top, emitting better error messages, from Jiri Olsa. * Disable live kvm command if timerfd is not supported, from David Ahern. * Add usage to 'perf list', from David Ahern. * Fix detection of non-core features, from David Ahern. * Consolidate __hists__add_*entry(), cleanup from Namhyung Kim. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile.perf4
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-diff.c3
-rw-r--r--tools/perf/builtin-kvm.c12
-rw-r--r--tools/perf/builtin-list.c84
-rw-r--r--tools/perf/builtin-record.c15
-rw-r--r--tools/perf/builtin-report.c16
-rw-r--r--tools/perf/builtin-top.c20
-rw-r--r--tools/perf/config/Makefile17
-rw-r--r--tools/perf/config/feature-checks/Makefile6
-rw-r--r--tools/perf/config/feature-checks/test-all.c5
-rw-r--r--tools/perf/config/feature-checks/test-timerfd.c18
-rw-r--r--tools/perf/scripts/python/Perf-Trace-Util/Context.c6
-rw-r--r--tools/perf/tests/hists_link.c6
-rw-r--r--tools/perf/tests/parse-events.c6
-rw-r--r--tools/perf/ui/browser.h32
-rw-r--r--tools/perf/ui/browsers/hists.c2
-rw-r--r--tools/perf/ui/browsers/map.c40
-rw-r--r--tools/perf/ui/browsers/map.h2
-rw-r--r--tools/perf/ui/browsers/scripts.c8
-rw-r--r--tools/perf/ui/stdio/hist.c14
-rw-r--r--tools/perf/util/build-id.h3
-rw-r--r--tools/perf/util/cpumap.c6
-rw-r--r--tools/perf/util/event.c6
-rw-r--r--tools/perf/util/event.h3
-rw-r--r--tools/perf/util/evlist.h3
-rw-r--r--tools/perf/util/fs.c119
-rw-r--r--tools/perf/util/fs.h7
-rw-r--r--tools/perf/util/hist.c75
-rw-r--r--tools/perf/util/hist.h51
-rw-r--r--tools/perf/util/include/linux/magic.h4
-rw-r--r--tools/perf/util/pmu.c17
-rw-r--r--tools/perf/util/probe-finder.c113
-rw-r--r--tools/perf/util/probe-finder.h10
-rw-r--r--tools/perf/util/pstack.h10
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/perf/util/record.c71
-rw-r--r--tools/perf/util/session.c121
-rw-r--r--tools/perf/util/session.h27
-rw-r--r--tools/perf/util/sort.h2
-rw-r--r--tools/perf/util/strfilter.c32
-rw-r--r--tools/perf/util/strfilter.h12
-rw-r--r--tools/perf/util/sysfs.c60
-rw-r--r--tools/perf/util/sysfs.h6
-rw-r--r--tools/perf/util/thread.h10
45 files changed, 591 insertions, 497 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5b8639025aae..7fc8f179cae7 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -242,7 +242,7 @@ LIB_H += util/cache.h
242LIB_H += util/callchain.h 242LIB_H += util/callchain.h
243LIB_H += util/build-id.h 243LIB_H += util/build-id.h
244LIB_H += util/debug.h 244LIB_H += util/debug.h
245LIB_H += util/sysfs.h 245LIB_H += util/fs.h
246LIB_H += util/pmu.h 246LIB_H += util/pmu.h
247LIB_H += util/event.h 247LIB_H += util/event.h
248LIB_H += util/evsel.h 248LIB_H += util/evsel.h
@@ -304,7 +304,7 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
304LIB_OBJS += $(OUTPUT)util/build-id.o 304LIB_OBJS += $(OUTPUT)util/build-id.o
305LIB_OBJS += $(OUTPUT)util/config.o 305LIB_OBJS += $(OUTPUT)util/config.o
306LIB_OBJS += $(OUTPUT)util/ctype.o 306LIB_OBJS += $(OUTPUT)util/ctype.o
307LIB_OBJS += $(OUTPUT)util/sysfs.o 307LIB_OBJS += $(OUTPUT)util/fs.o
308LIB_OBJS += $(OUTPUT)util/pmu.o 308LIB_OBJS += $(OUTPUT)util/pmu.o
309LIB_OBJS += $(OUTPUT)util/environment.o 309LIB_OBJS += $(OUTPUT)util/environment.o
310LIB_OBJS += $(OUTPUT)util/event.o 310LIB_OBJS += $(OUTPUT)util/event.o
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 6c5ae57831f6..4087ab19823c 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -65,7 +65,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
65 return 0; 65 return 0;
66 } 66 }
67 67
68 he = __hists__add_entry(&evsel->hists, al, NULL, 1, 1, 0); 68 he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, 1, 1, 0);
69 if (he == NULL) 69 if (he == NULL)
70 return -ENOMEM; 70 return -ENOMEM;
71 71
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index b605009e803f..3b67ea2444bd 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -307,7 +307,8 @@ static int hists__add_entry(struct hists *hists,
307 struct addr_location *al, u64 period, 307 struct addr_location *al, u64 period,
308 u64 weight, u64 transaction) 308 u64 weight, u64 transaction)
309{ 309{
310 if (__hists__add_entry(hists, al, NULL, period, weight, transaction) != NULL) 310 if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight,
311 transaction) != NULL)
311 return 0; 312 return 0;
312 return -ENOMEM; 313 return -ENOMEM;
313} 314}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index cb05f39d8a77..cd9f92078aba 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -20,7 +20,9 @@
20#include "util/data.h" 20#include "util/data.h"
21 21
22#include <sys/prctl.h> 22#include <sys/prctl.h>
23#ifdef HAVE_TIMERFD_SUPPORT
23#include <sys/timerfd.h> 24#include <sys/timerfd.h>
25#endif
24 26
25#include <termios.h> 27#include <termios.h>
26#include <semaphore.h> 28#include <semaphore.h>
@@ -337,6 +339,7 @@ static void init_kvm_event_record(struct perf_kvm_stat *kvm)
337 INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); 339 INIT_LIST_HEAD(&kvm->kvm_events_cache[i]);
338} 340}
339 341
342#ifdef HAVE_TIMERFD_SUPPORT
340static void clear_events_cache_stats(struct list_head *kvm_events_cache) 343static void clear_events_cache_stats(struct list_head *kvm_events_cache)
341{ 344{
342 struct list_head *head; 345 struct list_head *head;
@@ -358,6 +361,7 @@ static void clear_events_cache_stats(struct list_head *kvm_events_cache)
358 } 361 }
359 } 362 }
360} 363}
364#endif
361 365
362static int kvm_events_hash_fn(u64 key) 366static int kvm_events_hash_fn(u64 key)
363{ 367{
@@ -783,6 +787,7 @@ static void print_result(struct perf_kvm_stat *kvm)
783 pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events); 787 pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events);
784} 788}
785 789
790#ifdef HAVE_TIMERFD_SUPPORT
786static int process_lost_event(struct perf_tool *tool, 791static int process_lost_event(struct perf_tool *tool,
787 union perf_event *event __maybe_unused, 792 union perf_event *event __maybe_unused,
788 struct perf_sample *sample __maybe_unused, 793 struct perf_sample *sample __maybe_unused,
@@ -793,6 +798,7 @@ static int process_lost_event(struct perf_tool *tool,
793 kvm->lost_events++; 798 kvm->lost_events++;
794 return 0; 799 return 0;
795} 800}
801#endif
796 802
797static bool skip_sample(struct perf_kvm_stat *kvm, 803static bool skip_sample(struct perf_kvm_stat *kvm,
798 struct perf_sample *sample) 804 struct perf_sample *sample)
@@ -872,6 +878,7 @@ static bool verify_vcpu(int vcpu)
872 return true; 878 return true;
873} 879}
874 880
881#ifdef HAVE_TIMERFD_SUPPORT
875/* keeping the max events to a modest level to keep 882/* keeping the max events to a modest level to keep
876 * the processing of samples per mmap smooth. 883 * the processing of samples per mmap smooth.
877 */ 884 */
@@ -1213,6 +1220,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
1213out: 1220out:
1214 return rc; 1221 return rc;
1215} 1222}
1223#endif
1216 1224
1217static int read_events(struct perf_kvm_stat *kvm) 1225static int read_events(struct perf_kvm_stat *kvm)
1218{ 1226{
@@ -1379,6 +1387,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
1379 return kvm_events_report_vcpu(kvm); 1387 return kvm_events_report_vcpu(kvm);
1380} 1388}
1381 1389
1390#ifdef HAVE_TIMERFD_SUPPORT
1382static struct perf_evlist *kvm_live_event_list(void) 1391static struct perf_evlist *kvm_live_event_list(void)
1383{ 1392{
1384 struct perf_evlist *evlist; 1393 struct perf_evlist *evlist;
@@ -1566,6 +1575,7 @@ out:
1566 1575
1567 return err; 1576 return err;
1568} 1577}
1578#endif
1569 1579
1570static void print_kvm_stat_usage(void) 1580static void print_kvm_stat_usage(void)
1571{ 1581{
@@ -1604,8 +1614,10 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
1604 if (!strncmp(argv[1], "rep", 3)) 1614 if (!strncmp(argv[1], "rep", 3))
1605 return kvm_events_report(&kvm, argc - 1 , argv + 1); 1615 return kvm_events_report(&kvm, argc - 1 , argv + 1);
1606 1616
1617#ifdef HAVE_TIMERFD_SUPPORT
1607 if (!strncmp(argv[1], "live", 4)) 1618 if (!strncmp(argv[1], "live", 4))
1608 return kvm_events_live(&kvm, argc - 1 , argv + 1); 1619 return kvm_events_live(&kvm, argc - 1 , argv + 1);
1620#endif
1609 1621
1610perf_stat: 1622perf_stat:
1611 return cmd_stat(argc, argv, NULL); 1623 return cmd_stat(argc, argv, NULL);
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index e79f423cc302..011195e38f21 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -14,51 +14,63 @@
14#include "util/parse-events.h" 14#include "util/parse-events.h"
15#include "util/cache.h" 15#include "util/cache.h"
16#include "util/pmu.h" 16#include "util/pmu.h"
17#include "util/parse-options.h"
17 18
18int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) 19int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
19{ 20{
21 int i;
22 const struct option list_options[] = {
23 OPT_END()
24 };
25 const char * const list_usage[] = {
26 "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
27 NULL
28 };
29
30 argc = parse_options(argc, argv, list_options, list_usage,
31 PARSE_OPT_STOP_AT_NON_OPTION);
32
20 setup_pager(); 33 setup_pager();
21 34
22 if (argc == 1) 35 if (argc == 0) {
23 print_events(NULL, false); 36 print_events(NULL, false);
24 else { 37 return 0;
25 int i; 38 }
26
27 for (i = 1; i < argc; ++i) {
28 if (i > 2)
29 putchar('\n');
30 if (strncmp(argv[i], "tracepoint", 10) == 0)
31 print_tracepoint_events(NULL, NULL, false);
32 else if (strcmp(argv[i], "hw") == 0 ||
33 strcmp(argv[i], "hardware") == 0)
34 print_events_type(PERF_TYPE_HARDWARE);
35 else if (strcmp(argv[i], "sw") == 0 ||
36 strcmp(argv[i], "software") == 0)
37 print_events_type(PERF_TYPE_SOFTWARE);
38 else if (strcmp(argv[i], "cache") == 0 ||
39 strcmp(argv[i], "hwcache") == 0)
40 print_hwcache_events(NULL, false);
41 else if (strcmp(argv[i], "pmu") == 0)
42 print_pmu_events(NULL, false);
43 else if (strcmp(argv[i], "--raw-dump") == 0)
44 print_events(NULL, true);
45 else {
46 char *sep = strchr(argv[i], ':'), *s;
47 int sep_idx;
48 39
49 if (sep == NULL) { 40 for (i = 0; i < argc; ++i) {
50 print_events(argv[i], false); 41 if (i)
51 continue; 42 putchar('\n');
52 } 43 if (strncmp(argv[i], "tracepoint", 10) == 0)
53 sep_idx = sep - argv[i]; 44 print_tracepoint_events(NULL, NULL, false);
54 s = strdup(argv[i]); 45 else if (strcmp(argv[i], "hw") == 0 ||
55 if (s == NULL) 46 strcmp(argv[i], "hardware") == 0)
56 return -1; 47 print_events_type(PERF_TYPE_HARDWARE);
48 else if (strcmp(argv[i], "sw") == 0 ||
49 strcmp(argv[i], "software") == 0)
50 print_events_type(PERF_TYPE_SOFTWARE);
51 else if (strcmp(argv[i], "cache") == 0 ||
52 strcmp(argv[i], "hwcache") == 0)
53 print_hwcache_events(NULL, false);
54 else if (strcmp(argv[i], "pmu") == 0)
55 print_pmu_events(NULL, false);
56 else if (strcmp(argv[i], "--raw-dump") == 0)
57 print_events(NULL, true);
58 else {
59 char *sep = strchr(argv[i], ':'), *s;
60 int sep_idx;
57 61
58 s[sep_idx] = '\0'; 62 if (sep == NULL) {
59 print_tracepoint_events(s, s + sep_idx + 1, false); 63 print_events(argv[i], false);
60 free(s); 64 continue;
61 } 65 }
66 sep_idx = sep - argv[i];
67 s = strdup(argv[i]);
68 if (s == NULL)
69 return -1;
70
71 s[sep_idx] = '\0';
72 print_tracepoint_events(s, s + sep_idx + 1, false);
73 free(s);
62 } 74 }
63 } 75 }
64 return 0; 76 return 0;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8b45fcead5f6..ea4c04f7437e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -958,20 +958,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
958 if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0) 958 if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0)
959 usage_with_options(record_usage, record_options); 959 usage_with_options(record_usage, record_options);
960 960
961 if (rec->opts.user_interval != ULLONG_MAX) 961 if (perf_record_opts__config(&rec->opts)) {
962 rec->opts.default_interval = rec->opts.user_interval;
963 if (rec->opts.user_freq != UINT_MAX)
964 rec->opts.freq = rec->opts.user_freq;
965
966 /*
967 * User specified count overrides default frequency.
968 */
969 if (rec->opts.default_interval)
970 rec->opts.freq = 0;
971 else if (rec->opts.freq) {
972 rec->opts.default_interval = rec->opts.freq;
973 } else {
974 ui__error("frequency and count are zero, aborting\n");
975 err = -EINVAL; 962 err = -EINVAL;
976 goto out_free_fd; 963 goto out_free_fd;
977 } 964 }
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 25f83d5d66fd..8cf8e66ba594 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -115,7 +115,8 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
115 * and this is indirectly achieved by passing period=weight here 115 * and this is indirectly achieved by passing period=weight here
116 * and the he_stat__add_period() function. 116 * and the he_stat__add_period() function.
117 */ 117 */
118 he = __hists__add_mem_entry(&evsel->hists, al, parent, mi, cost, cost); 118 he = __hists__add_entry(&evsel->hists, al, parent, NULL, mi,
119 cost, cost, 0);
119 if (!he) 120 if (!he)
120 return -ENOMEM; 121 return -ENOMEM;
121 122
@@ -200,12 +201,16 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
200 201
201 err = -ENOMEM; 202 err = -ENOMEM;
202 203
204 /* overwrite the 'al' to branch-to info */
205 al->map = bi[i].to.map;
206 al->sym = bi[i].to.sym;
207 al->addr = bi[i].to.addr;
203 /* 208 /*
204 * The report shows the percentage of total branches captured 209 * The report shows the percentage of total branches captured
205 * and not events sampled. Thus we use a pseudo period of 1. 210 * and not events sampled. Thus we use a pseudo period of 1.
206 */ 211 */
207 he = __hists__add_branch_entry(&evsel->hists, al, parent, 212 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
208 &bi[i], 1, 1); 213 1, 1, 0);
209 if (he) { 214 if (he) {
210 struct annotation *notes; 215 struct annotation *notes;
211 bx = he->branch_info; 216 bx = he->branch_info;
@@ -266,8 +271,9 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool,
266 return err; 271 return err;
267 } 272 }
268 273
269 he = __hists__add_entry(&evsel->hists, al, parent, sample->period, 274 he = __hists__add_entry(&evsel->hists, al, parent, NULL, NULL,
270 sample->weight, sample->transaction); 275 sample->period, sample->weight,
276 sample->transaction);
271 if (he == NULL) 277 if (he == NULL)
272 return -ENOMEM; 278 return -ENOMEM;
273 279
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index ca5ca37980fb..9acca8856ccb 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -246,8 +246,9 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,
246 struct hist_entry *he; 246 struct hist_entry *he;
247 247
248 pthread_mutex_lock(&evsel->hists.lock); 248 pthread_mutex_lock(&evsel->hists.lock);
249 he = __hists__add_entry(&evsel->hists, al, NULL, sample->period, 249 he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL,
250 sample->weight, sample->transaction); 250 sample->period, sample->weight,
251 sample->transaction);
251 pthread_mutex_unlock(&evsel->hists.lock); 252 pthread_mutex_unlock(&evsel->hists.lock);
252 if (he == NULL) 253 if (he == NULL)
253 return NULL; 254 return NULL;
@@ -1208,20 +1209,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1208 if (top.delay_secs < 1) 1209 if (top.delay_secs < 1)
1209 top.delay_secs = 1; 1210 top.delay_secs = 1;
1210 1211
1211 if (opts->user_interval != ULLONG_MAX) 1212 if (perf_record_opts__config(opts)) {
1212 opts->default_interval = opts->user_interval;
1213 if (opts->user_freq != UINT_MAX)
1214 opts->freq = opts->user_freq;
1215
1216 /*
1217 * User specified count overrides default frequency.
1218 */
1219 if (opts->default_interval)
1220 opts->freq = 0;
1221 else if (opts->freq) {
1222 opts->default_interval = opts->freq;
1223 } else {
1224 ui__error("frequency and count are zero, aborting\n");
1225 status = -EINVAL; 1213 status = -EINVAL;
1226 goto out_delete_maps; 1214 goto out_delete_maps;
1227 } 1215 }
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index ffb5f55c8fba..58b2d37ae23a 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -98,7 +98,7 @@ endif
98 98
99feature_check = $(eval $(feature_check_code)) 99feature_check = $(eval $(feature_check_code))
100define feature_check_code 100define feature_check_code
101 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0) 101 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
102endef 102endef
103 103
104feature_set = $(eval $(feature_set_code)) 104feature_set = $(eval $(feature_set_code))
@@ -235,7 +235,7 @@ CFLAGS += -I$(LIB_INCLUDE)
235CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE 235CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
236 236
237ifndef NO_BIONIC 237ifndef NO_BIONIC
238 $(feature_check,bionic) 238 $(call feature_check,bionic)
239 ifeq ($(feature-bionic), 1) 239 ifeq ($(feature-bionic), 1)
240 BIONIC := 1 240 BIONIC := 1
241 EXTLIBS := $(filter-out -lrt,$(EXTLIBS)) 241 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
@@ -397,6 +397,13 @@ else
397 endif 397 endif
398endif 398endif
399 399
400$(call feature_check,timerfd)
401ifeq ($(feature-timerfd), 1)
402 CFLAGS += -DHAVE_TIMERFD_SUPPORT
403else
404 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
405endif
406
400disable-python = $(eval $(disable-python_code)) 407disable-python = $(eval $(disable-python_code))
401define disable-python_code 408define disable-python_code
402 CFLAGS += -DNO_LIBPYTHON 409 CFLAGS += -DNO_LIBPYTHON
@@ -472,15 +479,15 @@ else
472 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 479 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
473 else 480 else
474 ifneq ($(feature-libbfd), 1) 481 ifneq ($(feature-libbfd), 1)
475 $(feature_check,liberty) 482 $(call feature_check,liberty)
476 ifeq ($(feature-liberty), 1) 483 ifeq ($(feature-liberty), 1)
477 EXTLIBS += -lbfd -liberty 484 EXTLIBS += -lbfd -liberty
478 else 485 else
479 $(feature_check,liberty-z) 486 $(call feature_check,liberty-z)
480 ifeq ($(feature-liberty-z), 1) 487 ifeq ($(feature-liberty-z), 1)
481 EXTLIBS += -lbfd -liberty -lz 488 EXTLIBS += -lbfd -liberty -lz
482 else 489 else
483 $(feature_check,cplus-demangle) 490 $(call feature_check,cplus-demangle)
484 ifeq ($(feature-cplus-demangle), 1) 491 ifeq ($(feature-cplus-demangle), 1)
485 EXTLIBS += -liberty 492 EXTLIBS += -liberty
486 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 493 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile
index d37d58d273fe..c803f17fb986 100644
--- a/tools/perf/config/feature-checks/Makefile
+++ b/tools/perf/config/feature-checks/Makefile
@@ -25,7 +25,8 @@ FILES= \
25 test-libunwind \ 25 test-libunwind \
26 test-on-exit \ 26 test-on-exit \
27 test-stackprotector-all \ 27 test-stackprotector-all \
28 test-stackprotector 28 test-stackprotector \
29 test-timerfd
29 30
30CC := $(CC) -MD 31CC := $(CC) -MD
31 32
@@ -136,6 +137,9 @@ test-on-exit:
136test-backtrace: 137test-backtrace:
137 $(BUILD) 138 $(BUILD)
138 139
140test-timerfd:
141 $(BUILD)
142
139-include *.d 143-include *.d
140 144
141############################### 145###############################
diff --git a/tools/perf/config/feature-checks/test-all.c b/tools/perf/config/feature-checks/test-all.c
index 50d431892a0c..59e7a705e146 100644
--- a/tools/perf/config/feature-checks/test-all.c
+++ b/tools/perf/config/feature-checks/test-all.c
@@ -81,6 +81,10 @@
81# include "test-libnuma.c" 81# include "test-libnuma.c"
82#undef main 82#undef main
83 83
84#define main main_test_timerfd
85# include "test-timerfd.c"
86#undef main
87
84int main(int argc, char *argv[]) 88int main(int argc, char *argv[])
85{ 89{
86 main_test_libpython(); 90 main_test_libpython();
@@ -101,6 +105,7 @@ int main(int argc, char *argv[])
101 main_test_on_exit(); 105 main_test_on_exit();
102 main_test_backtrace(); 106 main_test_backtrace();
103 main_test_libnuma(); 107 main_test_libnuma();
108 main_test_timerfd();
104 109
105 return 0; 110 return 0;
106} 111}
diff --git a/tools/perf/config/feature-checks/test-timerfd.c b/tools/perf/config/feature-checks/test-timerfd.c
new file mode 100644
index 000000000000..8c5c083b4d3c
--- /dev/null
+++ b/tools/perf/config/feature-checks/test-timerfd.c
@@ -0,0 +1,18 @@
1/*
2 * test for timerfd functions used by perf-kvm-stat-live
3 */
4#include <sys/timerfd.h>
5
6int main(void)
7{
8 struct itimerspec new_value;
9
10 int fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
11 if (fd < 0)
12 return 1;
13
14 if (timerfd_settime(fd, 0, &new_value, NULL) != 0)
15 return 1;
16
17 return 0;
18}
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 315067b8f552..fcd1dd667906 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -25,7 +25,7 @@
25 25
26PyMODINIT_FUNC initperf_trace_context(void); 26PyMODINIT_FUNC initperf_trace_context(void);
27 27
28static PyObject *perf_trace_context_common_pc(PyObject *self, PyObject *args) 28static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
29{ 29{
30 static struct scripting_context *scripting_context; 30 static struct scripting_context *scripting_context;
31 PyObject *context; 31 PyObject *context;
@@ -40,7 +40,7 @@ static PyObject *perf_trace_context_common_pc(PyObject *self, PyObject *args)
40 return Py_BuildValue("i", retval); 40 return Py_BuildValue("i", retval);
41} 41}
42 42
43static PyObject *perf_trace_context_common_flags(PyObject *self, 43static PyObject *perf_trace_context_common_flags(PyObject *obj,
44 PyObject *args) 44 PyObject *args)
45{ 45{
46 static struct scripting_context *scripting_context; 46 static struct scripting_context *scripting_context;
@@ -56,7 +56,7 @@ static PyObject *perf_trace_context_common_flags(PyObject *self,
56 return Py_BuildValue("i", retval); 56 return Py_BuildValue("i", retval);
57} 57}
58 58
59static PyObject *perf_trace_context_common_lock_depth(PyObject *self, 59static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
60 PyObject *args) 60 PyObject *args)
61{ 61{
62 static struct scripting_context *scripting_context; 62 static struct scripting_context *scripting_context;
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 6c337e653540..173bf42cc03e 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -223,7 +223,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
223 goto out; 223 goto out;
224 224
225 he = __hists__add_entry(&evsel->hists, &al, NULL, 225 he = __hists__add_entry(&evsel->hists, &al, NULL,
226 1, 1, 0); 226 NULL, NULL, 1, 1, 0);
227 if (he == NULL) 227 if (he == NULL)
228 goto out; 228 goto out;
229 229
@@ -245,8 +245,8 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
245 &sample) < 0) 245 &sample) < 0)
246 goto out; 246 goto out;
247 247
248 he = __hists__add_entry(&evsel->hists, &al, NULL, 1, 1, 248 he = __hists__add_entry(&evsel->hists, &al, NULL,
249 0); 249 NULL, NULL, 1, 1, 0);
250 if (he == NULL) 250 if (he == NULL)
251 goto out; 251 goto out;
252 252
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 48114d164e9f..ef671cd41bb3 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -2,7 +2,7 @@
2#include "parse-events.h" 2#include "parse-events.h"
3#include "evsel.h" 3#include "evsel.h"
4#include "evlist.h" 4#include "evlist.h"
5#include "sysfs.h" 5#include "fs.h"
6#include <lk/debugfs.h> 6#include <lk/debugfs.h>
7#include "tests.h" 7#include "tests.h"
8#include <linux/hw_breakpoint.h> 8#include <linux/hw_breakpoint.h>
@@ -1456,7 +1456,7 @@ static int test_pmu(void)
1456 int ret; 1456 int ret;
1457 1457
1458 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/", 1458 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1459 sysfs_find_mountpoint()); 1459 sysfs__mountpoint());
1460 1460
1461 ret = stat(path, &st); 1461 ret = stat(path, &st);
1462 if (ret) 1462 if (ret)
@@ -1473,7 +1473,7 @@ static int test_pmu_events(void)
1473 int ret; 1473 int ret;
1474 1474
1475 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/", 1475 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1476 sysfs_find_mountpoint()); 1476 sysfs__mountpoint());
1477 1477
1478 ret = stat(path, &st); 1478 ret = stat(path, &st);
1479 if (ret) { 1479 if (ret) {
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 404ff66a3e36..7d45d2f53601 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -21,32 +21,32 @@ struct ui_browser {
21 void *priv; 21 void *priv;
22 const char *title; 22 const char *title;
23 char *helpline; 23 char *helpline;
24 unsigned int (*refresh)(struct ui_browser *self); 24 unsigned int (*refresh)(struct ui_browser *browser);
25 void (*write)(struct ui_browser *self, void *entry, int row); 25 void (*write)(struct ui_browser *browser, void *entry, int row);
26 void (*seek)(struct ui_browser *self, off_t offset, int whence); 26 void (*seek)(struct ui_browser *browser, off_t offset, int whence);
27 bool (*filter)(struct ui_browser *self, void *entry); 27 bool (*filter)(struct ui_browser *browser, void *entry);
28 u32 nr_entries; 28 u32 nr_entries;
29 bool navkeypressed; 29 bool navkeypressed;
30 bool use_navkeypressed; 30 bool use_navkeypressed;
31}; 31};
32 32
33int ui_browser__set_color(struct ui_browser *browser, int color); 33int ui_browser__set_color(struct ui_browser *browser, int color);
34void ui_browser__set_percent_color(struct ui_browser *self, 34void ui_browser__set_percent_color(struct ui_browser *browser,
35 double percent, bool current); 35 double percent, bool current);
36bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row); 36bool ui_browser__is_current_entry(struct ui_browser *browser, unsigned row);
37void ui_browser__refresh_dimensions(struct ui_browser *self); 37void ui_browser__refresh_dimensions(struct ui_browser *browser);
38void ui_browser__reset_index(struct ui_browser *self); 38void ui_browser__reset_index(struct ui_browser *browser);
39 39
40void ui_browser__gotorc(struct ui_browser *self, int y, int x); 40void ui_browser__gotorc(struct ui_browser *browser, int y, int x);
41void ui_browser__write_graph(struct ui_browser *browser, int graph); 41void ui_browser__write_graph(struct ui_browser *browser, int graph);
42void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column, 42void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
43 u64 start, u64 end); 43 u64 start, u64 end);
44void __ui_browser__show_title(struct ui_browser *browser, const char *title); 44void __ui_browser__show_title(struct ui_browser *browser, const char *title);
45void ui_browser__show_title(struct ui_browser *browser, const char *title); 45void ui_browser__show_title(struct ui_browser *browser, const char *title);
46int ui_browser__show(struct ui_browser *self, const char *title, 46int ui_browser__show(struct ui_browser *browser, const char *title,
47 const char *helpline, ...); 47 const char *helpline, ...);
48void ui_browser__hide(struct ui_browser *self); 48void ui_browser__hide(struct ui_browser *browser);
49int ui_browser__refresh(struct ui_browser *self); 49int ui_browser__refresh(struct ui_browser *browser);
50int ui_browser__run(struct ui_browser *browser, int delay_secs); 50int ui_browser__run(struct ui_browser *browser, int delay_secs);
51void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries); 51void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries);
52void ui_browser__handle_resize(struct ui_browser *browser); 52void ui_browser__handle_resize(struct ui_browser *browser);
@@ -63,11 +63,11 @@ int ui_browser__input_window(const char *title, const char *text, char *input,
63void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); 63void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
64unsigned int ui_browser__argv_refresh(struct ui_browser *browser); 64unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
65 65
66void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence); 66void ui_browser__rb_tree_seek(struct ui_browser *browser, off_t offset, int whence);
67unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self); 67unsigned int ui_browser__rb_tree_refresh(struct ui_browser *browser);
68 68
69void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence); 69void ui_browser__list_head_seek(struct ui_browser *browser, off_t offset, int whence);
70unsigned int ui_browser__list_head_refresh(struct ui_browser *self); 70unsigned int ui_browser__list_head_refresh(struct ui_browser *browser);
71 71
72void ui_browser__init(void); 72void ui_browser__init(void);
73void annotate_browser__init(void); 73void annotate_browser__init(void);
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a91b6b219412..16848bb4c418 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1889,7 +1889,7 @@ out:
1889 return key; 1889 return key;
1890} 1890}
1891 1891
1892static bool filter_group_entries(struct ui_browser *self __maybe_unused, 1892static bool filter_group_entries(struct ui_browser *browser __maybe_unused,
1893 void *entry) 1893 void *entry)
1894{ 1894{
1895 struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); 1895 struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node);
diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c
index 95c7cfb8f2c6..b11639f33682 100644
--- a/tools/perf/ui/browsers/map.c
+++ b/tools/perf/ui/browsers/map.c
@@ -18,30 +18,30 @@ struct map_browser {
18 u8 addrlen; 18 u8 addrlen;
19}; 19};
20 20
21static void map_browser__write(struct ui_browser *self, void *nd, int row) 21static void map_browser__write(struct ui_browser *browser, void *nd, int row)
22{ 22{
23 struct symbol *sym = rb_entry(nd, struct symbol, rb_node); 23 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
24 struct map_browser *mb = container_of(self, struct map_browser, b); 24 struct map_browser *mb = container_of(browser, struct map_browser, b);
25 bool current_entry = ui_browser__is_current_entry(self, row); 25 bool current_entry = ui_browser__is_current_entry(browser, row);
26 int width; 26 int width;
27 27
28 ui_browser__set_percent_color(self, 0, current_entry); 28 ui_browser__set_percent_color(browser, 0, current_entry);
29 slsmg_printf("%*" PRIx64 " %*" PRIx64 " %c ", 29 slsmg_printf("%*" PRIx64 " %*" PRIx64 " %c ",
30 mb->addrlen, sym->start, mb->addrlen, sym->end, 30 mb->addrlen, sym->start, mb->addrlen, sym->end,
31 sym->binding == STB_GLOBAL ? 'g' : 31 sym->binding == STB_GLOBAL ? 'g' :
32 sym->binding == STB_LOCAL ? 'l' : 'w'); 32 sym->binding == STB_LOCAL ? 'l' : 'w');
33 width = self->width - ((mb->addrlen * 2) + 4); 33 width = browser->width - ((mb->addrlen * 2) + 4);
34 if (width > 0) 34 if (width > 0)
35 slsmg_write_nstring(sym->name, width); 35 slsmg_write_nstring(sym->name, width);
36} 36}
37 37
38/* FIXME uber-kludgy, see comment on cmd_report... */ 38/* FIXME uber-kludgy, see comment on cmd_report... */
39static u32 *symbol__browser_index(struct symbol *self) 39static u32 *symbol__browser_index(struct symbol *browser)
40{ 40{
41 return ((void *)self) - sizeof(struct rb_node) - sizeof(u32); 41 return ((void *)browser) - sizeof(struct rb_node) - sizeof(u32);
42} 42}
43 43
44static int map_browser__search(struct map_browser *self) 44static int map_browser__search(struct map_browser *browser)
45{ 45{
46 char target[512]; 46 char target[512];
47 struct symbol *sym; 47 struct symbol *sym;
@@ -53,37 +53,37 @@ static int map_browser__search(struct map_browser *self)
53 53
54 if (target[0] == '0' && tolower(target[1]) == 'x') { 54 if (target[0] == '0' && tolower(target[1]) == 'x') {
55 u64 addr = strtoull(target, NULL, 16); 55 u64 addr = strtoull(target, NULL, 16);
56 sym = map__find_symbol(self->map, addr, NULL); 56 sym = map__find_symbol(browser->map, addr, NULL);
57 } else 57 } else
58 sym = map__find_symbol_by_name(self->map, target, NULL); 58 sym = map__find_symbol_by_name(browser->map, target, NULL);
59 59
60 if (sym != NULL) { 60 if (sym != NULL) {
61 u32 *idx = symbol__browser_index(sym); 61 u32 *idx = symbol__browser_index(sym);
62 62
63 self->b.top = &sym->rb_node; 63 browser->b.top = &sym->rb_node;
64 self->b.index = self->b.top_idx = *idx; 64 browser->b.index = browser->b.top_idx = *idx;
65 } else 65 } else
66 ui_helpline__fpush("%s not found!", target); 66 ui_helpline__fpush("%s not found!", target);
67 67
68 return 0; 68 return 0;
69} 69}
70 70
71static int map_browser__run(struct map_browser *self) 71static int map_browser__run(struct map_browser *browser)
72{ 72{
73 int key; 73 int key;
74 74
75 if (ui_browser__show(&self->b, self->map->dso->long_name, 75 if (ui_browser__show(&browser->b, browser->map->dso->long_name,
76 "Press <- or ESC to exit, %s / to search", 76 "Press <- or ESC to exit, %s / to search",
77 verbose ? "" : "restart with -v to use") < 0) 77 verbose ? "" : "restart with -v to use") < 0)
78 return -1; 78 return -1;
79 79
80 while (1) { 80 while (1) {
81 key = ui_browser__run(&self->b, 0); 81 key = ui_browser__run(&browser->b, 0);
82 82
83 switch (key) { 83 switch (key) {
84 case '/': 84 case '/':
85 if (verbose) 85 if (verbose)
86 map_browser__search(self); 86 map_browser__search(browser);
87 default: 87 default:
88 break; 88 break;
89 case K_LEFT: 89 case K_LEFT:
@@ -94,20 +94,20 @@ static int map_browser__run(struct map_browser *self)
94 } 94 }
95 } 95 }
96out: 96out:
97 ui_browser__hide(&self->b); 97 ui_browser__hide(&browser->b);
98 return key; 98 return key;
99} 99}
100 100
101int map__browse(struct map *self) 101int map__browse(struct map *map)
102{ 102{
103 struct map_browser mb = { 103 struct map_browser mb = {
104 .b = { 104 .b = {
105 .entries = &self->dso->symbols[self->type], 105 .entries = &map->dso->symbols[map->type],
106 .refresh = ui_browser__rb_tree_refresh, 106 .refresh = ui_browser__rb_tree_refresh,
107 .seek = ui_browser__rb_tree_seek, 107 .seek = ui_browser__rb_tree_seek,
108 .write = map_browser__write, 108 .write = map_browser__write,
109 }, 109 },
110 .map = self, 110 .map = map,
111 }; 111 };
112 struct rb_node *nd; 112 struct rb_node *nd;
113 char tmp[BITS_PER_LONG / 4]; 113 char tmp[BITS_PER_LONG / 4];
diff --git a/tools/perf/ui/browsers/map.h b/tools/perf/ui/browsers/map.h
index df8581a43e17..2d58e4b3eb6f 100644
--- a/tools/perf/ui/browsers/map.h
+++ b/tools/perf/ui/browsers/map.h
@@ -2,5 +2,5 @@
2#define _PERF_UI_MAP_BROWSER_H_ 1 2#define _PERF_UI_MAP_BROWSER_H_ 1
3struct map; 3struct map;
4 4
5int map__browse(struct map *self); 5int map__browse(struct map *map);
6#endif /* _PERF_UI_MAP_BROWSER_H_ */ 6#endif /* _PERF_UI_MAP_BROWSER_H_ */
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 12f009e61e94..d63c68ea02a8 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -84,22 +84,22 @@ static void script_browser__write(struct ui_browser *browser,
84 slsmg_write_nstring(sline->line, browser->width); 84 slsmg_write_nstring(sline->line, browser->width);
85} 85}
86 86
87static int script_browser__run(struct perf_script_browser *self) 87static int script_browser__run(struct perf_script_browser *browser)
88{ 88{
89 int key; 89 int key;
90 90
91 if (ui_browser__show(&self->b, self->script_name, 91 if (ui_browser__show(&browser->b, browser->script_name,
92 "Press <- or ESC to exit") < 0) 92 "Press <- or ESC to exit") < 0)
93 return -1; 93 return -1;
94 94
95 while (1) { 95 while (1) {
96 key = ui_browser__run(&self->b, 0); 96 key = ui_browser__run(&browser->b, 0);
97 97
98 /* We can add some special key handling here if needed */ 98 /* We can add some special key handling here if needed */
99 break; 99 break;
100 } 100 }
101 101
102 ui_browser__hide(&self->b); 102 ui_browser__hide(&browser->b);
103 return key; 103 return key;
104} 104}
105 105
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 6c152686e837..c244cb524ef2 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -213,20 +213,19 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
213 return ret; 213 return ret;
214} 214}
215 215
216static size_t __callchain__fprintf_flat(FILE *fp, 216static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
217 struct callchain_node *self,
218 u64 total_samples) 217 u64 total_samples)
219{ 218{
220 struct callchain_list *chain; 219 struct callchain_list *chain;
221 size_t ret = 0; 220 size_t ret = 0;
222 221
223 if (!self) 222 if (!node)
224 return 0; 223 return 0;
225 224
226 ret += __callchain__fprintf_flat(fp, self->parent, total_samples); 225 ret += __callchain__fprintf_flat(fp, node->parent, total_samples);
227 226
228 227
229 list_for_each_entry(chain, &self->val, list) { 228 list_for_each_entry(chain, &node->val, list) {
230 if (chain->ip >= PERF_CONTEXT_MAX) 229 if (chain->ip >= PERF_CONTEXT_MAX)
231 continue; 230 continue;
232 if (chain->ms.sym) 231 if (chain->ms.sym)
@@ -239,15 +238,14 @@ static size_t __callchain__fprintf_flat(FILE *fp,
239 return ret; 238 return ret;
240} 239}
241 240
242static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *self, 241static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
243 u64 total_samples) 242 u64 total_samples)
244{ 243{
245 size_t ret = 0; 244 size_t ret = 0;
246 u32 entries_printed = 0; 245 u32 entries_printed = 0;
247 struct rb_node *rb_node;
248 struct callchain_node *chain; 246 struct callchain_node *chain;
247 struct rb_node *rb_node = rb_first(tree);
249 248
250 rb_node = rb_first(self);
251 while (rb_node) { 249 while (rb_node) {
252 double percent; 250 double percent;
253 251
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index a811f5c62e18..929f28a7c14d 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -10,10 +10,9 @@ extern struct perf_tool build_id__mark_dso_hit_ops;
10struct dso; 10struct dso;
11 11
12int build_id__sprintf(const u8 *build_id, int len, char *bf); 12int build_id__sprintf(const u8 *build_id, int len, char *bf);
13char *dso__build_id_filename(struct dso *self, char *bf, size_t size); 13char *dso__build_id_filename(struct dso *dso, char *bf, size_t size);
14 14
15int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, 15int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
16 struct perf_sample *sample, struct perf_evsel *evsel, 16 struct perf_sample *sample, struct perf_evsel *evsel,
17 struct machine *machine); 17 struct machine *machine);
18
19#endif 18#endif
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index beb8cf9f9976..a9b48c42e81e 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,5 +1,5 @@
1#include "util.h" 1#include "util.h"
2#include "sysfs.h" 2#include "fs.h"
3#include "../perf.h" 3#include "../perf.h"
4#include "cpumap.h" 4#include "cpumap.h"
5#include <assert.h> 5#include <assert.h>
@@ -216,7 +216,7 @@ int cpu_map__get_socket(struct cpu_map *map, int idx)
216 216
217 cpu = map->map[idx]; 217 cpu = map->map[idx];
218 218
219 mnt = sysfs_find_mountpoint(); 219 mnt = sysfs__mountpoint();
220 if (!mnt) 220 if (!mnt)
221 return -1; 221 return -1;
222 222
@@ -279,7 +279,7 @@ int cpu_map__get_core(struct cpu_map *map, int idx)
279 279
280 cpu = map->map[idx]; 280 cpu = map->map[idx];
281 281
282 mnt = sysfs_find_mountpoint(); 282 mnt = sysfs__mountpoint();
283 if (!mnt) 283 if (!mnt)
284 return -1; 284 return -1;
285 285
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index c26b3539187b..ec9ae1114ed4 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -617,15 +617,15 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
617 return machine__process_event(machine, event, sample); 617 return machine__process_event(machine, event, sample);
618} 618}
619 619
620void thread__find_addr_map(struct thread *self, 620void thread__find_addr_map(struct thread *thread,
621 struct machine *machine, u8 cpumode, 621 struct machine *machine, u8 cpumode,
622 enum map_type type, u64 addr, 622 enum map_type type, u64 addr,
623 struct addr_location *al) 623 struct addr_location *al)
624{ 624{
625 struct map_groups *mg = &self->mg; 625 struct map_groups *mg = &thread->mg;
626 bool load_map = false; 626 bool load_map = false;
627 627
628 al->thread = self; 628 al->thread = thread;
629 al->addr = addr; 629 al->addr = addr;
630 al->cpumode = cpumode; 630 al->cpumode = cpumode;
631 al->filtered = false; 631 al->filtered = false;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 752709ccfb00..f8d70f3003ab 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -251,7 +251,8 @@ int perf_event__process(struct perf_tool *tool,
251 struct machine *machine); 251 struct machine *machine);
252 252
253struct addr_location; 253struct addr_location;
254int perf_event__preprocess_sample(const union perf_event *self, 254
255int perf_event__preprocess_sample(const union perf_event *event,
255 struct machine *machine, 256 struct machine *machine,
256 struct addr_location *al, 257 struct addr_location *al,
257 struct perf_sample *sample); 258 struct perf_sample *sample);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 6e8acc9abe38..e99eaed92682 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -88,7 +88,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
88 88
89struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id); 89struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
90 90
91union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx); 91union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
92 92
93void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx); 93void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
94 94
@@ -99,6 +99,7 @@ void perf_evlist__set_id_pos(struct perf_evlist *evlist);
99bool perf_can_sample_identifier(void); 99bool perf_can_sample_identifier(void);
100void perf_evlist__config(struct perf_evlist *evlist, 100void perf_evlist__config(struct perf_evlist *evlist,
101 struct perf_record_opts *opts); 101 struct perf_record_opts *opts);
102int perf_record_opts__config(struct perf_record_opts *opts);
102 103
103int perf_evlist__prepare_workload(struct perf_evlist *evlist, 104int perf_evlist__prepare_workload(struct perf_evlist *evlist,
104 struct perf_target *target, 105 struct perf_target *target,
diff --git a/tools/perf/util/fs.c b/tools/perf/util/fs.c
new file mode 100644
index 000000000000..f5be1f26e724
--- /dev/null
+++ b/tools/perf/util/fs.c
@@ -0,0 +1,119 @@
1
2/* TODO merge/factor into tools/lib/lk/debugfs.c */
3
4#include "util.h"
5#include "util/fs.h"
6
7static const char * const sysfs__fs_known_mountpoints[] = {
8 "/sys",
9 0,
10};
11
12static const char * const procfs__known_mountpoints[] = {
13 "/proc",
14 0,
15};
16
17struct fs {
18 const char *name;
19 const char * const *mounts;
20 char path[PATH_MAX + 1];
21 bool found;
22 long magic;
23};
24
25enum {
26 FS__SYSFS = 0,
27 FS__PROCFS = 1,
28};
29
30static struct fs fs__entries[] = {
31 [FS__SYSFS] = {
32 .name = "sysfs",
33 .mounts = sysfs__fs_known_mountpoints,
34 .magic = SYSFS_MAGIC,
35 },
36 [FS__PROCFS] = {
37 .name = "proc",
38 .mounts = procfs__known_mountpoints,
39 .magic = PROC_SUPER_MAGIC,
40 },
41};
42
43static bool fs__read_mounts(struct fs *fs)
44{
45 bool found = false;
46 char type[100];
47 FILE *fp;
48
49 fp = fopen("/proc/mounts", "r");
50 if (fp == NULL)
51 return NULL;
52
53 while (!found &&
54 fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
55 fs->path, type) == 2) {
56
57 if (strcmp(type, fs->name) == 0)
58 found = true;
59 }
60
61 fclose(fp);
62 return fs->found = found;
63}
64
65static int fs__valid_mount(const char *fs, long magic)
66{
67 struct statfs st_fs;
68
69 if (statfs(fs, &st_fs) < 0)
70 return -ENOENT;
71 else if (st_fs.f_type != magic)
72 return -ENOENT;
73
74 return 0;
75}
76
77static bool fs__check_mounts(struct fs *fs)
78{
79 const char * const *ptr;
80
81 ptr = fs->mounts;
82 while (*ptr) {
83 if (fs__valid_mount(*ptr, fs->magic) == 0) {
84 fs->found = true;
85 strcpy(fs->path, *ptr);
86 return true;
87 }
88 ptr++;
89 }
90
91 return false;
92}
93
94static const char *fs__get_mountpoint(struct fs *fs)
95{
96 if (fs__check_mounts(fs))
97 return fs->path;
98
99 return fs__read_mounts(fs) ? fs->path : NULL;
100}
101
102static const char *fs__mountpoint(int idx)
103{
104 struct fs *fs = &fs__entries[idx];
105
106 if (fs->found)
107 return (const char *)fs->path;
108
109 return fs__get_mountpoint(fs);
110}
111
112#define FS__MOUNTPOINT(name, idx) \
113const char *name##__mountpoint(void) \
114{ \
115 return fs__mountpoint(idx); \
116}
117
118FS__MOUNTPOINT(sysfs, FS__SYSFS);
119FS__MOUNTPOINT(procfs, FS__PROCFS);
diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h
new file mode 100644
index 000000000000..5e09ce1bab0e
--- /dev/null
+++ b/tools/perf/util/fs.h
@@ -0,0 +1,7 @@
1#ifndef __PERF_FS
2#define __PERF_FS
3
4const char *sysfs__mountpoint(void);
5const char *procfs__mountpoint(void);
6
7#endif /* __PERF_FS */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 30793f98c8bb..822903eaa201 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -407,73 +407,12 @@ out:
407 return he; 407 return he;
408} 408}
409 409
410struct hist_entry *__hists__add_mem_entry(struct hists *hists,
411 struct addr_location *al,
412 struct symbol *sym_parent,
413 struct mem_info *mi,
414 u64 period,
415 u64 weight)
416{
417 struct hist_entry entry = {
418 .thread = al->thread,
419 .comm = thread__comm(al->thread),
420 .ms = {
421 .map = al->map,
422 .sym = al->sym,
423 },
424 .stat = {
425 .period = period,
426 .weight = weight,
427 .nr_events = 1,
428 },
429 .cpu = al->cpu,
430 .ip = al->addr,
431 .level = al->level,
432 .parent = sym_parent,
433 .filtered = symbol__parent_filter(sym_parent),
434 .hists = hists,
435 .mem_info = mi,
436 .branch_info = NULL,
437 };
438 return add_hist_entry(hists, &entry, al, period, weight);
439}
440
441struct hist_entry *__hists__add_branch_entry(struct hists *hists,
442 struct addr_location *al,
443 struct symbol *sym_parent,
444 struct branch_info *bi,
445 u64 period,
446 u64 weight)
447{
448 struct hist_entry entry = {
449 .thread = al->thread,
450 .comm = thread__comm(al->thread),
451 .ms = {
452 .map = bi->to.map,
453 .sym = bi->to.sym,
454 },
455 .cpu = al->cpu,
456 .ip = bi->to.addr,
457 .level = al->level,
458 .stat = {
459 .period = period,
460 .nr_events = 1,
461 .weight = weight,
462 },
463 .parent = sym_parent,
464 .filtered = symbol__parent_filter(sym_parent),
465 .branch_info = bi,
466 .hists = hists,
467 .mem_info = NULL,
468 };
469
470 return add_hist_entry(hists, &entry, al, period, weight);
471}
472
473struct hist_entry *__hists__add_entry(struct hists *hists, 410struct hist_entry *__hists__add_entry(struct hists *hists,
474 struct addr_location *al, 411 struct addr_location *al,
475 struct symbol *sym_parent, u64 period, 412 struct symbol *sym_parent,
476 u64 weight, u64 transaction) 413 struct branch_info *bi,
414 struct mem_info *mi,
415 u64 period, u64 weight, u64 transaction)
477{ 416{
478 struct hist_entry entry = { 417 struct hist_entry entry = {
479 .thread = al->thread, 418 .thread = al->thread,
@@ -486,15 +425,15 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
486 .ip = al->addr, 425 .ip = al->addr,
487 .level = al->level, 426 .level = al->level,
488 .stat = { 427 .stat = {
489 .period = period,
490 .nr_events = 1, 428 .nr_events = 1,
429 .period = period,
491 .weight = weight, 430 .weight = weight,
492 }, 431 },
493 .parent = sym_parent, 432 .parent = sym_parent,
494 .filtered = symbol__parent_filter(sym_parent), 433 .filtered = symbol__parent_filter(sym_parent),
495 .hists = hists, 434 .hists = hists,
496 .branch_info = NULL, 435 .branch_info = bi,
497 .mem_info = NULL, 436 .mem_info = mi,
498 .transaction = transaction, 437 .transaction = transaction,
499 }; 438 };
500 439
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 9d2d022cdb79..b621347a1585 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -84,55 +84,43 @@ struct hists {
84 u16 col_len[HISTC_NR_COLS]; 84 u16 col_len[HISTC_NR_COLS];
85}; 85};
86 86
87struct hist_entry *__hists__add_entry(struct hists *self, 87struct hist_entry *__hists__add_entry(struct hists *hists,
88 struct addr_location *al, 88 struct addr_location *al,
89 struct symbol *parent, u64 period, 89 struct symbol *parent,
90 struct branch_info *bi,
91 struct mem_info *mi, u64 period,
90 u64 weight, u64 transaction); 92 u64 weight, u64 transaction);
91int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right); 93int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
92int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right); 94int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
93int hist_entry__transaction_len(void); 95int hist_entry__transaction_len(void);
94int hist_entry__sort_snprintf(struct hist_entry *self, char *bf, size_t size, 96int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
95 struct hists *hists); 97 struct hists *hists);
96void hist_entry__free(struct hist_entry *); 98void hist_entry__free(struct hist_entry *);
97 99
98struct hist_entry *__hists__add_branch_entry(struct hists *self, 100void hists__output_resort(struct hists *hists);
99 struct addr_location *al, 101void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
100 struct symbol *sym_parent,
101 struct branch_info *bi,
102 u64 period,
103 u64 weight);
104
105struct hist_entry *__hists__add_mem_entry(struct hists *self,
106 struct addr_location *al,
107 struct symbol *sym_parent,
108 struct mem_info *mi,
109 u64 period,
110 u64 weight);
111
112void hists__output_resort(struct hists *self);
113void hists__collapse_resort(struct hists *self, struct ui_progress *prog);
114 102
115void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel); 103void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
116void hists__output_recalc_col_len(struct hists *hists, int max_rows); 104void hists__output_recalc_col_len(struct hists *hists, int max_rows);
117 105
118void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h); 106void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h);
119void hists__inc_nr_events(struct hists *self, u32 type); 107void hists__inc_nr_events(struct hists *hists, u32 type);
120void events_stats__inc(struct events_stats *stats, u32 type); 108void events_stats__inc(struct events_stats *stats, u32 type);
121size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); 109size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
122 110
123size_t hists__fprintf(struct hists *self, bool show_header, int max_rows, 111size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
124 int max_cols, float min_pcnt, FILE *fp); 112 int max_cols, float min_pcnt, FILE *fp);
125 113
126int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr); 114int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 addr);
127int hist_entry__annotate(struct hist_entry *self, size_t privsize); 115int hist_entry__annotate(struct hist_entry *he, size_t privsize);
128 116
129void hists__filter_by_dso(struct hists *hists); 117void hists__filter_by_dso(struct hists *hists);
130void hists__filter_by_thread(struct hists *hists); 118void hists__filter_by_thread(struct hists *hists);
131void hists__filter_by_symbol(struct hists *hists); 119void hists__filter_by_symbol(struct hists *hists);
132 120
133u16 hists__col_len(struct hists *self, enum hist_column col); 121u16 hists__col_len(struct hists *hists, enum hist_column col);
134void hists__set_col_len(struct hists *self, enum hist_column col, u16 len); 122void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
135bool hists__new_col_len(struct hists *self, enum hist_column col, u16 len); 123bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
136void hists__reset_col_len(struct hists *hists); 124void hists__reset_col_len(struct hists *hists);
137void hists__calc_col_len(struct hists *hists, struct hist_entry *he); 125void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
138 126
@@ -222,12 +210,9 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
222 return 0; 210 return 0;
223} 211}
224 212
225static inline int hist_entry__tui_annotate(struct hist_entry *self 213static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
226 __maybe_unused, 214 struct perf_evsel *evsel __maybe_unused,
227 struct perf_evsel *evsel 215 struct hist_browser_timer *hbt __maybe_unused)
228 __maybe_unused,
229 struct hist_browser_timer *hbt
230 __maybe_unused)
231{ 216{
232 return 0; 217 return 0;
233} 218}
@@ -242,5 +227,5 @@ static inline int script_browse(const char *script_opt __maybe_unused)
242#define K_SWITCH_INPUT_DATA -3000 227#define K_SWITCH_INPUT_DATA -3000
243#endif 228#endif
244 229
245unsigned int hists__sort_list_width(struct hists *self); 230unsigned int hists__sort_list_width(struct hists *hists);
246#endif /* __PERF_HIST_H */ 231#endif /* __PERF_HIST_H */
diff --git a/tools/perf/util/include/linux/magic.h b/tools/perf/util/include/linux/magic.h
index 58b64ed4da12..07d63cf3e0f6 100644
--- a/tools/perf/util/include/linux/magic.h
+++ b/tools/perf/util/include/linux/magic.h
@@ -9,4 +9,8 @@
9#define SYSFS_MAGIC 0x62656572 9#define SYSFS_MAGIC 0x62656572
10#endif 10#endif
11 11
12#ifndef PROC_SUPER_MAGIC
13#define PROC_SUPER_MAGIC 0x9fa0
14#endif
15
12#endif 16#endif
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 64362fe45b71..c232d8dd410b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -4,7 +4,7 @@
4#include <unistd.h> 4#include <unistd.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <dirent.h> 6#include <dirent.h>
7#include "sysfs.h" 7#include "fs.h"
8#include "util.h" 8#include "util.h"
9#include "pmu.h" 9#include "pmu.h"
10#include "parse-events.h" 10#include "parse-events.h"
@@ -77,9 +77,8 @@ static int pmu_format(const char *name, struct list_head *format)
77{ 77{
78 struct stat st; 78 struct stat st;
79 char path[PATH_MAX]; 79 char path[PATH_MAX];
80 const char *sysfs; 80 const char *sysfs = sysfs__mountpoint();
81 81
82 sysfs = sysfs_find_mountpoint();
83 if (!sysfs) 82 if (!sysfs)
84 return -1; 83 return -1;
85 84
@@ -166,9 +165,8 @@ static int pmu_aliases(const char *name, struct list_head *head)
166{ 165{
167 struct stat st; 166 struct stat st;
168 char path[PATH_MAX]; 167 char path[PATH_MAX];
169 const char *sysfs; 168 const char *sysfs = sysfs__mountpoint();
170 169
171 sysfs = sysfs_find_mountpoint();
172 if (!sysfs) 170 if (!sysfs)
173 return -1; 171 return -1;
174 172
@@ -212,11 +210,10 @@ static int pmu_type(const char *name, __u32 *type)
212{ 210{
213 struct stat st; 211 struct stat st;
214 char path[PATH_MAX]; 212 char path[PATH_MAX];
215 const char *sysfs;
216 FILE *file; 213 FILE *file;
217 int ret = 0; 214 int ret = 0;
215 const char *sysfs = sysfs__mountpoint();
218 216
219 sysfs = sysfs_find_mountpoint();
220 if (!sysfs) 217 if (!sysfs)
221 return -1; 218 return -1;
222 219
@@ -241,11 +238,10 @@ static int pmu_type(const char *name, __u32 *type)
241static void pmu_read_sysfs(void) 238static void pmu_read_sysfs(void)
242{ 239{
243 char path[PATH_MAX]; 240 char path[PATH_MAX];
244 const char *sysfs;
245 DIR *dir; 241 DIR *dir;
246 struct dirent *dent; 242 struct dirent *dent;
243 const char *sysfs = sysfs__mountpoint();
247 244
248 sysfs = sysfs_find_mountpoint();
249 if (!sysfs) 245 if (!sysfs)
250 return; 246 return;
251 247
@@ -270,11 +266,10 @@ static struct cpu_map *pmu_cpumask(const char *name)
270{ 266{
271 struct stat st; 267 struct stat st;
272 char path[PATH_MAX]; 268 char path[PATH_MAX];
273 const char *sysfs;
274 FILE *file; 269 FILE *file;
275 struct cpu_map *cpus; 270 struct cpu_map *cpus;
271 const char *sysfs = sysfs__mountpoint();
276 272
277 sysfs = sysfs_find_mountpoint();
278 if (!sysfs) 273 if (!sysfs)
279 return NULL; 274 return NULL;
280 275
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 2200dad4c3f4..ffb657ffd327 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -115,7 +115,7 @@ static const Dwfl_Callbacks offline_callbacks = {
115}; 115};
116 116
117/* Get a Dwarf from offline image */ 117/* Get a Dwarf from offline image */
118static int debuginfo__init_offline_dwarf(struct debuginfo *self, 118static int debuginfo__init_offline_dwarf(struct debuginfo *dbg,
119 const char *path) 119 const char *path)
120{ 120{
121 int fd; 121 int fd;
@@ -124,25 +124,25 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *self,
124 if (fd < 0) 124 if (fd < 0)
125 return fd; 125 return fd;
126 126
127 self->dwfl = dwfl_begin(&offline_callbacks); 127 dbg->dwfl = dwfl_begin(&offline_callbacks);
128 if (!self->dwfl) 128 if (!dbg->dwfl)
129 goto error; 129 goto error;
130 130
131 self->mod = dwfl_report_offline(self->dwfl, "", "", fd); 131 dbg->mod = dwfl_report_offline(dbg->dwfl, "", "", fd);
132 if (!self->mod) 132 if (!dbg->mod)
133 goto error; 133 goto error;
134 134
135 self->dbg = dwfl_module_getdwarf(self->mod, &self->bias); 135 dbg->dbg = dwfl_module_getdwarf(dbg->mod, &dbg->bias);
136 if (!self->dbg) 136 if (!dbg->dbg)
137 goto error; 137 goto error;
138 138
139 return 0; 139 return 0;
140error: 140error:
141 if (self->dwfl) 141 if (dbg->dwfl)
142 dwfl_end(self->dwfl); 142 dwfl_end(dbg->dwfl);
143 else 143 else
144 close(fd); 144 close(fd);
145 memset(self, 0, sizeof(*self)); 145 memset(dbg, 0, sizeof(*dbg));
146 146
147 return -ENOENT; 147 return -ENOENT;
148} 148}
@@ -180,24 +180,24 @@ static const Dwfl_Callbacks kernel_callbacks = {
180}; 180};
181 181
182/* Get a Dwarf from live kernel image */ 182/* Get a Dwarf from live kernel image */
183static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self, 183static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg,
184 Dwarf_Addr addr) 184 Dwarf_Addr addr)
185{ 185{
186 self->dwfl = dwfl_begin(&kernel_callbacks); 186 dbg->dwfl = dwfl_begin(&kernel_callbacks);
187 if (!self->dwfl) 187 if (!dbg->dwfl)
188 return -EINVAL; 188 return -EINVAL;
189 189
190 /* Load the kernel dwarves: Don't care the result here */ 190 /* Load the kernel dwarves: Don't care the result here */
191 dwfl_linux_kernel_report_kernel(self->dwfl); 191 dwfl_linux_kernel_report_kernel(dbg->dwfl);
192 dwfl_linux_kernel_report_modules(self->dwfl); 192 dwfl_linux_kernel_report_modules(dbg->dwfl);
193 193
194 self->dbg = dwfl_addrdwarf(self->dwfl, addr, &self->bias); 194 dbg->dbg = dwfl_addrdwarf(dbg->dwfl, addr, &dbg->bias);
195 /* Here, check whether we could get a real dwarf */ 195 /* Here, check whether we could get a real dwarf */
196 if (!self->dbg) { 196 if (!dbg->dbg) {
197 pr_debug("Failed to find kernel dwarf at %lx\n", 197 pr_debug("Failed to find kernel dwarf at %lx\n",
198 (unsigned long)addr); 198 (unsigned long)addr);
199 dwfl_end(self->dwfl); 199 dwfl_end(dbg->dwfl);
200 memset(self, 0, sizeof(*self)); 200 memset(dbg, 0, sizeof(*dbg));
201 return -ENOENT; 201 return -ENOENT;
202 } 202 }
203 203
@@ -205,7 +205,7 @@ static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self,
205} 205}
206#else 206#else
207/* With older elfutils, this just support kernel module... */ 207/* With older elfutils, this just support kernel module... */
208static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self, 208static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg,
209 Dwarf_Addr addr __maybe_unused) 209 Dwarf_Addr addr __maybe_unused)
210{ 210{
211 const char *path = kernel_get_module_path("kernel"); 211 const char *path = kernel_get_module_path("kernel");
@@ -216,44 +216,45 @@ static int debuginfo__init_online_kernel_dwarf(struct debuginfo *self,
216 } 216 }
217 217
218 pr_debug2("Use file %s for debuginfo\n", path); 218 pr_debug2("Use file %s for debuginfo\n", path);
219 return debuginfo__init_offline_dwarf(self, path); 219 return debuginfo__init_offline_dwarf(dbg, path);
220} 220}
221#endif 221#endif
222 222
223struct debuginfo *debuginfo__new(const char *path) 223struct debuginfo *debuginfo__new(const char *path)
224{ 224{
225 struct debuginfo *self = zalloc(sizeof(struct debuginfo)); 225 struct debuginfo *dbg = zalloc(sizeof(*dbg));
226 if (!self) 226 if (!dbg)
227 return NULL; 227 return NULL;
228 228
229 if (debuginfo__init_offline_dwarf(self, path) < 0) { 229 if (debuginfo__init_offline_dwarf(dbg, path) < 0) {
230 free(self); 230 free(dbg);
231 self = NULL; 231 dbg = NULL;
232 } 232 }
233 233
234 return self; 234 return dbg;
235} 235}
236 236
237struct debuginfo *debuginfo__new_online_kernel(unsigned long addr) 237struct debuginfo *debuginfo__new_online_kernel(unsigned long addr)
238{ 238{
239 struct debuginfo *self = zalloc(sizeof(struct debuginfo)); 239 struct debuginfo *dbg = zalloc(sizeof(*dbg));
240 if (!self) 240
241 if (!dbg)
241 return NULL; 242 return NULL;
242 243
243 if (debuginfo__init_online_kernel_dwarf(self, (Dwarf_Addr)addr) < 0) { 244 if (debuginfo__init_online_kernel_dwarf(dbg, (Dwarf_Addr)addr) < 0) {
244 free(self); 245 free(dbg);
245 self = NULL; 246 dbg = NULL;
246 } 247 }
247 248
248 return self; 249 return dbg;
249} 250}
250 251
251void debuginfo__delete(struct debuginfo *self) 252void debuginfo__delete(struct debuginfo *dbg)
252{ 253{
253 if (self) { 254 if (dbg) {
254 if (self->dwfl) 255 if (dbg->dwfl)
255 dwfl_end(self->dwfl); 256 dwfl_end(dbg->dwfl);
256 free(self); 257 free(dbg);
257 } 258 }
258} 259}
259 260
@@ -1083,7 +1084,7 @@ static int pubname_search_cb(Dwarf *dbg, Dwarf_Global *gl, void *data)
1083} 1084}
1084 1085
1085/* Find probe points from debuginfo */ 1086/* Find probe points from debuginfo */
1086static int debuginfo__find_probes(struct debuginfo *self, 1087static int debuginfo__find_probes(struct debuginfo *dbg,
1087 struct probe_finder *pf) 1088 struct probe_finder *pf)
1088{ 1089{
1089 struct perf_probe_point *pp = &pf->pev->point; 1090 struct perf_probe_point *pp = &pf->pev->point;
@@ -1094,7 +1095,7 @@ static int debuginfo__find_probes(struct debuginfo *self,
1094 1095
1095#if _ELFUTILS_PREREQ(0, 142) 1096#if _ELFUTILS_PREREQ(0, 142)
1096 /* Get the call frame information from this dwarf */ 1097 /* Get the call frame information from this dwarf */
1097 pf->cfi = dwarf_getcfi(self->dbg); 1098 pf->cfi = dwarf_getcfi(dbg->dbg);
1098#endif 1099#endif
1099 1100
1100 off = 0; 1101 off = 0;
@@ -1113,7 +1114,7 @@ static int debuginfo__find_probes(struct debuginfo *self,
1113 .data = pf, 1114 .data = pf,
1114 }; 1115 };
1115 1116
1116 dwarf_getpubnames(self->dbg, pubname_search_cb, 1117 dwarf_getpubnames(dbg->dbg, pubname_search_cb,
1117 &pubname_param, 0); 1118 &pubname_param, 0);
1118 if (pubname_param.found) { 1119 if (pubname_param.found) {
1119 ret = probe_point_search_cb(&pf->sp_die, &probe_param); 1120 ret = probe_point_search_cb(&pf->sp_die, &probe_param);
@@ -1123,9 +1124,9 @@ static int debuginfo__find_probes(struct debuginfo *self,
1123 } 1124 }
1124 1125
1125 /* Loop on CUs (Compilation Unit) */ 1126 /* Loop on CUs (Compilation Unit) */
1126 while (!dwarf_nextcu(self->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) { 1127 while (!dwarf_nextcu(dbg->dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
1127 /* Get the DIE(Debugging Information Entry) of this CU */ 1128 /* Get the DIE(Debugging Information Entry) of this CU */
1128 diep = dwarf_offdie(self->dbg, off + cuhl, &pf->cu_die); 1129 diep = dwarf_offdie(dbg->dbg, off + cuhl, &pf->cu_die);
1129 if (!diep) 1130 if (!diep)
1130 continue; 1131 continue;
1131 1132
@@ -1281,13 +1282,13 @@ end:
1281} 1282}
1282 1283
1283/* Find probe_trace_events specified by perf_probe_event from debuginfo */ 1284/* Find probe_trace_events specified by perf_probe_event from debuginfo */
1284int debuginfo__find_trace_events(struct debuginfo *self, 1285int debuginfo__find_trace_events(struct debuginfo *dbg,
1285 struct perf_probe_event *pev, 1286 struct perf_probe_event *pev,
1286 struct probe_trace_event **tevs, int max_tevs) 1287 struct probe_trace_event **tevs, int max_tevs)
1287{ 1288{
1288 struct trace_event_finder tf = { 1289 struct trace_event_finder tf = {
1289 .pf = {.pev = pev, .callback = add_probe_trace_event}, 1290 .pf = {.pev = pev, .callback = add_probe_trace_event},
1290 .mod = self->mod, .max_tevs = max_tevs}; 1291 .mod = dbg->mod, .max_tevs = max_tevs};
1291 int ret; 1292 int ret;
1292 1293
1293 /* Allocate result tevs array */ 1294 /* Allocate result tevs array */
@@ -1298,7 +1299,7 @@ int debuginfo__find_trace_events(struct debuginfo *self,
1298 tf.tevs = *tevs; 1299 tf.tevs = *tevs;
1299 tf.ntevs = 0; 1300 tf.ntevs = 0;
1300 1301
1301 ret = debuginfo__find_probes(self, &tf.pf); 1302 ret = debuginfo__find_probes(dbg, &tf.pf);
1302 if (ret < 0) { 1303 if (ret < 0) {
1303 free(*tevs); 1304 free(*tevs);
1304 *tevs = NULL; 1305 *tevs = NULL;
@@ -1389,14 +1390,14 @@ out:
1389} 1390}
1390 1391
1391/* Find available variables at given probe point */ 1392/* Find available variables at given probe point */
1392int debuginfo__find_available_vars_at(struct debuginfo *self, 1393int debuginfo__find_available_vars_at(struct debuginfo *dbg,
1393 struct perf_probe_event *pev, 1394 struct perf_probe_event *pev,
1394 struct variable_list **vls, 1395 struct variable_list **vls,
1395 int max_vls, bool externs) 1396 int max_vls, bool externs)
1396{ 1397{
1397 struct available_var_finder af = { 1398 struct available_var_finder af = {
1398 .pf = {.pev = pev, .callback = add_available_vars}, 1399 .pf = {.pev = pev, .callback = add_available_vars},
1399 .mod = self->mod, 1400 .mod = dbg->mod,
1400 .max_vls = max_vls, .externs = externs}; 1401 .max_vls = max_vls, .externs = externs};
1401 int ret; 1402 int ret;
1402 1403
@@ -1408,7 +1409,7 @@ int debuginfo__find_available_vars_at(struct debuginfo *self,
1408 af.vls = *vls; 1409 af.vls = *vls;
1409 af.nvls = 0; 1410 af.nvls = 0;
1410 1411
1411 ret = debuginfo__find_probes(self, &af.pf); 1412 ret = debuginfo__find_probes(dbg, &af.pf);
1412 if (ret < 0) { 1413 if (ret < 0) {
1413 /* Free vlist for error */ 1414 /* Free vlist for error */
1414 while (af.nvls--) { 1415 while (af.nvls--) {
@@ -1426,7 +1427,7 @@ int debuginfo__find_available_vars_at(struct debuginfo *self,
1426} 1427}
1427 1428
1428/* Reverse search */ 1429/* Reverse search */
1429int debuginfo__find_probe_point(struct debuginfo *self, unsigned long addr, 1430int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
1430 struct perf_probe_point *ppt) 1431 struct perf_probe_point *ppt)
1431{ 1432{
1432 Dwarf_Die cudie, spdie, indie; 1433 Dwarf_Die cudie, spdie, indie;
@@ -1435,10 +1436,10 @@ int debuginfo__find_probe_point(struct debuginfo *self, unsigned long addr,
1435 int baseline = 0, lineno = 0, ret = 0; 1436 int baseline = 0, lineno = 0, ret = 0;
1436 1437
1437 /* Adjust address with bias */ 1438 /* Adjust address with bias */
1438 addr += self->bias; 1439 addr += dbg->bias;
1439 1440
1440 /* Find cu die */ 1441 /* Find cu die */
1441 if (!dwarf_addrdie(self->dbg, (Dwarf_Addr)addr - self->bias, &cudie)) { 1442 if (!dwarf_addrdie(dbg->dbg, (Dwarf_Addr)addr - dbg->bias, &cudie)) {
1442 pr_warning("Failed to find debug information for address %lx\n", 1443 pr_warning("Failed to find debug information for address %lx\n",
1443 addr); 1444 addr);
1444 ret = -EINVAL; 1445 ret = -EINVAL;
@@ -1639,7 +1640,7 @@ static int find_line_range_by_func(struct line_finder *lf)
1639 return param.retval; 1640 return param.retval;
1640} 1641}
1641 1642
1642int debuginfo__find_line_range(struct debuginfo *self, struct line_range *lr) 1643int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr)
1643{ 1644{
1644 struct line_finder lf = {.lr = lr, .found = 0}; 1645 struct line_finder lf = {.lr = lr, .found = 0};
1645 int ret = 0; 1646 int ret = 0;
@@ -1656,7 +1657,7 @@ int debuginfo__find_line_range(struct debuginfo *self, struct line_range *lr)
1656 struct dwarf_callback_param line_range_param = { 1657 struct dwarf_callback_param line_range_param = {
1657 .data = (void *)&lf, .retval = 0}; 1658 .data = (void *)&lf, .retval = 0};
1658 1659
1659 dwarf_getpubnames(self->dbg, pubname_search_cb, 1660 dwarf_getpubnames(dbg->dbg, pubname_search_cb,
1660 &pubname_param, 0); 1661 &pubname_param, 0);
1661 if (pubname_param.found) { 1662 if (pubname_param.found) {
1662 line_range_search_cb(&lf.sp_die, &line_range_param); 1663 line_range_search_cb(&lf.sp_die, &line_range_param);
@@ -1667,12 +1668,12 @@ int debuginfo__find_line_range(struct debuginfo *self, struct line_range *lr)
1667 1668
1668 /* Loop on CUs (Compilation Unit) */ 1669 /* Loop on CUs (Compilation Unit) */
1669 while (!lf.found && ret >= 0) { 1670 while (!lf.found && ret >= 0) {
1670 if (dwarf_nextcu(self->dbg, off, &noff, &cuhl, 1671 if (dwarf_nextcu(dbg->dbg, off, &noff, &cuhl,
1671 NULL, NULL, NULL) != 0) 1672 NULL, NULL, NULL) != 0)
1672 break; 1673 break;
1673 1674
1674 /* Get the DIE(Debugging Information Entry) of this CU */ 1675 /* Get the DIE(Debugging Information Entry) of this CU */
1675 diep = dwarf_offdie(self->dbg, off + cuhl, &lf.cu_die); 1676 diep = dwarf_offdie(dbg->dbg, off + cuhl, &lf.cu_die);
1676 if (!diep) 1677 if (!diep)
1677 continue; 1678 continue;
1678 1679
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index d6dab0e0a937..ffc33cdd25cc 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -31,25 +31,25 @@ struct debuginfo {
31 31
32extern struct debuginfo *debuginfo__new(const char *path); 32extern struct debuginfo *debuginfo__new(const char *path);
33extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr); 33extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr);
34extern void debuginfo__delete(struct debuginfo *self); 34extern void debuginfo__delete(struct debuginfo *dbg);
35 35
36/* Find probe_trace_events specified by perf_probe_event from debuginfo */ 36/* Find probe_trace_events specified by perf_probe_event from debuginfo */
37extern int debuginfo__find_trace_events(struct debuginfo *self, 37extern int debuginfo__find_trace_events(struct debuginfo *dbg,
38 struct perf_probe_event *pev, 38 struct perf_probe_event *pev,
39 struct probe_trace_event **tevs, 39 struct probe_trace_event **tevs,
40 int max_tevs); 40 int max_tevs);
41 41
42/* Find a perf_probe_point from debuginfo */ 42/* Find a perf_probe_point from debuginfo */
43extern int debuginfo__find_probe_point(struct debuginfo *self, 43extern int debuginfo__find_probe_point(struct debuginfo *dbg,
44 unsigned long addr, 44 unsigned long addr,
45 struct perf_probe_point *ppt); 45 struct perf_probe_point *ppt);
46 46
47/* Find a line range */ 47/* Find a line range */
48extern int debuginfo__find_line_range(struct debuginfo *self, 48extern int debuginfo__find_line_range(struct debuginfo *dbg,
49 struct line_range *lr); 49 struct line_range *lr);
50 50
51/* Find available variables */ 51/* Find available variables */
52extern int debuginfo__find_available_vars_at(struct debuginfo *self, 52extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,
53 struct perf_probe_event *pev, 53 struct perf_probe_event *pev,
54 struct variable_list **vls, 54 struct variable_list **vls,
55 int max_points, bool externs); 55 int max_points, bool externs);
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h
index 4cedea59f518..c3cb6584d527 100644
--- a/tools/perf/util/pstack.h
+++ b/tools/perf/util/pstack.h
@@ -5,10 +5,10 @@
5 5
6struct pstack; 6struct pstack;
7struct pstack *pstack__new(unsigned short max_nr_entries); 7struct pstack *pstack__new(unsigned short max_nr_entries);
8void pstack__delete(struct pstack *self); 8void pstack__delete(struct pstack *pstack);
9bool pstack__empty(const struct pstack *self); 9bool pstack__empty(const struct pstack *pstack);
10void pstack__remove(struct pstack *self, void *key); 10void pstack__remove(struct pstack *pstack, void *key);
11void pstack__push(struct pstack *self, void *key); 11void pstack__push(struct pstack *pstack, void *key);
12void *pstack__pop(struct pstack *self); 12void *pstack__pop(struct pstack *pstack);
13 13
14#endif /* _PERF_PSTACK_ */ 14#endif /* _PERF_PSTACK_ */
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index f75ae1b9900c..239036fb2b2c 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -17,5 +17,5 @@ util/xyarray.c
17util/cgroup.c 17util/cgroup.c
18util/rblist.c 18util/rblist.c
19util/strlist.c 19util/strlist.c
20util/sysfs.c 20util/fs.c
21../../lib/rbtree.c 21../../lib/rbtree.c
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 18d73aa2f0f8..c8845b107f60 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -2,6 +2,8 @@
2#include "evsel.h" 2#include "evsel.h"
3#include "cpumap.h" 3#include "cpumap.h"
4#include "parse-events.h" 4#include "parse-events.h"
5#include "fs.h"
6#include "util.h"
5 7
6typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel); 8typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel);
7 9
@@ -106,3 +108,72 @@ void perf_evlist__config(struct perf_evlist *evlist,
106 108
107 perf_evlist__set_id_pos(evlist); 109 perf_evlist__set_id_pos(evlist);
108} 110}
111
112static int get_max_rate(unsigned int *rate)
113{
114 char path[PATH_MAX];
115 const char *procfs = procfs__mountpoint();
116
117 if (!procfs)
118 return -1;
119
120 snprintf(path, PATH_MAX,
121 "%s/sys/kernel/perf_event_max_sample_rate", procfs);
122
123 return filename__read_int(path, (int *) rate);
124}
125
126static int perf_record_opts__config_freq(struct perf_record_opts *opts)
127{
128 bool user_freq = opts->user_freq != UINT_MAX;
129 unsigned int max_rate;
130
131 if (opts->user_interval != ULLONG_MAX)
132 opts->default_interval = opts->user_interval;
133 if (user_freq)
134 opts->freq = opts->user_freq;
135
136 /*
137 * User specified count overrides default frequency.
138 */
139 if (opts->default_interval)
140 opts->freq = 0;
141 else if (opts->freq) {
142 opts->default_interval = opts->freq;
143 } else {
144 pr_err("frequency and count are zero, aborting\n");
145 return -1;
146 }
147
148 if (get_max_rate(&max_rate))
149 return 0;
150
151 /*
152 * User specified frequency is over current maximum.
153 */
154 if (user_freq && (max_rate < opts->freq)) {
155 pr_err("Maximum frequency rate (%u) reached.\n"
156 "Please use -F freq option with lower value or consider\n"
157 "tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n",
158 max_rate);
159 return -1;
160 }
161
162 /*
163 * Default frequency is over current maximum.
164 */
165 if (max_rate < opts->freq) {
166 pr_warning("Lowering default frequency rate to %u.\n"
167 "Please consider tweaking "
168 "/proc/sys/kernel/perf_event_max_sample_rate.\n",
169 max_rate);
170 opts->freq = max_rate;
171 }
172
173 return 0;
174}
175
176int perf_record_opts__config(struct perf_record_opts *opts)
177{
178 return perf_record_opts__config_freq(opts);
179}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 3c1b30103d54..0ce46943d627 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -16,11 +16,11 @@
16#include "perf_regs.h" 16#include "perf_regs.h"
17#include "vdso.h" 17#include "vdso.h"
18 18
19static int perf_session__open(struct perf_session *self) 19static int perf_session__open(struct perf_session *session)
20{ 20{
21 struct perf_data_file *file = self->file; 21 struct perf_data_file *file = session->file;
22 22
23 if (perf_session__read_header(self) < 0) { 23 if (perf_session__read_header(session) < 0) {
24 pr_err("incompatible file format (rerun with -v to learn more)"); 24 pr_err("incompatible file format (rerun with -v to learn more)");
25 return -1; 25 return -1;
26 } 26 }
@@ -28,17 +28,17 @@ static int perf_session__open(struct perf_session *self)
28 if (perf_data_file__is_pipe(file)) 28 if (perf_data_file__is_pipe(file))
29 return 0; 29 return 0;
30 30
31 if (!perf_evlist__valid_sample_type(self->evlist)) { 31 if (!perf_evlist__valid_sample_type(session->evlist)) {
32 pr_err("non matching sample_type"); 32 pr_err("non matching sample_type");
33 return -1; 33 return -1;
34 } 34 }
35 35
36 if (!perf_evlist__valid_sample_id_all(self->evlist)) { 36 if (!perf_evlist__valid_sample_id_all(session->evlist)) {
37 pr_err("non matching sample_id_all"); 37 pr_err("non matching sample_id_all");
38 return -1; 38 return -1;
39 } 39 }
40 40
41 if (!perf_evlist__valid_read_format(self->evlist)) { 41 if (!perf_evlist__valid_read_format(session->evlist)) {
42 pr_err("non matching read_format"); 42 pr_err("non matching read_format");
43 return -1; 43 return -1;
44 } 44 }
@@ -53,46 +53,45 @@ void perf_session__set_id_hdr_size(struct perf_session *session)
53 machines__set_id_hdr_size(&session->machines, id_hdr_size); 53 machines__set_id_hdr_size(&session->machines, id_hdr_size);
54} 54}
55 55
56int perf_session__create_kernel_maps(struct perf_session *self) 56int perf_session__create_kernel_maps(struct perf_session *session)
57{ 57{
58 int ret = machine__create_kernel_maps(&self->machines.host); 58 int ret = machine__create_kernel_maps(&session->machines.host);
59 59
60 if (ret >= 0) 60 if (ret >= 0)
61 ret = machines__create_guest_kernel_maps(&self->machines); 61 ret = machines__create_guest_kernel_maps(&session->machines);
62 return ret; 62 return ret;
63} 63}
64 64
65static void perf_session__destroy_kernel_maps(struct perf_session *self) 65static void perf_session__destroy_kernel_maps(struct perf_session *session)
66{ 66{
67 machines__destroy_kernel_maps(&self->machines); 67 machines__destroy_kernel_maps(&session->machines);
68} 68}
69 69
70struct perf_session *perf_session__new(struct perf_data_file *file, 70struct perf_session *perf_session__new(struct perf_data_file *file,
71 bool repipe, struct perf_tool *tool) 71 bool repipe, struct perf_tool *tool)
72{ 72{
73 struct perf_session *self; 73 struct perf_session *session = zalloc(sizeof(*session));
74 74
75 self = zalloc(sizeof(*self)); 75 if (!session)
76 if (!self)
77 goto out; 76 goto out;
78 77
79 self->repipe = repipe; 78 session->repipe = repipe;
80 INIT_LIST_HEAD(&self->ordered_samples.samples); 79 INIT_LIST_HEAD(&session->ordered_samples.samples);
81 INIT_LIST_HEAD(&self->ordered_samples.sample_cache); 80 INIT_LIST_HEAD(&session->ordered_samples.sample_cache);
82 INIT_LIST_HEAD(&self->ordered_samples.to_free); 81 INIT_LIST_HEAD(&session->ordered_samples.to_free);
83 machines__init(&self->machines); 82 machines__init(&session->machines);
84 83
85 if (file) { 84 if (file) {
86 if (perf_data_file__open(file)) 85 if (perf_data_file__open(file))
87 goto out_delete; 86 goto out_delete;
88 87
89 self->file = file; 88 session->file = file;
90 89
91 if (perf_data_file__is_read(file)) { 90 if (perf_data_file__is_read(file)) {
92 if (perf_session__open(self) < 0) 91 if (perf_session__open(session) < 0)
93 goto out_close; 92 goto out_close;
94 93
95 perf_session__set_id_hdr_size(self); 94 perf_session__set_id_hdr_size(session);
96 } 95 }
97 } 96 }
98 97
@@ -101,22 +100,22 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
101 * In O_RDONLY mode this will be performed when reading the 100 * In O_RDONLY mode this will be performed when reading the
102 * kernel MMAP event, in perf_event__process_mmap(). 101 * kernel MMAP event, in perf_event__process_mmap().
103 */ 102 */
104 if (perf_session__create_kernel_maps(self) < 0) 103 if (perf_session__create_kernel_maps(session) < 0)
105 goto out_delete; 104 goto out_delete;
106 } 105 }
107 106
108 if (tool && tool->ordering_requires_timestamps && 107 if (tool && tool->ordering_requires_timestamps &&
109 tool->ordered_samples && !perf_evlist__sample_id_all(self->evlist)) { 108 tool->ordered_samples && !perf_evlist__sample_id_all(session->evlist)) {
110 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); 109 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
111 tool->ordered_samples = false; 110 tool->ordered_samples = false;
112 } 111 }
113 112
114 return self; 113 return session;
115 114
116 out_close: 115 out_close:
117 perf_data_file__close(file); 116 perf_data_file__close(file);
118 out_delete: 117 out_delete:
119 perf_session__delete(self); 118 perf_session__delete(session);
120 out: 119 out:
121 return NULL; 120 return NULL;
122} 121}
@@ -147,16 +146,16 @@ static void perf_session_env__delete(struct perf_session_env *env)
147 free(env->pmu_mappings); 146 free(env->pmu_mappings);
148} 147}
149 148
150void perf_session__delete(struct perf_session *self) 149void perf_session__delete(struct perf_session *session)
151{ 150{
152 perf_session__destroy_kernel_maps(self); 151 perf_session__destroy_kernel_maps(session);
153 perf_session__delete_dead_threads(self); 152 perf_session__delete_dead_threads(session);
154 perf_session__delete_threads(self); 153 perf_session__delete_threads(session);
155 perf_session_env__delete(&self->header.env); 154 perf_session_env__delete(&session->header.env);
156 machines__exit(&self->machines); 155 machines__exit(&session->machines);
157 if (self->file) 156 if (session->file)
158 perf_data_file__close(self->file); 157 perf_data_file__close(session->file);
159 free(self); 158 free(session);
160 vdso__exit(); 159 vdso__exit();
161} 160}
162 161
@@ -1084,11 +1083,11 @@ static int perf_session__process_event(struct perf_session *session,
1084 file_offset); 1083 file_offset);
1085} 1084}
1086 1085
1087void perf_event_header__bswap(struct perf_event_header *self) 1086void perf_event_header__bswap(struct perf_event_header *hdr)
1088{ 1087{
1089 self->type = bswap_32(self->type); 1088 hdr->type = bswap_32(hdr->type);
1090 self->misc = bswap_16(self->misc); 1089 hdr->misc = bswap_16(hdr->misc);
1091 self->size = bswap_16(self->size); 1090 hdr->size = bswap_16(hdr->size);
1092} 1091}
1093 1092
1094struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) 1093struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
@@ -1096,9 +1095,9 @@ struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
1096 return machine__findnew_thread(&session->machines.host, 0, pid); 1095 return machine__findnew_thread(&session->machines.host, 0, pid);
1097} 1096}
1098 1097
1099static struct thread *perf_session__register_idle_thread(struct perf_session *self) 1098static struct thread *perf_session__register_idle_thread(struct perf_session *session)
1100{ 1099{
1101 struct thread *thread = perf_session__findnew(self, 0); 1100 struct thread *thread = perf_session__findnew(session, 0);
1102 1101
1103 if (thread == NULL || thread__set_comm(thread, "swapper", 0)) { 1102 if (thread == NULL || thread__set_comm(thread, "swapper", 0)) {
1104 pr_err("problem inserting idle task.\n"); 1103 pr_err("problem inserting idle task.\n");
@@ -1150,10 +1149,10 @@ static void perf_session__warn_about_errors(const struct perf_session *session,
1150 1149
1151volatile int session_done; 1150volatile int session_done;
1152 1151
1153static int __perf_session__process_pipe_events(struct perf_session *self, 1152static int __perf_session__process_pipe_events(struct perf_session *session,
1154 struct perf_tool *tool) 1153 struct perf_tool *tool)
1155{ 1154{
1156 int fd = perf_data_file__fd(self->file); 1155 int fd = perf_data_file__fd(session->file);
1157 union perf_event *event; 1156 union perf_event *event;
1158 uint32_t size, cur_size = 0; 1157 uint32_t size, cur_size = 0;
1159 void *buf = NULL; 1158 void *buf = NULL;
@@ -1181,7 +1180,7 @@ more:
1181 goto out_err; 1180 goto out_err;
1182 } 1181 }
1183 1182
1184 if (self->header.needs_swap) 1183 if (session->header.needs_swap)
1185 perf_event_header__bswap(&event->header); 1184 perf_event_header__bswap(&event->header);
1186 1185
1187 size = event->header.size; 1186 size = event->header.size;
@@ -1216,7 +1215,7 @@ more:
1216 } 1215 }
1217 } 1216 }
1218 1217
1219 if ((skip = perf_session__process_event(self, event, tool, head)) < 0) { 1218 if ((skip = perf_session__process_event(session, event, tool, head)) < 0) {
1220 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n", 1219 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
1221 head, event->header.size, event->header.type); 1220 head, event->header.size, event->header.type);
1222 err = -EINVAL; 1221 err = -EINVAL;
@@ -1232,12 +1231,12 @@ more:
1232 goto more; 1231 goto more;
1233done: 1232done:
1234 /* do the final flush for ordered samples */ 1233 /* do the final flush for ordered samples */
1235 self->ordered_samples.next_flush = ULLONG_MAX; 1234 session->ordered_samples.next_flush = ULLONG_MAX;
1236 err = flush_sample_queue(self, tool); 1235 err = flush_sample_queue(session, tool);
1237out_err: 1236out_err:
1238 free(buf); 1237 free(buf);
1239 perf_session__warn_about_errors(self, tool); 1238 perf_session__warn_about_errors(session, tool);
1240 perf_session_free_sample_buffers(self); 1239 perf_session_free_sample_buffers(session);
1241 return err; 1240 return err;
1242} 1241}
1243 1242
@@ -1377,22 +1376,22 @@ out_err:
1377 return err; 1376 return err;
1378} 1377}
1379 1378
1380int perf_session__process_events(struct perf_session *self, 1379int perf_session__process_events(struct perf_session *session,
1381 struct perf_tool *tool) 1380 struct perf_tool *tool)
1382{ 1381{
1383 u64 size = perf_data_file__size(self->file); 1382 u64 size = perf_data_file__size(session->file);
1384 int err; 1383 int err;
1385 1384
1386 if (perf_session__register_idle_thread(self) == NULL) 1385 if (perf_session__register_idle_thread(session) == NULL)
1387 return -ENOMEM; 1386 return -ENOMEM;
1388 1387
1389 if (!perf_data_file__is_pipe(self->file)) 1388 if (!perf_data_file__is_pipe(session->file))
1390 err = __perf_session__process_events(self, 1389 err = __perf_session__process_events(session,
1391 self->header.data_offset, 1390 session->header.data_offset,
1392 self->header.data_size, 1391 session->header.data_size,
1393 size, tool); 1392 size, tool);
1394 else 1393 else
1395 err = __perf_session__process_pipe_events(self, tool); 1394 err = __perf_session__process_pipe_events(session, tool);
1396 1395
1397 return err; 1396 return err;
1398} 1397}
@@ -1441,15 +1440,15 @@ int maps__set_kallsyms_ref_reloc_sym(struct map **maps,
1441 return 0; 1440 return 0;
1442} 1441}
1443 1442
1444size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) 1443size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp)
1445{ 1444{
1446 return machines__fprintf_dsos(&self->machines, fp); 1445 return machines__fprintf_dsos(&session->machines, fp);
1447} 1446}
1448 1447
1449size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, 1448size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
1450 bool (skip)(struct dso *dso, int parm), int parm) 1449 bool (skip)(struct dso *dso, int parm), int parm)
1451{ 1450{
1452 return machines__fprintf_dsos_buildid(&self->machines, fp, skip, parm); 1451 return machines__fprintf_dsos_buildid(&session->machines, fp, skip, parm);
1453} 1452}
1454 1453
1455size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) 1454size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 27c74d38b868..50f640958f0f 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -51,12 +51,12 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
51 bool repipe, struct perf_tool *tool); 51 bool repipe, struct perf_tool *tool);
52void perf_session__delete(struct perf_session *session); 52void perf_session__delete(struct perf_session *session);
53 53
54void perf_event_header__bswap(struct perf_event_header *self); 54void perf_event_header__bswap(struct perf_event_header *hdr);
55 55
56int __perf_session__process_events(struct perf_session *self, 56int __perf_session__process_events(struct perf_session *session,
57 u64 data_offset, u64 data_size, u64 size, 57 u64 data_offset, u64 data_size, u64 size,
58 struct perf_tool *tool); 58 struct perf_tool *tool);
59int perf_session__process_events(struct perf_session *self, 59int perf_session__process_events(struct perf_session *session,
60 struct perf_tool *tool); 60 struct perf_tool *tool);
61 61
62int perf_session_queue_event(struct perf_session *s, union perf_event *event, 62int perf_session_queue_event(struct perf_session *s, union perf_event *event,
@@ -64,37 +64,38 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
64 64
65void perf_tool__fill_defaults(struct perf_tool *tool); 65void perf_tool__fill_defaults(struct perf_tool *tool);
66 66
67int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel *evsel, 67int perf_session__resolve_callchain(struct perf_session *session,
68 struct perf_evsel *evsel,
68 struct thread *thread, 69 struct thread *thread,
69 struct ip_callchain *chain, 70 struct ip_callchain *chain,
70 struct symbol **parent); 71 struct symbol **parent);
71 72
72bool perf_session__has_traces(struct perf_session *self, const char *msg); 73bool perf_session__has_traces(struct perf_session *session, const char *msg);
73 74
74void mem_bswap_64(void *src, int byte_size); 75void mem_bswap_64(void *src, int byte_size);
75void mem_bswap_32(void *src, int byte_size); 76void mem_bswap_32(void *src, int byte_size);
76void perf_event__attr_swap(struct perf_event_attr *attr); 77void perf_event__attr_swap(struct perf_event_attr *attr);
77 78
78int perf_session__create_kernel_maps(struct perf_session *self); 79int perf_session__create_kernel_maps(struct perf_session *session);
79 80
80void perf_session__set_id_hdr_size(struct perf_session *session); 81void perf_session__set_id_hdr_size(struct perf_session *session);
81 82
82static inline 83static inline
83struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) 84struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid)
84{ 85{
85 return machines__find(&self->machines, pid); 86 return machines__find(&session->machines, pid);
86} 87}
87 88
88static inline 89static inline
89struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) 90struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid)
90{ 91{
91 return machines__findnew(&self->machines, pid); 92 return machines__findnew(&session->machines, pid);
92} 93}
93 94
94struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); 95struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
95size_t perf_session__fprintf(struct perf_session *self, FILE *fp); 96size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
96 97
97size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); 98size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
98 99
99size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp, 100size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
100 bool (fn)(struct dso *dso, int parm), int parm); 101 bool (fn)(struct dso *dso, int parm), int parm);
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index f4e16f359d64..f4cc147e0220 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -180,7 +180,7 @@ struct sort_entry {
180 180
181 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); 181 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
182 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); 182 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
183 int (*se_snprintf)(struct hist_entry *self, char *bf, size_t size, 183 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
184 unsigned int width); 184 unsigned int width);
185 u8 se_width_idx; 185 u8 se_width_idx;
186 bool elide; 186 bool elide;
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index 67e4a0082822..3edd0538161f 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -62,15 +62,15 @@ static struct strfilter_node *strfilter_node__alloc(const char *op,
62 struct strfilter_node *l, 62 struct strfilter_node *l,
63 struct strfilter_node *r) 63 struct strfilter_node *r)
64{ 64{
65 struct strfilter_node *ret = zalloc(sizeof(struct strfilter_node)); 65 struct strfilter_node *node = zalloc(sizeof(*node));
66 66
67 if (ret) { 67 if (node) {
68 ret->p = op; 68 node->p = op;
69 ret->l = l; 69 node->l = l;
70 ret->r = r; 70 node->r = r;
71 } 71 }
72 72
73 return ret; 73 return node;
74} 74}
75 75
76static struct strfilter_node *strfilter_node__new(const char *s, 76static struct strfilter_node *strfilter_node__new(const char *s,
@@ -154,20 +154,20 @@ error:
154 */ 154 */
155struct strfilter *strfilter__new(const char *rules, const char **err) 155struct strfilter *strfilter__new(const char *rules, const char **err)
156{ 156{
157 struct strfilter *ret = zalloc(sizeof(struct strfilter)); 157 struct strfilter *filter = zalloc(sizeof(*filter));
158 const char *ep = NULL; 158 const char *ep = NULL;
159 159
160 if (ret) 160 if (filter)
161 ret->root = strfilter_node__new(rules, &ep); 161 filter->root = strfilter_node__new(rules, &ep);
162 162
163 if (!ret || !ret->root || *ep != '\0') { 163 if (!filter || !filter->root || *ep != '\0') {
164 if (err) 164 if (err)
165 *err = ep; 165 *err = ep;
166 strfilter__delete(ret); 166 strfilter__delete(filter);
167 ret = NULL; 167 filter = NULL;
168 } 168 }
169 169
170 return ret; 170 return filter;
171} 171}
172 172
173static bool strfilter_node__compare(struct strfilter_node *node, 173static bool strfilter_node__compare(struct strfilter_node *node,
@@ -191,9 +191,9 @@ static bool strfilter_node__compare(struct strfilter_node *node,
191} 191}
192 192
193/* Return true if STR matches the filter rules */ 193/* Return true if STR matches the filter rules */
194bool strfilter__compare(struct strfilter *node, const char *str) 194bool strfilter__compare(struct strfilter *filter, const char *str)
195{ 195{
196 if (!node) 196 if (!filter)
197 return false; 197 return false;
198 return strfilter_node__compare(node->root, str); 198 return strfilter_node__compare(filter->root, str);
199} 199}
diff --git a/tools/perf/util/strfilter.h b/tools/perf/util/strfilter.h
index 00f58a7506de..fe611f3c9e39 100644
--- a/tools/perf/util/strfilter.h
+++ b/tools/perf/util/strfilter.h
@@ -30,19 +30,19 @@ struct strfilter *strfilter__new(const char *rules, const char **err);
30 30
31/** 31/**
32 * strfilter__compare - compare given string and a string filter 32 * strfilter__compare - compare given string and a string filter
33 * @self: String filter 33 * @filter: String filter
34 * @str: target string 34 * @str: target string
35 * 35 *
36 * Compare @str and @self. Return true if the str match the rule 36 * Compare @str and @filter. Return true if the str match the rule
37 */ 37 */
38bool strfilter__compare(struct strfilter *self, const char *str); 38bool strfilter__compare(struct strfilter *filter, const char *str);
39 39
40/** 40/**
41 * strfilter__delete - delete a string filter 41 * strfilter__delete - delete a string filter
42 * @self: String filter to delete 42 * @filter: String filter to delete
43 * 43 *
44 * Delete @self. 44 * Delete @filter.
45 */ 45 */
46void strfilter__delete(struct strfilter *self); 46void strfilter__delete(struct strfilter *filter);
47 47
48#endif 48#endif
diff --git a/tools/perf/util/sysfs.c b/tools/perf/util/sysfs.c
deleted file mode 100644
index f71e9eafe15a..000000000000
--- a/tools/perf/util/sysfs.c
+++ /dev/null
@@ -1,60 +0,0 @@
1
2#include "util.h"
3#include "sysfs.h"
4
5static const char * const sysfs_known_mountpoints[] = {
6 "/sys",
7 0,
8};
9
10static int sysfs_found;
11char sysfs_mountpoint[PATH_MAX + 1];
12
13static int sysfs_valid_mountpoint(const char *sysfs)
14{
15 struct statfs st_fs;
16
17 if (statfs(sysfs, &st_fs) < 0)
18 return -ENOENT;
19 else if (st_fs.f_type != (long) SYSFS_MAGIC)
20 return -ENOENT;
21
22 return 0;
23}
24
25const char *sysfs_find_mountpoint(void)
26{
27 const char * const *ptr;
28 char type[100];
29 FILE *fp;
30
31 if (sysfs_found)
32 return (const char *) sysfs_mountpoint;
33
34 ptr = sysfs_known_mountpoints;
35 while (*ptr) {
36 if (sysfs_valid_mountpoint(*ptr) == 0) {
37 sysfs_found = 1;
38 strcpy(sysfs_mountpoint, *ptr);
39 return sysfs_mountpoint;
40 }
41 ptr++;
42 }
43
44 /* give up and parse /proc/mounts */
45 fp = fopen("/proc/mounts", "r");
46 if (fp == NULL)
47 return NULL;
48
49 while (!sysfs_found &&
50 fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
51 sysfs_mountpoint, type) == 2) {
52
53 if (strcmp(type, "sysfs") == 0)
54 sysfs_found = 1;
55 }
56
57 fclose(fp);
58
59 return sysfs_found ? sysfs_mountpoint : NULL;
60}
diff --git a/tools/perf/util/sysfs.h b/tools/perf/util/sysfs.h
deleted file mode 100644
index a813b7203938..000000000000
--- a/tools/perf/util/sysfs.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef __SYSFS_H__
2#define __SYSFS_H__
3
4const char *sysfs_find_mountpoint(void);
5
6#endif /* __DEBUGFS_H__ */
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 373c055989ed..897c1b2a750a 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -29,24 +29,24 @@ struct machine;
29struct comm; 29struct comm;
30 30
31struct thread *thread__new(pid_t pid, pid_t tid); 31struct thread *thread__new(pid_t pid, pid_t tid);
32void thread__delete(struct thread *self); 32void thread__delete(struct thread *thread);
33static inline void thread__exited(struct thread *thread) 33static inline void thread__exited(struct thread *thread)
34{ 34{
35 thread->dead = true; 35 thread->dead = true;
36} 36}
37 37
38int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp); 38int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
39int thread__comm_len(struct thread *self); 39int thread__comm_len(struct thread *thread);
40struct comm *thread__comm(const struct thread *thread); 40struct comm *thread__comm(const struct thread *thread);
41const char *thread__comm_str(const struct thread *thread); 41const char *thread__comm_str(const struct thread *thread);
42void thread__insert_map(struct thread *self, struct map *map); 42void thread__insert_map(struct thread *thread, struct map *map);
43int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); 43int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
44size_t thread__fprintf(struct thread *thread, FILE *fp); 44size_t thread__fprintf(struct thread *thread, FILE *fp);
45 45
46static inline struct map *thread__find_map(struct thread *self, 46static inline struct map *thread__find_map(struct thread *thread,
47 enum map_type type, u64 addr) 47 enum map_type type, u64 addr)
48{ 48{
49 return self ? map_groups__find(&self->mg, type, addr) : NULL; 49 return thread ? map_groups__find(&thread->mg, type, addr) : NULL;
50} 50}
51 51
52void thread__find_addr_map(struct thread *thread, struct machine *machine, 52void thread__find_addr_map(struct thread *thread, struct machine *machine,