diff mbox series

[v5,7/7] perf test: Add a test for default perf stat command

Message ID 20240828140736.156703-8-james.clark@linaro.org (mailing list archive)
State New, archived
Headers show
Series Event parsing fixes | expand

Commit Message

James Clark Aug. 28, 2024, 2:07 p.m. UTC
Test that one cycles event is opened for each core PMU when "perf stat"
is run without arguments.

The event line can either be output as "pmu/cycles/" or just "cycles" if
there is only one PMU. Include 2 spaces for padding in the one PMU case
to avoid matching when the word cycles is included in metric
descriptions.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/stat.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Namhyung Kim Aug. 30, 2024, 6:32 a.m. UTC | #1
Hello,

On Wed, Aug 28, 2024 at 03:07:21PM +0100, James Clark wrote:
> Test that one cycles event is opened for each core PMU when "perf stat"
> is run without arguments.
> 
> The event line can either be output as "pmu/cycles/" or just "cycles" if
> there is only one PMU. Include 2 spaces for padding in the one PMU case
> to avoid matching when the word cycles is included in metric
> descriptions.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
>  tools/perf/tests/shell/stat.sh | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
> index 525d0c44fdc6..24ace1de71cc 100755
> --- a/tools/perf/tests/shell/stat.sh
> +++ b/tools/perf/tests/shell/stat.sh
> @@ -148,6 +148,26 @@ test_cputype() {
>    echo "cputype test [Success]"
>  }
>  
> +test_hybrid() {
> +  # Test the default stat command on hybrid devices opens one cycles event for
> +  # each CPU type.
> +  echo "hybrid test"
> +
> +  # Count the number of core PMUs
> +  pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l)

Is it working on non-hybrid systems?  I don't think they have cpus file
in the core PMU.

Thanks,
Namhyung

> +
> +  # Run default Perf stat
> +  cycles_events=$(perf stat -- true 2>&1 | grep -E "/cycles/|  cycles  " | wc -l)
> +
> +  if [ "$pmus" -ne "$cycles_events" ]
> +  then
> +    echo "hybrid test [Found $pmus PMUs but $cycles_events cycles events. Failed]"
> +    err=1
> +    return
> +  fi
> +  echo "hybrid test [Success]"
> +}
> +
>  test_default_stat
>  test_stat_record_report
>  test_stat_record_script
> @@ -155,4 +175,5 @@ test_stat_repeat_weak_groups
>  test_topdown_groups
>  test_topdown_weak_groups
>  test_cputype
> +test_hybrid
>  exit $err
> -- 
> 2.34.1
>
James Clark Aug. 30, 2024, 8:29 a.m. UTC | #2
On 30/08/2024 7:32 am, Namhyung Kim wrote:
> Hello,
> 
> On Wed, Aug 28, 2024 at 03:07:21PM +0100, James Clark wrote:
>> Test that one cycles event is opened for each core PMU when "perf stat"
>> is run without arguments.
>>
>> The event line can either be output as "pmu/cycles/" or just "cycles" if
>> there is only one PMU. Include 2 spaces for padding in the one PMU case
>> to avoid matching when the word cycles is included in metric
>> descriptions.
>>
>> Signed-off-by: James Clark <james.clark@linaro.org>
>> ---
>>   tools/perf/tests/shell/stat.sh | 21 +++++++++++++++++++++
>>   1 file changed, 21 insertions(+)
>>
>> diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
>> index 525d0c44fdc6..24ace1de71cc 100755
>> --- a/tools/perf/tests/shell/stat.sh
>> +++ b/tools/perf/tests/shell/stat.sh
>> @@ -148,6 +148,26 @@ test_cputype() {
>>     echo "cputype test [Success]"
>>   }
>>   
>> +test_hybrid() {
>> +  # Test the default stat command on hybrid devices opens one cycles event for
>> +  # each CPU type.
>> +  echo "hybrid test"
>> +
>> +  # Count the number of core PMUs
>> +  pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l)
> 
> Is it working on non-hybrid systems?  I don't think they have cpus file
> in the core PMU.
> 
> Thanks,
> Namhyung
> 

Good point I only tested on Arm non-hybrid. I can change it to assume 1 
PMU for no cpus files?
James Clark Aug. 30, 2024, 8:45 a.m. UTC | #3
On 30/08/2024 9:29 am, James Clark wrote:
> 
> 
> On 30/08/2024 7:32 am, Namhyung Kim wrote:
>> Hello,
>>
>> On Wed, Aug 28, 2024 at 03:07:21PM +0100, James Clark wrote:
>>> Test that one cycles event is opened for each core PMU when "perf stat"
>>> is run without arguments.
>>>
>>> The event line can either be output as "pmu/cycles/" or just "cycles" if
>>> there is only one PMU. Include 2 spaces for padding in the one PMU case
>>> to avoid matching when the word cycles is included in metric
>>> descriptions.
>>>
>>> Signed-off-by: James Clark <james.clark@linaro.org>
>>> ---
>>>   tools/perf/tests/shell/stat.sh | 21 +++++++++++++++++++++
>>>   1 file changed, 21 insertions(+)
>>>
>>> diff --git a/tools/perf/tests/shell/stat.sh 
>>> b/tools/perf/tests/shell/stat.sh
>>> index 525d0c44fdc6..24ace1de71cc 100755
>>> --- a/tools/perf/tests/shell/stat.sh
>>> +++ b/tools/perf/tests/shell/stat.sh
>>> @@ -148,6 +148,26 @@ test_cputype() {
>>>     echo "cputype test [Success]"
>>>   }
>>> +test_hybrid() {
>>> +  # Test the default stat command on hybrid devices opens one cycles 
>>> event for
>>> +  # each CPU type.
>>> +  echo "hybrid test"
>>> +
>>> +  # Count the number of core PMUs
>>> +  pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l)
>>
>> Is it working on non-hybrid systems?  I don't think they have cpus file
>> in the core PMU.
>>
>> Thanks,
>> Namhyung
>>
> 
> Good point I only tested on Arm non-hybrid. I can change it to assume 1 
> PMU for no cpus files?

Or maybe assume 1 if a /sys/bus/event_source/devices/cpu folder exists? 
Not sure which is best but either will work.
Namhyung Kim Sept. 2, 2024, 5:43 p.m. UTC | #4
On Fri, Aug 30, 2024 at 09:45:11AM +0100, James Clark wrote:
> 
> 
> On 30/08/2024 9:29 am, James Clark wrote:
> > 
> > 
> > On 30/08/2024 7:32 am, Namhyung Kim wrote:
> > > Hello,
> > > 
> > > On Wed, Aug 28, 2024 at 03:07:21PM +0100, James Clark wrote:
> > > > Test that one cycles event is opened for each core PMU when "perf stat"
> > > > is run without arguments.
> > > > 
> > > > The event line can either be output as "pmu/cycles/" or just "cycles" if
> > > > there is only one PMU. Include 2 spaces for padding in the one PMU case
> > > > to avoid matching when the word cycles is included in metric
> > > > descriptions.
> > > > 
> > > > Signed-off-by: James Clark <james.clark@linaro.org>
> > > > ---
> > > >   tools/perf/tests/shell/stat.sh | 21 +++++++++++++++++++++
> > > >   1 file changed, 21 insertions(+)
> > > > 
> > > > diff --git a/tools/perf/tests/shell/stat.sh
> > > > b/tools/perf/tests/shell/stat.sh
> > > > index 525d0c44fdc6..24ace1de71cc 100755
> > > > --- a/tools/perf/tests/shell/stat.sh
> > > > +++ b/tools/perf/tests/shell/stat.sh
> > > > @@ -148,6 +148,26 @@ test_cputype() {
> > > >     echo "cputype test [Success]"
> > > >   }
> > > > +test_hybrid() {
> > > > +  # Test the default stat command on hybrid devices opens one
> > > > cycles event for
> > > > +  # each CPU type.
> > > > +  echo "hybrid test"
> > > > +
> > > > +  # Count the number of core PMUs
> > > > +  pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l)
> > > 
> > > Is it working on non-hybrid systems?  I don't think they have cpus file
> > > in the core PMU.
> > > 
> > > Thanks,
> > > Namhyung
> > > 
> > 
> > Good point I only tested on Arm non-hybrid. I can change it to assume 1
> > PMU for no cpus files?
> 
> Or maybe assume 1 if a /sys/bus/event_source/devices/cpu folder exists? Not
> sure which is best but either will work.

Some arch might not have a cpu PMU, I think we can assume 1 and update
only if it finds cpus files.

Thanks,
Namhyung
diff mbox series

Patch

diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
index 525d0c44fdc6..24ace1de71cc 100755
--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -148,6 +148,26 @@  test_cputype() {
   echo "cputype test [Success]"
 }
 
+test_hybrid() {
+  # Test the default stat command on hybrid devices opens one cycles event for
+  # each CPU type.
+  echo "hybrid test"
+
+  # Count the number of core PMUs
+  pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l)
+
+  # Run default Perf stat
+  cycles_events=$(perf stat -- true 2>&1 | grep -E "/cycles/|  cycles  " | wc -l)
+
+  if [ "$pmus" -ne "$cycles_events" ]
+  then
+    echo "hybrid test [Found $pmus PMUs but $cycles_events cycles events. Failed]"
+    err=1
+    return
+  fi
+  echo "hybrid test [Success]"
+}
+
 test_default_stat
 test_stat_record_report
 test_stat_record_script
@@ -155,4 +175,5 @@  test_stat_repeat_weak_groups
 test_topdown_groups
 test_topdown_weak_groups
 test_cputype
+test_hybrid
 exit $err