linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf sched timehist: Add support for filtering on CPU
@ 2019-12-04 17:39 David Ahern
  2019-12-04 19:28 ` Arnaldo Carvalho de Melo
  2020-01-10 17:53 ` [tip: perf/core] " tip-bot2 for David Ahern
  0 siblings, 2 replies; 3+ messages in thread
From: David Ahern @ 2019-12-04 17:39 UTC (permalink / raw)
  To: acme; +Cc: namhyung, jolsa, linux-kernel, linux-perf-users, David Ahern

From: David Ahern <dsahern@gmail.com>

Allow user to limit output to one or more CPUs. Really helpful on systems
with a large number of cpus.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 63f938b887dd..5fbe42bd599b 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -110,6 +110,10 @@ OPTIONS for 'perf sched timehist'
 --max-stack::
 	Maximum number of functions to display in backtrace, default 5.
 
+-C=::
+--cpu=::
+	Only show events for the given CPU(s) (comma separated list).
+
 -p=::
 --pid=::
 	Only show events for given process ID (comma separated list).
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 8a12d71364c3..82fcc2c15fe4 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -51,6 +51,9 @@
 #define SYM_LEN			129
 #define MAX_PID			1024000
 
+static const char *cpu_list;
+static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+
 struct sched_atom;
 
 struct task_desc {
@@ -2008,6 +2011,9 @@ static void timehist_print_sample(struct perf_sched *sched,
 	char nstr[30];
 	u64 wait_time;
 
+	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+		return;
+
 	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
 	printf("%15s [%04d] ", tstr, sample->cpu);
 
@@ -2994,6 +3000,12 @@ static int perf_sched__timehist(struct perf_sched *sched)
 	if (IS_ERR(session))
 		return PTR_ERR(session);
 
+	if (cpu_list) {
+		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
+		if (err < 0)
+			goto out;
+	}
+
 	evlist = session->evlist;
 
 	symbol__init(&session->header.env);
@@ -3429,6 +3441,7 @@ int cmd_sched(int argc, const char **argv)
 		   "analyze events only for given process id(s)"),
 	OPT_STRING('t', "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
 		   "analyze events only for given thread id(s)"),
+	OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 	OPT_PARENT(sched_options)
 	};
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf sched timehist: Add support for filtering on CPU
  2019-12-04 17:39 [PATCH] perf sched timehist: Add support for filtering on CPU David Ahern
@ 2019-12-04 19:28 ` Arnaldo Carvalho de Melo
  2020-01-10 17:53 ` [tip: perf/core] " tip-bot2 for David Ahern
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-12-04 19:28 UTC (permalink / raw)
  To: David Ahern; +Cc: namhyung, jolsa, linux-kernel, linux-perf-users, David Ahern

Em Wed, Dec 04, 2019 at 10:39:25AM -0700, David Ahern escreveu:
> From: David Ahern <dsahern@gmail.com>
> 
> Allow user to limit output to one or more CPUs. Really helpful on systems
> with a large number of cpus.

Thanks, tested and applied to perf/core, for 5.6.

- Arnaldo

> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
>  tools/perf/Documentation/perf-sched.txt |  4 ++++
>  tools/perf/builtin-sched.c              | 13 +++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
> index 63f938b887dd..5fbe42bd599b 100644
> --- a/tools/perf/Documentation/perf-sched.txt
> +++ b/tools/perf/Documentation/perf-sched.txt
> @@ -110,6 +110,10 @@ OPTIONS for 'perf sched timehist'
>  --max-stack::
>  	Maximum number of functions to display in backtrace, default 5.
>  
> +-C=::
> +--cpu=::
> +	Only show events for the given CPU(s) (comma separated list).
> +
>  -p=::
>  --pid=::
>  	Only show events for given process ID (comma separated list).
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 8a12d71364c3..82fcc2c15fe4 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -51,6 +51,9 @@
>  #define SYM_LEN			129
>  #define MAX_PID			1024000
>  
> +static const char *cpu_list;
> +static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
> +
>  struct sched_atom;
>  
>  struct task_desc {
> @@ -2008,6 +2011,9 @@ static void timehist_print_sample(struct perf_sched *sched,
>  	char nstr[30];
>  	u64 wait_time;
>  
> +	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
> +		return;
> +
>  	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
>  	printf("%15s [%04d] ", tstr, sample->cpu);
>  
> @@ -2994,6 +3000,12 @@ static int perf_sched__timehist(struct perf_sched *sched)
>  	if (IS_ERR(session))
>  		return PTR_ERR(session);
>  
> +	if (cpu_list) {
> +		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
> +		if (err < 0)
> +			goto out;
> +	}
> +
>  	evlist = session->evlist;
>  
>  	symbol__init(&session->header.env);
> @@ -3429,6 +3441,7 @@ int cmd_sched(int argc, const char **argv)
>  		   "analyze events only for given process id(s)"),
>  	OPT_STRING('t', "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
>  		   "analyze events only for given thread id(s)"),
> +	OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
>  	OPT_PARENT(sched_options)
>  	};
>  
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: perf/core] perf sched timehist: Add support for filtering on CPU
  2019-12-04 17:39 [PATCH] perf sched timehist: Add support for filtering on CPU David Ahern
  2019-12-04 19:28 ` Arnaldo Carvalho de Melo
@ 2020-01-10 17:53 ` tip-bot2 for David Ahern
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for David Ahern @ 2020-01-10 17:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: David Ahern, Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
	x86, LKML

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     c30d630d1bcfad8d2f70ff0cbb2a86d5a43bc152
Gitweb:        https://git.kernel.org/tip/c30d630d1bcfad8d2f70ff0cbb2a86d5a43bc152
Author:        David Ahern <dsahern@gmail.com>
AuthorDate:    Wed, 04 Dec 2019 10:39:25 -07:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Mon, 06 Jan 2020 11:46:09 -03:00

perf sched timehist: Add support for filtering on CPU

Allow user to limit output to one or more CPUs. Really helpful on
systems with a large number of cpus.

Committer testing:

  # perf sched record -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.765 MB perf.data (1412 samples) ]
  [root@quaco ~]# perf sched timehist | head
  Samples do not have callchains.
             time    cpu  task name                       wait time  sch delay   run time
                          [tid/pid]                          (msec)     (msec)     (msec)
  --------------- ------  ------------------------------  ---------  ---------  ---------
     66307.802686 [0000]  perf[13086]                         0.000      0.000      0.000
     66307.802700 [0000]  migration/0[12]                     0.000      0.001      0.014
     66307.802766 [0001]  perf[13086]                         0.000      0.000      0.000
     66307.802774 [0001]  migration/1[15]                     0.000      0.001      0.007
     66307.802841 [0002]  perf[13086]                         0.000      0.000      0.000
     66307.802849 [0002]  migration/2[20]                     0.000      0.001      0.008
     66307.802913 [0003]  perf[13086]                         0.000      0.000      0.000
  #
  # perf sched timehist --cpu 2 | head
  Samples do not have callchains.
             time    cpu  task name                       wait time  sch delay   run time
                          [tid/pid]                          (msec)     (msec)     (msec)
  --------------- ------  ------------------------------  ---------  ---------  ---------
     66307.802841 [0002]  perf[13086]                         0.000      0.000      0.000
     66307.802849 [0002]  migration/2[20]                     0.000      0.001      0.008
     66307.964485 [0002]  <idle>                              0.000      0.000    161.635
     66307.964811 [0002]  CPU 0/KVM[3589/3561]                0.000      0.056      0.325
     66307.965477 [0002]  <idle>                              0.325      0.000      0.666
     66307.965553 [0002]  CPU 0/KVM[3589/3561]                0.666      0.024      0.076
     66307.966456 [0002]  <idle>                              0.076      0.000      0.903
  #

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/20191204173925.66976-1-dsahern@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 63f938b..5fbe42b 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -110,6 +110,10 @@ OPTIONS for 'perf sched timehist'
 --max-stack::
 	Maximum number of functions to display in backtrace, default 5.
 
+-C=::
+--cpu=::
+	Only show events for the given CPU(s) (comma separated list).
+
 -p=::
 --pid=::
 	Only show events for given process ID (comma separated list).
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 8a12d71..82fcc2c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -51,6 +51,9 @@
 #define SYM_LEN			129
 #define MAX_PID			1024000
 
+static const char *cpu_list;
+static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+
 struct sched_atom;
 
 struct task_desc {
@@ -2008,6 +2011,9 @@ static void timehist_print_sample(struct perf_sched *sched,
 	char nstr[30];
 	u64 wait_time;
 
+	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+		return;
+
 	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
 	printf("%15s [%04d] ", tstr, sample->cpu);
 
@@ -2994,6 +3000,12 @@ static int perf_sched__timehist(struct perf_sched *sched)
 	if (IS_ERR(session))
 		return PTR_ERR(session);
 
+	if (cpu_list) {
+		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
+		if (err < 0)
+			goto out;
+	}
+
 	evlist = session->evlist;
 
 	symbol__init(&session->header.env);
@@ -3429,6 +3441,7 @@ int cmd_sched(int argc, const char **argv)
 		   "analyze events only for given process id(s)"),
 	OPT_STRING('t', "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
 		   "analyze events only for given thread id(s)"),
+	OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 	OPT_PARENT(sched_options)
 	};
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-10 17:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 17:39 [PATCH] perf sched timehist: Add support for filtering on CPU David Ahern
2019-12-04 19:28 ` Arnaldo Carvalho de Melo
2020-01-10 17:53 ` [tip: perf/core] " tip-bot2 for David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).