Skip to contentSkip to conversation

fix IPC output in perf intel-pt-events script

PATCH In review Roman Lozko 3 participants 7 messages Mar 10, 2023 – Mar 14, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix IPC output in perf intel-pt-events script

Integers are not converted to floats during division in Python 2 which results in incorrect IPC values, convert to float explicitly.

---
 tools/perf/scripts/python/intel-pt-events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/intel-pt-events.py +1 -1
index 08862a2582f4..26e840e17062 100644
@@ -269,7 +269,7 @@ def print_common_ip(param_dict, sample, symbol, dso):
 	if "cyc_cnt" in sample:
 		cyc_cnt = sample["cyc_cnt"]
 		insn_cnt = get_optional_zero(sample, "insn_cnt")
-		ipc_str = "  IPC: %#.2f (%u/%u)" % (insn_cnt / cyc_cnt, insn_cnt, cyc_cnt)
+		ipc_str = "  IPC: %#.2f (%u/%u)" % (float(insn_cnt) / cyc_cnt, insn_cnt, cyc_cnt)
 	else:
 		ipc_str = ""
 	if glb_insn and glb_disassembler is not None:
Signature · 1 line
2.25.1
reviewer
#1 lore raw
Quoted 2 lines · Roman Lozko

Integers are not converted to floats during division in Python 2 which results in incorrect IPC values, convert to float explicitly.

Thanks for finding this. Obviously Python 3 is preferred nowadays but Python 2 seems to be still a thing.

AFAICT, it would be better to fix this by adding:

from __future__ import division

at the top of the script, next to from __future__ import print_function

Also the patch subject should be:

perf scripts: intel-pt-events.py: Fix IPC output for Python 2

Also a Fixes tag could be added i.e.

Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")
Quoted 19 lines
---
 tools/perf/scripts/python/intel-pt-events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/intel-pt-events.py +1 -1
index 08862a2582f4..26e840e17062 100644
@@ -269,7 +269,7 @@ def print_common_ip(param_dict, sample, symbol, dso):
 	if "cyc_cnt" in sample:
 		cyc_cnt = sample["cyc_cnt"]
 		insn_cnt = get_optional_zero(sample, "insn_cnt")
-		ipc_str = "  IPC: %#.2f (%u/%u)" % (insn_cnt / cyc_cnt, insn_cnt, cyc_cnt)
+		ipc_str = "  IPC: %#.2f (%u/%u)" % (float(insn_cnt) / cyc_cnt, insn_cnt, cyc_cnt)
 	else:
 		ipc_str = ""
 	if glb_insn and glb_disassembler is not None:
#2 lore raw
Quoted 9 lines · Adrian Hunter

Thanks for finding this. Obviously Python 3 is preferred nowadays but Python 2 seems to be still a thing.

AFAICT, it would be better to fix this by adding:

from __future__ import division

at the top of the script, next to from __future__ import print_function

Is it possible to build perf with python3? May it be better to stop supporting Python 2?

Quoted 7 lines

Also the patch subject should be:

perf scripts: intel-pt-events.py: Fix IPC output for Python 2

Also a Fixes tag could be added i.e.

Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")

Thanks for details, this is my first patch, I knew I would miss something :)

reviewer
#3 lore raw
Quoted 5 lines · Roman Lozko
Quoted 4 lines · Adrian Hunter

Thanks for finding this. Obviously Python 3 is preferred nowadays but Python 2 seems to be still a thing.

Quoted 8 lines
Quoted 5 lines

AFAICT, it would be better to fix this by adding:

from __future__ import division

at the top of the script, next to from __future__ import print_function

Is it possible to build perf with python3? May it be better to stop supporting Python 2?

PYTHON=python3 make -C tools/perf install

For more information refer:

https://perf.wiki.kernel.org/index.php/Perf_tools_support_for_Intel%C2%AE_Processor_Trace#Downloading_and_building_the_latest_perf_tools

Quoted 10 lines
Quoted 8 lines

Also the patch subject should be:

perf scripts: intel-pt-events.py: Fix IPC output for Python 2

Also a Fixes tag could be added i.e.

Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")

Thanks for details, this is my first patch, I knew I would miss something :)

#4 lore raw

PATCH v2 1/1 perf scripts: intel-pt-events.py: Fix IPC output for Python 2

In reply to Adrian Hunter

Integers are not converted to floats during division in Python 2 which results in incorrect IPC values. Fix by switching to new division behavior.

Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")
---
 tools/perf/scripts/python/intel-pt-events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/intel-pt-events.py +1 -1
index 08862a2582f4..1c76368f13c1 100644
@@ -11,7 +11,7 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
-from __future__ import print_function
+from __future__ import division, print_function
 
 import io
 import os
Signature · 1 line
2.25.1
reviewer Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] perf scripts: intel-pt-events.py: Fix IPC output for Python 2

Quoted 3 lines · Roman Lozko

Integers are not converted to floats during division in Python 2 which results in incorrect IPC values. Fix by switching to new division behavior.

There is usually a blank line here

Quoted 2 lines
Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")
Quoted 17 lines
---
 tools/perf/scripts/python/intel-pt-events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/intel-pt-events.py +1 -1
index 08862a2582f4..1c76368f13c1 100644
@@ -11,7 +11,7 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
-from __future__ import print_function
+from __future__ import division, print_function
 
 import io
 import os
maintainer Applied
#6 lore raw

Re: [PATCH v2] perf scripts: intel-pt-events.py: Fix IPC output for Python 2

Em Fri, Mar 10, 2023 at 06:50:48PM +0200, Adrian Hunter escreveu:

Quoted 6 lines · Roman Lozko
Quoted 3 lines

Integers are not converted to floats during division in Python 2 which results in incorrect IPC values. Fix by switching to new division behavior.

There is usually a blank line here

Fixed

Quoted 4 lines
Quoted 2 lines
Fixes a483e64c0b62 ("perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace")

Thanks, applied.

- Arnaldo

Quoted 18 lines
Quoted 17 lines
---
 tools/perf/scripts/python/intel-pt-events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/intel-pt-events.py +1 -1
index 08862a2582f4..1c76368f13c1 100644
@@ -11,7 +11,7 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
-from __future__ import print_function
+from __future__ import division, print_function
 
 import io
 import os
Signature · 1 line
- Arnaldo