Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/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]>
  • Loading branch information
Ingo Molnar committed Feb 17, 2012
2 parents f8d98f1 + 808e122 commit d1e169d
Show file tree
Hide file tree
Showing 33 changed files with 616 additions and 416 deletions.
4 changes: 2 additions & 2 deletions tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ OPTIONS

-p::
--pid=::
Record events on existing process ID.
Record events on existing process ID (comma separated list).

-t::
--tid=::
Record events on existing thread ID.
Record events on existing thread ID (comma separated list).

-u::
--uid=::
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/Documentation/perf-stat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ OPTIONS
child tasks do not inherit counters
-p::
--pid=<pid>::
stat events on existing process id
stat events on existing process id (comma separated list)

-t::
--tid=<tid>::
stat events on existing thread id
stat events on existing thread id (comma separated list)


-a::
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/Documentation/perf-top.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ Default is to monitor all CPUS.

-p <pid>::
--pid=<pid>::
Profile events on existing Process ID.
Profile events on existing Process ID (comma separated list).

-t <tid>::
--tid=<tid>::
Profile events on existing thread ID.
Profile events on existing thread ID (comma separated list).

-u::
--uid=::
Expand Down
1 change: 1 addition & 0 deletions tools/perf/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib/rbtree.c
include/linux/swab.h
arch/*/include/asm/unistd*.h
arch/*/lib/memcpy*.S
arch/*/lib/memset*.S
include/linux/poison.h
include/linux/magic.h
include/linux/hw_breakpoint.h
7 changes: 6 additions & 1 deletion tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ SCRIPT_SH += perf-archive.sh
grep-libs = $(filter -l%,$(1))
strip-libs = $(filter-out -l%,$(1))

$(OUTPUT)python/perf.so: $(PYRF_OBJS)
PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py

$(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
$(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \
--quiet build_ext; \
mkdir -p $(OUTPUT)python && \
Expand Down Expand Up @@ -256,6 +259,7 @@ LIB_H += util/callchain.h
LIB_H += util/build-id.h
LIB_H += util/debug.h
LIB_H += util/debugfs.h
LIB_H += util/sysfs.h
LIB_H += util/event.h
LIB_H += util/evsel.h
LIB_H += util/evlist.h
Expand Down Expand Up @@ -302,6 +306,7 @@ LIB_OBJS += $(OUTPUT)util/build-id.o
LIB_OBJS += $(OUTPUT)util/config.o
LIB_OBJS += $(OUTPUT)util/ctype.o
LIB_OBJS += $(OUTPUT)util/debugfs.o
LIB_OBJS += $(OUTPUT)util/sysfs.o
LIB_OBJS += $(OUTPUT)util/environment.o
LIB_OBJS += $(OUTPUT)util/event.o
LIB_OBJS += $(OUTPUT)util/evlist.o
Expand Down
46 changes: 27 additions & 19 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ static void perf_record__open(struct perf_record *rec)

if (opts->group && pos != first)
group_fd = first->fd;
fallback_missing_features:
if (opts->exclude_guest_missing)
attr->exclude_guest = attr->exclude_host = 0;
retry_sample_id:
attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0;
attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
try_again:
if (perf_evsel__open(pos, evlist->cpus, evlist->threads,
opts->group, group_fd) < 0) {
Expand All @@ -218,15 +221,23 @@ static void perf_record__open(struct perf_record *rec)
} else if (err == ENODEV && opts->cpu_list) {
die("No such device - did you specify"
" an out-of-range profile CPU?\n");
} else if (err == EINVAL && opts->sample_id_all_avail) {
/*
* Old kernel, no attr->sample_id_type_all field
*/
opts->sample_id_all_avail = false;
if (!opts->sample_time && !opts->raw_samples && !time_needed)
attr->sample_type &= ~PERF_SAMPLE_TIME;

goto retry_sample_id;
} else if (err == EINVAL) {
if (!opts->exclude_guest_missing &&
(attr->exclude_guest || attr->exclude_host)) {
pr_debug("Old kernel, cannot exclude "
"guest or host samples.\n");
opts->exclude_guest_missing = true;
goto fallback_missing_features;
} else if (!opts->sample_id_all_missing) {
/*
* Old kernel, no attr->sample_id_type_all field
*/
opts->sample_id_all_missing = true;
if (!opts->sample_time && !opts->raw_samples && !time_needed)
attr->sample_type &= ~PERF_SAMPLE_TIME;

goto retry_sample_id;
}
}

/*
Expand Down Expand Up @@ -494,9 +505,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
return err;
}

if (!!rec->no_buildid
if (!rec->no_buildid
&& !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) {
pr_err("Couldn't generating buildids. "
pr_err("Couldn't generate buildids. "
"Use --no-buildid to profile anyway.\n");
return -1;
}
Expand Down Expand Up @@ -645,13 +656,10 @@ static const char * const record_usage[] = {
*/
static struct perf_record record = {
.opts = {
.target_pid = -1,
.target_tid = -1,
.mmap_pages = UINT_MAX,
.user_freq = UINT_MAX,
.user_interval = ULLONG_MAX,
.freq = 1000,
.sample_id_all_avail = true,
},
.write_mode = WRITE_FORCE,
.file_new = true,
Expand All @@ -670,9 +678,9 @@ const struct option record_options[] = {
parse_events_option),
OPT_CALLBACK(0, "filter", &record.evlist, "filter",
"event filter", parse_filter),
OPT_INTEGER('p', "pid", &record.opts.target_pid,
OPT_STRING('p', "pid", &record.opts.target_pid, "pid",
"record events on existing process id"),
OPT_INTEGER('t', "tid", &record.opts.target_tid,
OPT_STRING('t', "tid", &record.opts.target_tid, "tid",
"record events on existing thread id"),
OPT_INTEGER('r', "realtime", &record.realtime_prio,
"collect data with this RT SCHED_FIFO priority"),
Expand Down Expand Up @@ -739,7 +747,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)

argc = parse_options(argc, argv, record_options, record_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (!argc && rec->opts.target_pid == -1 && rec->opts.target_tid == -1 &&
if (!argc && !rec->opts.target_pid && !rec->opts.target_tid &&
!rec->opts.system_wide && !rec->opts.cpu_list && !rec->uid_str)
usage_with_options(record_usage, record_options);

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

if (rec->opts.target_pid != -1)
if (rec->opts.target_pid)
rec->opts.target_tid = rec->opts.target_pid;

if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid,
Expand Down
31 changes: 16 additions & 15 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ static int run_count = 1;
static bool no_inherit = false;
static bool scale = true;
static bool no_aggr = false;
static pid_t target_pid = -1;
static pid_t target_tid = -1;
static const char *target_pid;
static const char *target_tid;
static pid_t child_pid = -1;
static bool null_run = false;
static int detailed_run = 0;
Expand Down Expand Up @@ -296,7 +296,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
if (system_wide)
return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
group, group_fd);
if (target_pid == -1 && target_tid == -1) {
if (!target_pid && !target_tid) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}
Expand Down Expand Up @@ -446,7 +446,7 @@ static int run_perf_stat(int argc __used, const char **argv)
exit(-1);
}

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

/*
Expand Down Expand Up @@ -968,14 +968,14 @@ static void print_stat(int argc, const char **argv)
if (!csv_output) {
fprintf(output, "\n");
fprintf(output, " Performance counter stats for ");
if(target_pid == -1 && target_tid == -1) {
if (!target_pid && !target_tid) {
fprintf(output, "\'%s", argv[0]);
for (i = 1; i < argc; i++)
fprintf(output, " %s", argv[i]);
} else if (target_pid != -1)
fprintf(output, "process id \'%d", target_pid);
} else if (target_pid)
fprintf(output, "process id \'%s", target_pid);
else
fprintf(output, "thread id \'%d", target_tid);
fprintf(output, "thread id \'%s", target_tid);

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

if (!argc && target_pid == -1 && target_tid == -1)
if (!argc && !target_pid && !target_tid)
usage_with_options(stat_usage, options);
if (run_count <= 0)
usage_with_options(stat_usage, options);
Expand All @@ -1206,10 +1206,11 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
if (add_default_attributes())
goto out;

if (target_pid != -1)
if (target_pid)
target_tid = target_pid;

evsel_list->threads = thread_map__new(target_pid, target_tid, UINT_MAX);
evsel_list->threads = thread_map__new_str(target_pid,
target_tid, UINT_MAX);
if (evsel_list->threads == NULL) {
pr_err("Problems finding threads of monitor\n");
usage_with_options(stat_usage, options);
Expand Down
3 changes: 0 additions & 3 deletions tools/perf/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,9 @@ static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp,
static int test__PERF_RECORD(void)
{
struct perf_record_opts opts = {
.target_pid = -1,
.target_tid = -1,
.no_delay = true,
.freq = 10,
.mmap_pages = 256,
.sample_id_all_avail = true,
};
cpu_set_t *cpu_mask = NULL;
size_t cpu_mask_size = 0;
Expand Down
44 changes: 29 additions & 15 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ static void perf_event__process_sample(struct perf_tool *tool,
return;
}

if (!machine) {
pr_err("%u unprocessable samples recorded.",
top->session->hists.stats.nr_unprocessable_samples++);
return;
}

if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
top->exact_samples++;

Expand Down Expand Up @@ -866,8 +872,11 @@ static void perf_top__start_counters(struct perf_top *top)
attr->mmap = 1;
attr->comm = 1;
attr->inherit = top->inherit;
fallback_missing_features:
if (top->exclude_guest_missing)
attr->exclude_guest = attr->exclude_host = 0;
retry_sample_id:
attr->sample_id_all = top->sample_id_all_avail ? 1 : 0;
attr->sample_id_all = top->sample_id_all_missing ? 0 : 1;
try_again:
if (perf_evsel__open(counter, top->evlist->cpus,
top->evlist->threads, top->group,
Expand All @@ -877,12 +886,20 @@ static void perf_top__start_counters(struct perf_top *top)
if (err == EPERM || err == EACCES) {
ui__error_paranoid();
goto out_err;
} else if (err == EINVAL && top->sample_id_all_avail) {
/*
* Old kernel, no attr->sample_id_type_all field
*/
top->sample_id_all_avail = false;
goto retry_sample_id;
} else if (err == EINVAL) {
if (!top->exclude_guest_missing &&
(attr->exclude_guest || attr->exclude_host)) {
pr_debug("Old kernel, cannot exclude "
"guest or host samples.\n");
top->exclude_guest_missing = true;
goto fallback_missing_features;
} else if (!top->sample_id_all_missing) {
/*
* Old kernel, no attr->sample_id_type_all field
*/
top->sample_id_all_missing = true;
goto retry_sample_id;
}
}
/*
* If it's cycles then fall back to hrtimer
Expand Down Expand Up @@ -965,7 +982,7 @@ static int __cmd_top(struct perf_top *top)
if (ret)
goto out_delete;

if (top->target_tid != -1 || top->uid != UINT_MAX)
if (top->target_tid || top->uid != UINT_MAX)
perf_event__synthesize_thread_map(&top->tool, top->evlist->threads,
perf_event__process,
&top->session->host_machine);
Expand Down Expand Up @@ -1103,11 +1120,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
struct perf_top top = {
.count_filter = 5,
.delay_secs = 2,
.target_pid = -1,
.target_tid = -1,
.uid = UINT_MAX,
.freq = 1000, /* 1 KHz */
.sample_id_all_avail = true,
.mmap_pages = 128,
.sym_pcnt_filter = 5,
};
Expand All @@ -1118,9 +1132,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
parse_events_option),
OPT_INTEGER('c', "count", &top.default_interval,
"event period to sample"),
OPT_INTEGER('p', "pid", &top.target_pid,
OPT_STRING('p', "pid", &top.target_pid, "pid",
"profile events on existing process id"),
OPT_INTEGER('t', "tid", &top.target_tid,
OPT_STRING('t', "tid", &top.target_tid, "tid",
"profile events on existing thread id"),
OPT_BOOLEAN('a', "all-cpus", &top.system_wide,
"system-wide collection from all CPUs"),
Expand Down Expand Up @@ -1210,13 +1224,13 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
goto out_delete_evlist;

/* CPU and PID are mutually exclusive */
if (top.target_tid > 0 && top.cpu_list) {
if (top.target_tid && top.cpu_list) {
printf("WARNING: PID switch overriding CPU\n");
sleep(1);
top.cpu_list = NULL;
}

if (top.target_pid != -1)
if (top.target_pid)
top.target_tid = top.target_pid;

if (perf_evlist__create_maps(top.evlist, top.target_pid,
Expand Down
Loading

0 comments on commit d1e169d

Please sign in to comment.