Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b52956c9 authored by David Ahern's avatar David Ahern Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Allow multiple threads or processes in record, stat, top

Allow a user to collect events for multiple threads or processes
using a comma separated list.

e.g., collect data on a VM and its vhost thread:
  perf top -p 21483,21485
  perf stat -p 21483,21485 -ddd
  perf record -p 21483,21485

or monitoring vcpu threads
  perf top -t 21488,21489
  perf stat -t 21488,21489 -ddd
  perf record -t 21488,21489

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1328718772-16688-1-git-send-email-dsahern@gmail.com


Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent eca1c3e3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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=::
+2 −2
Original line number Diff line number Diff line
@@ -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::
+2 −2
Original line number Diff line number Diff line
@@ -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=::
+4 −6
Original line number Diff line number Diff line
@@ -645,8 +645,6 @@ 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,
@@ -670,9 +668,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"),
@@ -739,7 +737,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);

@@ -785,7 +783,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,
+16 −15
Original line number Diff line number Diff line
@@ -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;
@@ -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;
	}
@@ -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;

		/*
@@ -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)
@@ -1049,9 +1049,9 @@ 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,
	OPT_STRING('p', "pid", &target_pid, "pid",
		   "stat events on existing process id"),
	OPT_INTEGER('t', "tid", &target_tid,
	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"),
@@ -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);
@@ -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);
Loading