diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-04-26 01:15:15 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-02 14:17:58 -0400 |
commit | bea0340582dc47b447a014f5bf9f460925afdaf4 (patch) | |
tree | 0fe4a6fe7b287367b127ac7394086ff0c913588a /tools | |
parent | c651214e90e5c150015f7524a6bfc298ad61435f (diff) |
perf tools: Introduce struct perf_target
The perf_target struct will be used for taking care of cpu/thread maps
based on user's input. Since it is used on various subcommands it'd
better factoring it out.
Thanks to Arnaldo for suggesting the better name.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1335417327-11796-2-git-send-email-namhyung.kim@lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-record.c | 41 | ||||
-rw-r--r-- | tools/perf/builtin-test.c | 5 | ||||
-rw-r--r-- | tools/perf/perf.h | 15 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 2 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 10 |
5 files changed, 41 insertions, 32 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 10b1f1f25ed7..4dcf27057bd2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -44,7 +44,6 @@ struct perf_record { | |||
44 | struct perf_evlist *evlist; | 44 | struct perf_evlist *evlist; |
45 | struct perf_session *session; | 45 | struct perf_session *session; |
46 | const char *progname; | 46 | const char *progname; |
47 | const char *uid_str; | ||
48 | int output; | 47 | int output; |
49 | unsigned int page_size; | 48 | unsigned int page_size; |
50 | int realtime_prio; | 49 | int realtime_prio; |
@@ -218,7 +217,7 @@ try_again: | |||
218 | if (err == EPERM || err == EACCES) { | 217 | if (err == EPERM || err == EACCES) { |
219 | ui__error_paranoid(); | 218 | ui__error_paranoid(); |
220 | exit(EXIT_FAILURE); | 219 | exit(EXIT_FAILURE); |
221 | } else if (err == ENODEV && opts->cpu_list) { | 220 | } else if (err == ENODEV && opts->target.cpu_list) { |
222 | die("No such device - did you specify" | 221 | die("No such device - did you specify" |
223 | " an out-of-range profile CPU?\n"); | 222 | " an out-of-range profile CPU?\n"); |
224 | } else if (err == EINVAL) { | 223 | } else if (err == EINVAL) { |
@@ -578,7 +577,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) | |||
578 | perf_session__process_machines(session, tool, | 577 | perf_session__process_machines(session, tool, |
579 | perf_event__synthesize_guest_os); | 578 | perf_event__synthesize_guest_os); |
580 | 579 | ||
581 | if (!opts->system_wide) | 580 | if (!opts->target.system_wide) |
582 | perf_event__synthesize_thread_map(tool, evsel_list->threads, | 581 | perf_event__synthesize_thread_map(tool, evsel_list->threads, |
583 | process_synthesized_event, | 582 | process_synthesized_event, |
584 | machine); | 583 | machine); |
@@ -765,9 +764,9 @@ const struct option record_options[] = { | |||
765 | parse_events_option), | 764 | parse_events_option), |
766 | OPT_CALLBACK(0, "filter", &record.evlist, "filter", | 765 | OPT_CALLBACK(0, "filter", &record.evlist, "filter", |
767 | "event filter", parse_filter), | 766 | "event filter", parse_filter), |
768 | OPT_STRING('p', "pid", &record.opts.target_pid, "pid", | 767 | OPT_STRING('p', "pid", &record.opts.target.pid, "pid", |
769 | "record events on existing process id"), | 768 | "record events on existing process id"), |
770 | OPT_STRING('t', "tid", &record.opts.target_tid, "tid", | 769 | OPT_STRING('t', "tid", &record.opts.target.tid, "tid", |
771 | "record events on existing thread id"), | 770 | "record events on existing thread id"), |
772 | OPT_INTEGER('r', "realtime", &record.realtime_prio, | 771 | OPT_INTEGER('r', "realtime", &record.realtime_prio, |
773 | "collect data with this RT SCHED_FIFO priority"), | 772 | "collect data with this RT SCHED_FIFO priority"), |
@@ -775,11 +774,11 @@ const struct option record_options[] = { | |||
775 | "collect data without buffering"), | 774 | "collect data without buffering"), |
776 | OPT_BOOLEAN('R', "raw-samples", &record.opts.raw_samples, | 775 | OPT_BOOLEAN('R', "raw-samples", &record.opts.raw_samples, |
777 | "collect raw sample records from all opened counters"), | 776 | "collect raw sample records from all opened counters"), |
778 | OPT_BOOLEAN('a', "all-cpus", &record.opts.system_wide, | 777 | OPT_BOOLEAN('a', "all-cpus", &record.opts.target.system_wide, |
779 | "system-wide collection from all CPUs"), | 778 | "system-wide collection from all CPUs"), |
780 | OPT_BOOLEAN('A', "append", &record.append_file, | 779 | OPT_BOOLEAN('A', "append", &record.append_file, |
781 | "append to the output file to do incremental profiling"), | 780 | "append to the output file to do incremental profiling"), |
782 | OPT_STRING('C', "cpu", &record.opts.cpu_list, "cpu", | 781 | OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", |
783 | "list of cpus to monitor"), | 782 | "list of cpus to monitor"), |
784 | OPT_BOOLEAN('f', "force", &record.force, | 783 | OPT_BOOLEAN('f', "force", &record.force, |
785 | "overwrite existing data file (deprecated)"), | 784 | "overwrite existing data file (deprecated)"), |
@@ -813,7 +812,8 @@ const struct option record_options[] = { | |||
813 | OPT_CALLBACK('G', "cgroup", &record.evlist, "name", | 812 | OPT_CALLBACK('G', "cgroup", &record.evlist, "name", |
814 | "monitor event in cgroup name only", | 813 | "monitor event in cgroup name only", |
815 | parse_cgroups), | 814 | parse_cgroups), |
816 | OPT_STRING('u', "uid", &record.uid_str, "user", "user to profile"), | 815 | OPT_STRING('u', "uid", &record.opts.target.uid_str, "user", |
816 | "user to profile"), | ||
817 | 817 | ||
818 | OPT_CALLBACK_NOOPT('b', "branch-any", &record.opts.branch_stack, | 818 | OPT_CALLBACK_NOOPT('b', "branch-any", &record.opts.branch_stack, |
819 | "branch any", "sample any taken branches", | 819 | "branch any", "sample any taken branches", |
@@ -842,8 +842,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
842 | 842 | ||
843 | argc = parse_options(argc, argv, record_options, record_usage, | 843 | argc = parse_options(argc, argv, record_options, record_usage, |
844 | PARSE_OPT_STOP_AT_NON_OPTION); | 844 | PARSE_OPT_STOP_AT_NON_OPTION); |
845 | if (!argc && !rec->opts.target_pid && !rec->opts.target_tid && | 845 | if (!argc && !rec->opts.target.pid && !rec->opts.target.tid && |
846 | !rec->opts.system_wide && !rec->opts.cpu_list && !rec->uid_str) | 846 | !rec->opts.target.system_wide && !rec->opts.target.cpu_list && |
847 | !rec->opts.target.uid_str) | ||
847 | usage_with_options(record_usage, record_options); | 848 | usage_with_options(record_usage, record_options); |
848 | 849 | ||
849 | if (rec->force && rec->append_file) { | 850 | if (rec->force && rec->append_file) { |
@@ -856,7 +857,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
856 | rec->write_mode = WRITE_FORCE; | 857 | rec->write_mode = WRITE_FORCE; |
857 | } | 858 | } |
858 | 859 | ||
859 | if (nr_cgroups && !rec->opts.system_wide) { | 860 | if (nr_cgroups && !rec->opts.target.system_wide) { |
860 | fprintf(stderr, "cgroup monitoring only available in" | 861 | fprintf(stderr, "cgroup monitoring only available in" |
861 | " system-wide mode\n"); | 862 | " system-wide mode\n"); |
862 | usage_with_options(record_usage, record_options); | 863 | usage_with_options(record_usage, record_options); |
@@ -883,17 +884,19 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
883 | goto out_symbol_exit; | 884 | goto out_symbol_exit; |
884 | } | 885 | } |
885 | 886 | ||
886 | rec->opts.uid = parse_target_uid(rec->uid_str, rec->opts.target_tid, | 887 | rec->opts.target.uid = parse_target_uid(rec->opts.target.uid_str, |
887 | rec->opts.target_pid); | 888 | rec->opts.target.tid, |
888 | if (rec->uid_str != NULL && rec->opts.uid == UINT_MAX - 1) | 889 | rec->opts.target.pid); |
890 | if (rec->opts.target.uid_str != NULL && | ||
891 | rec->opts.target.uid == UINT_MAX - 1) | ||
889 | goto out_free_fd; | 892 | goto out_free_fd; |
890 | 893 | ||
891 | if (rec->opts.target_pid) | 894 | if (rec->opts.target.pid) |
892 | rec->opts.target_tid = rec->opts.target_pid; | 895 | rec->opts.target.tid = rec->opts.target.pid; |
893 | 896 | ||
894 | if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid, | 897 | if (perf_evlist__create_maps(evsel_list, rec->opts.target.pid, |
895 | rec->opts.target_tid, rec->opts.uid, | 898 | rec->opts.target.tid, rec->opts.target.uid, |
896 | rec->opts.cpu_list) < 0) | 899 | rec->opts.target.cpu_list) < 0) |
897 | usage_with_options(record_usage, record_options); | 900 | usage_with_options(record_usage, record_options); |
898 | 901 | ||
899 | list_for_each_entry(pos, &evsel_list->entries, node) { | 902 | list_for_each_entry(pos, &evsel_list->entries, node) { |
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 5502a4a2a4f6..27882d86e9ab 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -1207,8 +1207,9 @@ static int test__PERF_RECORD(void) | |||
1207 | * perf_evlist__prepare_workload we'll fill in the only thread | 1207 | * perf_evlist__prepare_workload we'll fill in the only thread |
1208 | * we're monitoring, the one forked there. | 1208 | * we're monitoring, the one forked there. |
1209 | */ | 1209 | */ |
1210 | err = perf_evlist__create_maps(evlist, opts.target_pid, | 1210 | err = perf_evlist__create_maps(evlist, opts.target.pid, |
1211 | opts.target_tid, UINT_MAX, opts.cpu_list); | 1211 | opts.target.tid, UINT_MAX, |
1212 | opts.target.cpu_list); | ||
1212 | if (err < 0) { | 1213 | if (err < 0) { |
1213 | pr_debug("Not enough memory to create thread/cpu maps\n"); | 1214 | pr_debug("Not enough memory to create thread/cpu maps\n"); |
1214 | goto out_delete_evlist; | 1215 | goto out_delete_evlist; |
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 89e3355ab173..7e226c0e0e31 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -207,10 +207,17 @@ extern const char perf_version_string[]; | |||
207 | 207 | ||
208 | void pthread__unblock_sigwinch(void); | 208 | void pthread__unblock_sigwinch(void); |
209 | 209 | ||
210 | struct perf_record_opts { | 210 | struct perf_target { |
211 | const char *target_pid; | 211 | const char *pid; |
212 | const char *target_tid; | 212 | const char *tid; |
213 | const char *cpu_list; | ||
214 | const char *uid_str; | ||
213 | uid_t uid; | 215 | uid_t uid; |
216 | bool system_wide; | ||
217 | }; | ||
218 | |||
219 | struct perf_record_opts { | ||
220 | struct perf_target target; | ||
214 | bool call_graph; | 221 | bool call_graph; |
215 | bool group; | 222 | bool group; |
216 | bool inherit_stat; | 223 | bool inherit_stat; |
@@ -223,7 +230,6 @@ struct perf_record_opts { | |||
223 | bool sample_time; | 230 | bool sample_time; |
224 | bool sample_id_all_missing; | 231 | bool sample_id_all_missing; |
225 | bool exclude_guest_missing; | 232 | bool exclude_guest_missing; |
226 | bool system_wide; | ||
227 | bool period; | 233 | bool period; |
228 | unsigned int freq; | 234 | unsigned int freq; |
229 | unsigned int mmap_pages; | 235 | unsigned int mmap_pages; |
@@ -231,7 +237,6 @@ struct perf_record_opts { | |||
231 | int branch_stack; | 237 | int branch_stack; |
232 | u64 default_interval; | 238 | u64 default_interval; |
233 | u64 user_interval; | 239 | u64 user_interval; |
234 | const char *cpu_list; | ||
235 | }; | 240 | }; |
236 | 241 | ||
237 | #endif | 242 | #endif |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 1986d8051bd1..7080901a2717 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -827,7 +827,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, | |||
827 | exit(-1); | 827 | exit(-1); |
828 | } | 828 | } |
829 | 829 | ||
830 | if (!opts->system_wide && !opts->target_tid && !opts->target_pid) | 830 | if (!opts->target.system_wide && !opts->target.tid && !opts->target.pid) |
831 | evlist->threads->map[0] = evlist->workload.pid; | 831 | evlist->threads->map[0] = evlist->workload.pid; |
832 | 832 | ||
833 | close(child_ready_pipe[1]); | 833 | close(child_ready_pipe[1]); |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8c13dbcb84b9..d90598edcf1d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -106,15 +106,15 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | |||
106 | if (opts->call_graph) | 106 | if (opts->call_graph) |
107 | attr->sample_type |= PERF_SAMPLE_CALLCHAIN; | 107 | attr->sample_type |= PERF_SAMPLE_CALLCHAIN; |
108 | 108 | ||
109 | if (opts->system_wide) | 109 | if (opts->target.system_wide) |
110 | attr->sample_type |= PERF_SAMPLE_CPU; | 110 | attr->sample_type |= PERF_SAMPLE_CPU; |
111 | 111 | ||
112 | if (opts->period) | 112 | if (opts->period) |
113 | attr->sample_type |= PERF_SAMPLE_PERIOD; | 113 | attr->sample_type |= PERF_SAMPLE_PERIOD; |
114 | 114 | ||
115 | if (!opts->sample_id_all_missing && | 115 | if (!opts->sample_id_all_missing && |
116 | (opts->sample_time || opts->system_wide || | 116 | (opts->sample_time || opts->target.system_wide || |
117 | !opts->no_inherit || opts->cpu_list)) | 117 | !opts->no_inherit || opts->target.cpu_list)) |
118 | attr->sample_type |= PERF_SAMPLE_TIME; | 118 | attr->sample_type |= PERF_SAMPLE_TIME; |
119 | 119 | ||
120 | if (opts->raw_samples) { | 120 | if (opts->raw_samples) { |
@@ -135,8 +135,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | |||
135 | attr->mmap = track; | 135 | attr->mmap = track; |
136 | attr->comm = track; | 136 | attr->comm = track; |
137 | 137 | ||
138 | if (!opts->target_pid && !opts->target_tid && !opts->system_wide && | 138 | if (!opts->target.pid && !opts->target.tid && |
139 | (!opts->group || evsel == first)) { | 139 | !opts->target.system_wide && (!opts->group || evsel == first)) { |
140 | attr->disabled = 1; | 140 | attr->disabled = 1; |
141 | attr->enable_on_exec = 1; | 141 | attr->enable_on_exec = 1; |
142 | } | 142 | } |