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

Commit 0d37aa34 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf tools: Introduce per user view

The new --uid command line option will show only the tasks for a given
user, using the proc interface to figure out the existing tasks.

Kernel work is needed to close races at startup, but this should already
be useful in many use cases.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bdnspm000gw2l984a2t53o8z@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9ae7d335
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,10 @@ OPTIONS
--tid=::
--tid=::
        Record events on existing thread ID.
        Record events on existing thread ID.


-u::
--uid=::
        Record events in threads owned by uid. Name or number.

-r::
-r::
--realtime=::
--realtime=::
	Collect data with this RT SCHED_FIFO priority.
	Collect data with this RT SCHED_FIFO priority.
+4 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,10 @@ Default is to monitor all CPUS.
--tid=<tid>::
--tid=<tid>::
        Profile events on existing thread ID.
        Profile events on existing thread ID.


-u::
--uid=::
        Record events in threads owned by uid. Name or number.

-r <priority>::
-r <priority>::
--realtime=<priority>::
--realtime=<priority>::
	Collect data with this RT SCHED_FIFO priority.
	Collect data with this RT SCHED_FIFO priority.
+10 −2
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ struct perf_record {
	struct perf_evlist	*evlist;
	struct perf_evlist	*evlist;
	struct perf_session	*session;
	struct perf_session	*session;
	const char		*progname;
	const char		*progname;
	const char		*uid_str;
	int			output;
	int			output;
	unsigned int		page_size;
	unsigned int		page_size;
	int			realtime_prio;
	int			realtime_prio;
@@ -727,6 +728,7 @@ const struct option record_options[] = {
	OPT_CALLBACK('G', "cgroup", &record.evlist, "name",
	OPT_CALLBACK('G', "cgroup", &record.evlist, "name",
		     "monitor event in cgroup name only",
		     "monitor event in cgroup name only",
		     parse_cgroups),
		     parse_cgroups),
	OPT_STRING('u', "uid", &record.uid_str, "user", "user to profile"),
	OPT_END()
	OPT_END()
};
};


@@ -748,7 +750,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
	argc = parse_options(argc, argv, record_options, record_usage,
	argc = parse_options(argc, argv, record_options, record_usage,
			    PARSE_OPT_STOP_AT_NON_OPTION);
			    PARSE_OPT_STOP_AT_NON_OPTION);
	if (!argc && rec->opts.target_pid == -1 && rec->opts.target_tid == -1 &&
	if (!argc && rec->opts.target_pid == -1 && rec->opts.target_tid == -1 &&
		!rec->opts.system_wide && !rec->opts.cpu_list)
		!rec->opts.system_wide && !rec->opts.cpu_list && !rec->uid_str)
		usage_with_options(record_usage, record_options);
		usage_with_options(record_usage, record_options);


	if (rec->force && rec->append_file) {
	if (rec->force && rec->append_file) {
@@ -788,11 +790,17 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
		goto out_symbol_exit;
		goto out_symbol_exit;
	}
	}


	rec->opts.uid = parse_target_uid(rec->uid_str, rec->opts.target_tid,
					 rec->opts.target_pid);
	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 != -1)
		rec->opts.target_tid = rec->opts.target_pid;
		rec->opts.target_tid = rec->opts.target_pid;


	if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid,
	if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid,
				     rec->opts.target_tid, rec->opts.cpu_list) < 0)
				     rec->opts.target_tid, rec->opts.uid,
				     rec->opts.cpu_list) < 0)
		usage_with_options(record_usage, record_options);
		usage_with_options(record_usage, record_options);


	list_for_each_entry(pos, &evsel_list->entries, node) {
	list_for_each_entry(pos, &evsel_list->entries, node) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -1201,7 +1201,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
	if (target_pid != -1)
	if (target_pid != -1)
		target_tid = target_pid;
		target_tid = target_pid;


	evsel_list->threads = thread_map__new(target_pid, target_tid);
	evsel_list->threads = thread_map__new(target_pid, target_tid, UINT_MAX);
	if (evsel_list->threads == NULL) {
	if (evsel_list->threads == NULL) {
		pr_err("Problems finding threads of monitor\n");
		pr_err("Problems finding threads of monitor\n");
		usage_with_options(stat_usage, options);
		usage_with_options(stat_usage, options);
+4 −4
Original line number Original line Diff line number Diff line
@@ -276,7 +276,7 @@ static int test__open_syscall_event(void)
		return -1;
		return -1;
	}
	}


	threads = thread_map__new(-1, getpid());
	threads = thread_map__new(-1, getpid(), UINT_MAX);
	if (threads == NULL) {
	if (threads == NULL) {
		pr_debug("thread_map__new\n");
		pr_debug("thread_map__new\n");
		return -1;
		return -1;
@@ -342,7 +342,7 @@ static int test__open_syscall_event_on_all_cpus(void)
		return -1;
		return -1;
	}
	}


	threads = thread_map__new(-1, getpid());
	threads = thread_map__new(-1, getpid(), UINT_MAX);
	if (threads == NULL) {
	if (threads == NULL) {
		pr_debug("thread_map__new\n");
		pr_debug("thread_map__new\n");
		return -1;
		return -1;
@@ -490,7 +490,7 @@ static int test__basic_mmap(void)
		expected_nr_events[i] = random() % 257;
		expected_nr_events[i] = random() % 257;
	}
	}


	threads = thread_map__new(-1, getpid());
	threads = thread_map__new(-1, getpid(), UINT_MAX);
	if (threads == NULL) {
	if (threads == NULL) {
		pr_debug("thread_map__new\n");
		pr_debug("thread_map__new\n");
		return -1;
		return -1;
@@ -1054,7 +1054,7 @@ static int test__PERF_RECORD(void)
	 * we're monitoring, the one forked there.
	 * we're monitoring, the one forked there.
	 */
	 */
	err = perf_evlist__create_maps(evlist, opts.target_pid,
	err = perf_evlist__create_maps(evlist, opts.target_pid,
				       opts.target_tid, opts.cpu_list);
				       opts.target_tid, UINT_MAX, opts.cpu_list);
	if (err < 0) {
	if (err < 0) {
		pr_debug("Not enough memory to create thread/cpu maps\n");
		pr_debug("Not enough memory to create thread/cpu maps\n");
		goto out_delete_evlist;
		goto out_delete_evlist;
Loading