[tip:perf/core] perf tests: Fix record+probe_libc_inet_pton.sh for powerpc64
Commit-ID: bff5a556c149804de29347a88a884d25e4e4e3a2 Gitweb: https://git.kernel.org/tip/bff5a556c149804de29347a88a884d25e4e4e3a2 Author: Seeteena Thoufeek AuthorDate: Thu, 27 Jun 2019 15:46:54 +0530 Committer: Arnaldo Carvalho de Melo CommitDate: Sat, 6 Jul 2019 14:31:01 -0300 perf tests: Fix record+probe_libc_inet_pton.sh for powerpc64 'probe libc's inet_pton & backtrace it with ping' testcase sometimes fails on powerpc because distro ping binary does not have symbol information and thus it prints "[unknown]" function name in the backtrace. Accept "[unknown]" as valid function name for powerpc as well. # perf test -v "probe libc's inet_pton & backtrace it with ping" Before: 59: probe libc's inet_pton & backtrace it with ping : --- start --- test child forked, pid 79695 ping 79718 [077] 96483.787025: probe_libc:inet_pton: (7fff83a754c8) 7fff83a754c8 __GI___inet_pton+0x8 (/usr/lib64/power9/libc-2.28.so) 7fff83a2b7a0 gaih_inet.constprop.7+0x1020 (/usr/lib64/power9/libc-2.28.so) 7fff83a2c170 getaddrinfo+0x160 (/usr/lib64/power9/libc-2.28.so) 1171830f4 [unknown] (/usr/bin/ping) FAIL: expected backtrace entry ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" got "1171830f4 [unknown] (/usr/bin/ping)" test child finished with -1 end probe libc's inet_pton & backtrace it with ping: FAILED! After: 59: probe libc's inet_pton & backtrace it with ping : --- start --- test child forked, pid 79085 ping 79108 [045] 96400.214177: probe_libc:inet_pton: (7fffbb9654c8) 7fffbb9654c8 __GI___inet_pton+0x8 (/usr/lib64/power9/libc-2.28.so) 7fffbb91b7a0 gaih_inet.constprop.7+0x1020 (/usr/lib64/power9/libc-2.28.so) 7fffbb91c170 getaddrinfo+0x160 (/usr/lib64/power9/libc-2.28.so) 132e830f4 [unknown] (/usr/bin/ping) test child finished with 0 end probe libc's inet_pton & backtrace it with ping: Ok Signed-off-by: Seeteena Thoufeek Reviewed-by: Kim Phillips Cc: Alexander Shishkin Cc: Hendrik Brueckner Cc: Jiri Olsa Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Sandipan Das Fixes: 1632936480a5 ("perf tests: Fix record+probe_libc_inet_pton.sh without ping's debuginfo") Link: http://lkml.kernel.org/r/1561630614-3216-1-git-send-email-s1see...@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh index 61c9f8fc6fa1..58a99a292930 100755 --- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh +++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh @@ -44,7 +44,7 @@ trace_libc_inet_pton_backtrace() { eventattr='max-stack=4' echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected - echo ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected + echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected ;; *) eventattr='max-stack=3'
[PATCH] perf tests: Fix record+probe_libc_inet_pton.sh for powerpc64
'probe libc's inet_pton & backtrace it with ping' testcase sometimes fails on powerpc because distro ping binary does not have symbol information and thus it prints "[unknown]" function name in the backtrace. Accept "[unknown]" as valid function name for powerpc as well. # perf test -v "probe libc's inet_pton & backtrace it with ping" Before: 59: probe libc's inet_pton & backtrace it with ping : --- start --- test child forked, pid 79695 ping 79718 [077] 96483.787025: probe_libc:inet_pton: (7fff83a754c8) 7fff83a754c8 __GI___inet_pton+0x8 (/usr/lib64/power9/libc-2.28.so) 7fff83a2b7a0 gaih_inet.constprop.7+0x1020 (/usr/lib64/power9/libc-2.28.so) 7fff83a2c170 getaddrinfo+0x160 (/usr/lib64/power9/libc-2.28.so) 1171830f4 [unknown] (/usr/bin/ping) FAIL: expected backtrace entry ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" got "1171830f4 [unknown] (/usr/bin/ping)" test child finished with -1 end probe libc's inet_pton & backtrace it with ping: FAILED! After: 59: probe libc's inet_pton & backtrace it with ping : --- start --- test child forked, pid 79085 ping 79108 [045] 96400.214177: probe_libc:inet_pton: (7fffbb9654c8) 7fffbb9654c8 __GI___inet_pton+0x8 (/usr/lib64/power9/libc-2.28.so) 7fffbb91b7a0 gaih_inet.constprop.7+0x1020 (/usr/lib64/power9/libc-2.28.so) 7fffbb91c170 getaddrinfo+0x160 (/usr/lib64/power9/libc-2.28.so) 132e830f4 [unknown] (/usr/bin/ping) test child finished with 0 end probe libc's inet_pton & backtrace it with ping: Ok Signed-off-by: Seeteena Thoufeek --- tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh index 61c9f8f..58a99a2 100755 --- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh +++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh @@ -44,7 +44,7 @@ trace_libc_inet_pton_backtrace() { eventattr='max-stack=4' echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected - echo ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected + echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected ;; *) eventattr='max-stack=3' -- 1.8.3.1
[PATCH v3] perf scripts python: Add Python 3 support to export-to-postgresql.py
Support both Python 2 and Python 3 in export-to-postgresql.py. ``print`` is now a function rather than a statement. This should have no functional change. Also, handles the conversion of "print >> sys.stderr". Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-postgresql.py | 25 --- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py index 0564dd7..b2ff375 100644 --- a/tools/perf/scripts/python/export-to-postgresql.py +++ b/tools/perf/scripts/python/export-to-postgresql.py @@ -9,6 +9,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import os import sys @@ -236,10 +237,10 @@ perf_db_export_callchains = False def usage(): - print >> sys.stderr, "Usage is: export-to-postgresql.py [] [] []" - print >> sys.stderr, "where:columns 'all' or 'branches'" - print >> sys.stderr, " calls 'calls' => create calls and call_paths table" - print >> sys.stderr, " callchains 'callchains' => create call_paths table" + sys.stderr.write("Usage is: export-to-postgresql.py [] [] []"); + sys.stderr.write("where:columns 'all' or 'branches'"); + sys.stderr.write(" calls 'calls' => create calls and call_paths table"); + sys.stderr.write(" callchains 'callchains' => create call_paths table"); raise Exception("Too few arguments") if (len(sys.argv) < 2): @@ -273,7 +274,7 @@ def do_query(q, s): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db = QSqlDatabase.addDatabase('QPSQL') query = QSqlQuery(db) @@ -564,7 +565,7 @@ if perf_db_export_calls: call_file = open_output_file("call_table.bin") def trace_begin(): - print datetime.datetime.today(), "Writing to intermediate files..." + print(datetime.datetime.today(), "Writing to intermediate files...") # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") machine_table(0, 0, "unknown") @@ -579,7 +580,7 @@ def trace_begin(): unhandled_count = 0 def trace_end(): - print datetime.datetime.today(), "Copying to database..." + print(datetime.datetime.today(), "Copying to database...") copy_output_file(evsel_file,"selected_events") copy_output_file(machine_file, "machines") copy_output_file(thread_file, "threads") @@ -594,7 +595,7 @@ def trace_end(): if perf_db_export_calls: copy_output_file(call_file, "calls") - print datetime.datetime.today(), "Removing intermediate files..." + print(datetime.datetime.today(), "Removing intermediate files...") remove_output_file(evsel_file) remove_output_file(machine_file) remove_output_file(thread_file) @@ -609,7 +610,7 @@ def trace_end(): if perf_db_export_calls: remove_output_file(call_file) os.rmdir(output_dir_name) - print datetime.datetime.today(), "Adding primary keys" + print(datetime.datetime.today(), "Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE machinesADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') @@ -624,7 +625,7 @@ def trace_end(): if perf_db_export_calls: do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') - print datetime.datetime.today(), "Adding foreign keys" + print(datetime.datetime.today(), "Adding foreign keys") do_query(query, 'ALTER TABLE threads ' 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads(id)') @@ -659,8 +660,8 @@ def trace_end(): do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today()
[PATCH v3] perf scripts python: Add Python 3 support to export-to-sqlite.py
Support both Python 2 and Python 3 in export-to-sqlite.py. ``print`` is now a function rather than a statement. This should have no functional change. Also, handles the conversion of "print >> sys.stderr". Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-sqlite.py | 19 ++- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py index 245caf2..95bfcb2 100644 --- a/tools/perf/scripts/python/export-to-sqlite.py +++ b/tools/perf/scripts/python/export-to-sqlite.py @@ -9,6 +9,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import os import sys @@ -61,10 +62,10 @@ perf_db_export_calls = False perf_db_export_callchains = False def usage(): - print >> sys.stderr, "Usage is: export-to-sqlite.py [] [] []" - print >> sys.stderr, "where:columns 'all' or 'branches'" - print >> sys.stderr, " calls 'calls' => create calls and call_paths table" - print >> sys.stderr, " callchains 'callchains' => create call_paths table" + sys.stderr.write("Usage is: export-to-sqlite.py [] [] []"); + sys.stderr.write("where:columns 'all' or 'branches'"); + sys.stderr.write(" calls 'calls' => create calls and call_paths table"); + sys.stderr.write(" callchains 'callchains' => create call_paths table"); raise Exception("Too few arguments") if (len(sys.argv) < 2): @@ -100,7 +101,7 @@ def do_query_(q): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db_exists = False try: @@ -376,7 +377,7 @@ if perf_db_export_calls: call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): - print datetime.datetime.today(), "Writing records..." + print(datetime.datetime.today(), "Writing records...") do_query(query, 'BEGIN TRANSACTION') # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") @@ -394,13 +395,13 @@ unhandled_count = 0 def trace_end(): do_query(query, 'END TRANSACTION') - print datetime.datetime.today(), "Adding indexes" + print(datetime.datetime.today(), "Adding indexes") if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" - print datetime.datetime.today(), "Done" + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") + print(datetime.datetime.today(), "Done") def trace_unhandled(event_name, context, event_fields_dict): global unhandled_count -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to net_dropmonitor.py
Support both Python 2 and Python 3 in net_dropmonitor.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/net_dropmonitor.py | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py index a150164..88fe4a2 100755 --- a/tools/perf/scripts/python/net_dropmonitor.py +++ b/tools/perf/scripts/python/net_dropmonitor.py @@ -1,5 +1,6 @@ # Monitor the system for dropped packets and proudce a report of drop locations and counts # SPDX-License-Identifier: GPL-2.0 +from __future__ import print_function import os import sys @@ -50,19 +51,19 @@ def get_sym(sloc): return (None, 0) def print_drop_table(): - print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") + print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")) for i in drop_log.keys(): (sym, off) = get_sym(i) if sym == None: sym = i - print "%25s %25s %25s" % (sym, off, drop_log[i]) + print("%25s %25s %25s" % (sym, off, drop_log[i])) def trace_begin(): - print "Starting trace (Ctrl-C to dump results)" + print("Starting trace (Ctrl-C to dump results)") def trace_end(): - print "Gathering kallsyms data" + print("Gathering kallsyms data") get_kallsyms_table() print_drop_table() -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to exported-sql-viewer.py
Support both Python 2 and Python 3 in exported-sql-viewer.py. ``print`` is now a function rather than a statement. This should have no functional change. Add support of _pickle module in Python3 Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/exported-sql-viewer.py | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index f278ce5..a4aef58 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -1,4 +1,3 @@ -#!/usr/bin/python2 # SPDX-License-Identifier: GPL-2.0 # exported-sql-viewer.py: view data from sql database # Copyright (c) 2014-2018, Intel Corporation. @@ -87,12 +86,12 @@ # 7fab593ea94f 48 8b 05 1a 15 22 00movq 0x22151a(%rip), %rax # 7fab593ea956 48 89 15 3b 13 22 00movq %rdx, 0x22133b(%rip) # 8107675243232 2ls 22011 22011 hardware interrupt No 7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> 86a012e0 page_fault ([kernel]) +from __future__ import print_function import sys import weakref import threading import string -import cPickle import re import os from PySide.QtCore import * @@ -102,6 +101,11 @@ from decimal import * from ctypes import * from multiprocessing import Process, Array, Value, Event +if sys.version_info[0] < 3: +import cPickle +else: +import _pickle as cPickle + # Data formatting helpers def tohex(ip): @@ -1560,7 +1564,7 @@ class SQLTableDialogDataItem(): return str(lower_id) def ConvertRelativeTime(self, val): - print "val ", val + print("val ", val) mult = 1 suffix = val[-2:] if suffix == "ms": @@ -1582,29 +1586,29 @@ class SQLTableDialogDataItem(): return str(val) def ConvertTimeRange(self, vrange): - print "vrange ", vrange + print("vrange ", vrange) if vrange[0] == "": vrange[0] = str(self.first_time) if vrange[1] == "": vrange[1] = str(self.last_time) vrange[0] = self.ConvertRelativeTime(vrange[0]) vrange[1] = self.ConvertRelativeTime(vrange[1]) - print "vrange2 ", vrange + print("vrange2 ", vrange) if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]): return False - print "ok1" + print("ok1") beg_range = max(int(vrange[0]), self.first_time) end_range = min(int(vrange[1]), self.last_time) if beg_range > self.last_time or end_range < self.first_time: return False - print "ok2" + print("ok2") vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True) vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False) - print "vrange3 ", vrange + print("vrange3 ", vrange) return True def AddTimeRange(self, value, ranges): - print "value ", value + print("value ", value) n = value.count("-") if n == 1: pass -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to intel-pt-events.py
Support both Python 2 and Python 3 in intel-pt-events.py.``print`` is now a function rather than a statement. This should have no functional change. Fixes indentation issue, replace spaces with tab. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/intel-pt-events.py | 57 ++-- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index b19172d..de153f7 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py @@ -9,6 +9,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import os import sys @@ -22,34 +23,34 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ #from Core import * def trace_begin(): - print "Intel PT Power Events and PTWRITE" + print("Intel PT Power Events and PTWRITE") def trace_end(): - print "End" + print("End") def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])) def print_ptwrite(raw_buf): data = struct.unpack_from("> 32) & 0x3 - print "hints: %#x extensions: %#x" % (hints, extensions), + print("hints: %#x extensions: %#x" % (hints, extensions)), def print_pwre(raw_buf): data = struct.unpack_from("> 7) & 1 cstate = (payload >> 12) & 0xf subcstate = (payload >> 8) & 0xf - print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), + print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate)), def print_exstop(raw_buf): data = struct.unpack_from("> 4) & 0xf wake_reason = (payload >> 8) & 0xf - print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), + print("deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason)), def print_common_start(comm, sample, name): ts = sample["time"] cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10, ts %10, name), + print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10, ts %10, name)), def print_common_ip(sample, symbol, dso): ip = sample["ip"] - print "%16x %s (%s)" % (ip, symbol, dso) + print("%16x %s (%s)" % (ip, symbol, dso)) def process_event(param_dict): -event_attr = param_dict["attr"] -sample = param_dict["sample"] -raw_buf= param_dict["raw_buf"] -comm = param_dict["comm"] -name = param_dict["ev_name"] - -# Symbol and dso info are not always resolved -if (param_dict.has_key("dso")): -dso = param_dict["dso"] -else: -dso = "[unknown]" - -if (param_dict.has_key("symbol")): -symbol = param_dict["symbol"] -else: -symbol = "[unknown]" - + event_attr = param_dict["attr"] + sample = param_dict["sample"] + raw_buf= param_dict["raw_buf"] + comm = param_dict["comm"] + name = param_dict["ev_name"] + + # Symbol and dso info are not always resolved + if ('dso' in param_dict): + dso = param_dict["dso"] + else: + dso = "[unknown]" + + if ('symbol' in param_dict): + symbol = param_dict["symbol"] + else: + symbol = "[unknown]" + if name == "ptwrite": print_common_start(comm, sample, name) print_ptwrite(raw_buf) -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to netdev-times.py
Support both Python 2 and Python 3 in netdev-times.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/netdev-times.py | 77 --- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py index 9b2050f..c25965c 100644 --- a/tools/perf/scripts/python/netdev-times.py +++ b/tools/perf/scripts/python/netdev-times.py @@ -7,6 +7,7 @@ # rx: show only rx chart # dev=: show only thing related to specified device # debug: work with debug mode. It shows buffer status. +from __future__ import print_function import os import sys @@ -61,12 +62,12 @@ def diff_msec(src, dst): def print_transmit(hunk): if dev != 0 and hunk['dev'].find(dev) < 0: return - print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ + print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ (hunk['dev'], hunk['len'], nsecs_secs(hunk['queue_t']), nsecs_nsecs(hunk['queue_t'])/1000, diff_msec(hunk['queue_t'], hunk['xmit_t']), - diff_msec(hunk['xmit_t'], hunk['free_t'])) + diff_msec(hunk['xmit_t'], hunk['free_t']))) # Format for displaying rx packet processing PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" @@ -98,55 +99,55 @@ def print_receive(hunk): if show_hunk == 0: return - print "%d.%06dsec cpu=%d" % \ - (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) + print("%d.%06dsec cpu=%d" % \ + (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)) for i in range(len(irq_list)): - print PF_IRQ_ENTRY % \ + print(PF_IRQ_ENTRY % \ (diff_msec(base_t, irq_list[i]['irq_ent_t']), - irq_list[i]['irq'], irq_list[i]['name']) - print PF_JOINT + irq_list[i]['irq'], irq_list[i]['name'])) + print(PF_JOINT) irq_event_list = irq_list[i]['event_list'] for j in range(len(irq_event_list)): irq_event = irq_event_list[j] if irq_event['event'] == 'netif_rx': - print PF_NET_RX % \ + print(PF_NET_RX % \ (diff_msec(base_t, irq_event['time']), - irq_event['skbaddr']) - print PF_JOINT - print PF_SOFT_ENTRY % \ - diff_msec(base_t, hunk['sirq_ent_t']) - print PF_JOINT + irq_event['skbaddr'])) + print(PF_JOINT) + print(PF_SOFT_ENTRY % \ + diff_msec(base_t, hunk['sirq_ent_t'])) + print(PF_JOINT) event_list = hunk['event_list'] for i in range(len(event_list)): event = event_list[i] if event['event_name'] == 'napi_poll': - print PF_NAPI_POLL % \ - (diff_msec(base_t, event['event_t']), event['dev']) + print(PF_NAPI_POLL % \ + (diff_msec(base_t, event['event_t']), event['dev'])) if i == len(event_list) - 1: - print "" + print("") else: - print PF_JOINT + print(PF_JOINT) else: - print PF_NET_RECV % \ + print(PF_NET_RECV % \ (diff_msec(base_t, event['event_t']), event['skbaddr'], - event['len']) + event['len'])) if 'comm' in event.keys(): - print PF_WJOINT - print PF_CPY_DGRAM % \ + print(PF_WJOINT) + print(PF_CPY_DGRAM % \ (diff_msec(base_t, event['comm_t']), - event['pid'], event['comm']) + event['pid'], event['comm'])) elif 'handle' in event.keys(): - print PF_WJOINT + print(PF_WJOINT) if event['handle'] == "kfree_skb": - print PF_KFREE_SKB % \ + print(PF_KFREE_SKB % \
[PATCH v2] perf scripts python: Add Python 3 support to failed-syscalls-by-pid.py
Support both Python 2 and Python 3 in failed-syscalls-by-pid.py. ``print`` is now a function rather than a statement. This should have no functional change. Fixes lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria Please enter the commit message for your changes. Lines starting --- tools/perf/scripts/python/failed-syscalls-by-pid.py | 21 +++-- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py index cafeff3..a174755 100644 --- a/tools/perf/scripts/python/failed-syscalls-by-pid.py +++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py @@ -4,6 +4,7 @@ # # Displays system-wide failed system call totals, broken down by pid. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. +from __future__ import print_function import os import sys @@ -32,7 +33,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_error_totals() @@ -57,22 +58,22 @@ def syscalls__sys_exit(event_name, context, common_cpu, def print_error_totals(): if for_comm is not None: - print "\nsyscall errors for %s:\n\n" % (for_comm), + print("\nsyscall errors for %s:\n\n" % (for_comm)), else: - print "\nsyscall errors:\n\n", + print("\nsyscall errors:\n\n"), -print "%-30s %10s\n" % ("comm [pid]", "count"), -print "%-30s %10s\n" % ("--", \ - "--"), +print("%-30s %10s\n" % ("comm [pid]", "count")), +print("%-30s %10s\n" % ("--", \ + "--")), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: - print "\n%s [%d]\n" % (comm, pid), + print("\n%s [%d]\n" % (comm, pid)), id_keys = syscalls[comm][pid].keys() for id in id_keys: - print " syscall: %-16s\n" % syscall_name(id), + print(" syscall: %-16s\n" % syscall_name(id)), ret_keys = syscalls[comm][pid][id].keys() - for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): - print "err = %-20s %10d\n" % (strerror(ret), val), + for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print("err = %-20s %10d\n" % (strerror(ret), val)), -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to sctop.py
Support both Python 2 and Python 3 in sctop.py.``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/sctop.py | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py index 61621b9..d059a2a 100644 --- a/tools/perf/scripts/python/sctop.py +++ b/tools/perf/scripts/python/sctop.py @@ -7,6 +7,7 @@ # [comm] are displayed. If an [interval] arg is specified, the display # will be refreshed every [interval] seconds. The default interval is # 3 seconds. +from __future__ import print_function import os, sys, thread, time @@ -62,18 +63,18 @@ def print_syscall_totals(interval): while 1: clear_term() if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events:\n\n", + print("\nsyscall events:\n\n"), - print "%-40s %10s\n" % ("event", "count"), - print "%-40s %10s\n" % ("", \ -"--"), + print("%-40s %10s\n" % ("event", "count")), + print("%-40s %10s\n" % ("", \ +"--")), - for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ + for id, val in sorted(syscalls.iteritems(), key = lambda k_v: (k_v[1], k_v[0]), \ reverse = True): try: - print "%-40s %10d\n" % (syscall_name(id), val), + print("%-40s %10d\n" % (syscall_name(id), val)), except TypeError: pass syscalls.clear() -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to stackcollapse.py
Support both Python 2 and Python 3 in stackcollapse.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/stackcollapse.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py index 1697b5e..f77bc0d 100755 --- a/tools/perf/scripts/python/stackcollapse.py +++ b/tools/perf/scripts/python/stackcollapse.py @@ -18,6 +18,7 @@ # # Written by Paolo Bonzini # Based on Brendan Gregg's stackcollapse-perf.pl script. +from __future__ import print_function import os import sys @@ -123,4 +124,4 @@ def trace_end(): list = lines.keys() list.sort() for stack in list: -print "%s %d" % (stack, lines[stack]) +print("%s %d" % (stack, lines[stack])) -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to syscall-counts-by-pid.py
Support both Python 2 and Python 3 in syscall-counts-by-pid.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/syscall-counts-by-pid.py | 19 ++- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py index daf314c..3146094 100644 --- a/tools/perf/scripts/python/syscall-counts-by-pid.py +++ b/tools/perf/scripts/python/syscall-counts-by-pid.py @@ -4,6 +4,7 @@ # # Displays system-wide system call totals, broken down by syscall. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. +from __future__ import print_function import os, sys @@ -31,7 +32,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_syscall_totals() @@ -55,20 +56,20 @@ def syscalls__sys_enter(event_name, context, common_cpu, def print_syscall_totals(): if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events by comm/pid:\n\n", + print("\nsyscall events by comm/pid:\n\n"), -print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"), -print "%-40s %10s\n" % ("", \ - "--"), +print("%-40s %10s\n" % ("comm [pid]/syscalls", "count")), +print("%-40s %10s\n" % ("", \ + "--")), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: - print "\n%s [%d]\n" % (comm, pid), + print("\n%s [%d]\n" % (comm, pid)), id_keys = syscalls[comm][pid].keys() for id, val in sorted(syscalls[comm][pid].iteritems(), \ - key = lambda(k, v): (v, k), reverse = True): - print " %-38s %10d\n" % (syscall_name(id), val), + key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print(" %-38s %10d\n" % (syscall_name(id), val)), -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to export-to-postgresql.py
Support both Python 2 and Python 3 in export-to-postgresql.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-postgresql.py | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py index 0564dd7..82e10a6 100644 --- a/tools/perf/scripts/python/export-to-postgresql.py +++ b/tools/perf/scripts/python/export-to-postgresql.py @@ -9,6 +9,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import os import sys @@ -273,7 +274,7 @@ def do_query(q, s): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db = QSqlDatabase.addDatabase('QPSQL') query = QSqlQuery(db) @@ -564,7 +565,7 @@ if perf_db_export_calls: call_file = open_output_file("call_table.bin") def trace_begin(): - print datetime.datetime.today(), "Writing to intermediate files..." + print(datetime.datetime.today(), "Writing to intermediate files...") # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") machine_table(0, 0, "unknown") @@ -579,7 +580,7 @@ def trace_begin(): unhandled_count = 0 def trace_end(): - print datetime.datetime.today(), "Copying to database..." + print(datetime.datetime.today(), "Copying to database...") copy_output_file(evsel_file,"selected_events") copy_output_file(machine_file, "machines") copy_output_file(thread_file, "threads") @@ -594,7 +595,7 @@ def trace_end(): if perf_db_export_calls: copy_output_file(call_file, "calls") - print datetime.datetime.today(), "Removing intermediate files..." + print(datetime.datetime.today(), "Removing intermediate files...") remove_output_file(evsel_file) remove_output_file(machine_file) remove_output_file(thread_file) @@ -609,7 +610,7 @@ def trace_end(): if perf_db_export_calls: remove_output_file(call_file) os.rmdir(output_dir_name) - print datetime.datetime.today(), "Adding primary keys" + print(datetime.datetime.today(), "Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE machinesADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') @@ -624,7 +625,7 @@ def trace_end(): if perf_db_export_calls: do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') - print datetime.datetime.today(), "Adding foreign keys" + print(datetime.datetime.today(), "Adding foreign keys") do_query(query, 'ALTER TABLE threads ' 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads(id)') @@ -659,8 +660,8 @@ def trace_end(): do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" - print datetime.datetime.today(), "Done" + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") + print(datetime.datetime.today(), "Done") def trace_unhandled(event_name, context, event_fields_dict): global unhandled_count -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to syscall-counts.py
Support both Python 2 and Python 3 in syscall-counts.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/syscall-counts.py | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py index e66a773..6ca67bd 100644 --- a/tools/perf/scripts/python/syscall-counts.py +++ b/tools/perf/scripts/python/syscall-counts.py @@ -4,6 +4,7 @@ # # Displays system-wide system call totals, broken down by syscall. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. +from __future__ import print_function import os import sys @@ -28,7 +29,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_syscall_totals() @@ -51,14 +52,14 @@ def syscalls__sys_enter(event_name, context, common_cpu, def print_syscall_totals(): if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events:\n\n", + print("\nsyscall events:\n\n"), -print "%-40s %10s\n" % ("event", "count"), -print "%-40s %10s\n" % ("", \ - "---"), +print("%-40s %10s\n" % ("event", "count")), +print("%-40s %10s\n" % ("", \ + "---")), -for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ +for id, val in sorted(syscalls.iteritems(), key = lambda k_v: (k_v[1], k_v[0]), \ reverse = True): - print "%-40s %10d\n" % (syscall_name(id), val), + print("%-40s %10d\n" % (syscall_name(id), val)), -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to powerpc-hcalls.py
Support both Python 2 and Python 3 in powerpc-hcalls.py. ``print`` is now a function rather than a statement. This should have no functional change. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/powerpc-hcalls.py | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py index 00e0e74..19ff684 100644 --- a/tools/perf/scripts/python/powerpc-hcalls.py +++ b/tools/perf/scripts/python/powerpc-hcalls.py @@ -3,6 +3,7 @@ # Copyright (C) 2018 Ravi Bangoria, IBM Corporation # # Hypervisor call statisics +from __future__ import print_function import os import sys @@ -149,7 +150,7 @@ hcall_table = { } def hcall_table_lookup(opcode): - if (hcall_table.has_key(opcode)): + if (opcode in hcall_table): return hcall_table[opcode] else: return opcode @@ -157,8 +158,8 @@ def hcall_table_lookup(opcode): print_ptrn = '%-28s%10s%10s%10s%10s' def trace_end(): - print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)') - print '-' * 68 + print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')) + print('-' * 68) for opcode in output: h_name = hcall_table_lookup(opcode) time = output[opcode]['time'] @@ -166,14 +167,14 @@ def trace_end(): min_t = output[opcode]['min'] max_t = output[opcode]['max'] - print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt) + print(print_ptrn % (h_name, cnt, min_t, max_t, time/cnt)) def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, opcode, retval): - if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)): + if ((cpu in d_enter) and (opcode in d_enter[cpu])): diff = nsecs(sec, nsec) - d_enter[cpu][opcode] - if (output.has_key(opcode)): + if (opcode in output): output[opcode]['time'] += diff output[opcode]['cnt'] += 1 if (output[opcode]['min'] > diff): @@ -194,7 +195,7 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm, callchain, opcode): - if (d_enter.has_key(cpu)): + if (cpu in d_enter): d_enter[cpu][opcode] = nsecs(sec, nsec) else: d_enter[cpu] = {opcode: nsecs(sec, nsec)} -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to mem-phys-addr.py
Support both Python 2 and Python 3 in mem-phys-addr.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/mem-phys-addr.py | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py index ebee2c5..e30fc9d 100644 --- a/tools/perf/scripts/python/mem-phys-addr.py +++ b/tools/perf/scripts/python/mem-phys-addr.py @@ -3,6 +3,7 @@ # # Copyright (c) 2018, Intel Corporation. +from __future__ import print_function from __future__ import division import os import sys @@ -38,14 +39,14 @@ def parse_iomem(): pmem.append(long(m[1], 16)) def print_memory_type(): - print "Event: %s" % (event_name) - print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), - print "%-40s %10s %10s\n" % ("", \ - "---", "---"), + print("Event: %s" % (event_name)) + print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage")), + print("%-40s %10s %10s\n" % ("", \ + "---", "---")), total = sum(load_mem_type_cnt.values()) for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ - key = lambda(k, v): (v, k), reverse = True): - print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), + key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total)), def trace_begin(): parse_iomem() -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to stat-cpi.py
Support both Python 2 and Python 3 in stat-cpi.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/stat-cpi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py index 8410672..1d8e8b7 100644 --- a/tools/perf/scripts/python/stat-cpi.py +++ b/tools/perf/scripts/python/stat-cpi.py @@ -59,7 +59,7 @@ def stat__interval(time): if ins != 0: cpi = cyc/float(ins) -print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(10)), cpu, thread, cpi, cyc, ins) +print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(10)), cpu, thread, cpi, cyc, ins)) def trace_end(): pass -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to export-to-sqlite.py
Support both Python 2 and Python 3 in export-to-sqlite.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-sqlite.py | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py index 245caf2..66be899 100644 --- a/tools/perf/scripts/python/export-to-sqlite.py +++ b/tools/perf/scripts/python/export-to-sqlite.py @@ -9,6 +9,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import os import sys @@ -100,7 +101,7 @@ def do_query_(q): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db_exists = False try: @@ -376,7 +377,7 @@ if perf_db_export_calls: call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): - print datetime.datetime.today(), "Writing records..." + print(datetime.datetime.today(), "Writing records...") do_query(query, 'BEGIN TRANSACTION') # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") @@ -394,13 +395,13 @@ unhandled_count = 0 def trace_end(): do_query(query, 'END TRANSACTION') - print datetime.datetime.today(), "Adding indexes" + print(datetime.datetime.today(), "Adding indexes") if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" - print datetime.datetime.today(), "Done" + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") + print(datetime.datetime.today(), "Done") def trace_unhandled(event_name, context, event_fields_dict): global unhandled_count -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to futex-contention.py
Support both Python 2 and Python 3 in futex-contention.py. ``print`` is now a function rather than a statement. This should have no functional change. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria Please enter the commit message for your changes. Lines starting --- tools/perf/scripts/python/futex-contention.py | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/futex-contention.py b/tools/perf/scripts/python/futex-contention.py index 0f5cf43..794a9f0 100644 --- a/tools/perf/scripts/python/futex-contention.py +++ b/tools/perf/scripts/python/futex-contention.py @@ -9,6 +9,7 @@ # to perf python scripting. # # Measures futex contention +from __future__ import print_function import os, sys sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') @@ -33,18 +34,18 @@ def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, nr, ret): - if thread_blocktime.has_key(tid): + if (tid in thread_blocktime): elapsed = nsecs(s, ns) - thread_blocktime[tid] add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) del thread_blocktime[tid] del thread_thislock[tid] def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): for (tid, lock) in lock_waits: min, max, avg, count = lock_waits[tid, lock] - print "%s[%d] lock %x contended %d times, %d avg ns" % \ - (process_names[tid], tid, lock, count, avg) + print("%s[%d] lock %x contended %d times, %d avg ns" % \ + (process_names[tid], tid, lock, count, avg)) -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to check-perf-trace.py
Support both Python 2 and Python 3 in check-perf-trace.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix indentation issue, replace spaces with tab Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/check-perf-trace.py | 33 ++- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tools/perf/scripts/python/check-perf-trace.py b/tools/perf/scripts/python/check-perf-trace.py index 334599c..91fc499 100644 --- a/tools/perf/scripts/python/check-perf-trace.py +++ b/tools/perf/scripts/python/check-perf-trace.py @@ -7,6 +7,7 @@ # events, etc. Basically, if this script runs successfully and # displays expected results, Python scripting support should be ok. +from __future__ import print_function import os import sys @@ -19,7 +20,7 @@ from perf_trace_context import * unhandled = autodict() def trace_begin(): - print "trace_begin" + print("trace_begin") pass def trace_end(): @@ -31,10 +32,10 @@ def irq__softirq_entry(event_name, context, common_cpu, print_header(event_name, common_cpu, common_secs, common_nsecs, common_pid, common_comm) -print_uncommon(context) + print_uncommon(context) - print "vec=%s\n" % \ - (symbol_str("irq__softirq_entry", "vec", vec)), + print("vec=%s\n" % \ + (symbol_str("irq__softirq_entry", "vec", vec))), def kmem__kmalloc(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, @@ -43,13 +44,13 @@ def kmem__kmalloc(event_name, context, common_cpu, print_header(event_name, common_cpu, common_secs, common_nsecs, common_pid, common_comm) -print_uncommon(context) + print_uncommon(context) - print "call_site=%u, ptr=%u, bytes_req=%u, " \ + print("call_site=%u, ptr=%u, bytes_req=%u, " \ "bytes_alloc=%u, gfp_flags=%s\n" % \ (call_site, ptr, bytes_req, bytes_alloc, - flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)), + flag_str("kmem__kmalloc", "gfp_flags", gfp_flags))), def trace_unhandled(event_name, context, event_fields_dict): try: @@ -58,25 +59,25 @@ def trace_unhandled(event_name, context, event_fields_dict): unhandled[event_name] = 1 def print_header(event_name, cpu, secs, nsecs, pid, comm): - print "%-20s %5u %05u.%09u %8u %-20s " % \ - (event_name, cpu, secs, nsecs, pid, comm), + print("%-20s %5u %05u.%09u %8u %-20s " % \ + (event_name, cpu, secs, nsecs, pid, comm)), # print trace fields not included in handler args def print_uncommon(context): -print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ +print("common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ % (common_pc(context), trace_flag_str(common_flags(context)), \ - common_lock_depth(context)) + common_lock_depth(context))) def print_unhandled(): keys = unhandled.keys() if not keys: return -print "\nunhandled events:\n\n", +print("\nunhandled events:\n\n"), -print "%-40s %10s\n" % ("event", "count"), -print "%-40s %10s\n" % ("", \ - "---"), +print("%-40s %10s\n" % ("event", "count")), +print("%-40s %10s\n" % ("", \ + "---")), for event_name in keys: - print "%-40s %10d\n" % (event_name, unhandled[event_name]) +print("%-40s %10d\n" % (event_name, unhandled[event_name])) -- 1.8.3.1
[PATCH v2] perf scripts python: Add Python 3 support to event_analyzing_sample.py
Support both Python 2 and Python 3 in event_analyzing_sample.py. ``print`` is now a function rather than a statement. This should have no functional change. Fixes indentation issue, replace spaces with tab. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- .../perf/scripts/python/event_analyzing_sample.py | 57 +++--- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tools/perf/scripts/python/event_analyzing_sample.py b/tools/perf/scripts/python/event_analyzing_sample.py index 4e843b9..4ae239d 100644 --- a/tools/perf/scripts/python/event_analyzing_sample.py +++ b/tools/perf/scripts/python/event_analyzing_sample.py @@ -14,6 +14,7 @@ # generic events with the help of sqlite, and the 2nd one "show_pebs_ll" is # for a x86 HW PMU event: PEBS with load latency data. # +from __future__ import print_function import os import sys @@ -37,20 +38,20 @@ con = sqlite3.connect("/dev/shm/perf.db") con.isolation_level = None def trace_begin(): - print "In trace_begin:\n" + print("In trace_begin:\n") # # Will create several tables at the start, pebs_ll is for PEBS data with # load latency info, while gen_events is for general event. # -con.execute(""" + con.execute(""" create table if not exists gen_events ( name text, symbol text, comm text, dso text );""") -con.execute(""" + con.execute(""" create table if not exists pebs_ll ( name text, symbol text, @@ -76,12 +77,12 @@ def process_event(param_dict): name = param_dict["ev_name"] # Symbol and dso info are not always resolved -if (param_dict.has_key("dso")): +if ('dso' in param_dict): dso = param_dict["dso"] else: dso = "Unknown_dso" -if (param_dict.has_key("symbol")): +if ('symbol' in param_dict): symbol = param_dict["symbol"] else: symbol = "Unknown_symbol" @@ -102,11 +103,11 @@ def insert_db(event): event.ip, event.status, event.dse, event.dla, event.lat)) def trace_end(): - print "In trace_end:\n" + print("In trace_end:\n") # We show the basic info for the 2 type of event classes -show_general_events() -show_pebs_ll() -con.close() + show_general_events() + show_pebs_ll() + con.close() # # As the event number may be very big, so we can't use linear way @@ -123,29 +124,29 @@ def show_general_events(): # Check the total record number in the table count = con.execute("select count(*) from gen_events") for t in count: -print "There is %d records in gen_events table" % t[0] +print("There is %d records in gen_events table" % t[0]) if t[0] == 0: return -print "Statistics about the general events grouped by thread/symbol/dso: \n" +print("Statistics about the general events grouped by thread/symbol/dso: \n") # Group by thread commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)") -print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) +print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) for row in commq: - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by symbol -print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) +print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)") for row in symbolq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by dso -print "\n%40s %8s %16s\n%s" % ("dso",
[PATCH] perf scripts python: Add Python 3 support to futex-contention.py
Support both Python 2 and Python 3 in futex-contention.py. ``print`` is now a function rather than a statement. This should have no functional change. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria Please enter the commit message for your changes. Lines starting --- tools/perf/scripts/python/futex-contention.py | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/futex-contention.py b/tools/perf/scripts/python/futex-contention.py index 0f5cf43..2f8eb81 100644 --- a/tools/perf/scripts/python/futex-contention.py +++ b/tools/perf/scripts/python/futex-contention.py @@ -33,18 +33,18 @@ def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, nr, ret): - if thread_blocktime.has_key(tid): + if (tid in thread_blocktime): elapsed = nsecs(s, ns) - thread_blocktime[tid] add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) del thread_blocktime[tid] del thread_thislock[tid] def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): for (tid, lock) in lock_waits: min, max, avg, count = lock_waits[tid, lock] - print "%s[%d] lock %x contended %d times, %d avg ns" % \ - (process_names[tid], tid, lock, count, avg) + print("%s[%d] lock %x contended %d times, %d avg ns" % \ + (process_names[tid], tid, lock, count, avg)) -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to stat-cpi.py
Support both Python 2 and Python 3 in stat-cpi.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/stat-cpi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py index 8410672..1d8e8b7 100644 --- a/tools/perf/scripts/python/stat-cpi.py +++ b/tools/perf/scripts/python/stat-cpi.py @@ -59,7 +59,7 @@ def stat__interval(time): if ins != 0: cpi = cyc/float(ins) -print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(10)), cpu, thread, cpi, cyc, ins) +print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(10)), cpu, thread, cpi, cyc, ins)) def trace_end(): pass -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to export-to-postgresql.py
Support both Python 2 and Python 3 in export-to-postgresql.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-postgresql.py | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py index 0564dd7..6774909 100644 --- a/tools/perf/scripts/python/export-to-postgresql.py +++ b/tools/perf/scripts/python/export-to-postgresql.py @@ -273,7 +273,7 @@ def do_query(q, s): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db = QSqlDatabase.addDatabase('QPSQL') query = QSqlQuery(db) @@ -564,7 +564,7 @@ if perf_db_export_calls: call_file = open_output_file("call_table.bin") def trace_begin(): - print datetime.datetime.today(), "Writing to intermediate files..." + print(datetime.datetime.today(), "Writing to intermediate files...") # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") machine_table(0, 0, "unknown") @@ -579,7 +579,7 @@ def trace_begin(): unhandled_count = 0 def trace_end(): - print datetime.datetime.today(), "Copying to database..." + print(datetime.datetime.today(), "Copying to database...") copy_output_file(evsel_file,"selected_events") copy_output_file(machine_file, "machines") copy_output_file(thread_file, "threads") @@ -594,7 +594,7 @@ def trace_end(): if perf_db_export_calls: copy_output_file(call_file, "calls") - print datetime.datetime.today(), "Removing intermediate files..." + print(datetime.datetime.today(), "Removing intermediate files...") remove_output_file(evsel_file) remove_output_file(machine_file) remove_output_file(thread_file) @@ -609,7 +609,7 @@ def trace_end(): if perf_db_export_calls: remove_output_file(call_file) os.rmdir(output_dir_name) - print datetime.datetime.today(), "Adding primary keys" + print(datetime.datetime.today(), "Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE machinesADD PRIMARY KEY (id)') do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') @@ -624,7 +624,7 @@ def trace_end(): if perf_db_export_calls: do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') - print datetime.datetime.today(), "Adding foreign keys" + print(datetime.datetime.today(), "Adding foreign keys") do_query(query, 'ALTER TABLE threads ' 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads(id)') @@ -659,8 +659,8 @@ def trace_end(): do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" - print datetime.datetime.today(), "Done" + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") + print(datetime.datetime.today(), "Done") def trace_unhandled(event_name, context, event_fields_dict): global unhandled_count -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to syscall-counts-by-pid.py
Support both Python 2 and Python 3 in syscall-counts-by-pid.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/syscall-counts-by-pid.py | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py index daf314c..f3f17fd 100644 --- a/tools/perf/scripts/python/syscall-counts-by-pid.py +++ b/tools/perf/scripts/python/syscall-counts-by-pid.py @@ -31,7 +31,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_syscall_totals() @@ -55,20 +55,20 @@ def syscalls__sys_enter(event_name, context, common_cpu, def print_syscall_totals(): if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events by comm/pid:\n\n", + print("\nsyscall events by comm/pid:\n\n"), -print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"), -print "%-40s %10s\n" % ("", \ - "--"), +print("%-40s %10s\n" % ("comm [pid]/syscalls", "count")), +print("%-40s %10s\n" % ("", \ + "--")), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: - print "\n%s [%d]\n" % (comm, pid), + print("\n%s [%d]\n" % (comm, pid)), id_keys = syscalls[comm][pid].keys() for id, val in sorted(syscalls[comm][pid].iteritems(), \ - key = lambda(k, v): (v, k), reverse = True): - print " %-38s %10d\n" % (syscall_name(id), val), + key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print(" %-38s %10d\n" % (syscall_name(id), val)), -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to syscall-counts.py
Support both Python 2 and Python 3 in syscall-counts.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/syscall-counts.py | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py index e66a773..141b7fc 100644 --- a/tools/perf/scripts/python/syscall-counts.py +++ b/tools/perf/scripts/python/syscall-counts.py @@ -28,7 +28,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_syscall_totals() @@ -51,14 +51,14 @@ def syscalls__sys_enter(event_name, context, common_cpu, def print_syscall_totals(): if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events:\n\n", + print("\nsyscall events:\n\n"), -print "%-40s %10s\n" % ("event", "count"), -print "%-40s %10s\n" % ("", \ - "---"), +print("%-40s %10s\n" % ("event", "count")), +print("%-40s %10s\n" % ("", \ + "---")), -for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ +for id, val in sorted(syscalls.iteritems(), key = lambda k_v: (k_v[1], k_v[0]), \ reverse = True): - print "%-40s %10d\n" % (syscall_name(id), val), + print("%-40s %10d\n" % (syscall_name(id), val)), -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to event_analyzing_sample.py
Support both Python 2 and Python 3 in event_analyzing_sample.py. ``print`` is now a function rather than a statement. This should have no functional change. Fixes indentation issue, replace spaces with tab. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- .../perf/scripts/python/event_analyzing_sample.py | 56 +++--- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/perf/scripts/python/event_analyzing_sample.py b/tools/perf/scripts/python/event_analyzing_sample.py index 4e843b9..8cb116f 100644 --- a/tools/perf/scripts/python/event_analyzing_sample.py +++ b/tools/perf/scripts/python/event_analyzing_sample.py @@ -37,20 +37,20 @@ con = sqlite3.connect("/dev/shm/perf.db") con.isolation_level = None def trace_begin(): - print "In trace_begin:\n" + print("In trace_begin:\n") # # Will create several tables at the start, pebs_ll is for PEBS data with # load latency info, while gen_events is for general event. # -con.execute(""" + con.execute(""" create table if not exists gen_events ( name text, symbol text, comm text, dso text );""") -con.execute(""" + con.execute(""" create table if not exists pebs_ll ( name text, symbol text, @@ -76,12 +76,12 @@ def process_event(param_dict): name = param_dict["ev_name"] # Symbol and dso info are not always resolved -if (param_dict.has_key("dso")): +if ('dso' in param_dict): dso = param_dict["dso"] else: dso = "Unknown_dso" -if (param_dict.has_key("symbol")): +if ('symbol' in param_dict): symbol = param_dict["symbol"] else: symbol = "Unknown_symbol" @@ -102,11 +102,11 @@ def insert_db(event): event.ip, event.status, event.dse, event.dla, event.lat)) def trace_end(): - print "In trace_end:\n" + print("In trace_end:\n") # We show the basic info for the 2 type of event classes -show_general_events() -show_pebs_ll() -con.close() + show_general_events() + show_pebs_ll() + con.close() # # As the event number may be very big, so we can't use linear way @@ -123,29 +123,29 @@ def show_general_events(): # Check the total record number in the table count = con.execute("select count(*) from gen_events") for t in count: -print "There is %d records in gen_events table" % t[0] +print("There is %d records in gen_events table" % t[0]) if t[0] == 0: return -print "Statistics about the general events grouped by thread/symbol/dso: \n" +print("Statistics about the general events grouped by thread/symbol/dso: \n") # Group by thread commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)") -print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) +print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) for row in commq: - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by symbol -print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) +print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)") for row in symbolq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by dso -print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74) +print("\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)) dsoq = con.execute(&quo
[PATCH] perf scripts python: Add Python 3 support to net_dropmonitor.py
Support both Python 2 and Python 3 in net_dropmonitor.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/net_dropmonitor.py | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py index a150164..091f4b3 100755 --- a/tools/perf/scripts/python/net_dropmonitor.py +++ b/tools/perf/scripts/python/net_dropmonitor.py @@ -50,19 +50,19 @@ def get_sym(sloc): return (None, 0) def print_drop_table(): - print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") + print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")) for i in drop_log.keys(): (sym, off) = get_sym(i) if sym == None: sym = i - print "%25s %25s %25s" % (sym, off, drop_log[i]) + print("%25s %25s %25s" % (sym, off, drop_log[i])) def trace_begin(): - print "Starting trace (Ctrl-C to dump results)" + print("Starting trace (Ctrl-C to dump results)") def trace_end(): - print "Gathering kallsyms data" + print("Gathering kallsyms data") get_kallsyms_table() print_drop_table() -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to stackcollapse.py
Support both Python 2 and Python 3 in stackcollapse.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/stackcollapse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py index 1697b5e..3edeb7e 100755 --- a/tools/perf/scripts/python/stackcollapse.py +++ b/tools/perf/scripts/python/stackcollapse.py @@ -123,4 +123,4 @@ def trace_end(): list = lines.keys() list.sort() for stack in list: -print "%s %d" % (stack, lines[stack]) +print("%s %d" % (stack, lines[stack])) -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to intel-pt-events.py
Support both Python 2 and Python 3 in intel-pt-events.py.``print`` is now a function rather than a statement. This should have no functional change. Fixes indentation issue, replace spaces with tab. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/intel-pt-events.py | 56 ++-- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index b19172d..a02a810 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py @@ -22,34 +22,34 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ #from Core import * def trace_begin(): - print "Intel PT Power Events and PTWRITE" + print("Intel PT Power Events and PTWRITE") def trace_end(): - print "End" + print("End") def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])) def print_ptwrite(raw_buf): data = struct.unpack_from("> 32) & 0x3 - print "hints: %#x extensions: %#x" % (hints, extensions), + print("hints: %#x extensions: %#x" % (hints, extensions)), def print_pwre(raw_buf): data = struct.unpack_from("> 7) & 1 cstate = (payload >> 12) & 0xf subcstate = (payload >> 8) & 0xf - print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), + print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate)), def print_exstop(raw_buf): data = struct.unpack_from("> 4) & 0xf wake_reason = (payload >> 8) & 0xf - print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), + print("deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason)), def print_common_start(comm, sample, name): ts = sample["time"] cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10, ts %10, name), + print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10, ts %10, name)), def print_common_ip(sample, symbol, dso): ip = sample["ip"] - print "%16x %s (%s)" % (ip, symbol, dso) + print("%16x %s (%s)" % (ip, symbol, dso)) def process_event(param_dict): -event_attr = param_dict["attr"] -sample = param_dict["sample"] -raw_buf= param_dict["raw_buf"] -comm = param_dict["comm"] -name = param_dict["ev_name"] - -# Symbol and dso info are not always resolved -if (param_dict.has_key("dso")): -dso = param_dict["dso"] -else: -dso = "[unknown]" - -if (param_dict.has_key("symbol")): -symbol = param_dict["symbol"] -else: -symbol = "[unknown]" - + event_attr = param_dict["attr"] + sample = param_dict["sample"] + raw_buf= param_dict["raw_buf"] + comm = param_dict["comm"] + name = param_dict["ev_name"] + + # Symbol and dso info are not always resolved + if ('dso' in param_dict): + dso = param_dict["dso"] + else: + dso = "[unknown]" + + if ('symbol' in param_dict): + symbol = param_dict["symbol"] + else: + symbol = "[unknown]" + if name == "ptwrite": print_common_start(comm, sample, name) print_ptwrite(raw_buf) -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to exported-sql-viewer.py
Support both Python 2 and Python 3 in exported-sql-viewer.py. ``print`` is now a function rather than a statement. This should have no functional change. Add support of _pickle module in Python3 Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/exported-sql-viewer.py | 21 - 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index f278ce5..02f964a 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -1,4 +1,3 @@ -#!/usr/bin/python2 # SPDX-License-Identifier: GPL-2.0 # exported-sql-viewer.py: view data from sql database # Copyright (c) 2014-2018, Intel Corporation. @@ -92,7 +91,6 @@ import sys import weakref import threading import string -import cPickle import re import os from PySide.QtCore import * @@ -102,6 +100,11 @@ from decimal import * from ctypes import * from multiprocessing import Process, Array, Value, Event +if sys.version_info[0] < 3: +import cPickle +else: +import _pickle as cPickle + # Data formatting helpers def tohex(ip): @@ -1560,7 +1563,7 @@ class SQLTableDialogDataItem(): return str(lower_id) def ConvertRelativeTime(self, val): - print "val ", val + print("val ", val) mult = 1 suffix = val[-2:] if suffix == "ms": @@ -1582,29 +1585,29 @@ class SQLTableDialogDataItem(): return str(val) def ConvertTimeRange(self, vrange): - print "vrange ", vrange + print("vrange ", vrange) if vrange[0] == "": vrange[0] = str(self.first_time) if vrange[1] == "": vrange[1] = str(self.last_time) vrange[0] = self.ConvertRelativeTime(vrange[0]) vrange[1] = self.ConvertRelativeTime(vrange[1]) - print "vrange2 ", vrange + print("vrange2 ", vrange) if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]): return False - print "ok1" + print("ok1") beg_range = max(int(vrange[0]), self.first_time) end_range = min(int(vrange[1]), self.last_time) if beg_range > self.last_time or end_range < self.first_time: return False - print "ok2" + print("ok2") vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True) vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False) - print "vrange3 ", vrange + print("vrange3 ", vrange) return True def AddTimeRange(self, value, ranges): - print "value ", value + print("value ", value) n = value.count("-") if n == 1: pass -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to powerpc-hcalls.py
Support both Python 2 and Python 3 in powerpc-hcalls.py. ``print`` is now a function rather than a statement. This should have no functional change. The "has_key()" method is deprecated in favor of the "in" operator. So incorporate those changes here. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/powerpc-hcalls.py | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py index 00e0e74..6cf33f0 100644 --- a/tools/perf/scripts/python/powerpc-hcalls.py +++ b/tools/perf/scripts/python/powerpc-hcalls.py @@ -149,7 +149,7 @@ hcall_table = { } def hcall_table_lookup(opcode): - if (hcall_table.has_key(opcode)): + if (opcode in hcall_table): return hcall_table[opcode] else: return opcode @@ -157,8 +157,8 @@ def hcall_table_lookup(opcode): print_ptrn = '%-28s%10s%10s%10s%10s' def trace_end(): - print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)') - print '-' * 68 + print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')) + print('-' * 68) for opcode in output: h_name = hcall_table_lookup(opcode) time = output[opcode]['time'] @@ -166,14 +166,14 @@ def trace_end(): min_t = output[opcode]['min'] max_t = output[opcode]['max'] - print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt) + print(print_ptrn % (h_name, cnt, min_t, max_t, time/cnt)) def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, opcode, retval): - if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)): + if ((cpu in d_enter) and (opcode in d_enter[cpu])): diff = nsecs(sec, nsec) - d_enter[cpu][opcode] - if (output.has_key(opcode)): + if (opcode in output): output[opcode]['time'] += diff output[opcode]['cnt'] += 1 if (output[opcode]['min'] > diff): @@ -194,7 +194,7 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm, callchain, opcode): - if (d_enter.has_key(cpu)): + if (cpu in d_enter): d_enter[cpu][opcode] = nsecs(sec, nsec) else: d_enter[cpu] = {opcode: nsecs(sec, nsec)} -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to sctop.py
Support both Python 2 and Python 3 in sctop.py.``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/sctop.py | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py index 61621b9..ea8edcf 100644 --- a/tools/perf/scripts/python/sctop.py +++ b/tools/perf/scripts/python/sctop.py @@ -62,18 +62,18 @@ def print_syscall_totals(interval): while 1: clear_term() if for_comm is not None: - print "\nsyscall events for %s:\n\n" % (for_comm), + print("\nsyscall events for %s:\n\n" % (for_comm)), else: - print "\nsyscall events:\n\n", + print("\nsyscall events:\n\n"), - print "%-40s %10s\n" % ("event", "count"), - print "%-40s %10s\n" % ("", \ -"--"), + print("%-40s %10s\n" % ("event", "count")), + print("%-40s %10s\n" % ("", \ +"--")), - for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ + for id, val in sorted(syscalls.iteritems(), key = lambda k_v: (k_v[1], k_v[0]), \ reverse = True): try: - print "%-40s %10d\n" % (syscall_name(id), val), + print("%-40s %10d\n" % (syscall_name(id), val)), except TypeError: pass syscalls.clear() -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to failed-syscalls-by-pid.py
Support both Python 2 and Python 3 in failed-syscalls-by-pid.py. ``print`` is now a function rather than a statement. This should have no functional change. Fixes lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria Please enter the commit message for your changes. Lines starting --- tools/perf/scripts/python/failed-syscalls-by-pid.py | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py index cafeff3..333c762 100644 --- a/tools/perf/scripts/python/failed-syscalls-by-pid.py +++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py @@ -32,7 +32,7 @@ if len(sys.argv) > 1: syscalls = autodict() def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): print_error_totals() @@ -57,22 +57,22 @@ def syscalls__sys_exit(event_name, context, common_cpu, def print_error_totals(): if for_comm is not None: - print "\nsyscall errors for %s:\n\n" % (for_comm), + print("\nsyscall errors for %s:\n\n" % (for_comm)), else: - print "\nsyscall errors:\n\n", + print("\nsyscall errors:\n\n"), -print "%-30s %10s\n" % ("comm [pid]", "count"), -print "%-30s %10s\n" % ("--", \ - "--"), +print("%-30s %10s\n" % ("comm [pid]", "count")), +print("%-30s %10s\n" % ("--", \ + "--")), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: - print "\n%s [%d]\n" % (comm, pid), + print("\n%s [%d]\n" % (comm, pid)), id_keys = syscalls[comm][pid].keys() for id in id_keys: - print " syscall: %-16s\n" % syscall_name(id), + print(" syscall: %-16s\n" % syscall_name(id)), ret_keys = syscalls[comm][pid][id].keys() - for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): - print "err = %-20s %10d\n" % (strerror(ret), val), + for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print("err = %-20s %10d\n" % (strerror(ret), val)), -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to mem-phys-addr.py
Support both Python 2 and Python 3 in mem-phys-addr.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix lambda syntax error. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/mem-phys-addr.py | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py index ebee2c5..52fe9bd 100644 --- a/tools/perf/scripts/python/mem-phys-addr.py +++ b/tools/perf/scripts/python/mem-phys-addr.py @@ -38,14 +38,14 @@ def parse_iomem(): pmem.append(long(m[1], 16)) def print_memory_type(): - print "Event: %s" % (event_name) - print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), - print "%-40s %10s %10s\n" % ("", \ - "---", "---"), + print("Event: %s" % (event_name)) + print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage")), + print("%-40s %10s %10s\n" % ("", \ + "---", "---")), total = sum(load_mem_type_cnt.values()) for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ - key = lambda(k, v): (v, k), reverse = True): - print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), + key = lambda k_v: (k_v[1], k_v[0]), reverse = True): + print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total)), def trace_begin(): parse_iomem() -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to export-to-sqlite.py
Support both Python 2 and Python 3 in export-to-sqlite.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/export-to-sqlite.py | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py index 245caf2..530b9e3 100644 --- a/tools/perf/scripts/python/export-to-sqlite.py +++ b/tools/perf/scripts/python/export-to-sqlite.py @@ -100,7 +100,7 @@ def do_query_(q): return raise Exception("Query failed: " + q.lastError().text()) -print datetime.datetime.today(), "Creating database..." +print(datetime.datetime.today(), "Creating database...") db_exists = False try: @@ -376,7 +376,7 @@ if perf_db_export_calls: call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): - print datetime.datetime.today(), "Writing records..." + print(datetime.datetime.today(), "Writing records...") do_query(query, 'BEGIN TRANSACTION') # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs evsel_table(0, "unknown") @@ -394,13 +394,13 @@ unhandled_count = 0 def trace_end(): do_query(query, 'END TRANSACTION') - print datetime.datetime.today(), "Adding indexes" + print(datetime.datetime.today(), "Adding indexes") if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') if (unhandled_count): - print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" - print datetime.datetime.today(), "Done" + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") + print(datetime.datetime.today(), "Done") def trace_unhandled(event_name, context, event_fields_dict): global unhandled_count -- 1.8.3.1
[PATCH] perf scripts python: Add Python 3 support to netdev-times.py
Support both Python 2 and Python 3 in netdev-times.py. ``print`` is now a function rather than a statement. This should have no functional change. Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/netdev-times.py | 76 +++ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py index 9b2050f..65cf276 100644 --- a/tools/perf/scripts/python/netdev-times.py +++ b/tools/perf/scripts/python/netdev-times.py @@ -61,12 +61,12 @@ def diff_msec(src, dst): def print_transmit(hunk): if dev != 0 and hunk['dev'].find(dev) < 0: return - print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ + print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ (hunk['dev'], hunk['len'], nsecs_secs(hunk['queue_t']), nsecs_nsecs(hunk['queue_t'])/1000, diff_msec(hunk['queue_t'], hunk['xmit_t']), - diff_msec(hunk['xmit_t'], hunk['free_t'])) + diff_msec(hunk['xmit_t'], hunk['free_t']))) # Format for displaying rx packet processing PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" @@ -98,55 +98,55 @@ def print_receive(hunk): if show_hunk == 0: return - print "%d.%06dsec cpu=%d" % \ - (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) + print("%d.%06dsec cpu=%d" % \ + (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)) for i in range(len(irq_list)): - print PF_IRQ_ENTRY % \ + print(PF_IRQ_ENTRY % \ (diff_msec(base_t, irq_list[i]['irq_ent_t']), - irq_list[i]['irq'], irq_list[i]['name']) - print PF_JOINT + irq_list[i]['irq'], irq_list[i]['name'])) + print(PF_JOINT) irq_event_list = irq_list[i]['event_list'] for j in range(len(irq_event_list)): irq_event = irq_event_list[j] if irq_event['event'] == 'netif_rx': - print PF_NET_RX % \ + print(PF_NET_RX % \ (diff_msec(base_t, irq_event['time']), - irq_event['skbaddr']) - print PF_JOINT - print PF_SOFT_ENTRY % \ - diff_msec(base_t, hunk['sirq_ent_t']) - print PF_JOINT + irq_event['skbaddr'])) + print(PF_JOINT) + print(PF_SOFT_ENTRY % \ + diff_msec(base_t, hunk['sirq_ent_t'])) + print(PF_JOINT) event_list = hunk['event_list'] for i in range(len(event_list)): event = event_list[i] if event['event_name'] == 'napi_poll': - print PF_NAPI_POLL % \ - (diff_msec(base_t, event['event_t']), event['dev']) + print(PF_NAPI_POLL % \ + (diff_msec(base_t, event['event_t']), event['dev'])) if i == len(event_list) - 1: - print "" + print("") else: - print PF_JOINT + print(PF_JOINT) else: - print PF_NET_RECV % \ + print(PF_NET_RECV % \ (diff_msec(base_t, event['event_t']), event['skbaddr'], - event['len']) + event['len'])) if 'comm' in event.keys(): - print PF_WJOINT - print PF_CPY_DGRAM % \ + print(PF_WJOINT) + print(PF_CPY_DGRAM % \ (diff_msec(base_t, event['comm_t']), - event['pid'], event['comm']) + event['pid'], event['comm'])) elif 'handle' in event.keys(): - print PF_WJOINT + print(PF_WJOINT) if event['handle'] == "kfree_skb": - print PF_KFREE_SKB % \ + print(PF_KFREE_SKB % \ (diff_msec(base_t, event['comm_t']), - event['location']) + event['location'])) e
[PATCH] perf scripts python: Add Python 3 support to check-perf-trace.py
Support both Python 2 and Python 3 in check-perf-trace.py. ``print`` is now a function rather than a statement. This should have no functional change. Fix indentation issue, replace spaces with tab Signed-off-by: Seeteena Thoufeek Reviewed-by: Ravi Bangoria --- tools/perf/scripts/python/check-perf-trace.py | 32 +-- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/perf/scripts/python/check-perf-trace.py b/tools/perf/scripts/python/check-perf-trace.py index 334599c..1c5fab9 100644 --- a/tools/perf/scripts/python/check-perf-trace.py +++ b/tools/perf/scripts/python/check-perf-trace.py @@ -19,7 +19,7 @@ from perf_trace_context import * unhandled = autodict() def trace_begin(): - print "trace_begin" + print("trace_begin") pass def trace_end(): @@ -31,10 +31,10 @@ def irq__softirq_entry(event_name, context, common_cpu, print_header(event_name, common_cpu, common_secs, common_nsecs, common_pid, common_comm) -print_uncommon(context) + print_uncommon(context) - print "vec=%s\n" % \ - (symbol_str("irq__softirq_entry", "vec", vec)), + print("vec=%s\n" % \ + (symbol_str("irq__softirq_entry", "vec", vec))), def kmem__kmalloc(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, @@ -43,13 +43,13 @@ def kmem__kmalloc(event_name, context, common_cpu, print_header(event_name, common_cpu, common_secs, common_nsecs, common_pid, common_comm) -print_uncommon(context) + print_uncommon(context) - print "call_site=%u, ptr=%u, bytes_req=%u, " \ + print("call_site=%u, ptr=%u, bytes_req=%u, " \ "bytes_alloc=%u, gfp_flags=%s\n" % \ (call_site, ptr, bytes_req, bytes_alloc, - flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)), + flag_str("kmem__kmalloc", "gfp_flags", gfp_flags))), def trace_unhandled(event_name, context, event_fields_dict): try: @@ -58,25 +58,25 @@ def trace_unhandled(event_name, context, event_fields_dict): unhandled[event_name] = 1 def print_header(event_name, cpu, secs, nsecs, pid, comm): - print "%-20s %5u %05u.%09u %8u %-20s " % \ - (event_name, cpu, secs, nsecs, pid, comm), + print("%-20s %5u %05u.%09u %8u %-20s " % \ + (event_name, cpu, secs, nsecs, pid, comm)), # print trace fields not included in handler args def print_uncommon(context): -print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ +print("common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ % (common_pc(context), trace_flag_str(common_flags(context)), \ - common_lock_depth(context)) + common_lock_depth(context))) def print_unhandled(): keys = unhandled.keys() if not keys: return -print "\nunhandled events:\n\n", +print("\nunhandled events:\n\n"), -print "%-40s %10s\n" % ("event", "count"), -print "%-40s %10s\n" % ("", \ - "---"), +print("%-40s %10s\n" % ("event", "count")), +print("%-40s %10s\n" % ("", \ + "---")), for event_name in keys: - print "%-40s %10d\n" % (event_name, unhandled[event_name]) +print("%-40s %10d\n" % (event_name, unhandled[event_name])) -- 1.8.3.1
[tip:perf/urgent] perf script: Show hw-cache events
Commit-ID: fad76d4333fe73cf3f73704aa34d4ce523b1c458 Gitweb: https://git.kernel.org/tip/fad76d4333fe73cf3f73704aa34d4ce523b1c458 Author: Seeteena Thoufeek AuthorDate: Fri, 8 Jun 2018 16:32:28 +0530 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 Jun 2018 13:41:30 -0300 perf script: Show hw-cache events 'perf script' fails to report hardware cache events (PERF_TYPE_HW_CACHE) where as 'perf report' shows the samples. Fix it. Ex, # perf record -e L1-dcache-loads ./a.out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (11 samples)] Before patch: # perf script | wc -l 0 After patch: # perf script | wc -l 11 Committer testing: [root@jouet ~]# perf script | head -30 | tail Timer 9803 [2] 8.963330: 1554 L1-dcache-loads: 7ffef89baae4 __vdso_clock_gettime+0xf4 ([vdso]) swapper0 [2] 8.963343: 5626 L1-dcache-loads: a66f4f6b cpuidle_not_av+0xb (/lib/modules/4.17.0-rc5/build/vmlinux) firefox 4853 [2] 8.964070: 18935 L1-dcache-loads: 7f0b9a00dc30 xcb_poll_for_event+0x0 (/usr/lib64/libxcb.so.1.1.0) Softwar~cTh 4928 [2] 8.964548: 15928 L1-dcache-loads: a60d795c update_curr+0x10c (/lib/modules/4.17.0-rc5/build/vmlinux) firefox 4853 [2] 8.964675: 14978 L1-dcache-loads: a6897018 mutex_unlock+0x18 (/lib/modules/4.17.0-rc5/build/vmlinux) gnome-shell 2026 [3] 8.964693: 50670 L1-dcache-loads: 7fa08854de6d g_source_iter_next+0x6d (/usr/lib64/libglib-2.0.so.0.5400.3) Compositor 4929 [1] 8.964784: 71772 L1-dcache-loads: 7f0b936bf078 [unknown] (/usr/lib64/firefox/libxul.so) Xwayland 2096 [2] 8.964919: 16799 L1-dcache-loads: 7f68ce2fcb8a glXGetCurrentContext+0x1a (/usr/lib64/libGLX.so.0.0.0) gnome-shell 2026 [3] 8.964997: 50670 L1-dcache-loads: 7fa08854de6d g_source_iter_next+0x6d (/usr/lib64/libglib-2.0.so.0.5400.3) [root@jouet ~]# Signed-off-by: Seeteena Thoufeek Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1528455748-20087-1-git-send-email-s1see...@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 12 1 file changed, 12 insertions(+) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b3bf35512d21..a31d7082188e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -180,6 +180,18 @@ static struct { PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE }, + [PERF_TYPE_HW_CACHE] = { + .user_set = false, + + .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | + PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | + PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | + PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, + [PERF_TYPE_RAW] = { .user_set = false,
[tip:perf/urgent] perf script: Show hw-cache events
Commit-ID: fad76d4333fe73cf3f73704aa34d4ce523b1c458 Gitweb: https://git.kernel.org/tip/fad76d4333fe73cf3f73704aa34d4ce523b1c458 Author: Seeteena Thoufeek AuthorDate: Fri, 8 Jun 2018 16:32:28 +0530 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 Jun 2018 13:41:30 -0300 perf script: Show hw-cache events 'perf script' fails to report hardware cache events (PERF_TYPE_HW_CACHE) where as 'perf report' shows the samples. Fix it. Ex, # perf record -e L1-dcache-loads ./a.out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (11 samples)] Before patch: # perf script | wc -l 0 After patch: # perf script | wc -l 11 Committer testing: [root@jouet ~]# perf script | head -30 | tail Timer 9803 [2] 8.963330: 1554 L1-dcache-loads: 7ffef89baae4 __vdso_clock_gettime+0xf4 ([vdso]) swapper0 [2] 8.963343: 5626 L1-dcache-loads: a66f4f6b cpuidle_not_av+0xb (/lib/modules/4.17.0-rc5/build/vmlinux) firefox 4853 [2] 8.964070: 18935 L1-dcache-loads: 7f0b9a00dc30 xcb_poll_for_event+0x0 (/usr/lib64/libxcb.so.1.1.0) Softwar~cTh 4928 [2] 8.964548: 15928 L1-dcache-loads: a60d795c update_curr+0x10c (/lib/modules/4.17.0-rc5/build/vmlinux) firefox 4853 [2] 8.964675: 14978 L1-dcache-loads: a6897018 mutex_unlock+0x18 (/lib/modules/4.17.0-rc5/build/vmlinux) gnome-shell 2026 [3] 8.964693: 50670 L1-dcache-loads: 7fa08854de6d g_source_iter_next+0x6d (/usr/lib64/libglib-2.0.so.0.5400.3) Compositor 4929 [1] 8.964784: 71772 L1-dcache-loads: 7f0b936bf078 [unknown] (/usr/lib64/firefox/libxul.so) Xwayland 2096 [2] 8.964919: 16799 L1-dcache-loads: 7f68ce2fcb8a glXGetCurrentContext+0x1a (/usr/lib64/libGLX.so.0.0.0) gnome-shell 2026 [3] 8.964997: 50670 L1-dcache-loads: 7fa08854de6d g_source_iter_next+0x6d (/usr/lib64/libglib-2.0.so.0.5400.3) [root@jouet ~]# Signed-off-by: Seeteena Thoufeek Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1528455748-20087-1-git-send-email-s1see...@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 12 1 file changed, 12 insertions(+) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b3bf35512d21..a31d7082188e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -180,6 +180,18 @@ static struct { PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE }, + [PERF_TYPE_HW_CACHE] = { + .user_set = false, + + .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | + PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | + PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | + PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, + [PERF_TYPE_RAW] = { .user_set = false,
[PATCH] perf script: Show hw-cache events
perf script fails to report hardware cache events (PERF_TYPE_HW_CACHE) where as perf report shows the samples. Fix it. Ex, # perf record -e L1-dcache-loads ./a.out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (11 samples)] Before patch: # perf script | wc -l 0 After patch: # perf script | wc -l 11 Signed-off-by: Seeteena Thoufeek --- tools/perf/builtin-script.c | 12 1 file changed, 12 insertions(+) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index cefc881..9e94bb7 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -180,6 +180,18 @@ enum { PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE }, + [PERF_TYPE_HW_CACHE] = { + .user_set = false, + + .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | + PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | + PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | + PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, + [PERF_TYPE_RAW] = { .user_set = false, -- 1.8.3.1
[PATCH] perf script: Show hw-cache events
perf script fails to report hardware cache events (PERF_TYPE_HW_CACHE) where as perf report shows the samples. Fix it. Ex, # perf record -e L1-dcache-loads ./a.out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (11 samples)] Before patch: # perf script | wc -l 0 After patch: # perf script | wc -l 11 Signed-off-by: Seeteena Thoufeek --- tools/perf/builtin-script.c | 12 1 file changed, 12 insertions(+) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index cefc881..9e94bb7 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -180,6 +180,18 @@ enum { PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE }, + [PERF_TYPE_HW_CACHE] = { + .user_set = false, + + .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | + PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | + PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | + PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, + [PERF_TYPE_RAW] = { .user_set = false, -- 1.8.3.1
[PATCH v3] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); -
[PATCH v3] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); -
[PATCH v3] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); -
[PATCH v3] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); -
[PATCH v3] Fix header-name to read state name and adjust column width
root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); - if (ret) - printf("**"); - else if (percent >= 100.0) - printf("%
[PATCH v3] Fix header-name to read state name and adjust column width
root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); - if (ret) - printf("**"); - else if (percent >= 100.0) - printf("%6.1f", percent); -
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, ,
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_t
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, ,
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_t
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, ,
[PATCH v2] Fix header-name to read state name and adjust column width
The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00|0.00| 60.04 0| 8| 1| 0.00|0.00| 38.97 0| 8| 2| 0.00|0.00|0.00 0| 8| 3| 0.00|0.00|0.00 0| 12| 4| 0.00|0.00| 99.25 0| 12| 5| 0.00|0.00|0.00 0| 12| 6| 0.00|0.00| 99.71 0| 12| 7| 0.00|0.00| 99.85 8|2048| 8| 0.00|0.00| 54.66 8|2048| 9| 0.00|0.00|0.00 8|2048| 10| 0.00|0.00|0.00 8|2048| 11| 0.00|0.00| 97.83 8|2052| 12| 0.00|0.00|0.00 8|2052| 13| 0.00|0.00|0.00 8|2052| 14| 0.00|0.00|1.99 8|2052| 15| 0.00|0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 47 +++--- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..cf3a1ad 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,7 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" - +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , struct cpuidle_monitor *all_monitors[] = { @@ -85,7 +88,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +119,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,11 +139,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) @@ -163,23 +169,34 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_t
[PATCH] Fix header-name to read full state name and adjust column width
---Steps to Reproduce--- 1.Execute the cpupower monitor command to fetch all the Idle_Stats values. root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 User interpret it as 2 columns for stop Idle_stats. root:/sys/devices/system/cpu/cpu8/cpuidle# cat */name snooze stop0_lite stop1_lite cpupower monitor now shows full state name and adjust colomn width. root:~/linux/tools/power/cpupower# cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_lite|stop1_lite 0| 8| 0| 0.00| 0.00| 99.83 0| 8| 1| 0.00| 0.00| 43.82 0| 8| 2| 0.00| 0.00| 102.1 0| 8| 3| 0.00| 0.00| 96.56 tested on x86 as well. Signed-off-by: Seeteena Thoufeek <s1see...@linux.vnet.ibm.com> --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 25 ++ .../cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..5e708d5 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -88,7 +88,7 @@ void print_header(int topology_depth) int state, need_len; cstate_t s; char buf[128] = ""; - int percent_width = 4; + unsigned int percent_width = 6; fill_string_with_spaces(buf, topology_depth * 5 - 1); printf("%s|", buf); @@ -116,17 +116,18 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; sprintf(buf, "%s", s.name); - fill_string_with_spaces(buf, percent_width); + if (strlen(s.name) > percent_width) + fill_string_with_spaces(buf, strlen(s.name)); + else + fill_string_with_spaces(buf, percent_width); + printf("%s", buf); - } - printf(" "); + } } printf("\n"); } @@ -139,7 +140,9 @@ void print_results(int topology_depth, int cpu) double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; + unsigned int percent_width = 6; + unsigned int width; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,7 +166,11 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + if (strlen(s.name) > percent_width) { + width = strlen(s.name) - percent_width; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h index 9e43f33..c9179c6 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h @@ -15,7 +15,7 @@ #define MONITORS_MAX 20 #define MONITOR_NAME_LEN 20 -#define CSTATE_NAME_LEN 5 +#define CSTATE_NAME_LEN 16 #define CSTATE_DESC_LEN 60 int cpu_count; -- 1.8.3.1
[PATCH] Fix header-name to read full state name and adjust column width
---Steps to Reproduce--- 1.Execute the cpupower monitor command to fetch all the Idle_Stats values. root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 User interpret it as 2 columns for stop Idle_stats. root:/sys/devices/system/cpu/cpu8/cpuidle# cat */name snooze stop0_lite stop1_lite cpupower monitor now shows full state name and adjust colomn width. root:~/linux/tools/power/cpupower# cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_lite|stop1_lite 0| 8| 0| 0.00| 0.00| 99.83 0| 8| 1| 0.00| 0.00| 43.82 0| 8| 2| 0.00| 0.00| 102.1 0| 8| 3| 0.00| 0.00| 96.56 tested on x86 as well. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 25 ++ .../cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..5e708d5 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -88,7 +88,7 @@ void print_header(int topology_depth) int state, need_len; cstate_t s; char buf[128] = ""; - int percent_width = 4; + unsigned int percent_width = 6; fill_string_with_spaces(buf, topology_depth * 5 - 1); printf("%s|", buf); @@ -116,17 +116,18 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; sprintf(buf, "%s", s.name); - fill_string_with_spaces(buf, percent_width); + if (strlen(s.name) > percent_width) + fill_string_with_spaces(buf, strlen(s.name)); + else + fill_string_with_spaces(buf, percent_width); + printf("%s", buf); - } - printf(" "); + } } printf("\n"); } @@ -139,7 +140,9 @@ void print_results(int topology_depth, int cpu) double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; + unsigned int percent_width = 6; + unsigned int width; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,7 +166,11 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + if (strlen(s.name) > percent_width) { + width = strlen(s.name) - percent_width; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, , cpu_top.core_info[cpu].cpu); diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h index 9e43f33..c9179c6 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h @@ -15,7 +15,7 @@ #define MONITORS_MAX 20 #define MONITOR_NAME_LEN 20 -#define CSTATE_NAME_LEN 5 +#define CSTATE_NAME_LEN 16 #define CSTATE_DESC_LEN 60 int cpu_count; -- 1.8.3.1