Skip to contentSkip to conversation

perf parse-events: Back to support for parsing of field "-"

PATCH In review Junhao He 1 participant 2 messages Jun 26, 2024 – Aug 7, 2024 perf events

lore
Share & tools
lore

Junhao He

author
#0 lore raw

PATCH 1/1 perf parse-events: Back to support for parsing of field "-"

When merger the patch [1], event_term can not parse the field of "-". When use the following cmd, "-5/5-/5--" gives the same result as "5", and the value collected by the PMU is 0 when user input "--5", which is not the expected result?

If the first field after "=" of PE_TERM is "-", this means the user has entered a negative number. If the field of PE_TERM is followed by two consecutive hyphens "-", this means that the entry may not be valid. So if the user input "--5/-5/5-/5--" the perf tool may need return false or unsupport.

                 0      -e armv8_pmuv3_0/event=--5/
             1,359      -e armv8_pmuv3_0/event=-5/
             1,359      -e armv8_pmuv3_0/event=5/
             1,359      -e armv8_pmuv3_0/event=5-/
             1,359      -e armv8_pmuv3_0/event=5--/

If user enters "-" followed by the event alias name or event number (such as r0010), perf also works, and this format is more like an options to stat cmd than the -e argument.

  $ perf stat -e -r0010 -e -cycles -e cycles
	     11288      -e -r0010
	     7084679    -e -cycles
	     7084631    -e cycles

Back to support for parsing of field "-", they have the same results as apply the patch and before patch [1].

Testing:
1) $ perf stat -e armv8_pmuv3_0/event=-5/ sleep 1 event syntax error: '..uv3_0/event=-5/' \___ parser error

2) $ perf stat -e armv8_pmuv3_0/event=--5/ sleep 1 event syntax error: '..uv3_0/event=--5/' \___ parser error

3) $ perf stat -e armv8_pmuv3_0/event=5-/ -- sleep 1 event syntax error: '..v3_0/event=5-/' \___ parser error

4) $ perf stat -e armv8_pmuv3_0/event=5--/ -- sleep 1 event syntax error: '..v3_0/event=5--/' \___ parser error

5) $ perf stat -e -r0010 sleep 1
event syntax error: '-r0010'
\___ parser error

6) $ perf stat -e r0010 -e cycles -b cycles sleep 1
Error: unknown switch `b'

[1] commit 70c90e4a6b2f ("perf parse-events: Avoid scanning PMUs before parsing")

---
 tools/perf/util/parse-events.l | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/parse-events.l +1 -0
index 16045c383ada..1f0bdb89c43b 100644
@@ -426,6 +426,7 @@ r{num_raw_hex}		{ return str(yyscanner, PE_RAW); }
 "{"			{ BEGIN(event); return '{'; }
 "}"			{ return '}'; }
 =			{ return '='; }
+-			{ return '-'; }
 \n			{ }
 .			{ }
 
Signature · 1 line
2.33.0
author
#1 lore raw

Gentle ping... Any comment or suggestion is appreciated.

Quoted 72 lines · Junhao He

When merger the patch [1], event_term can not parse the field of "-". When use the following cmd, "-5/5-/5--" gives the same result as "5", and the value collected by the PMU is 0 when user input "--5", which is not the expected result?

If the first field after "=" of PE_TERM is "-", this means the user has entered a negative number. If the field of PE_TERM is followed by two consecutive hyphens "-", this means that the entry may not be valid. So if the user input "--5/-5/5-/5--" the perf tool may need return false or unsupport.

                  0      -e armv8_pmuv3_0/event=--5/
              1,359      -e armv8_pmuv3_0/event=-5/
              1,359      -e armv8_pmuv3_0/event=5/
              1,359      -e armv8_pmuv3_0/event=5-/
              1,359      -e armv8_pmuv3_0/event=5--/

If user enters "-" followed by the event alias name or event number (such as r0010), perf also works, and this format is more like an options to stat cmd than the -e argument.

   $ perf stat -e -r0010 -e -cycles -e cycles
	     11288      -e -r0010
	     7084679    -e -cycles
	     7084631    -e cycles

Back to support for parsing of field "-", they have the same results as apply the patch and before patch [1].

Testing:
1) $ perf stat -e armv8_pmuv3_0/event=-5/ sleep 1 event syntax error: '..uv3_0/event=-5/' \___ parser error

2) $ perf stat -e armv8_pmuv3_0/event=--5/ sleep 1 event syntax error: '..uv3_0/event=--5/' \___ parser error

3) $ perf stat -e armv8_pmuv3_0/event=5-/ -- sleep 1 event syntax error: '..v3_0/event=5-/' \___ parser error

4) $ perf stat -e armv8_pmuv3_0/event=5--/ -- sleep 1 event syntax error: '..v3_0/event=5--/' \___ parser error

5) $ perf stat -e -r0010 sleep 1
event syntax error: '-r0010'
\___ parser error

6) $ perf stat -e r0010 -e cycles -b cycles sleep 1
Error: unknown switch `b'

[1] commit 70c90e4a6b2f ("perf parse-events: Avoid scanning PMUs before parsing")

---
  tools/perf/util/parse-events.l | 1 +
  1 file changed, 1 insertion(+)
tools/perf/util/parse-events.l +1 -0
index 16045c383ada..1f0bdb89c43b 100644
@@ -426,6 +426,7 @@ r{num_raw_hex}		{ return str(yyscanner, PE_RAW); }
  "{"			{ BEGIN(event); return '{'; }
  "}"			{ return '}'; }
  =			{ return '='; }
+-			{ return '-'; }
  \n			{ }
  .			{ }