diff options
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r-- | tools/perf/builtin-record.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index edc3555098c8..07f8d6d852c2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -42,7 +42,6 @@ static u64 user_interval = ULLONG_MAX; | |||
42 | static u64 default_interval = 0; | 42 | static u64 default_interval = 0; |
43 | static u64 sample_type; | 43 | static u64 sample_type; |
44 | 44 | ||
45 | static struct cpu_map *cpus; | ||
46 | static unsigned int page_size; | 45 | static unsigned int page_size; |
47 | static unsigned int mmap_pages = 128; | 46 | static unsigned int mmap_pages = 128; |
48 | static unsigned int user_freq = UINT_MAX; | 47 | static unsigned int user_freq = UINT_MAX; |
@@ -58,7 +57,6 @@ static bool sample_id_all_avail = true; | |||
58 | static bool system_wide = false; | 57 | static bool system_wide = false; |
59 | static pid_t target_pid = -1; | 58 | static pid_t target_pid = -1; |
60 | static pid_t target_tid = -1; | 59 | static pid_t target_tid = -1; |
61 | static struct thread_map *threads; | ||
62 | static pid_t child_pid = -1; | 60 | static pid_t child_pid = -1; |
63 | static bool no_inherit = false; | 61 | static bool no_inherit = false; |
64 | static enum write_mode_t write_mode = WRITE_FORCE; | 62 | static enum write_mode_t write_mode = WRITE_FORCE; |
@@ -189,7 +187,7 @@ static void create_counter(struct perf_evsel *evsel, int cpu) | |||
189 | int thread_index; | 187 | int thread_index; |
190 | int ret; | 188 | int ret; |
191 | 189 | ||
192 | for (thread_index = 0; thread_index < threads->nr; thread_index++) { | 190 | for (thread_index = 0; thread_index < evsel_list->threads->nr; thread_index++) { |
193 | h_attr = get_header_attr(attr, evsel->idx); | 191 | h_attr = get_header_attr(attr, evsel->idx); |
194 | if (h_attr == NULL) | 192 | if (h_attr == NULL) |
195 | die("nomem\n"); | 193 | die("nomem\n"); |
@@ -317,7 +315,8 @@ static void open_counters(struct perf_evlist *evlist) | |||
317 | retry_sample_id: | 315 | retry_sample_id: |
318 | attr->sample_id_all = sample_id_all_avail ? 1 : 0; | 316 | attr->sample_id_all = sample_id_all_avail ? 1 : 0; |
319 | try_again: | 317 | try_again: |
320 | if (perf_evsel__open(pos, cpus, threads, group, !no_inherit) < 0) { | 318 | if (perf_evsel__open(pos, evlist->cpus, evlist->threads, group, |
319 | !no_inherit) < 0) { | ||
321 | int err = errno; | 320 | int err = errno; |
322 | 321 | ||
323 | if (err == EPERM || err == EACCES) | 322 | if (err == EPERM || err == EACCES) |
@@ -368,10 +367,10 @@ try_again: | |||
368 | } | 367 | } |
369 | } | 368 | } |
370 | 369 | ||
371 | if (perf_evlist__mmap(evlist, cpus, threads, mmap_pages, false) < 0) | 370 | if (perf_evlist__mmap(evlist, mmap_pages, false) < 0) |
372 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 371 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
373 | 372 | ||
374 | for (cpu = 0; cpu < cpus->nr; ++cpu) { | 373 | for (cpu = 0; cpu < evsel_list->cpus->nr; ++cpu) { |
375 | list_for_each_entry(pos, &evlist->entries, node) | 374 | list_for_each_entry(pos, &evlist->entries, node) |
376 | create_counter(pos, cpu); | 375 | create_counter(pos, cpu); |
377 | } | 376 | } |
@@ -450,7 +449,7 @@ static void mmap_read_all(void) | |||
450 | { | 449 | { |
451 | int i; | 450 | int i; |
452 | 451 | ||
453 | for (i = 0; i < cpus->nr; i++) { | 452 | for (i = 0; i < evsel_list->cpus->nr; i++) { |
454 | if (evsel_list->mmap[i].base) | 453 | if (evsel_list->mmap[i].base) |
455 | mmap_read(&evsel_list->mmap[i]); | 454 | mmap_read(&evsel_list->mmap[i]); |
456 | } | 455 | } |
@@ -584,7 +583,7 @@ static int __cmd_record(int argc, const char **argv) | |||
584 | } | 583 | } |
585 | 584 | ||
586 | if (!system_wide && target_tid == -1 && target_pid == -1) | 585 | if (!system_wide && target_tid == -1 && target_pid == -1) |
587 | threads->map[0] = child_pid; | 586 | evsel_list->threads->map[0] = child_pid; |
588 | 587 | ||
589 | close(child_ready_pipe[1]); | 588 | close(child_ready_pipe[1]); |
590 | close(go_pipe[0]); | 589 | close(go_pipe[0]); |
@@ -718,12 +717,12 @@ static int __cmd_record(int argc, const char **argv) | |||
718 | } | 717 | } |
719 | 718 | ||
720 | if (done) { | 719 | if (done) { |
721 | for (i = 0; i < cpus->nr; i++) { | 720 | for (i = 0; i < evsel_list->cpus->nr; i++) { |
722 | struct perf_evsel *pos; | 721 | struct perf_evsel *pos; |
723 | 722 | ||
724 | list_for_each_entry(pos, &evsel_list->entries, node) { | 723 | list_for_each_entry(pos, &evsel_list->entries, node) { |
725 | for (thread = 0; | 724 | for (thread = 0; |
726 | thread < threads->nr; | 725 | thread < evsel_list->threads->nr; |
727 | thread++) | 726 | thread++) |
728 | ioctl(FD(pos, i, thread), | 727 | ioctl(FD(pos, i, thread), |
729 | PERF_EVENT_IOC_DISABLE); | 728 | PERF_EVENT_IOC_DISABLE); |
@@ -816,7 +815,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
816 | int err = -ENOMEM; | 815 | int err = -ENOMEM; |
817 | struct perf_evsel *pos; | 816 | struct perf_evsel *pos; |
818 | 817 | ||
819 | evsel_list = perf_evlist__new(); | 818 | evsel_list = perf_evlist__new(NULL, NULL); |
820 | if (evsel_list == NULL) | 819 | if (evsel_list == NULL) |
821 | return -ENOMEM; | 820 | return -ENOMEM; |
822 | 821 | ||
@@ -850,28 +849,19 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
850 | if (target_pid != -1) | 849 | if (target_pid != -1) |
851 | target_tid = target_pid; | 850 | target_tid = target_pid; |
852 | 851 | ||
853 | threads = thread_map__new(target_pid, target_tid); | 852 | if (perf_evlist__create_maps(evsel_list, target_pid, |
854 | if (threads == NULL) { | 853 | target_tid, cpu_list) < 0) |
855 | pr_err("Problems finding threads of monitor\n"); | ||
856 | usage_with_options(record_usage, record_options); | ||
857 | } | ||
858 | |||
859 | if (target_tid != -1) | ||
860 | cpus = cpu_map__dummy_new(); | ||
861 | else | ||
862 | cpus = cpu_map__new(cpu_list); | ||
863 | |||
864 | if (cpus == NULL) | ||
865 | usage_with_options(record_usage, record_options); | 854 | usage_with_options(record_usage, record_options); |
866 | 855 | ||
867 | list_for_each_entry(pos, &evsel_list->entries, node) { | 856 | list_for_each_entry(pos, &evsel_list->entries, node) { |
868 | if (perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0) | 857 | if (perf_evsel__alloc_fd(pos, evsel_list->cpus->nr, |
858 | evsel_list->threads->nr) < 0) | ||
869 | goto out_free_fd; | 859 | goto out_free_fd; |
870 | if (perf_header__push_event(pos->attr.config, event_name(pos))) | 860 | if (perf_header__push_event(pos->attr.config, event_name(pos))) |
871 | goto out_free_fd; | 861 | goto out_free_fd; |
872 | } | 862 | } |
873 | 863 | ||
874 | if (perf_evlist__alloc_pollfd(evsel_list, cpus->nr, threads->nr) < 0) | 864 | if (perf_evlist__alloc_pollfd(evsel_list) < 0) |
875 | goto out_free_fd; | 865 | goto out_free_fd; |
876 | 866 | ||
877 | if (user_interval != ULLONG_MAX) | 867 | if (user_interval != ULLONG_MAX) |
@@ -893,10 +883,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
893 | } | 883 | } |
894 | 884 | ||
895 | err = __cmd_record(argc, argv); | 885 | err = __cmd_record(argc, argv); |
896 | |||
897 | out_free_fd: | 886 | out_free_fd: |
898 | thread_map__delete(threads); | 887 | perf_evlist__delete_maps(evsel_list); |
899 | threads = NULL; | ||
900 | out_symbol_exit: | 888 | out_symbol_exit: |
901 | symbol__exit(); | 889 | symbol__exit(); |
902 | return err; | 890 | return err; |