All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf script: Add option to display guest samples in host
@ 2017-10-18  7:09 ` Mengting Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Mengting Zhang @ 2017-10-18  7:09 UTC (permalink / raw)
  To: linux-perf-users, linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, ak, jolsa, namhyung,
	dsa, wangnan0, huawei.libin, zhangmengting

By default, 'perf script' always exclude guest samples in host.
However, for some tracepoint events(e.g. sched_switch), the tracing
output lost sched_out samples for vcpu thread if 'perf script'
filter guest samples, which is confusing. Therefore, it'd be better
to display guest samples together with host samples.

Add '--show-guest-samples' option to display guest samples in host.

Without --show-guest-samples option,
         swapper     0 [008] 18479978.454475: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479978.454482: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
         swapper     0 [008] 18479979.230473: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479979.230478: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120

With --show-guest-samples option,
         swapper     0 [008] 18479978.454475: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479978.454482: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
       CPU 0/KVM 32396 [008] 18479978.454516: sched:sched_switch: prev_comm=CPU 0/KVM prev_pid=32396 prev_prio=120 prev_state=S ==> next_comm=swapper/8 next_pid=0 next_prio=120
         swapper     0 [008] 18479979.230473: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479979.230478: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
       CPU 0/KVM 32396 [008] 18479979.230520: sched:sched_switch: prev_comm=CPU 0/KVM prev_pid=32396 prev_prio=120 prev_state=S ==> next_comm=swapper/8 next_pid=0 next_prio=120

Signed-off-by: Mengting Zhang <zhangmengting@huawei.com>
---
 tools/perf/Documentation/perf-script.txt | 3 +++
 tools/perf/builtin-script.c              | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 18dfcfa..85a080c 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -274,6 +274,9 @@ OPTIONS
 	Display context switch events i.e. events of type PERF_RECORD_SWITCH or
 	PERF_RECORD_SWITCH_CPU_WIDE.
 
+--show-guest-samples
+	Dispaly guest samples in host.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3d4c3b5..c34d241 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1340,6 +1340,7 @@ struct perf_script {
 	bool			show_switch_events;
 	bool			show_namespace_events;
 	bool			allocated;
+	bool			show_guest_samples;
 	struct cpu_map		*cpus;
 	struct thread_map	*threads;
 	int			name_width;
@@ -1557,7 +1558,7 @@ static int process_sample_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	if (al.filtered)
+	if (al.filtered && (!scr->show_guest_samples || !(al.filtered & (1 << HIST_FILTER__GUEST))))
 		goto out_put;
 
 	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
@@ -2771,6 +2772,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show context switch events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
 		    "Show namespace events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-guest-samples", &script.show_guest_samples,
+		    "Show guest samples (if recorded)"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
 	OPT_INTEGER(0, "max-blocks", &max_blocks,
 		    "Maximum number of code blocks to dump with brstackinsn"),
-- 
1.7.12.4

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

* [PATCH] perf script: Add option to display guest samples in host
@ 2017-10-18  7:09 ` Mengting Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Mengting Zhang @ 2017-10-18  7:09 UTC (permalink / raw)
  To: linux-perf-users, linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, ak, jolsa, namhyung,
	dsa, wangnan0, huawei.libin, zhangmengting

By default, 'perf script' always exclude guest samples in host.
However, for some tracepoint events(e.g. sched_switch), the tracing
output lost sched_out samples for vcpu thread if 'perf script'
filter guest samples, which is confusing. Therefore, it'd be better
to display guest samples together with host samples.

Add '--show-guest-samples' option to display guest samples in host.

Without --show-guest-samples option,
         swapper     0 [008] 18479978.454475: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479978.454482: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
         swapper     0 [008] 18479979.230473: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479979.230478: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120

With --show-guest-samples option,
         swapper     0 [008] 18479978.454475: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479978.454482: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
       CPU 0/KVM 32396 [008] 18479978.454516: sched:sched_switch: prev_comm=CPU 0/KVM prev_pid=32396 prev_prio=120 prev_state=S ==> next_comm=swapper/8 next_pid=0 next_prio=120
         swapper     0 [008] 18479979.230473: sched:sched_switch: prev_comm=swapper/8 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/8:0 next_pid=7342 next_prio=120
     kworker/8:0  7342 [008] 18479979.230478: sched:sched_switch: prev_comm=kworker/8:0 prev_pid=7342 prev_prio=120 prev_state=S ==> next_comm=CPU 0/KVM next_pid=32396 next_prio=120
       CPU 0/KVM 32396 [008] 18479979.230520: sched:sched_switch: prev_comm=CPU 0/KVM prev_pid=32396 prev_prio=120 prev_state=S ==> next_comm=swapper/8 next_pid=0 next_prio=120

Signed-off-by: Mengting Zhang <zhangmengting@huawei.com>
---
 tools/perf/Documentation/perf-script.txt | 3 +++
 tools/perf/builtin-script.c              | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 18dfcfa..85a080c 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -274,6 +274,9 @@ OPTIONS
 	Display context switch events i.e. events of type PERF_RECORD_SWITCH or
 	PERF_RECORD_SWITCH_CPU_WIDE.
 
+--show-guest-samples
+	Dispaly guest samples in host.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3d4c3b5..c34d241 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1340,6 +1340,7 @@ struct perf_script {
 	bool			show_switch_events;
 	bool			show_namespace_events;
 	bool			allocated;
+	bool			show_guest_samples;
 	struct cpu_map		*cpus;
 	struct thread_map	*threads;
 	int			name_width;
@@ -1557,7 +1558,7 @@ static int process_sample_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	if (al.filtered)
+	if (al.filtered && (!scr->show_guest_samples || !(al.filtered & (1 << HIST_FILTER__GUEST))))
 		goto out_put;
 
 	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
@@ -2771,6 +2772,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show context switch events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
 		    "Show namespace events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-guest-samples", &script.show_guest_samples,
+		    "Show guest samples (if recorded)"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
 	OPT_INTEGER(0, "max-blocks", &max_blocks,
 		    "Maximum number of code blocks to dump with brstackinsn"),
-- 
1.7.12.4

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

* Re: [PATCH] perf script: Add option to display guest samples in host
  2017-10-18  7:09 ` Mengting Zhang
  (?)
@ 2017-10-18 14:37 ` David Ahern
  2017-10-23  6:40     ` zhangmengting
  -1 siblings, 1 reply; 5+ messages in thread
From: David Ahern @ 2017-10-18 14:37 UTC (permalink / raw)
  To: Mengting Zhang, linux-perf-users, linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, ak, jolsa, namhyung,
	dsa, wangnan0, huawei.libin

On 10/18/17 1:09 AM, Mengting Zhang wrote:
> @@ -2771,6 +2772,8 @@ int cmd_script(int argc, const char **argv)
>  		    "Show context switch events (if recorded)"),
>  	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
>  		    "Show namespace events (if recorded)"),
> +	OPT_BOOLEAN('\0', "show-guest-samples", &script.show_guest_samples,
> +		    "Show guest samples (if recorded)"),
>  	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
>  	OPT_INTEGER(0, "max-blocks", &max_blocks,
>  		    "Maximum number of code blocks to dump with brstackinsn"),

At this point we need a 'show-all' option.

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

* Re: [PATCH] perf script: Add option to display guest samples in host
  2017-10-18 14:37 ` David Ahern
@ 2017-10-23  6:40     ` zhangmengting
  0 siblings, 0 replies; 5+ messages in thread
From: zhangmengting @ 2017-10-23  6:40 UTC (permalink / raw)
  To: David Ahern, linux-perf-users, linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, ak, jolsa, namhyung,
	dsa, wangnan0, huawei.libin

Hi all,
For sched_switch tracepoint, I guess maybe it would be more reasonable 
to show guest samples together with host samples by default, instead of 
setting an option to display guest samples when we meet with this 
confused situation.
To take care of this issue, the code should be changed as below:

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0c977b6..dcfab00 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1557,7 +1557,7 @@ static int process_sample_event(struct perf_tool 
*tool,
          return -1;
      }

-    if (al.filtered)
+    if (al.filtered && !(strcmp(evsel->name, "sched:sched_switch")== 0 
&& perf_host &&(al.filtered & (1 << HIST_FILTER__GUEST))))
          goto out_put;

      if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))

Right?

Thanks,
Mengting Zhang


On 2017/10/18 22:37, David Ahern wrote:
> On 10/18/17 1:09 AM, Mengting Zhang wrote:
>> @@ -2771,6 +2772,8 @@ int cmd_script(int argc, const char **argv)
>>   		    "Show context switch events (if recorded)"),
>>   	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
>>   		    "Show namespace events (if recorded)"),
>> +	OPT_BOOLEAN('\0', "show-guest-samples", &script.show_guest_samples,
>> +		    "Show guest samples (if recorded)"),
>>   	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
>>   	OPT_INTEGER(0, "max-blocks", &max_blocks,
>>   		    "Maximum number of code blocks to dump with brstackinsn"),
> At this point we need a 'show-all' option.
>
> .
>

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

* Re: [PATCH] perf script: Add option to display guest samples in host
@ 2017-10-23  6:40     ` zhangmengting
  0 siblings, 0 replies; 5+ messages in thread
From: zhangmengting @ 2017-10-23  6:40 UTC (permalink / raw)
  To: David Ahern, linux-perf-users, linux-kernel
  Cc: peterz, mingo, acme, alexander.shishkin, ak, jolsa, namhyung,
	dsa, wangnan0, huawei.libin

Hi all,
For sched_switch tracepoint, I guess maybe it would be more reasonable 
to show guest samples together with host samples by default, instead of 
setting an option to display guest samples when we meet with this 
confused situation.
To take care of this issue, the code should be changed as below:

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0c977b6..dcfab00 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1557,7 +1557,7 @@ static int process_sample_event(struct perf_tool 
*tool,
          return -1;
      }

-    if (al.filtered)
+    if (al.filtered && !(strcmp(evsel->name, "sched:sched_switch")== 0 
&& perf_host &&(al.filtered & (1 << HIST_FILTER__GUEST))))
          goto out_put;

      if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))

Right?

Thanks,
Mengting Zhang


On 2017/10/18 22:37, David Ahern wrote:
> On 10/18/17 1:09 AM, Mengting Zhang wrote:
>> @@ -2771,6 +2772,8 @@ int cmd_script(int argc, const char **argv)
>>   		    "Show context switch events (if recorded)"),
>>   	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
>>   		    "Show namespace events (if recorded)"),
>> +	OPT_BOOLEAN('\0', "show-guest-samples", &script.show_guest_samples,
>> +		    "Show guest samples (if recorded)"),
>>   	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
>>   	OPT_INTEGER(0, "max-blocks", &max_blocks,
>>   		    "Maximum number of code blocks to dump with brstackinsn"),
> At this point we need a 'show-all' option.
>
> .
>

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

end of thread, other threads:[~2017-10-23  6:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-18  7:09 [PATCH] perf script: Add option to display guest samples in host Mengting Zhang
2017-10-18  7:09 ` Mengting Zhang
2017-10-18 14:37 ` David Ahern
2017-10-23  6:40   ` zhangmengting
2017-10-23  6:40     ` zhangmengting

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.