[PATCH 00/11] perf test: test_intel_pt.sh: Add per-thread test

Adrian Hunter posted 11 patches 3 years, 6 months ago
tools/lib/perf/evlist.c                 |   2 +
tools/perf/builtin-record.c             |   8 +
tools/perf/tests/shell/test_intel_pt.sh | 307 ++++++++++++++++++++++++++++++--
tools/perf/util/evsel.c                 |   2 +
4 files changed, 304 insertions(+), 15 deletions(-)
[PATCH 00/11] perf test: test_intel_pt.sh: Add per-thread test
Posted by Adrian Hunter 3 years, 6 months ago
Hi

Here is a new per-thread test for the test_intel_pt.sh test script.

The first 9 patches are tidy-ups for the script, mostly based on results
from the shellcheck utility.

The 10th patch adds debug prints that the script will capture to help
verify correct operation.

The final patch actually adds the new test.


Adrian Hunter (11):
      perf test: test_intel_pt.sh: Add cleanup function
      perf test: test_intel_pt.sh: Use a temp directory
      perf test: test_intel_pt.sh: Fix redirection
      perf test: test_intel_pt.sh: Stop using expr
      perf test: test_intel_pt.sh: Stop using backticks
      perf test: test_intel_pt.sh: Use grep -c instead of grep plus wc -l
      perf test: test_intel_pt.sh: Use quotes around variable expansion
      perf test: test_intel_pt.sh: Fix return checking
      perf test: test_intel_pt.sh: Add more output in preparation for more tests
      perf tools: Add debug messages and comments for testing
      perf test: test_intel_pt.sh: Add per-thread test

 tools/lib/perf/evlist.c                 |   2 +
 tools/perf/builtin-record.c             |   8 +
 tools/perf/tests/shell/test_intel_pt.sh | 307 ++++++++++++++++++++++++++++++--
 tools/perf/util/evsel.c                 |   2 +
 4 files changed, 304 insertions(+), 15 deletions(-)


Regards
Adrian
Re: [PATCH 00/11] perf test: test_intel_pt.sh: Add per-thread test
Posted by Namhyung Kim 3 years, 6 months ago
On Mon, Sep 12, 2022 at 1:34 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> Hi
>
> Here is a new per-thread test for the test_intel_pt.sh test script.
>
> The first 9 patches are tidy-ups for the script, mostly based on results
> from the shellcheck utility.
>
> The 10th patch adds debug prints that the script will capture to help
> verify correct operation.
>
> The final patch actually adds the new test.
>
>
> Adrian Hunter (11):
>       perf test: test_intel_pt.sh: Add cleanup function
>       perf test: test_intel_pt.sh: Use a temp directory
>       perf test: test_intel_pt.sh: Fix redirection
>       perf test: test_intel_pt.sh: Stop using expr
>       perf test: test_intel_pt.sh: Stop using backticks
>       perf test: test_intel_pt.sh: Use grep -c instead of grep plus wc -l
>       perf test: test_intel_pt.sh: Use quotes around variable expansion
>       perf test: test_intel_pt.sh: Fix return checking
>       perf test: test_intel_pt.sh: Add more output in preparation for more tests
>       perf tools: Add debug messages and comments for testing
>       perf test: test_intel_pt.sh: Add per-thread test

I don't think I understood all the black magic in patch 11. :)
At least we can move some helper functions to the lib and
reuse them in other tests.  I'll test that later..

So for patch 01-10,

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


>
>  tools/lib/perf/evlist.c                 |   2 +
>  tools/perf/builtin-record.c             |   8 +
>  tools/perf/tests/shell/test_intel_pt.sh | 307 ++++++++++++++++++++++++++++++--
>  tools/perf/util/evsel.c                 |   2 +
>  4 files changed, 304 insertions(+), 15 deletions(-)
>
>
> Regards
> Adrian
Re: [PATCH 00/11] perf test: test_intel_pt.sh: Add per-thread test
Posted by Adrian Hunter 3 years, 6 months ago
On 13/09/22 20:41, Namhyung Kim wrote:
> On Mon, Sep 12, 2022 at 1:34 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>>
>> Hi
>>
>> Here is a new per-thread test for the test_intel_pt.sh test script.
>>
>> The first 9 patches are tidy-ups for the script, mostly based on results
>> from the shellcheck utility.
>>
>> The 10th patch adds debug prints that the script will capture to help
>> verify correct operation.
>>
>> The final patch actually adds the new test.
>>
>>
>> Adrian Hunter (11):
>>       perf test: test_intel_pt.sh: Add cleanup function
>>       perf test: test_intel_pt.sh: Use a temp directory
>>       perf test: test_intel_pt.sh: Fix redirection
>>       perf test: test_intel_pt.sh: Stop using expr
>>       perf test: test_intel_pt.sh: Stop using backticks
>>       perf test: test_intel_pt.sh: Use grep -c instead of grep plus wc -l
>>       perf test: test_intel_pt.sh: Use quotes around variable expansion
>>       perf test: test_intel_pt.sh: Fix return checking
>>       perf test: test_intel_pt.sh: Add more output in preparation for more tests
>>       perf tools: Add debug messages and comments for testing
>>       perf test: test_intel_pt.sh: Add per-thread test
> 
> I don't think I understood all the black magic in patch 11. :)

It is not that bad :-)

Consider the output from the test:


	$ perf test -v " intel pt"
	Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
	102: Miscellaneous Intel PT testing                                  :
	--- start ---
	test child forked, pid 155646
<SNIP>
	--- Test per-thread recording ---
	Workload PIDs are 155669 and 155670
	perf PID is 155681
	Waiting for "perf record has started" message
	OK
	pid 155669 cpu -1 fd 5 : sys_perf_event_open: pid 155669  cpu -1 group_fd -1  flags 0x8 = 5

awk has matched the debug message and determined the values for pid, cpu and fd

	pid 155673 cpu -1 fd 6 : sys_perf_event_open: pid 155673  cpu -1 group_fd -1  flags 0x8 = 6
	pid 155670 cpu -1 fd 7 : sys_perf_event_open: pid 155670  cpu -1 group_fd -1  flags 0x8 = 7
	pid 155672 cpu -1 fd 8 : sys_perf_event_open: pid 155672  cpu -1 group_fd -1  flags 0x8 = 8
	pid 155669 cpu -1 fd 9 : sys_perf_event_open: pid 155669  cpu -1 group_fd -1  flags 0x8 = 9
	pid 155673 cpu -1 fd 10 : sys_perf_event_open: pid 155673  cpu -1 group_fd -1  flags 0x8 = 10
	pid 155670 cpu -1 fd 11 : sys_perf_event_open: pid 155670  cpu -1 group_fd -1  flags 0x8 = 11
	pid 155672 cpu -1 fd 12 : sys_perf_event_open: pid 155672  cpu -1 group_fd -1  flags 0x8 = 12
	fd 5 : idx 0: mmapping fd 5
	
awk has matched the debug message and determined the values for fd
	
	fd 9 fd_to 5 : idx 0: set output fd 9 -> 5
	
awk has matched the debug message and determined the values for fd and fd_to

	fd 6 : idx 1: mmapping fd 6
	fd 10 fd_to 6 : idx 1: set output fd 10 -> 6
	fd 7 : idx 2: mmapping fd 7
	fd 11 fd_to 7 : idx 2: set output fd 11 -> 7
	fd 8 : idx 3: mmapping fd 8
	fd 12 fd_to 8 : idx 3: set output fd 12 -> 8
	Checking 8 fds

Now awk is checking:
- every fd is mmapped or set-output
- there is 1 mmap per unique pid
- there is 1 mmap per unique cpu
- there are the right number of different pids
i.e.
	END {
		print "Checking " length(fd_array) " fds"
		for (fd in fd_array) {
			if (fd in mmap_array) {
				pid = pid_array[fd]
				if (pid != -1) {
					if (pid in pids) {
						print "More than 1 mmap for PID " pid
						exit 1
					}
					pids[pid] = 1
				}
				cpu = cpu_array[fd]
				if (cpu != -1) {
					if (cpu in cpus) {
						print "More than 1 mmap for CPU " cpu
						exit 1
					}
					cpus[cpu] = 1
				}
			} else if (!(fd in set_output_array)) {
				print "No mmap for fd " fd
				exit 1
			}
		}
		n = length(pids)
		if (n != thread_cnt) {
			print "Expected " thread_cnt " per-thread mmaps - found " n
			exit 1
		}
	}

> At least we can move some helper functions to the lib and
> reuse them in other tests.  I'll test that later..
> 
> So for patch 01-10,
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>
> 
> Thanks,
> Namhyung
> 
> 
>>
>>  tools/lib/perf/evlist.c                 |   2 +
>>  tools/perf/builtin-record.c             |   8 +
>>  tools/perf/tests/shell/test_intel_pt.sh | 307 ++++++++++++++++++++++++++++++--
>>  tools/perf/util/evsel.c                 |   2 +
>>  4 files changed, 304 insertions(+), 15 deletions(-)
>>
>>
>> Regards
>> Adrian
Re: [PATCH 00/11] perf test: test_intel_pt.sh: Add per-thread test
Posted by Arnaldo Carvalho de Melo 3 years, 6 months ago
Em Wed, Sep 14, 2022 at 11:25:07AM +0300, Adrian Hunter escreveu:
> On 13/09/22 20:41, Namhyung Kim wrote:
> > On Mon, Sep 12, 2022 at 1:34 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
> >>
> >> Hi
> >>
> >> Here is a new per-thread test for the test_intel_pt.sh test script.
> >>
> >> The first 9 patches are tidy-ups for the script, mostly based on results
> >> from the shellcheck utility.
> >>
> >> The 10th patch adds debug prints that the script will capture to help
> >> verify correct operation.
> >>
> >> The final patch actually adds the new test.
> >>
> >>
> >> Adrian Hunter (11):
> >>       perf test: test_intel_pt.sh: Add cleanup function
> >>       perf test: test_intel_pt.sh: Use a temp directory
> >>       perf test: test_intel_pt.sh: Fix redirection
> >>       perf test: test_intel_pt.sh: Stop using expr
> >>       perf test: test_intel_pt.sh: Stop using backticks
> >>       perf test: test_intel_pt.sh: Use grep -c instead of grep plus wc -l
> >>       perf test: test_intel_pt.sh: Use quotes around variable expansion
> >>       perf test: test_intel_pt.sh: Fix return checking
> >>       perf test: test_intel_pt.sh: Add more output in preparation for more tests
> >>       perf tools: Add debug messages and comments for testing
> >>       perf test: test_intel_pt.sh: Add per-thread test
> > 
> > I don't think I understood all the black magic in patch 11. :)
> 
> It is not that bad :-)

:-)

Thanks, applied the series.

- Arnaldo
 
> Consider the output from the test:
> 
> 
> 	$ perf test -v " intel pt"
> 	Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
> 	102: Miscellaneous Intel PT testing                                  :
> 	--- start ---
> 	test child forked, pid 155646
> <SNIP>
> 	--- Test per-thread recording ---
> 	Workload PIDs are 155669 and 155670
> 	perf PID is 155681
> 	Waiting for "perf record has started" message
> 	OK
> 	pid 155669 cpu -1 fd 5 : sys_perf_event_open: pid 155669  cpu -1 group_fd -1  flags 0x8 = 5
> 
> awk has matched the debug message and determined the values for pid, cpu and fd
> 
> 	pid 155673 cpu -1 fd 6 : sys_perf_event_open: pid 155673  cpu -1 group_fd -1  flags 0x8 = 6
> 	pid 155670 cpu -1 fd 7 : sys_perf_event_open: pid 155670  cpu -1 group_fd -1  flags 0x8 = 7
> 	pid 155672 cpu -1 fd 8 : sys_perf_event_open: pid 155672  cpu -1 group_fd -1  flags 0x8 = 8
> 	pid 155669 cpu -1 fd 9 : sys_perf_event_open: pid 155669  cpu -1 group_fd -1  flags 0x8 = 9
> 	pid 155673 cpu -1 fd 10 : sys_perf_event_open: pid 155673  cpu -1 group_fd -1  flags 0x8 = 10
> 	pid 155670 cpu -1 fd 11 : sys_perf_event_open: pid 155670  cpu -1 group_fd -1  flags 0x8 = 11
> 	pid 155672 cpu -1 fd 12 : sys_perf_event_open: pid 155672  cpu -1 group_fd -1  flags 0x8 = 12
> 	fd 5 : idx 0: mmapping fd 5
> 	
> awk has matched the debug message and determined the values for fd
> 	
> 	fd 9 fd_to 5 : idx 0: set output fd 9 -> 5
> 	
> awk has matched the debug message and determined the values for fd and fd_to
> 
> 	fd 6 : idx 1: mmapping fd 6
> 	fd 10 fd_to 6 : idx 1: set output fd 10 -> 6
> 	fd 7 : idx 2: mmapping fd 7
> 	fd 11 fd_to 7 : idx 2: set output fd 11 -> 7
> 	fd 8 : idx 3: mmapping fd 8
> 	fd 12 fd_to 8 : idx 3: set output fd 12 -> 8
> 	Checking 8 fds
> 
> Now awk is checking:
> - every fd is mmapped or set-output
> - there is 1 mmap per unique pid
> - there is 1 mmap per unique cpu
> - there are the right number of different pids
> i.e.
> 	END {
> 		print "Checking " length(fd_array) " fds"
> 		for (fd in fd_array) {
> 			if (fd in mmap_array) {
> 				pid = pid_array[fd]
> 				if (pid != -1) {
> 					if (pid in pids) {
> 						print "More than 1 mmap for PID " pid
> 						exit 1
> 					}
> 					pids[pid] = 1
> 				}
> 				cpu = cpu_array[fd]
> 				if (cpu != -1) {
> 					if (cpu in cpus) {
> 						print "More than 1 mmap for CPU " cpu
> 						exit 1
> 					}
> 					cpus[cpu] = 1
> 				}
> 			} else if (!(fd in set_output_array)) {
> 				print "No mmap for fd " fd
> 				exit 1
> 			}
> 		}
> 		n = length(pids)
> 		if (n != thread_cnt) {
> 			print "Expected " thread_cnt " per-thread mmaps - found " n
> 			exit 1
> 		}
> 	}
> 
> > At least we can move some helper functions to the lib and
> > reuse them in other tests.  I'll test that later..
> > 
> > So for patch 01-10,
> > 
> > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > 
> > Thanks,
> > Namhyung
> > 
> > 
> >>
> >>  tools/lib/perf/evlist.c                 |   2 +
> >>  tools/perf/builtin-record.c             |   8 +
> >>  tools/perf/tests/shell/test_intel_pt.sh | 307 ++++++++++++++++++++++++++++++--
> >>  tools/perf/util/evsel.c                 |   2 +
> >>  4 files changed, 304 insertions(+), 15 deletions(-)
> >>
> >>
> >> Regards
> >> Adrian

-- 

- Arnaldo