Skip to content

Commit d1e169d

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Includes smaller fixes and improvements plus the exclude_{host,guest} feature test and fallback to handle older kernels. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
2 parents f8d98f1 + 808e122 commit d1e169d

33 files changed

+616
-416
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ OPTIONS
5252

5353
-p::
5454
--pid=::
55-
Record events on existing process ID.
55+
Record events on existing process ID (comma separated list).
5656

5757
-t::
5858
--tid=::
59-
Record events on existing thread ID.
59+
Record events on existing thread ID (comma separated list).
6060

6161
-u::
6262
--uid=::

tools/perf/Documentation/perf-stat.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ OPTIONS
3535
child tasks do not inherit counters
3636
-p::
3737
--pid=<pid>::
38-
stat events on existing process id
38+
stat events on existing process id (comma separated list)
3939

4040
-t::
4141
--tid=<tid>::
42-
stat events on existing thread id
42+
stat events on existing thread id (comma separated list)
4343

4444

4545
-a::

tools/perf/Documentation/perf-top.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Default is to monitor all CPUS.
7272

7373
-p <pid>::
7474
--pid=<pid>::
75-
Profile events on existing Process ID.
75+
Profile events on existing Process ID (comma separated list).
7676

7777
-t <tid>::
7878
--tid=<tid>::
79-
Profile events on existing thread ID.
79+
Profile events on existing thread ID (comma separated list).
8080

8181
-u::
8282
--uid=::

tools/perf/MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ lib/rbtree.c
99
include/linux/swab.h
1010
arch/*/include/asm/unistd*.h
1111
arch/*/lib/memcpy*.S
12+
arch/*/lib/memset*.S
1213
include/linux/poison.h
1314
include/linux/magic.h
1415
include/linux/hw_breakpoint.h

tools/perf/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ SCRIPT_SH += perf-archive.sh
183183
grep-libs = $(filter -l%,$(1))
184184
strip-libs = $(filter-out -l%,$(1))
185185

186-
$(OUTPUT)python/perf.so: $(PYRF_OBJS)
186+
PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
187+
PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py
188+
189+
$(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
187190
$(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \
188191
--quiet build_ext; \
189192
mkdir -p $(OUTPUT)python && \
@@ -256,6 +259,7 @@ LIB_H += util/callchain.h
256259
LIB_H += util/build-id.h
257260
LIB_H += util/debug.h
258261
LIB_H += util/debugfs.h
262+
LIB_H += util/sysfs.h
259263
LIB_H += util/event.h
260264
LIB_H += util/evsel.h
261265
LIB_H += util/evlist.h
@@ -302,6 +306,7 @@ LIB_OBJS += $(OUTPUT)util/build-id.o
302306
LIB_OBJS += $(OUTPUT)util/config.o
303307
LIB_OBJS += $(OUTPUT)util/ctype.o
304308
LIB_OBJS += $(OUTPUT)util/debugfs.o
309+
LIB_OBJS += $(OUTPUT)util/sysfs.o
305310
LIB_OBJS += $(OUTPUT)util/environment.o
306311
LIB_OBJS += $(OUTPUT)util/event.o
307312
LIB_OBJS += $(OUTPUT)util/evlist.o

tools/perf/builtin-record.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ static void perf_record__open(struct perf_record *rec)
205205

206206
if (opts->group && pos != first)
207207
group_fd = first->fd;
208+
fallback_missing_features:
209+
if (opts->exclude_guest_missing)
210+
attr->exclude_guest = attr->exclude_host = 0;
208211
retry_sample_id:
209-
attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0;
212+
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
210213
try_again:
211214
if (perf_evsel__open(pos, evlist->cpus, evlist->threads,
212215
opts->group, group_fd) < 0) {
@@ -218,15 +221,23 @@ static void perf_record__open(struct perf_record *rec)
218221
} else if (err == ENODEV && opts->cpu_list) {
219222
die("No such device - did you specify"
220223
" an out-of-range profile CPU?\n");
221-
} else if (err == EINVAL && opts->sample_id_all_avail) {
222-
/*
223-
* Old kernel, no attr->sample_id_type_all field
224-
*/
225-
opts->sample_id_all_avail = false;
226-
if (!opts->sample_time && !opts->raw_samples && !time_needed)
227-
attr->sample_type &= ~PERF_SAMPLE_TIME;
228-
229-
goto retry_sample_id;
224+
} else if (err == EINVAL) {
225+
if (!opts->exclude_guest_missing &&
226+
(attr->exclude_guest || attr->exclude_host)) {
227+
pr_debug("Old kernel, cannot exclude "
228+
"guest or host samples.\n");
229+
opts->exclude_guest_missing = true;
230+
goto fallback_missing_features;
231+
} else if (!opts->sample_id_all_missing) {
232+
/*
233+
* Old kernel, no attr->sample_id_type_all field
234+
*/
235+
opts->sample_id_all_missing = true;
236+
if (!opts->sample_time && !opts->raw_samples && !time_needed)
237+
attr->sample_type &= ~PERF_SAMPLE_TIME;
238+
239+
goto retry_sample_id;
240+
}
230241
}
231242

232243
/*
@@ -494,9 +505,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
494505
return err;
495506
}
496507

497-
if (!!rec->no_buildid
508+
if (!rec->no_buildid
498509
&& !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) {
499-
pr_err("Couldn't generating buildids. "
510+
pr_err("Couldn't generate buildids. "
500511
"Use --no-buildid to profile anyway.\n");
501512
return -1;
502513
}
@@ -645,13 +656,10 @@ static const char * const record_usage[] = {
645656
*/
646657
static struct perf_record record = {
647658
.opts = {
648-
.target_pid = -1,
649-
.target_tid = -1,
650659
.mmap_pages = UINT_MAX,
651660
.user_freq = UINT_MAX,
652661
.user_interval = ULLONG_MAX,
653662
.freq = 1000,
654-
.sample_id_all_avail = true,
655663
},
656664
.write_mode = WRITE_FORCE,
657665
.file_new = true,
@@ -670,9 +678,9 @@ const struct option record_options[] = {
670678
parse_events_option),
671679
OPT_CALLBACK(0, "filter", &record.evlist, "filter",
672680
"event filter", parse_filter),
673-
OPT_INTEGER('p', "pid", &record.opts.target_pid,
681+
OPT_STRING('p', "pid", &record.opts.target_pid, "pid",
674682
"record events on existing process id"),
675-
OPT_INTEGER('t', "tid", &record.opts.target_tid,
683+
OPT_STRING('t', "tid", &record.opts.target_tid, "tid",
676684
"record events on existing thread id"),
677685
OPT_INTEGER('r', "realtime", &record.realtime_prio,
678686
"collect data with this RT SCHED_FIFO priority"),
@@ -739,7 +747,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
739747

740748
argc = parse_options(argc, argv, record_options, record_usage,
741749
PARSE_OPT_STOP_AT_NON_OPTION);
742-
if (!argc && rec->opts.target_pid == -1 && rec->opts.target_tid == -1 &&
750+
if (!argc && !rec->opts.target_pid && !rec->opts.target_tid &&
743751
!rec->opts.system_wide && !rec->opts.cpu_list && !rec->uid_str)
744752
usage_with_options(record_usage, record_options);
745753

@@ -785,7 +793,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
785793
if (rec->uid_str != NULL && rec->opts.uid == UINT_MAX - 1)
786794
goto out_free_fd;
787795

788-
if (rec->opts.target_pid != -1)
796+
if (rec->opts.target_pid)
789797
rec->opts.target_tid = rec->opts.target_pid;
790798

791799
if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid,

tools/perf/builtin-stat.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ static int run_count = 1;
182182
static bool no_inherit = false;
183183
static bool scale = true;
184184
static bool no_aggr = false;
185-
static pid_t target_pid = -1;
186-
static pid_t target_tid = -1;
185+
static const char *target_pid;
186+
static const char *target_tid;
187187
static pid_t child_pid = -1;
188188
static bool null_run = false;
189189
static int detailed_run = 0;
@@ -296,7 +296,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
296296
if (system_wide)
297297
return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
298298
group, group_fd);
299-
if (target_pid == -1 && target_tid == -1) {
299+
if (!target_pid && !target_tid) {
300300
attr->disabled = 1;
301301
attr->enable_on_exec = 1;
302302
}
@@ -446,7 +446,7 @@ static int run_perf_stat(int argc __used, const char **argv)
446446
exit(-1);
447447
}
448448

449-
if (target_tid == -1 && target_pid == -1 && !system_wide)
449+
if (!target_tid && !target_pid && !system_wide)
450450
evsel_list->threads->map[0] = child_pid;
451451

452452
/*
@@ -968,14 +968,14 @@ static void print_stat(int argc, const char **argv)
968968
if (!csv_output) {
969969
fprintf(output, "\n");
970970
fprintf(output, " Performance counter stats for ");
971-
if(target_pid == -1 && target_tid == -1) {
971+
if (!target_pid && !target_tid) {
972972
fprintf(output, "\'%s", argv[0]);
973973
for (i = 1; i < argc; i++)
974974
fprintf(output, " %s", argv[i]);
975-
} else if (target_pid != -1)
976-
fprintf(output, "process id \'%d", target_pid);
975+
} else if (target_pid)
976+
fprintf(output, "process id \'%s", target_pid);
977977
else
978-
fprintf(output, "thread id \'%d", target_tid);
978+
fprintf(output, "thread id \'%s", target_tid);
979979

980980
fprintf(output, "\'");
981981
if (run_count > 1)
@@ -1049,10 +1049,10 @@ static const struct option options[] = {
10491049
"event filter", parse_filter),
10501050
OPT_BOOLEAN('i', "no-inherit", &no_inherit,
10511051
"child tasks do not inherit counters"),
1052-
OPT_INTEGER('p', "pid", &target_pid,
1053-
"stat events on existing process id"),
1054-
OPT_INTEGER('t', "tid", &target_tid,
1055-
"stat events on existing thread id"),
1052+
OPT_STRING('p', "pid", &target_pid, "pid",
1053+
"stat events on existing process id"),
1054+
OPT_STRING('t', "tid", &target_tid, "tid",
1055+
"stat events on existing thread id"),
10561056
OPT_BOOLEAN('a', "all-cpus", &system_wide,
10571057
"system-wide collection from all CPUs"),
10581058
OPT_BOOLEAN('g', "group", &group,
@@ -1190,7 +1190,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
11901190
} else if (big_num_opt == 0) /* User passed --no-big-num */
11911191
big_num = false;
11921192

1193-
if (!argc && target_pid == -1 && target_tid == -1)
1193+
if (!argc && !target_pid && !target_tid)
11941194
usage_with_options(stat_usage, options);
11951195
if (run_count <= 0)
11961196
usage_with_options(stat_usage, options);
@@ -1206,10 +1206,11 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
12061206
if (add_default_attributes())
12071207
goto out;
12081208

1209-
if (target_pid != -1)
1209+
if (target_pid)
12101210
target_tid = target_pid;
12111211

1212-
evsel_list->threads = thread_map__new(target_pid, target_tid, UINT_MAX);
1212+
evsel_list->threads = thread_map__new_str(target_pid,
1213+
target_tid, UINT_MAX);
12131214
if (evsel_list->threads == NULL) {
12141215
pr_err("Problems finding threads of monitor\n");
12151216
usage_with_options(stat_usage, options);

tools/perf/builtin-test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,9 @@ static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp,
10101010
static int test__PERF_RECORD(void)
10111011
{
10121012
struct perf_record_opts opts = {
1013-
.target_pid = -1,
1014-
.target_tid = -1,
10151013
.no_delay = true,
10161014
.freq = 10,
10171015
.mmap_pages = 256,
1018-
.sample_id_all_avail = true,
10191016
};
10201017
cpu_set_t *cpu_mask = NULL;
10211018
size_t cpu_mask_size = 0;

tools/perf/builtin-top.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ static void perf_event__process_sample(struct perf_tool *tool,
677677
return;
678678
}
679679

680+
if (!machine) {
681+
pr_err("%u unprocessable samples recorded.",
682+
top->session->hists.stats.nr_unprocessable_samples++);
683+
return;
684+
}
685+
680686
if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
681687
top->exact_samples++;
682688

@@ -866,8 +872,11 @@ static void perf_top__start_counters(struct perf_top *top)
866872
attr->mmap = 1;
867873
attr->comm = 1;
868874
attr->inherit = top->inherit;
875+
fallback_missing_features:
876+
if (top->exclude_guest_missing)
877+
attr->exclude_guest = attr->exclude_host = 0;
869878
retry_sample_id:
870-
attr->sample_id_all = top->sample_id_all_avail ? 1 : 0;
879+
attr->sample_id_all = top->sample_id_all_missing ? 0 : 1;
871880
try_again:
872881
if (perf_evsel__open(counter, top->evlist->cpus,
873882
top->evlist->threads, top->group,
@@ -877,12 +886,20 @@ static void perf_top__start_counters(struct perf_top *top)
877886
if (err == EPERM || err == EACCES) {
878887
ui__error_paranoid();
879888
goto out_err;
880-
} else if (err == EINVAL && top->sample_id_all_avail) {
881-
/*
882-
* Old kernel, no attr->sample_id_type_all field
883-
*/
884-
top->sample_id_all_avail = false;
885-
goto retry_sample_id;
889+
} else if (err == EINVAL) {
890+
if (!top->exclude_guest_missing &&
891+
(attr->exclude_guest || attr->exclude_host)) {
892+
pr_debug("Old kernel, cannot exclude "
893+
"guest or host samples.\n");
894+
top->exclude_guest_missing = true;
895+
goto fallback_missing_features;
896+
} else if (!top->sample_id_all_missing) {
897+
/*
898+
* Old kernel, no attr->sample_id_type_all field
899+
*/
900+
top->sample_id_all_missing = true;
901+
goto retry_sample_id;
902+
}
886903
}
887904
/*
888905
* If it's cycles then fall back to hrtimer
@@ -965,7 +982,7 @@ static int __cmd_top(struct perf_top *top)
965982
if (ret)
966983
goto out_delete;
967984

968-
if (top->target_tid != -1 || top->uid != UINT_MAX)
985+
if (top->target_tid || top->uid != UINT_MAX)
969986
perf_event__synthesize_thread_map(&top->tool, top->evlist->threads,
970987
perf_event__process,
971988
&top->session->host_machine);
@@ -1103,11 +1120,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
11031120
struct perf_top top = {
11041121
.count_filter = 5,
11051122
.delay_secs = 2,
1106-
.target_pid = -1,
1107-
.target_tid = -1,
11081123
.uid = UINT_MAX,
11091124
.freq = 1000, /* 1 KHz */
1110-
.sample_id_all_avail = true,
11111125
.mmap_pages = 128,
11121126
.sym_pcnt_filter = 5,
11131127
};
@@ -1118,9 +1132,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
11181132
parse_events_option),
11191133
OPT_INTEGER('c', "count", &top.default_interval,
11201134
"event period to sample"),
1121-
OPT_INTEGER('p', "pid", &top.target_pid,
1135+
OPT_STRING('p', "pid", &top.target_pid, "pid",
11221136
"profile events on existing process id"),
1123-
OPT_INTEGER('t', "tid", &top.target_tid,
1137+
OPT_STRING('t', "tid", &top.target_tid, "tid",
11241138
"profile events on existing thread id"),
11251139
OPT_BOOLEAN('a', "all-cpus", &top.system_wide,
11261140
"system-wide collection from all CPUs"),
@@ -1210,13 +1224,13 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
12101224
goto out_delete_evlist;
12111225

12121226
/* CPU and PID are mutually exclusive */
1213-
if (top.target_tid > 0 && top.cpu_list) {
1227+
if (top.target_tid && top.cpu_list) {
12141228
printf("WARNING: PID switch overriding CPU\n");
12151229
sleep(1);
12161230
top.cpu_list = NULL;
12171231
}
12181232

1219-
if (top.target_pid != -1)
1233+
if (top.target_pid)
12201234
top.target_tid = top.target_pid;
12211235

12221236
if (perf_evlist__create_maps(top.evlist, top.target_pid,

0 commit comments

Comments
 (0)