fix IPC output in perf intel-pt-events script
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
@@ -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
Adrian Hunter
reviewerQuoted 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.
Quoted 19 lines
Signed-off-by Roman Lozko <[email protected]>--- 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@@ -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:
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 divisionat the top of the script, next to from
__future__importprint_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 2Also 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 :)
Adrian Hunter
reviewerQuoted 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 divisionat the top of the script, next to from
__future__importprint_functionIs 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:
Quoted 10 lines
Quoted 8 lines
Also the patch subject should be:
perf scripts:
intel-pt-events.py: Fix IPC output for Python 2Also 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 :)
PATCH v2 1/1 perf scripts: intel-pt-events.py: Fix IPC output for Python 2
In reply to Adrian HunterIntegers are not converted to floats during division in Python 2 which results in incorrect IPC values. Fix by switching to new division behavior.
--- 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
@@ -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
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")Signed-off-by Roman Lozko <[email protected]>
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@@ -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
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")Signed-off-by Roman Lozko <[email protected]>Acked-by Adrian Hunter <[email protected]>
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@@ -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