aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-06 10:59:36 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-06 10:59:36 -0500
commit203b6609e0ede49eb0b97008b1150c69e9d2ffd3 (patch)
tree7d9c1227eeec17f75b2a827e385387f640a365a6 /tools/perf/scripts/python
parent3478588b5136966c80c571cf0006f08e9e5b8f04 (diff)
parentc978b9460fe1d4a1e1effa0abd6bd69b18a098a8 (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "Lots of tooling updates - too many to list, here's a few highlights: - Various subcommand updates to 'perf trace', 'perf report', 'perf record', 'perf annotate', 'perf script', 'perf test', etc. - CPU and NUMA topology and affinity handling improvements, - HW tracing and HW support updates: - Intel PT updates - ARM CoreSight updates - vendor HW event updates - BPF updates - Tons of infrastructure updates, both on the build system and the library support side - Documentation updates. - ... and lots of other changes, see the changelog for details. Kernel side updates: - Tighten up kprobes blacklist handling, reduce the number of places where developers can install a kprobe and hang/crash the system. - Fix/enhance vma address filter handling. - Various PMU driver updates, small fixes and additions. - refcount_t conversions - BPF updates - error code propagation enhancements - misc other changes" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (238 commits) perf script python: Add Python3 support to syscall-counts-by-pid.py perf script python: Add Python3 support to syscall-counts.py perf script python: Add Python3 support to stat-cpi.py perf script python: Add Python3 support to stackcollapse.py perf script python: Add Python3 support to sctop.py perf script python: Add Python3 support to powerpc-hcalls.py perf script python: Add Python3 support to net_dropmonitor.py perf script python: Add Python3 support to mem-phys-addr.py perf script python: Add Python3 support to failed-syscalls-by-pid.py perf script python: Add Python3 support to netdev-times.py perf tools: Add perf_exe() helper to find perf binary perf script: Handle missing fields with -F +.. perf data: Add perf_data__open_dir_data function perf data: Add perf_data__(create_dir|close_dir) functions perf data: Fail check_backup in case of error perf data: Make check_backup work over directories perf tools: Add rm_rf_perf_data function perf tools: Add pattern name checking to rm_rf perf tools: Add depth checking to rm_rf perf data: Add global path holder ...
Diffstat (limited to 'tools/perf/scripts/python')
-rw-r--r--tools/perf/scripts/python/Perf-Trace-Util/Build2
-rw-r--r--tools/perf/scripts/python/export-to-postgresql.py2
-rw-r--r--tools/perf/scripts/python/export-to-sqlite.py2
-rwxr-xr-xtools/perf/scripts/python/exported-sql-viewer.py511
-rw-r--r--tools/perf/scripts/python/failed-syscalls-by-pid.py21
-rw-r--r--tools/perf/scripts/python/mem-phys-addr.py24
-rwxr-xr-xtools/perf/scripts/python/net_dropmonitor.py10
-rw-r--r--tools/perf/scripts/python/netdev-times.py82
-rw-r--r--tools/perf/scripts/python/powerpc-hcalls.py18
-rw-r--r--tools/perf/scripts/python/sched-migration.py2
-rw-r--r--tools/perf/scripts/python/sctop.py24
-rwxr-xr-xtools/perf/scripts/python/stackcollapse.py7
-rw-r--r--tools/perf/scripts/python/stat-cpi.py11
-rw-r--r--tools/perf/scripts/python/syscall-counts-by-pid.py22
-rw-r--r--tools/perf/scripts/python/syscall-counts.py18
15 files changed, 485 insertions, 271 deletions
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Build b/tools/perf/scripts/python/Perf-Trace-Util/Build
index aefc15c9444a..7d0e33ce6aba 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Build
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Build
@@ -1,3 +1,3 @@
1libperf-y += Context.o 1perf-y += Context.o
2 2
3CFLAGS_Context.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs 3CFLAGS_Context.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 0564dd7377f2..30130213da7e 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -478,7 +478,7 @@ if perf_db_export_calls:
478 'branch_count,' 478 'branch_count,'
479 'call_id,' 479 'call_id,'
480 'return_id,' 480 'return_id,'
481 'CASE WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' ELSE \'\' END AS flags,' 481 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE flags END AS flags,'
482 'parent_call_path_id' 482 'parent_call_path_id'
483 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id') 483 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
484 484
diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py
index 245caf2643ed..ed237f2ed03f 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -320,7 +320,7 @@ if perf_db_export_calls:
320 'branch_count,' 320 'branch_count,'
321 'call_id,' 321 'call_id,'
322 'return_id,' 322 'return_id,'
323 'CASE WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' ELSE \'\' END AS flags,' 323 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE flags END AS flags,'
324 'parent_call_path_id' 324 'parent_call_path_id'
325 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id') 325 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
326 326
diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
index f278ce5ebab7..09ce73b07d35 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python2 1#!/usr/bin/env python2
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3# exported-sql-viewer.py: view data from sql database 3# exported-sql-viewer.py: view data from sql database
4# Copyright (c) 2014-2018, Intel Corporation. 4# Copyright (c) 2014-2018, Intel Corporation.
@@ -1398,18 +1398,28 @@ class BranchModel(TreeModel):
1398 def HasMoreRecords(self): 1398 def HasMoreRecords(self):
1399 return self.more 1399 return self.more
1400 1400
1401# Report Variables
1402
1403class ReportVars():
1404
1405 def __init__(self, name = "", where_clause = "", limit = ""):
1406 self.name = name
1407 self.where_clause = where_clause
1408 self.limit = limit
1409
1410 def UniqueId(self):
1411 return str(self.where_clause + ";" + self.limit)
1412
1401# Branch window 1413# Branch window
1402 1414
1403class BranchWindow(QMdiSubWindow): 1415class BranchWindow(QMdiSubWindow):
1404 1416
1405 def __init__(self, glb, event_id, name, where_clause, parent=None): 1417 def __init__(self, glb, event_id, report_vars, parent=None):
1406 super(BranchWindow, self).__init__(parent) 1418 super(BranchWindow, self).__init__(parent)
1407 1419
1408 model_name = "Branch Events " + str(event_id) 1420 model_name = "Branch Events " + str(event_id) + " " + report_vars.UniqueId()
1409 if len(where_clause):
1410 model_name = where_clause + " " + model_name
1411 1421
1412 self.model = LookupCreateModel(model_name, lambda: BranchModel(glb, event_id, where_clause)) 1422 self.model = LookupCreateModel(model_name, lambda: BranchModel(glb, event_id, report_vars.where_clause))
1413 1423
1414 self.view = QTreeView() 1424 self.view = QTreeView()
1415 self.view.setUniformRowHeights(True) 1425 self.view.setUniformRowHeights(True)
@@ -1427,7 +1437,7 @@ class BranchWindow(QMdiSubWindow):
1427 1437
1428 self.setWidget(self.vbox.Widget()) 1438 self.setWidget(self.vbox.Widget())
1429 1439
1430 AddSubWindow(glb.mainwindow.mdi_area, self, name + " Branch Events") 1440 AddSubWindow(glb.mainwindow.mdi_area, self, report_vars.name + " Branch Events")
1431 1441
1432 def ResizeColumnToContents(self, column, n): 1442 def ResizeColumnToContents(self, column, n):
1433 # Using the view's resizeColumnToContents() here is extrememly slow 1443 # Using the view's resizeColumnToContents() here is extrememly slow
@@ -1472,47 +1482,134 @@ class BranchWindow(QMdiSubWindow):
1472 else: 1482 else:
1473 self.find_bar.NotFound() 1483 self.find_bar.NotFound()
1474 1484
1475# Dialog data item converted and validated using a SQL table 1485# Line edit data item
1476 1486
1477class SQLTableDialogDataItem(): 1487class LineEditDataItem(object):
1478 1488
1479 def __init__(self, glb, label, placeholder_text, table_name, match_column, column_name1, column_name2, parent): 1489 def __init__(self, glb, label, placeholder_text, parent, id = "", default = ""):
1480 self.glb = glb 1490 self.glb = glb
1481 self.label = label 1491 self.label = label
1482 self.placeholder_text = placeholder_text 1492 self.placeholder_text = placeholder_text
1483 self.table_name = table_name
1484 self.match_column = match_column
1485 self.column_name1 = column_name1
1486 self.column_name2 = column_name2
1487 self.parent = parent 1493 self.parent = parent
1494 self.id = id
1488 1495
1489 self.value = "" 1496 self.value = default
1490 1497
1491 self.widget = QLineEdit() 1498 self.widget = QLineEdit(default)
1492 self.widget.editingFinished.connect(self.Validate) 1499 self.widget.editingFinished.connect(self.Validate)
1493 self.widget.textChanged.connect(self.Invalidate) 1500 self.widget.textChanged.connect(self.Invalidate)
1494 self.red = False 1501 self.red = False
1495 self.error = "" 1502 self.error = ""
1496 self.validated = True 1503 self.validated = True
1497 1504
1498 self.last_id = 0
1499 self.first_time = 0
1500 self.last_time = 2 ** 64
1501 if self.table_name == "<timeranges>":
1502 query = QSqlQuery(self.glb.db)
1503 QueryExec(query, "SELECT id, time FROM samples ORDER BY id DESC LIMIT 1")
1504 if query.next():
1505 self.last_id = int(query.value(0))
1506 self.last_time = int(query.value(1))
1507 QueryExec(query, "SELECT time FROM samples WHERE time != 0 ORDER BY id LIMIT 1")
1508 if query.next():
1509 self.first_time = int(query.value(0))
1510 if placeholder_text:
1511 placeholder_text += ", between " + str(self.first_time) + " and " + str(self.last_time)
1512
1513 if placeholder_text: 1505 if placeholder_text:
1514 self.widget.setPlaceholderText(placeholder_text) 1506 self.widget.setPlaceholderText(placeholder_text)
1515 1507
1508 def TurnTextRed(self):
1509 if not self.red:
1510 palette = QPalette()
1511 palette.setColor(QPalette.Text,Qt.red)
1512 self.widget.setPalette(palette)
1513 self.red = True
1514
1515 def TurnTextNormal(self):
1516 if self.red:
1517 palette = QPalette()
1518 self.widget.setPalette(palette)
1519 self.red = False
1520
1521 def InvalidValue(self, value):
1522 self.value = ""
1523 self.TurnTextRed()
1524 self.error = self.label + " invalid value '" + value + "'"
1525 self.parent.ShowMessage(self.error)
1526
1527 def Invalidate(self):
1528 self.validated = False
1529
1530 def DoValidate(self, input_string):
1531 self.value = input_string.strip()
1532
1533 def Validate(self):
1534 self.validated = True
1535 self.error = ""
1536 self.TurnTextNormal()
1537 self.parent.ClearMessage()
1538 input_string = self.widget.text()
1539 if not len(input_string.strip()):
1540 self.value = ""
1541 return
1542 self.DoValidate(input_string)
1543
1544 def IsValid(self):
1545 if not self.validated:
1546 self.Validate()
1547 if len(self.error):
1548 self.parent.ShowMessage(self.error)
1549 return False
1550 return True
1551
1552 def IsNumber(self, value):
1553 try:
1554 x = int(value)
1555 except:
1556 x = 0
1557 return str(x) == value
1558
1559# Non-negative integer ranges dialog data item
1560
1561class NonNegativeIntegerRangesDataItem(LineEditDataItem):
1562
1563 def __init__(self, glb, label, placeholder_text, column_name, parent):
1564 super(NonNegativeIntegerRangesDataItem, self).__init__(glb, label, placeholder_text, parent)
1565
1566 self.column_name = column_name
1567
1568 def DoValidate(self, input_string):
1569 singles = []
1570 ranges = []
1571 for value in [x.strip() for x in input_string.split(",")]:
1572 if "-" in value:
1573 vrange = value.split("-")
1574 if len(vrange) != 2 or not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]):
1575 return self.InvalidValue(value)
1576 ranges.append(vrange)
1577 else:
1578 if not self.IsNumber(value):
1579 return self.InvalidValue(value)
1580 singles.append(value)
1581 ranges = [("(" + self.column_name + " >= " + r[0] + " AND " + self.column_name + " <= " + r[1] + ")") for r in ranges]
1582 if len(singles):
1583 ranges.append(self.column_name + " IN (" + ",".join(singles) + ")")
1584 self.value = " OR ".join(ranges)
1585
1586# Positive integer dialog data item
1587
1588class PositiveIntegerDataItem(LineEditDataItem):
1589
1590 def __init__(self, glb, label, placeholder_text, parent, id = "", default = ""):
1591 super(PositiveIntegerDataItem, self).__init__(glb, label, placeholder_text, parent, id, default)
1592
1593 def DoValidate(self, input_string):
1594 if not self.IsNumber(input_string.strip()):
1595 return self.InvalidValue(input_string)
1596 value = int(input_string.strip())
1597 if value <= 0:
1598 return self.InvalidValue(input_string)
1599 self.value = str(value)
1600
1601# Dialog data item converted and validated using a SQL table
1602
1603class SQLTableDataItem(LineEditDataItem):
1604
1605 def __init__(self, glb, label, placeholder_text, table_name, match_column, column_name1, column_name2, parent):
1606 super(SQLTableDataItem, self).__init__(glb, label, placeholder_text, parent)
1607
1608 self.table_name = table_name
1609 self.match_column = match_column
1610 self.column_name1 = column_name1
1611 self.column_name2 = column_name2
1612
1516 def ValueToIds(self, value): 1613 def ValueToIds(self, value):
1517 ids = [] 1614 ids = []
1518 query = QSqlQuery(self.glb.db) 1615 query = QSqlQuery(self.glb.db)
@@ -1523,6 +1620,42 @@ class SQLTableDialogDataItem():
1523 ids.append(str(query.value(0))) 1620 ids.append(str(query.value(0)))
1524 return ids 1621 return ids
1525 1622
1623 def DoValidate(self, input_string):
1624 all_ids = []
1625 for value in [x.strip() for x in input_string.split(",")]:
1626 ids = self.ValueToIds(value)
1627 if len(ids):
1628 all_ids.extend(ids)
1629 else:
1630 return self.InvalidValue(value)
1631 self.value = self.column_name1 + " IN (" + ",".join(all_ids) + ")"
1632 if self.column_name2:
1633 self.value = "( " + self.value + " OR " + self.column_name2 + " IN (" + ",".join(all_ids) + ") )"
1634
1635# Sample time ranges dialog data item converted and validated using 'samples' SQL table
1636
1637class SampleTimeRangesDataItem(LineEditDataItem):
1638
1639 def __init__(self, glb, label, placeholder_text, column_name, parent):
1640 self.column_name = column_name
1641
1642 self.last_id = 0
1643 self.first_time = 0
1644 self.last_time = 2 ** 64
1645
1646 query = QSqlQuery(glb.db)
1647 QueryExec(query, "SELECT id, time FROM samples ORDER BY id DESC LIMIT 1")
1648 if query.next():
1649 self.last_id = int(query.value(0))
1650 self.last_time = int(query.value(1))
1651 QueryExec(query, "SELECT time FROM samples WHERE time != 0 ORDER BY id LIMIT 1")
1652 if query.next():
1653 self.first_time = int(query.value(0))
1654 if placeholder_text:
1655 placeholder_text += ", between " + str(self.first_time) + " and " + str(self.last_time)
1656
1657 super(SampleTimeRangesDataItem, self).__init__(glb, label, placeholder_text, parent)
1658
1526 def IdBetween(self, query, lower_id, higher_id, order): 1659 def IdBetween(self, query, lower_id, higher_id, order):
1527 QueryExec(query, "SELECT id FROM samples WHERE id > " + str(lower_id) + " AND id < " + str(higher_id) + " ORDER BY id " + order + " LIMIT 1") 1660 QueryExec(query, "SELECT id FROM samples WHERE id > " + str(lower_id) + " AND id < " + str(higher_id) + " ORDER BY id " + order + " LIMIT 1")
1528 if query.next(): 1661 if query.next():
@@ -1560,7 +1693,6 @@ class SQLTableDialogDataItem():
1560 return str(lower_id) 1693 return str(lower_id)
1561 1694
1562 def ConvertRelativeTime(self, val): 1695 def ConvertRelativeTime(self, val):
1563 print "val ", val
1564 mult = 1 1696 mult = 1
1565 suffix = val[-2:] 1697 suffix = val[-2:]
1566 if suffix == "ms": 1698 if suffix == "ms":
@@ -1582,29 +1714,23 @@ class SQLTableDialogDataItem():
1582 return str(val) 1714 return str(val)
1583 1715
1584 def ConvertTimeRange(self, vrange): 1716 def ConvertTimeRange(self, vrange):
1585 print "vrange ", vrange
1586 if vrange[0] == "": 1717 if vrange[0] == "":
1587 vrange[0] = str(self.first_time) 1718 vrange[0] = str(self.first_time)
1588 if vrange[1] == "": 1719 if vrange[1] == "":
1589 vrange[1] = str(self.last_time) 1720 vrange[1] = str(self.last_time)
1590 vrange[0] = self.ConvertRelativeTime(vrange[0]) 1721 vrange[0] = self.ConvertRelativeTime(vrange[0])
1591 vrange[1] = self.ConvertRelativeTime(vrange[1]) 1722 vrange[1] = self.ConvertRelativeTime(vrange[1])
1592 print "vrange2 ", vrange
1593 if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]): 1723 if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]):
1594 return False 1724 return False
1595 print "ok1"
1596 beg_range = max(int(vrange[0]), self.first_time) 1725 beg_range = max(int(vrange[0]), self.first_time)
1597 end_range = min(int(vrange[1]), self.last_time) 1726 end_range = min(int(vrange[1]), self.last_time)
1598 if beg_range > self.last_time or end_range < self.first_time: 1727 if beg_range > self.last_time or end_range < self.first_time:
1599 return False 1728 return False
1600 print "ok2"
1601 vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True) 1729 vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True)
1602 vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False) 1730 vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False)
1603 print "vrange3 ", vrange
1604 return True 1731 return True
1605 1732
1606 def AddTimeRange(self, value, ranges): 1733 def AddTimeRange(self, value, ranges):
1607 print "value ", value
1608 n = value.count("-") 1734 n = value.count("-")
1609 if n == 1: 1735 if n == 1:
1610 pass 1736 pass
@@ -1622,111 +1748,31 @@ class SQLTableDialogDataItem():
1622 return True 1748 return True
1623 return False 1749 return False
1624 1750
1625 def InvalidValue(self, value): 1751 def DoValidate(self, input_string):
1626 self.value = "" 1752 ranges = []
1627 palette = QPalette() 1753 for value in [x.strip() for x in input_string.split(",")]:
1628 palette.setColor(QPalette.Text,Qt.red) 1754 if not self.AddTimeRange(value, ranges):
1629 self.widget.setPalette(palette) 1755 return self.InvalidValue(value)
1630 self.red = True 1756 ranges = [("(" + self.column_name + " >= " + r[0] + " AND " + self.column_name + " <= " + r[1] + ")") for r in ranges]
1631 self.error = self.label + " invalid value '" + value + "'" 1757 self.value = " OR ".join(ranges)
1632 self.parent.ShowMessage(self.error)
1633 1758
1634 def IsNumber(self, value): 1759# Report Dialog Base
1635 try:
1636 x = int(value)
1637 except:
1638 x = 0
1639 return str(x) == value
1640 1760
1641 def Invalidate(self): 1761class ReportDialogBase(QDialog):
1642 self.validated = False
1643 1762
1644 def Validate(self): 1763 def __init__(self, glb, title, items, partial, parent=None):
1645 input_string = self.widget.text() 1764 super(ReportDialogBase, self).__init__(parent)
1646 self.validated = True
1647 if self.red:
1648 palette = QPalette()
1649 self.widget.setPalette(palette)
1650 self.red = False
1651 if not len(input_string.strip()):
1652 self.error = ""
1653 self.value = ""
1654 return
1655 if self.table_name == "<timeranges>":
1656 ranges = []
1657 for value in [x.strip() for x in input_string.split(",")]:
1658 if not self.AddTimeRange(value, ranges):
1659 return self.InvalidValue(value)
1660 ranges = [("(" + self.column_name1 + " >= " + r[0] + " AND " + self.column_name1 + " <= " + r[1] + ")") for r in ranges]
1661 self.value = " OR ".join(ranges)
1662 elif self.table_name == "<ranges>":
1663 singles = []
1664 ranges = []
1665 for value in [x.strip() for x in input_string.split(",")]:
1666 if "-" in value:
1667 vrange = value.split("-")
1668 if len(vrange) != 2 or not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]):
1669 return self.InvalidValue(value)
1670 ranges.append(vrange)
1671 else:
1672 if not self.IsNumber(value):
1673 return self.InvalidValue(value)
1674 singles.append(value)
1675 ranges = [("(" + self.column_name1 + " >= " + r[0] + " AND " + self.column_name1 + " <= " + r[1] + ")") for r in ranges]
1676 if len(singles):
1677 ranges.append(self.column_name1 + " IN (" + ",".join(singles) + ")")
1678 self.value = " OR ".join(ranges)
1679 elif self.table_name:
1680 all_ids = []
1681 for value in [x.strip() for x in input_string.split(",")]:
1682 ids = self.ValueToIds(value)
1683 if len(ids):
1684 all_ids.extend(ids)
1685 else:
1686 return self.InvalidValue(value)
1687 self.value = self.column_name1 + " IN (" + ",".join(all_ids) + ")"
1688 if self.column_name2:
1689 self.value = "( " + self.value + " OR " + self.column_name2 + " IN (" + ",".join(all_ids) + ") )"
1690 else:
1691 self.value = input_string.strip()
1692 self.error = ""
1693 self.parent.ClearMessage()
1694
1695 def IsValid(self):
1696 if not self.validated:
1697 self.Validate()
1698 if len(self.error):
1699 self.parent.ShowMessage(self.error)
1700 return False
1701 return True
1702
1703# Selected branch report creation dialog
1704
1705class SelectedBranchDialog(QDialog):
1706
1707 def __init__(self, glb, parent=None):
1708 super(SelectedBranchDialog, self).__init__(parent)
1709 1765
1710 self.glb = glb 1766 self.glb = glb
1711 1767
1712 self.name = "" 1768 self.report_vars = ReportVars()
1713 self.where_clause = ""
1714 1769
1715 self.setWindowTitle("Selected Branches") 1770 self.setWindowTitle(title)
1716 self.setMinimumWidth(600) 1771 self.setMinimumWidth(600)
1717 1772
1718 items = ( 1773 self.data_items = [x(glb, self) for x in items]
1719 ("Report name:", "Enter a name to appear in the window title bar", "", "", "", ""), 1774
1720 ("Time ranges:", "Enter time ranges", "<timeranges>", "", "samples.id", ""), 1775 self.partial = partial
1721 ("CPUs:", "Enter CPUs or ranges e.g. 0,5-6", "<ranges>", "", "cpu", ""),
1722 ("Commands:", "Only branches with these commands will be included", "comms", "comm", "comm_id", ""),
1723 ("PIDs:", "Only branches with these process IDs will be included", "threads", "pid", "thread_id", ""),
1724 ("TIDs:", "Only branches with these thread IDs will be included", "threads", "tid", "thread_id", ""),
1725 ("DSOs:", "Only branches with these DSOs will be included", "dsos", "short_name", "samples.dso_id", "to_dso_id"),
1726 ("Symbols:", "Only branches with these symbols will be included", "symbols", "name", "symbol_id", "to_symbol_id"),
1727 ("Raw SQL clause: ", "Enter a raw SQL WHERE clause", "", "", "", ""),
1728 )
1729 self.data_items = [SQLTableDialogDataItem(glb, *x, parent=self) for x in items]
1730 1776
1731 self.grid = QGridLayout() 1777 self.grid = QGridLayout()
1732 1778
@@ -1758,23 +1804,28 @@ class SelectedBranchDialog(QDialog):
1758 self.setLayout(self.vbox); 1804 self.setLayout(self.vbox);
1759 1805
1760 def Ok(self): 1806 def Ok(self):
1761 self.name = self.data_items[0].value 1807 vars = self.report_vars
1762 if not self.name: 1808 for d in self.data_items:
1809 if d.id == "REPORTNAME":
1810 vars.name = d.value
1811 if not vars.name:
1763 self.ShowMessage("Report name is required") 1812 self.ShowMessage("Report name is required")
1764 return 1813 return
1765 for d in self.data_items: 1814 for d in self.data_items:
1766 if not d.IsValid(): 1815 if not d.IsValid():
1767 return 1816 return
1768 for d in self.data_items[1:]: 1817 for d in self.data_items[1:]:
1769 if len(d.value): 1818 if d.id == "LIMIT":
1770 if len(self.where_clause): 1819 vars.limit = d.value
1771 self.where_clause += " AND " 1820 elif len(d.value):
1772 self.where_clause += d.value 1821 if len(vars.where_clause):
1773 if len(self.where_clause): 1822 vars.where_clause += " AND "
1774 self.where_clause = " AND ( " + self.where_clause + " ) " 1823 vars.where_clause += d.value
1775 else: 1824 if len(vars.where_clause):
1776 self.ShowMessage("No selection") 1825 if self.partial:
1777 return 1826 vars.where_clause = " AND ( " + vars.where_clause + " ) "
1827 else:
1828 vars.where_clause = " WHERE " + vars.where_clause + " "
1778 self.accept() 1829 self.accept()
1779 1830
1780 def ShowMessage(self, msg): 1831 def ShowMessage(self, msg):
@@ -1783,6 +1834,23 @@ class SelectedBranchDialog(QDialog):
1783 def ClearMessage(self): 1834 def ClearMessage(self):
1784 self.status.setText("") 1835 self.status.setText("")
1785 1836
1837# Selected branch report creation dialog
1838
1839class SelectedBranchDialog(ReportDialogBase):
1840
1841 def __init__(self, glb, parent=None):
1842 title = "Selected Branches"
1843 items = (lambda g, p: LineEditDataItem(g, "Report name:", "Enter a name to appear in the window title bar", p, "REPORTNAME"),
1844 lambda g, p: SampleTimeRangesDataItem(g, "Time ranges:", "Enter time ranges", "samples.id", p),
1845 lambda g, p: NonNegativeIntegerRangesDataItem(g, "CPUs:", "Enter CPUs or ranges e.g. 0,5-6", "cpu", p),
1846 lambda g, p: SQLTableDataItem(g, "Commands:", "Only branches with these commands will be included", "comms", "comm", "comm_id", "", p),
1847 lambda g, p: SQLTableDataItem(g, "PIDs:", "Only branches with these process IDs will be included", "threads", "pid", "thread_id", "", p),
1848 lambda g, p: SQLTableDataItem(g, "TIDs:", "Only branches with these thread IDs will be included", "threads", "tid", "thread_id", "", p),
1849 lambda g, p: SQLTableDataItem(g, "DSOs:", "Only branches with these DSOs will be included", "dsos", "short_name", "samples.dso_id", "to_dso_id", p),
1850 lambda g, p: SQLTableDataItem(g, "Symbols:", "Only branches with these symbols will be included", "symbols", "name", "symbol_id", "to_symbol_id", p),
1851 lambda g, p: LineEditDataItem(g, "Raw SQL clause: ", "Enter a raw SQL WHERE clause", p))
1852 super(SelectedBranchDialog, self).__init__(glb, title, items, True, parent)
1853
1786# Event list 1854# Event list
1787 1855
1788def GetEventList(db): 1856def GetEventList(db):
@@ -1793,6 +1861,16 @@ def GetEventList(db):
1793 events.append(query.value(0)) 1861 events.append(query.value(0))
1794 return events 1862 return events
1795 1863
1864# Is a table selectable
1865
1866def IsSelectable(db, table):
1867 query = QSqlQuery(db)
1868 try:
1869 QueryExec(query, "SELECT * FROM " + table + " LIMIT 1")
1870 except:
1871 return False
1872 return True
1873
1796# SQL data preparation 1874# SQL data preparation
1797 1875
1798def SQLTableDataPrep(query, count): 1876def SQLTableDataPrep(query, count):
@@ -1818,12 +1896,13 @@ class SQLTableModel(TableModel):
1818 1896
1819 progress = Signal(object) 1897 progress = Signal(object)
1820 1898
1821 def __init__(self, glb, sql, column_count, parent=None): 1899 def __init__(self, glb, sql, column_headers, parent=None):
1822 super(SQLTableModel, self).__init__(parent) 1900 super(SQLTableModel, self).__init__(parent)
1823 self.glb = glb 1901 self.glb = glb
1824 self.more = True 1902 self.more = True
1825 self.populated = 0 1903 self.populated = 0
1826 self.fetcher = SQLFetcher(glb, sql, lambda x, y=column_count: SQLTableDataPrep(x, y), self.AddSample) 1904 self.column_headers = column_headers
1905 self.fetcher = SQLFetcher(glb, sql, lambda x, y=len(column_headers): SQLTableDataPrep(x, y), self.AddSample)
1827 self.fetcher.done.connect(self.Update) 1906 self.fetcher.done.connect(self.Update)
1828 self.fetcher.Fetch(glb_chunk_sz) 1907 self.fetcher.Fetch(glb_chunk_sz)
1829 1908
@@ -1861,6 +1940,12 @@ class SQLTableModel(TableModel):
1861 def HasMoreRecords(self): 1940 def HasMoreRecords(self):
1862 return self.more 1941 return self.more
1863 1942
1943 def columnCount(self, parent=None):
1944 return len(self.column_headers)
1945
1946 def columnHeader(self, column):
1947 return self.column_headers[column]
1948
1864# SQL automatic table data model 1949# SQL automatic table data model
1865 1950
1866class SQLAutoTableModel(SQLTableModel): 1951class SQLAutoTableModel(SQLTableModel):
@@ -1870,12 +1955,12 @@ class SQLAutoTableModel(SQLTableModel):
1870 if table_name == "comm_threads_view": 1955 if table_name == "comm_threads_view":
1871 # For now, comm_threads_view has no id column 1956 # For now, comm_threads_view has no id column
1872 sql = "SELECT * FROM " + table_name + " WHERE comm_id > $$last_id$$ ORDER BY comm_id LIMIT " + str(glb_chunk_sz) 1957 sql = "SELECT * FROM " + table_name + " WHERE comm_id > $$last_id$$ ORDER BY comm_id LIMIT " + str(glb_chunk_sz)
1873 self.column_headers = [] 1958 column_headers = []
1874 query = QSqlQuery(glb.db) 1959 query = QSqlQuery(glb.db)
1875 if glb.dbref.is_sqlite3: 1960 if glb.dbref.is_sqlite3:
1876 QueryExec(query, "PRAGMA table_info(" + table_name + ")") 1961 QueryExec(query, "PRAGMA table_info(" + table_name + ")")
1877 while query.next(): 1962 while query.next():
1878 self.column_headers.append(query.value(1)) 1963 column_headers.append(query.value(1))
1879 if table_name == "sqlite_master": 1964 if table_name == "sqlite_master":
1880 sql = "SELECT * FROM " + table_name 1965 sql = "SELECT * FROM " + table_name
1881 else: 1966 else:
@@ -1888,14 +1973,8 @@ class SQLAutoTableModel(SQLTableModel):
1888 schema = "public" 1973 schema = "public"
1889 QueryExec(query, "SELECT column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' and table_name = '" + select_table_name + "'") 1974 QueryExec(query, "SELECT column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' and table_name = '" + select_table_name + "'")
1890 while query.next(): 1975 while query.next():
1891 self.column_headers.append(query.value(0)) 1976 column_headers.append(query.value(0))
1892 super(SQLAutoTableModel, self).__init__(glb, sql, len(self.column_headers), parent) 1977 super(SQLAutoTableModel, self).__init__(glb, sql, column_headers, parent)
1893
1894 def columnCount(self, parent=None):
1895 return len(self.column_headers)
1896
1897 def columnHeader(self, column):
1898 return self.column_headers[column]
1899 1978
1900# Base class for custom ResizeColumnsToContents 1979# Base class for custom ResizeColumnsToContents
1901 1980
@@ -1998,6 +2077,103 @@ def GetTableList(glb):
1998 tables.append("information_schema.columns") 2077 tables.append("information_schema.columns")
1999 return tables 2078 return tables
2000 2079
2080# Top Calls data model
2081
2082class TopCallsModel(SQLTableModel):
2083
2084 def __init__(self, glb, report_vars, parent=None):
2085 text = ""
2086 if not glb.dbref.is_sqlite3:
2087 text = "::text"
2088 limit = ""
2089 if len(report_vars.limit):
2090 limit = " LIMIT " + report_vars.limit
2091 sql = ("SELECT comm, pid, tid, name,"
2092 " CASE"
2093 " WHEN (short_name = '[kernel.kallsyms]') THEN '[kernel]'" + text +
2094 " ELSE short_name"
2095 " END AS dso,"
2096 " call_time, return_time, (return_time - call_time) AS elapsed_time, branch_count, "
2097 " CASE"
2098 " WHEN (calls.flags = 1) THEN 'no call'" + text +
2099 " WHEN (calls.flags = 2) THEN 'no return'" + text +
2100 " WHEN (calls.flags = 3) THEN 'no call/return'" + text +
2101 " ELSE ''" + text +
2102 " END AS flags"
2103 " FROM calls"
2104 " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
2105 " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
2106 " INNER JOIN dsos ON symbols.dso_id = dsos.id"
2107 " INNER JOIN comms ON calls.comm_id = comms.id"
2108 " INNER JOIN threads ON calls.thread_id = threads.id" +
2109 report_vars.where_clause +
2110 " ORDER BY elapsed_time DESC" +
2111 limit
2112 )
2113 column_headers = ("Command", "PID", "TID", "Symbol", "Object", "Call Time", "Return Time", "Elapsed Time (ns)", "Branch Count", "Flags")
2114 self.alignment = (Qt.AlignLeft, Qt.AlignLeft, Qt.AlignLeft, Qt.AlignLeft, Qt.AlignLeft, Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignLeft)
2115 super(TopCallsModel, self).__init__(glb, sql, column_headers, parent)
2116
2117 def columnAlignment(self, column):
2118 return self.alignment[column]
2119
2120# Top Calls report creation dialog
2121
2122class TopCallsDialog(ReportDialogBase):
2123
2124 def __init__(self, glb, parent=None):
2125 title = "Top Calls by Elapsed Time"
2126 items = (lambda g, p: LineEditDataItem(g, "Report name:", "Enter a name to appear in the window title bar", p, "REPORTNAME"),
2127 lambda g, p: SQLTableDataItem(g, "Commands:", "Only calls with these commands will be included", "comms", "comm", "comm_id", "", p),
2128 lambda g, p: SQLTableDataItem(g, "PIDs:", "Only calls with these process IDs will be included", "threads", "pid", "thread_id", "", p),
2129 lambda g, p: SQLTableDataItem(g, "TIDs:", "Only calls with these thread IDs will be included", "threads", "tid", "thread_id", "", p),
2130 lambda g, p: SQLTableDataItem(g, "DSOs:", "Only calls with these DSOs will be included", "dsos", "short_name", "dso_id", "", p),
2131 lambda g, p: SQLTableDataItem(g, "Symbols:", "Only calls with these symbols will be included", "symbols", "name", "symbol_id", "", p),
2132 lambda g, p: LineEditDataItem(g, "Raw SQL clause: ", "Enter a raw SQL WHERE clause", p),
2133 lambda g, p: PositiveIntegerDataItem(g, "Record limit:", "Limit selection to this number of records", p, "LIMIT", "100"))
2134 super(TopCallsDialog, self).__init__(glb, title, items, False, parent)
2135
2136# Top Calls window
2137
2138class TopCallsWindow(QMdiSubWindow, ResizeColumnsToContentsBase):
2139
2140 def __init__(self, glb, report_vars, parent=None):
2141 super(TopCallsWindow, self).__init__(parent)
2142
2143 self.data_model = LookupCreateModel("Top Calls " + report_vars.UniqueId(), lambda: TopCallsModel(glb, report_vars))
2144 self.model = self.data_model
2145
2146 self.view = QTableView()
2147 self.view.setModel(self.model)
2148 self.view.setEditTriggers(QAbstractItemView.NoEditTriggers)
2149 self.view.verticalHeader().setVisible(False)
2150
2151 self.ResizeColumnsToContents()
2152
2153 self.find_bar = FindBar(self, self, True)
2154
2155 self.finder = ChildDataItemFinder(self.model)
2156
2157 self.fetch_bar = FetchMoreRecordsBar(self.data_model, self)
2158
2159 self.vbox = VBox(self.view, self.find_bar.Widget(), self.fetch_bar.Widget())
2160
2161 self.setWidget(self.vbox.Widget())
2162
2163 AddSubWindow(glb.mainwindow.mdi_area, self, report_vars.name)
2164
2165 def Find(self, value, direction, pattern, context):
2166 self.view.setFocus()
2167 self.find_bar.Busy()
2168 self.finder.Find(value, direction, pattern, context, self.FindDone)
2169
2170 def FindDone(self, row):
2171 self.find_bar.Idle()
2172 if row >= 0:
2173 self.view.setCurrentIndex(self.model.index(row, 0, QModelIndex()))
2174 else:
2175 self.find_bar.NotFound()
2176
2001# Action Definition 2177# Action Definition
2002 2178
2003def CreateAction(label, tip, callback, parent=None, shortcut=None): 2179def CreateAction(label, tip, callback, parent=None, shortcut=None):
@@ -2101,6 +2277,7 @@ p.c2 {
2101<p class=c2><a href=#callgraph>1.1 Context-Sensitive Call Graph</a></p> 2277<p class=c2><a href=#callgraph>1.1 Context-Sensitive Call Graph</a></p>
2102<p class=c2><a href=#allbranches>1.2 All branches</a></p> 2278<p class=c2><a href=#allbranches>1.2 All branches</a></p>
2103<p class=c2><a href=#selectedbranches>1.3 Selected branches</a></p> 2279<p class=c2><a href=#selectedbranches>1.3 Selected branches</a></p>
2280<p class=c2><a href=#topcallsbyelapsedtime>1.4 Top calls by elapsed time</a></p>
2104<p class=c1><a href=#tables>2. Tables</a></p> 2281<p class=c1><a href=#tables>2. Tables</a></p>
2105<h1 id=reports>1. Reports</h1> 2282<h1 id=reports>1. Reports</h1>
2106<h2 id=callgraph>1.1 Context-Sensitive Call Graph</h2> 2283<h2 id=callgraph>1.1 Context-Sensitive Call Graph</h2>
@@ -2176,6 +2353,10 @@ ms, us or ns. Also, negative values are relative to the end of trace. Examples:
2176 -10ms- The last 10ms 2353 -10ms- The last 10ms
2177</pre> 2354</pre>
2178N.B. Due to the granularity of timestamps, there could be no branches in any given time range. 2355N.B. Due to the granularity of timestamps, there could be no branches in any given time range.
2356<h2 id=topcallsbyelapsedtime>1.4 Top calls by elapsed time</h2>
2357The Top calls by elapsed time report displays calls in descending order of time elapsed between when the function was called and when it returned.
2358The data is reduced by various selection criteria. A dialog box displays available criteria which are AND'ed together.
2359If not all data is fetched, a Fetch bar is provided. Ctrl-F displays a Find bar.
2179<h1 id=tables>2. Tables</h1> 2360<h1 id=tables>2. Tables</h1>
2180The Tables menu shows all tables and views in the database. Most tables have an associated view 2361The Tables menu shows all tables and views in the database. Most tables have an associated view
2181which displays the information in a more friendly way. Not all data for large tables is fetched 2362which displays the information in a more friendly way. Not all data for large tables is fetched
@@ -2305,10 +2486,14 @@ class MainWindow(QMainWindow):
2305 edit_menu.addAction(CreateAction("&Enlarge Font", "Make text bigger", self.EnlargeFont, self, [QKeySequence("Ctrl++")])) 2486 edit_menu.addAction(CreateAction("&Enlarge Font", "Make text bigger", self.EnlargeFont, self, [QKeySequence("Ctrl++")]))
2306 2487
2307 reports_menu = menu.addMenu("&Reports") 2488 reports_menu = menu.addMenu("&Reports")
2308 reports_menu.addAction(CreateAction("Context-Sensitive Call &Graph", "Create a new window containing a context-sensitive call graph", self.NewCallGraph, self)) 2489 if IsSelectable(glb.db, "calls"):
2490 reports_menu.addAction(CreateAction("Context-Sensitive Call &Graph", "Create a new window containing a context-sensitive call graph", self.NewCallGraph, self))
2309 2491
2310 self.EventMenu(GetEventList(glb.db), reports_menu) 2492 self.EventMenu(GetEventList(glb.db), reports_menu)
2311 2493
2494 if IsSelectable(glb.db, "calls"):
2495 reports_menu.addAction(CreateAction("&Top calls by elapsed time", "Create a new window displaying top calls by elapsed time", self.NewTopCalls, self))
2496
2312 self.TableMenu(GetTableList(glb), menu) 2497 self.TableMenu(GetTableList(glb), menu)
2313 2498
2314 self.window_menu = WindowMenu(self.mdi_area, menu) 2499 self.window_menu = WindowMenu(self.mdi_area, menu)
@@ -2364,14 +2549,20 @@ class MainWindow(QMainWindow):
2364 def NewCallGraph(self): 2549 def NewCallGraph(self):
2365 CallGraphWindow(self.glb, self) 2550 CallGraphWindow(self.glb, self)
2366 2551
2552 def NewTopCalls(self):
2553 dialog = TopCallsDialog(self.glb, self)
2554 ret = dialog.exec_()
2555 if ret:
2556 TopCallsWindow(self.glb, dialog.report_vars, self)
2557
2367 def NewBranchView(self, event_id): 2558 def NewBranchView(self, event_id):
2368 BranchWindow(self.glb, event_id, "", "", self) 2559 BranchWindow(self.glb, event_id, ReportVars(), self)
2369 2560
2370 def NewSelectedBranchView(self, event_id): 2561 def NewSelectedBranchView(self, event_id):
2371 dialog = SelectedBranchDialog(self.glb, self) 2562 dialog = SelectedBranchDialog(self.glb, self)
2372 ret = dialog.exec_() 2563 ret = dialog.exec_()
2373 if ret: 2564 if ret:
2374 BranchWindow(self.glb, event_id, dialog.name, dialog.where_clause, self) 2565 BranchWindow(self.glb, event_id, dialog.report_vars, self)
2375 2566
2376 def NewTableView(self, table_name): 2567 def NewTableView(self, table_name):
2377 TableWindow(self.glb, table_name, self) 2568 TableWindow(self.glb, table_name, self)
diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
index cafeff3d74db..3648e8b986ec 100644
--- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
+++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
@@ -5,6 +5,8 @@
5# Displays system-wide failed system call totals, broken down by pid. 5# Displays system-wide failed system call totals, broken down by pid.
6# If a [comm] arg is specified, only syscalls called by [comm] are displayed. 6# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
7 7
8from __future__ import print_function
9
8import os 10import os
9import sys 11import sys
10 12
@@ -32,7 +34,7 @@ if len(sys.argv) > 1:
32syscalls = autodict() 34syscalls = autodict()
33 35
34def trace_begin(): 36def trace_begin():
35 print "Press control+C to stop and show the summary" 37 print("Press control+C to stop and show the summary")
36 38
37def trace_end(): 39def trace_end():
38 print_error_totals() 40 print_error_totals()
@@ -57,22 +59,21 @@ def syscalls__sys_exit(event_name, context, common_cpu,
57 59
58def print_error_totals(): 60def print_error_totals():
59 if for_comm is not None: 61 if for_comm is not None:
60 print "\nsyscall errors for %s:\n\n" % (for_comm), 62 print("\nsyscall errors for %s:\n" % (for_comm))
61 else: 63 else:
62 print "\nsyscall errors:\n\n", 64 print("\nsyscall errors:\n")
63 65
64 print "%-30s %10s\n" % ("comm [pid]", "count"), 66 print("%-30s %10s" % ("comm [pid]", "count"))
65 print "%-30s %10s\n" % ("------------------------------", \ 67 print("%-30s %10s" % ("------------------------------", "----------"))
66 "----------"),
67 68
68 comm_keys = syscalls.keys() 69 comm_keys = syscalls.keys()
69 for comm in comm_keys: 70 for comm in comm_keys:
70 pid_keys = syscalls[comm].keys() 71 pid_keys = syscalls[comm].keys()
71 for pid in pid_keys: 72 for pid in pid_keys:
72 print "\n%s [%d]\n" % (comm, pid), 73 print("\n%s [%d]" % (comm, pid))
73 id_keys = syscalls[comm][pid].keys() 74 id_keys = syscalls[comm][pid].keys()
74 for id in id_keys: 75 for id in id_keys:
75 print " syscall: %-16s\n" % syscall_name(id), 76 print(" syscall: %-16s" % syscall_name(id))
76 ret_keys = syscalls[comm][pid][id].keys() 77 ret_keys = syscalls[comm][pid][id].keys()
77 for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): 78 for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]), reverse = True):
78 print " err = %-20s %10d\n" % (strerror(ret), val), 79 print(" err = %-20s %10d" % (strerror(ret), val))
diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py
index ebee2c5ae496..fb0bbcbfa0f0 100644
--- a/tools/perf/scripts/python/mem-phys-addr.py
+++ b/tools/perf/scripts/python/mem-phys-addr.py
@@ -4,6 +4,8 @@
4# Copyright (c) 2018, Intel Corporation. 4# Copyright (c) 2018, Intel Corporation.
5 5
6from __future__ import division 6from __future__ import division
7from __future__ import print_function
8
7import os 9import os
8import sys 10import sys
9import struct 11import struct
@@ -31,21 +33,23 @@ def parse_iomem():
31 for i, j in enumerate(f): 33 for i, j in enumerate(f):
32 m = re.split('-|:',j,2) 34 m = re.split('-|:',j,2)
33 if m[2].strip() == 'System RAM': 35 if m[2].strip() == 'System RAM':
34 system_ram.append(long(m[0], 16)) 36 system_ram.append(int(m[0], 16))
35 system_ram.append(long(m[1], 16)) 37 system_ram.append(int(m[1], 16))
36 if m[2].strip() == 'Persistent Memory': 38 if m[2].strip() == 'Persistent Memory':
37 pmem.append(long(m[0], 16)) 39 pmem.append(int(m[0], 16))
38 pmem.append(long(m[1], 16)) 40 pmem.append(int(m[1], 16))
39 41
40def print_memory_type(): 42def print_memory_type():
41 print "Event: %s" % (event_name) 43 print("Event: %s" % (event_name))
42 print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), 44 print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), end='')
43 print "%-40s %10s %10s\n" % ("----------------------------------------", \ 45 print("%-40s %10s %10s\n" % ("----------------------------------------",
44 "-----------", "-----------"), 46 "-----------", "-----------"),
47 end='');
45 total = sum(load_mem_type_cnt.values()) 48 total = sum(load_mem_type_cnt.values())
46 for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ 49 for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
47 key = lambda(k, v): (v, k), reverse = True): 50 key = lambda kv: (kv[1], kv[0]), reverse = True):
48 print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), 51 print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total),
52 end='')
49 53
50def trace_begin(): 54def trace_begin():
51 parse_iomem() 55 parse_iomem()
@@ -80,7 +84,7 @@ def find_memory_type(phys_addr):
80 f.seek(0, 0) 84 f.seek(0, 0)
81 for j in f: 85 for j in f:
82 m = re.split('-|:',j,2) 86 m = re.split('-|:',j,2)
83 if long(m[0], 16) <= phys_addr <= long(m[1], 16): 87 if int(m[0], 16) <= phys_addr <= int(m[1], 16):
84 return m[2] 88 return m[2]
85 return "N/A" 89 return "N/A"
86 90
diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
index a150164b44a3..212557a02c50 100755
--- a/tools/perf/scripts/python/net_dropmonitor.py
+++ b/tools/perf/scripts/python/net_dropmonitor.py
@@ -1,6 +1,8 @@
1# Monitor the system for dropped packets and proudce a report of drop locations and counts 1# Monitor the system for dropped packets and proudce a report of drop locations and counts
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3 3
4from __future__ import print_function
5
4import os 6import os
5import sys 7import sys
6 8
@@ -50,19 +52,19 @@ def get_sym(sloc):
50 return (None, 0) 52 return (None, 0)
51 53
52def print_drop_table(): 54def print_drop_table():
53 print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") 55 print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
54 for i in drop_log.keys(): 56 for i in drop_log.keys():
55 (sym, off) = get_sym(i) 57 (sym, off) = get_sym(i)
56 if sym == None: 58 if sym == None:
57 sym = i 59 sym = i
58 print "%25s %25s %25s" % (sym, off, drop_log[i]) 60 print("%25s %25s %25s" % (sym, off, drop_log[i]))
59 61
60 62
61def trace_begin(): 63def trace_begin():
62 print "Starting trace (Ctrl-C to dump results)" 64 print("Starting trace (Ctrl-C to dump results)")
63 65
64def trace_end(): 66def trace_end():
65 print "Gathering kallsyms data" 67 print("Gathering kallsyms data")
66 get_kallsyms_table() 68 get_kallsyms_table()
67 print_drop_table() 69 print_drop_table()
68 70
diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py
index 9b2050f778f1..267bda49325d 100644
--- a/tools/perf/scripts/python/netdev-times.py
+++ b/tools/perf/scripts/python/netdev-times.py
@@ -8,6 +8,8 @@
8# dev=: show only thing related to specified device 8# dev=: show only thing related to specified device
9# debug: work with debug mode. It shows buffer status. 9# debug: work with debug mode. It shows buffer status.
10 10
11from __future__ import print_function
12
11import os 13import os
12import sys 14import sys
13 15
@@ -17,6 +19,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
17from perf_trace_context import * 19from perf_trace_context import *
18from Core import * 20from Core import *
19from Util import * 21from Util import *
22from functools import cmp_to_key
20 23
21all_event_list = []; # insert all tracepoint event related with this script 24all_event_list = []; # insert all tracepoint event related with this script
22irq_dic = {}; # key is cpu and value is a list which stacks irqs 25irq_dic = {}; # key is cpu and value is a list which stacks irqs
@@ -61,12 +64,12 @@ def diff_msec(src, dst):
61def print_transmit(hunk): 64def print_transmit(hunk):
62 if dev != 0 and hunk['dev'].find(dev) < 0: 65 if dev != 0 and hunk['dev'].find(dev) < 0:
63 return 66 return
64 print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ 67 print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" %
65 (hunk['dev'], hunk['len'], 68 (hunk['dev'], hunk['len'],
66 nsecs_secs(hunk['queue_t']), 69 nsecs_secs(hunk['queue_t']),
67 nsecs_nsecs(hunk['queue_t'])/1000, 70 nsecs_nsecs(hunk['queue_t'])/1000,
68 diff_msec(hunk['queue_t'], hunk['xmit_t']), 71 diff_msec(hunk['queue_t'], hunk['xmit_t']),
69 diff_msec(hunk['xmit_t'], hunk['free_t'])) 72 diff_msec(hunk['xmit_t'], hunk['free_t'])))
70 73
71# Format for displaying rx packet processing 74# Format for displaying rx packet processing
72PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" 75PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)"
@@ -98,55 +101,55 @@ def print_receive(hunk):
98 if show_hunk == 0: 101 if show_hunk == 0:
99 return 102 return
100 103
101 print "%d.%06dsec cpu=%d" % \ 104 print("%d.%06dsec cpu=%d" %
102 (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) 105 (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu))
103 for i in range(len(irq_list)): 106 for i in range(len(irq_list)):
104 print PF_IRQ_ENTRY % \ 107 print(PF_IRQ_ENTRY %
105 (diff_msec(base_t, irq_list[i]['irq_ent_t']), 108 (diff_msec(base_t, irq_list[i]['irq_ent_t']),
106 irq_list[i]['irq'], irq_list[i]['name']) 109 irq_list[i]['irq'], irq_list[i]['name']))
107 print PF_JOINT 110 print(PF_JOINT)
108 irq_event_list = irq_list[i]['event_list'] 111 irq_event_list = irq_list[i]['event_list']
109 for j in range(len(irq_event_list)): 112 for j in range(len(irq_event_list)):
110 irq_event = irq_event_list[j] 113 irq_event = irq_event_list[j]
111 if irq_event['event'] == 'netif_rx': 114 if irq_event['event'] == 'netif_rx':
112 print PF_NET_RX % \ 115 print(PF_NET_RX %
113 (diff_msec(base_t, irq_event['time']), 116 (diff_msec(base_t, irq_event['time']),
114 irq_event['skbaddr']) 117 irq_event['skbaddr']))
115 print PF_JOINT 118 print(PF_JOINT)
116 print PF_SOFT_ENTRY % \ 119 print(PF_SOFT_ENTRY %
117 diff_msec(base_t, hunk['sirq_ent_t']) 120 diff_msec(base_t, hunk['sirq_ent_t']))
118 print PF_JOINT 121 print(PF_JOINT)
119 event_list = hunk['event_list'] 122 event_list = hunk['event_list']
120 for i in range(len(event_list)): 123 for i in range(len(event_list)):
121 event = event_list[i] 124 event = event_list[i]
122 if event['event_name'] == 'napi_poll': 125 if event['event_name'] == 'napi_poll':
123 print PF_NAPI_POLL % \ 126 print(PF_NAPI_POLL %
124 (diff_msec(base_t, event['event_t']), event['dev']) 127 (diff_msec(base_t, event['event_t']), event['dev']))
125 if i == len(event_list) - 1: 128 if i == len(event_list) - 1:
126 print "" 129 print("")
127 else: 130 else:
128 print PF_JOINT 131 print(PF_JOINT)
129 else: 132 else:
130 print PF_NET_RECV % \ 133 print(PF_NET_RECV %
131 (diff_msec(base_t, event['event_t']), event['skbaddr'], 134 (diff_msec(base_t, event['event_t']), event['skbaddr'],
132 event['len']) 135 event['len']))
133 if 'comm' in event.keys(): 136 if 'comm' in event.keys():
134 print PF_WJOINT 137 print(PF_WJOINT)
135 print PF_CPY_DGRAM % \ 138 print(PF_CPY_DGRAM %
136 (diff_msec(base_t, event['comm_t']), 139 (diff_msec(base_t, event['comm_t']),
137 event['pid'], event['comm']) 140 event['pid'], event['comm']))
138 elif 'handle' in event.keys(): 141 elif 'handle' in event.keys():
139 print PF_WJOINT 142 print(PF_WJOINT)
140 if event['handle'] == "kfree_skb": 143 if event['handle'] == "kfree_skb":
141 print PF_KFREE_SKB % \ 144 print(PF_KFREE_SKB %
142 (diff_msec(base_t, 145 (diff_msec(base_t,
143 event['comm_t']), 146 event['comm_t']),
144 event['location']) 147 event['location']))
145 elif event['handle'] == "consume_skb": 148 elif event['handle'] == "consume_skb":
146 print PF_CONS_SKB % \ 149 print(PF_CONS_SKB %
147 diff_msec(base_t, 150 diff_msec(base_t,
148 event['comm_t']) 151 event['comm_t']))
149 print PF_JOINT 152 print(PF_JOINT)
150 153
151def trace_begin(): 154def trace_begin():
152 global show_tx 155 global show_tx
@@ -172,8 +175,7 @@ def trace_begin():
172 175
173def trace_end(): 176def trace_end():
174 # order all events in time 177 # order all events in time
175 all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], 178 all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME]))
176 b[EINFO_IDX_TIME]))
177 # process all events 179 # process all events
178 for i in range(len(all_event_list)): 180 for i in range(len(all_event_list)):
179 event_info = all_event_list[i] 181 event_info = all_event_list[i]
@@ -210,19 +212,19 @@ def trace_end():
210 print_receive(receive_hunk_list[i]) 212 print_receive(receive_hunk_list[i])
211 # display transmit hunks 213 # display transmit hunks
212 if show_tx: 214 if show_tx:
213 print " dev len Qdisc " \ 215 print(" dev len Qdisc "
214 " netdevice free" 216 " netdevice free")
215 for i in range(len(tx_free_list)): 217 for i in range(len(tx_free_list)):
216 print_transmit(tx_free_list[i]) 218 print_transmit(tx_free_list[i])
217 if debug: 219 if debug:
218 print "debug buffer status" 220 print("debug buffer status")
219 print "----------------------------" 221 print("----------------------------")
220 print "xmit Qdisc:remain:%d overflow:%d" % \ 222 print("xmit Qdisc:remain:%d overflow:%d" %
221 (len(tx_queue_list), of_count_tx_queue_list) 223 (len(tx_queue_list), of_count_tx_queue_list))
222 print "xmit netdevice:remain:%d overflow:%d" % \ 224 print("xmit netdevice:remain:%d overflow:%d" %
223 (len(tx_xmit_list), of_count_tx_xmit_list) 225 (len(tx_xmit_list), of_count_tx_xmit_list))
224 print "receive:remain:%d overflow:%d" % \ 226 print("receive:remain:%d overflow:%d" %
225 (len(rx_skb_list), of_count_rx_skb_list) 227 (len(rx_skb_list), of_count_rx_skb_list))
226 228
227# called from perf, when it finds a correspoinding event 229# called from perf, when it finds a correspoinding event
228def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec): 230def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec):
diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py
index 00e0e7476e55..8b78dc790adb 100644
--- a/tools/perf/scripts/python/powerpc-hcalls.py
+++ b/tools/perf/scripts/python/powerpc-hcalls.py
@@ -4,6 +4,8 @@
4# 4#
5# Hypervisor call statisics 5# Hypervisor call statisics
6 6
7from __future__ import print_function
8
7import os 9import os
8import sys 10import sys
9 11
@@ -149,7 +151,7 @@ hcall_table = {
149} 151}
150 152
151def hcall_table_lookup(opcode): 153def hcall_table_lookup(opcode):
152 if (hcall_table.has_key(opcode)): 154 if (opcode in hcall_table):
153 return hcall_table[opcode] 155 return hcall_table[opcode]
154 else: 156 else:
155 return opcode 157 return opcode
@@ -157,8 +159,8 @@ def hcall_table_lookup(opcode):
157print_ptrn = '%-28s%10s%10s%10s%10s' 159print_ptrn = '%-28s%10s%10s%10s%10s'
158 160
159def trace_end(): 161def trace_end():
160 print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)') 162 print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)'))
161 print '-' * 68 163 print('-' * 68)
162 for opcode in output: 164 for opcode in output:
163 h_name = hcall_table_lookup(opcode) 165 h_name = hcall_table_lookup(opcode)
164 time = output[opcode]['time'] 166 time = output[opcode]['time']
@@ -166,14 +168,14 @@ def trace_end():
166 min_t = output[opcode]['min'] 168 min_t = output[opcode]['min']
167 max_t = output[opcode]['max'] 169 max_t = output[opcode]['max']
168 170
169 print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt) 171 print(print_ptrn % (h_name, cnt, min_t, max_t, time//cnt))
170 172
171def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, 173def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
172 opcode, retval): 174 opcode, retval):
173 if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)): 175 if (cpu in d_enter and opcode in d_enter[cpu]):
174 diff = nsecs(sec, nsec) - d_enter[cpu][opcode] 176 diff = nsecs(sec, nsec) - d_enter[cpu][opcode]
175 177
176 if (output.has_key(opcode)): 178 if (opcode in output):
177 output[opcode]['time'] += diff 179 output[opcode]['time'] += diff
178 output[opcode]['cnt'] += 1 180 output[opcode]['cnt'] += 1
179 if (output[opcode]['min'] > diff): 181 if (output[opcode]['min'] > diff):
@@ -190,11 +192,11 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
190 192
191 del d_enter[cpu][opcode] 193 del d_enter[cpu][opcode]
192# else: 194# else:
193# print "Can't find matching hcall_enter event. Ignoring sample" 195# print("Can't find matching hcall_enter event. Ignoring sample")
194 196
195def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm, 197def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,
196 callchain, opcode): 198 callchain, opcode):
197 if (d_enter.has_key(cpu)): 199 if (cpu in d_enter):
198 d_enter[cpu][opcode] = nsecs(sec, nsec) 200 d_enter[cpu][opcode] = nsecs(sec, nsec)
199 else: 201 else:
200 d_enter[cpu] = {opcode: nsecs(sec, nsec)} 202 d_enter[cpu] = {opcode: nsecs(sec, nsec)}
diff --git a/tools/perf/scripts/python/sched-migration.py b/tools/perf/scripts/python/sched-migration.py
index 3473e7f66081..3984bf51f3c5 100644
--- a/tools/perf/scripts/python/sched-migration.py
+++ b/tools/perf/scripts/python/sched-migration.py
@@ -1,5 +1,3 @@
1#!/usr/bin/python
2#
3# Cpu task migration overview toy 1# Cpu task migration overview toy
4# 2#
5# Copyright (C) 2010 Frederic Weisbecker <fweisbec@gmail.com> 3# Copyright (C) 2010 Frederic Weisbecker <fweisbec@gmail.com>
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py
index 61621b93affb..987ffae7c8ca 100644
--- a/tools/perf/scripts/python/sctop.py
+++ b/tools/perf/scripts/python/sctop.py
@@ -8,7 +8,14 @@
8# will be refreshed every [interval] seconds. The default interval is 8# will be refreshed every [interval] seconds. The default interval is
9# 3 seconds. 9# 3 seconds.
10 10
11import os, sys, thread, time 11from __future__ import print_function
12
13import os, sys, time
14
15try:
16 import thread
17except ImportError:
18 import _thread as thread
12 19
13sys.path.append(os.environ['PERF_EXEC_PATH'] + \ 20sys.path.append(os.environ['PERF_EXEC_PATH'] + \
14 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') 21 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -62,18 +69,19 @@ def print_syscall_totals(interval):
62 while 1: 69 while 1:
63 clear_term() 70 clear_term()
64 if for_comm is not None: 71 if for_comm is not None:
65 print "\nsyscall events for %s:\n\n" % (for_comm), 72 print("\nsyscall events for %s:\n" % (for_comm))
66 else: 73 else:
67 print "\nsyscall events:\n\n", 74 print("\nsyscall events:\n")
68 75
69 print "%-40s %10s\n" % ("event", "count"), 76 print("%-40s %10s" % ("event", "count"))
70 print "%-40s %10s\n" % ("----------------------------------------", \ 77 print("%-40s %10s" %
71 "----------"), 78 ("----------------------------------------",
79 "----------"))
72 80
73 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ 81 for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
74 reverse = True): 82 reverse = True):
75 try: 83 try:
76 print "%-40s %10d\n" % (syscall_name(id), val), 84 print("%-40s %10d" % (syscall_name(id), val))
77 except TypeError: 85 except TypeError:
78 pass 86 pass
79 syscalls.clear() 87 syscalls.clear()
diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
index 1697b5e18c96..5e703efaddcc 100755
--- a/tools/perf/scripts/python/stackcollapse.py
+++ b/tools/perf/scripts/python/stackcollapse.py
@@ -19,6 +19,8 @@
19# Written by Paolo Bonzini <pbonzini@redhat.com> 19# Written by Paolo Bonzini <pbonzini@redhat.com>
20# Based on Brendan Gregg's stackcollapse-perf.pl script. 20# Based on Brendan Gregg's stackcollapse-perf.pl script.
21 21
22from __future__ import print_function
23
22import os 24import os
23import sys 25import sys
24from collections import defaultdict 26from collections import defaultdict
@@ -120,7 +122,6 @@ def process_event(param_dict):
120 lines[stack_string] = lines[stack_string] + 1 122 lines[stack_string] = lines[stack_string] + 1
121 123
122def trace_end(): 124def trace_end():
123 list = lines.keys() 125 list = sorted(lines)
124 list.sort()
125 for stack in list: 126 for stack in list:
126 print "%s %d" % (stack, lines[stack]) 127 print("%s %d" % (stack, lines[stack]))
diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py
index 8410672efb8b..01fa933ff3cf 100644
--- a/tools/perf/scripts/python/stat-cpi.py
+++ b/tools/perf/scripts/python/stat-cpi.py
@@ -1,6 +1,7 @@
1#!/usr/bin/env python
2# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
3 2
3from __future__ import print_function
4
4data = {} 5data = {}
5times = [] 6times = []
6threads = [] 7threads = []
@@ -20,8 +21,8 @@ def store_key(time, cpu, thread):
20 threads.append(thread) 21 threads.append(thread)
21 22
22def store(time, event, cpu, thread, val, ena, run): 23def store(time, event, cpu, thread, val, ena, run):
23 #print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \ 24 #print("event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" %
24 # (event, cpu, thread, time, val, ena, run) 25 # (event, cpu, thread, time, val, ena, run))
25 26
26 store_key(time, cpu, thread) 27 store_key(time, cpu, thread)
27 key = get_key(time, event, cpu, thread) 28 key = get_key(time, event, cpu, thread)
@@ -59,7 +60,7 @@ def stat__interval(time):
59 if ins != 0: 60 if ins != 0:
60 cpi = cyc/float(ins) 61 cpi = cyc/float(ins)
61 62
62 print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins) 63 print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins))
63 64
64def trace_end(): 65def trace_end():
65 pass 66 pass
@@ -75,4 +76,4 @@ def trace_end():
75# if ins != 0: 76# if ins != 0:
76# cpi = cyc/float(ins) 77# cpi = cyc/float(ins)
77# 78#
78# print "time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi) 79# print("time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi))
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py
index daf314cc5dd3..42782487b0e9 100644
--- a/tools/perf/scripts/python/syscall-counts-by-pid.py
+++ b/tools/perf/scripts/python/syscall-counts-by-pid.py
@@ -5,6 +5,8 @@
5# Displays system-wide system call totals, broken down by syscall. 5# Displays system-wide system call totals, broken down by syscall.
6# If a [comm] arg is specified, only syscalls called by [comm] are displayed. 6# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
7 7
8from __future__ import print_function
9
8import os, sys 10import os, sys
9 11
10sys.path.append(os.environ['PERF_EXEC_PATH'] + \ 12sys.path.append(os.environ['PERF_EXEC_PATH'] + \
@@ -31,7 +33,7 @@ if len(sys.argv) > 1:
31syscalls = autodict() 33syscalls = autodict()
32 34
33def trace_begin(): 35def trace_begin():
34 print "Press control+C to stop and show the summary" 36 print("Press control+C to stop and show the summary")
35 37
36def trace_end(): 38def trace_end():
37 print_syscall_totals() 39 print_syscall_totals()
@@ -55,20 +57,20 @@ def syscalls__sys_enter(event_name, context, common_cpu,
55 57
56def print_syscall_totals(): 58def print_syscall_totals():
57 if for_comm is not None: 59 if for_comm is not None:
58 print "\nsyscall events for %s:\n\n" % (for_comm), 60 print("\nsyscall events for %s:\n" % (for_comm))
59 else: 61 else:
60 print "\nsyscall events by comm/pid:\n\n", 62 print("\nsyscall events by comm/pid:\n")
61 63
62 print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"), 64 print("%-40s %10s" % ("comm [pid]/syscalls", "count"))
63 print "%-40s %10s\n" % ("----------------------------------------", \ 65 print("%-40s %10s" % ("----------------------------------------",
64 "----------"), 66 "----------"))
65 67
66 comm_keys = syscalls.keys() 68 comm_keys = syscalls.keys()
67 for comm in comm_keys: 69 for comm in comm_keys:
68 pid_keys = syscalls[comm].keys() 70 pid_keys = syscalls[comm].keys()
69 for pid in pid_keys: 71 for pid in pid_keys:
70 print "\n%s [%d]\n" % (comm, pid), 72 print("\n%s [%d]" % (comm, pid))
71 id_keys = syscalls[comm][pid].keys() 73 id_keys = syscalls[comm][pid].keys()
72 for id, val in sorted(syscalls[comm][pid].iteritems(), \ 74 for id, val in sorted(syscalls[comm][pid].items(), \
73 key = lambda(k, v): (v, k), reverse = True): 75 key = lambda kv: (kv[1], kv[0]), reverse = True):
74 print " %-38s %10d\n" % (syscall_name(id), val), 76 print(" %-38s %10d" % (syscall_name(id), val))
diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py
index e66a7730aeb5..0ebd89cfd42c 100644
--- a/tools/perf/scripts/python/syscall-counts.py
+++ b/tools/perf/scripts/python/syscall-counts.py
@@ -5,6 +5,8 @@
5# Displays system-wide system call totals, broken down by syscall. 5# Displays system-wide system call totals, broken down by syscall.
6# If a [comm] arg is specified, only syscalls called by [comm] are displayed. 6# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
7 7
8from __future__ import print_function
9
8import os 10import os
9import sys 11import sys
10 12
@@ -28,7 +30,7 @@ if len(sys.argv) > 1:
28syscalls = autodict() 30syscalls = autodict()
29 31
30def trace_begin(): 32def trace_begin():
31 print "Press control+C to stop and show the summary" 33 print("Press control+C to stop and show the summary")
32 34
33def trace_end(): 35def trace_end():
34 print_syscall_totals() 36 print_syscall_totals()
@@ -51,14 +53,14 @@ def syscalls__sys_enter(event_name, context, common_cpu,
51 53
52def print_syscall_totals(): 54def print_syscall_totals():
53 if for_comm is not None: 55 if for_comm is not None:
54 print "\nsyscall events for %s:\n\n" % (for_comm), 56 print("\nsyscall events for %s:\n" % (for_comm))
55 else: 57 else:
56 print "\nsyscall events:\n\n", 58 print("\nsyscall events:\n")
57 59
58 print "%-40s %10s\n" % ("event", "count"), 60 print("%-40s %10s" % ("event", "count"))
59 print "%-40s %10s\n" % ("----------------------------------------", \ 61 print("%-40s %10s" % ("----------------------------------------",
60 "-----------"), 62 "-----------"))
61 63
62 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ 64 for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
63 reverse = True): 65 reverse = True):
64 print "%-40s %10d\n" % (syscall_name(id), val), 66 print("%-40s %10d" % (syscall_name(id), val))