Skip to content

Commit 530e22f

Browse files
ahunter6acmel
authored andcommitted
perf scripts python: exported-sql-viewer.py: Add IPC information to the Branch reports
Enhance the "All branches" and "Selected branches" reports to display IPC information if it is available. Committer testing: So, testing this I noticed that it all starts with the left arrow in every line, that should mean there is some tree there, i.e. look at all those ▶ symbols: Reports -> All Branches: Time CPU Command PID TID Branch Type In Tx Insn Cnt Cyc Cnt IPC Branch ▶ 187836112195670 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4f110 +_start (ld-2.28.so) ▶ 187836112195987 7 simple-retpolin 23003 23003 trace end No 0 883 0 7f6f33d4f110 _start (ld-2.28.so) -> 0 unknown +(unknown) ▶ 187836112199189 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4f110 +_start (ld-2.28.so) ▶ 187836112199189 7 simple-retpolin 23003 23003 call No 0 0 0 7f6f33d4f113 _start+0x3 (ld-2.28.so) -> 7f6f33d4ff50 +_dl_start (ld-2.28.so) ▶ 187836112199544 7 simple-retpolin 23003 23003 trace end No 17 996 0.02 7f6f33d4ff73 _dl_start+0x23 (ld-2.28.so) -> 0 +unknown (unknown) ▶ 187836112200939 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4ff73 +_dl_start+0x23 (ld-2.28.so) ▶ 187836112201229 7 simple-retpolin 23003 23003 trace end No 1 816 0.00 7f6f33d4ff7a _dl_start+0x2a (ld-2.28.so) -> 0 +unknown (unknown) ▶ 187836112203500 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4ff7a +_dl_start+0x2a (ld-2.28.so) But if you click on it, that ▶ disappears and a new click doesn't make it reappear, looks buggy, minor oddity, reported to Adrian. Reports -> Selected Branches, then ask for branches in the ld-2.28.so DSO: Time CPU Command PID TID Branch Type In Tx Insn Cnt Cyc Cnt IPC Branch ▶ 187836112195987 7 simple-retpolin 23003 23003 trace end No 0 883 0 7f6f33d4f110 _start (ld-2.28.so) -> 0 unknown (unknown) ▶ 187836112199189 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4f110 _start (ld-2.28.so) ▶ 187836112199189 7 simple-retpolin 23003 23003 call No 0 0 0 7f6f33d4f113 _start+0x3 (ld-2.28.so) -> 7f6f33d4ff50 _dl_start (ld-2.28.so) ▶ 187836112199544 7 simple-retpolin 23003 23003 trace end No 17 996 0.02 7f6f33d4ff73 _dl_start+0x23 (ld-2.28.so) -> 0 unknown (unknown) ▶ 187836112200939 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4ff73 _dl_start+0x23 (ld-2.28.so) ▶ 187836112201229 7 simple-retpolin 23003 23003 trace end No 1 816 0.00 7f6f33d4ff7a _dl_start+0x2a (ld-2.28.so) -> 0 unknown (unknown) ▶ 187836112203500 7 simple-retpolin 23003 23003 trace begin No 0 0 0 0 unknown (unknown) -> 7f6f33d4ff7a _dl_start+0x2a (ld-2.28.so) ▶ 187836112203528 7 simple-retpolin 23003 23003 unconditional jump No 0 0 0 7f6f33d4ffe7 _dl_start+0x97 (ld-2.28.so) -> 7f6f33d5000b _dl_start+0xbb (ld-2.28.so) ▶ 187836112203528 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d5000f _dl_start+0xbf (ld-2.28.so) -> 7f6f33d4fffb _dl_start+0xab (ld-2.28.so) ▶ 187836112203528 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d5000f _dl_start+0xbf (ld-2.28.so) -> 7f6f33d4fffb _dl_start+0xab (ld-2.28.so) ▶ 187836112203539 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d50025 _dl_start+0xd5 (ld-2.28.so) -> 7f6f33d50210 _dl_start+0x2c0 (ld-2.28.so) ▶ 187836112203539 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d5021a _dl_start+0x2ca (ld-2.28.so) -> 7f6f33d50360 _dl_start+0x410 (ld-2.28.so) ▶ 187836112203539 7 simple-retpolin 23003 23003 unconditional jump No 0 0 0 7f6f33d50377 _dl_start+0x427 (ld-2.28.so) -> 7f6f33d4ffff _dl_start+0xaf (ld-2.28.so) ▶ 187836112203539 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d5000f _dl_start+0xbf (ld-2.28.so) -> 7f6f33d4fffb _dl_start+0xab (ld-2.28.so) ▶ 187836112203562 7 simple-retpolin 23003 23003 conditional jump No 0 0 0 7f6f33d5000f _dl_start+0xbf (ld-2.28.so) -> 7f6f33d4fffb _dl_start+0xab (ld-2.28.so) Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/20190520113728.14389-19-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ec7f448 commit 530e22f

1 file changed

Lines changed: 83 additions & 19 deletions

File tree

‎tools/perf/scripts/python/exported-sql-viewer.py‎

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,11 +1369,11 @@ def FetchMoreRecords(self):
13691369

13701370
class BranchLevelTwoItem():
13711371

1372-
def __init__(self, row, text, parent_item):
1372+
def __init__(self, row, col, text, parent_item):
13731373
self.row = row
13741374
self.parent_item = parent_item
1375-
self.data = [""] * 8
1376-
self.data[7] = text
1375+
self.data = [""] * (col + 1)
1376+
self.data[col] = text
13771377
self.level = 2
13781378

13791379
def getParentItem(self):
@@ -1405,6 +1405,7 @@ def __init__(self, glb, row, data, parent_item):
14051405
self.dbid = data[0]
14061406
self.level = 1
14071407
self.query_done = False
1408+
self.br_col = len(self.data) - 1
14081409

14091410
def getChildItem(self, row):
14101411
return self.child_items[row]
@@ -1485,7 +1486,7 @@ def Select(self):
14851486
while k < 15:
14861487
byte_str += " "
14871488
k += 1
1488-
self.child_items.append(BranchLevelTwoItem(0, byte_str + " " + text, self))
1489+
self.child_items.append(BranchLevelTwoItem(0, self.br_col, byte_str + " " + text, self))
14891490
self.child_count += 1
14901491
else:
14911492
return
@@ -1536,16 +1537,37 @@ def hasChildren(self):
15361537
def getData(self, column):
15371538
return ""
15381539

1540+
# Calculate instructions per cycle
1541+
1542+
def CalcIPC(cyc_cnt, insn_cnt):
1543+
if cyc_cnt and insn_cnt:
1544+
ipc = Decimal(float(insn_cnt) / cyc_cnt)
1545+
ipc = str(ipc.quantize(Decimal(".01"), rounding=ROUND_HALF_UP))
1546+
else:
1547+
ipc = "0"
1548+
return ipc
1549+
15391550
# Branch data preparation
15401551

1541-
def BranchDataPrep(query):
1542-
data = []
1543-
for i in xrange(0, 8):
1544-
data.append(query.value(i))
1552+
def BranchDataPrepBr(query, data):
15451553
data.append(tohex(query.value(8)).rjust(16) + " " + query.value(9) + offstr(query.value(10)) +
15461554
" (" + dsoname(query.value(11)) + ")" + " -> " +
15471555
tohex(query.value(12)) + " " + query.value(13) + offstr(query.value(14)) +
15481556
" (" + dsoname(query.value(15)) + ")")
1557+
1558+
def BranchDataPrepIPC(query, data):
1559+
insn_cnt = query.value(16)
1560+
cyc_cnt = query.value(17)
1561+
ipc = CalcIPC(cyc_cnt, insn_cnt)
1562+
data.append(insn_cnt)
1563+
data.append(cyc_cnt)
1564+
data.append(ipc)
1565+
1566+
def BranchDataPrep(query):
1567+
data = []
1568+
for i in xrange(0, 8):
1569+
data.append(query.value(i))
1570+
BranchDataPrepBr(query, data)
15491571
return data
15501572

15511573
def BranchDataPrepWA(query):
@@ -1555,10 +1577,26 @@ def BranchDataPrepWA(query):
15551577
data.append("{:>19}".format(query.value(1)))
15561578
for i in xrange(2, 8):
15571579
data.append(query.value(i))
1558-
data.append(tohex(query.value(8)).rjust(16) + " " + query.value(9) + offstr(query.value(10)) +
1559-
" (" + dsoname(query.value(11)) + ")" + " -> " +
1560-
tohex(query.value(12)) + " " + query.value(13) + offstr(query.value(14)) +
1561-
" (" + dsoname(query.value(15)) + ")")
1580+
BranchDataPrepBr(query, data)
1581+
return data
1582+
1583+
def BranchDataWithIPCPrep(query):
1584+
data = []
1585+
for i in xrange(0, 8):
1586+
data.append(query.value(i))
1587+
BranchDataPrepIPC(query, data)
1588+
BranchDataPrepBr(query, data)
1589+
return data
1590+
1591+
def BranchDataWithIPCPrepWA(query):
1592+
data = []
1593+
data.append(query.value(0))
1594+
# Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string
1595+
data.append("{:>19}".format(query.value(1)))
1596+
for i in xrange(2, 8):
1597+
data.append(query.value(i))
1598+
BranchDataPrepIPC(query, data)
1599+
BranchDataPrepBr(query, data)
15621600
return data
15631601

15641602
# Branch data model
@@ -1572,10 +1610,20 @@ def __init__(self, glb, event_id, where_clause, parent=None):
15721610
self.event_id = event_id
15731611
self.more = True
15741612
self.populated = 0
1613+
self.have_ipc = IsSelectable(glb.db, "samples", columns = "insn_count, cyc_count")
1614+
if self.have_ipc:
1615+
select_ipc = ", insn_count, cyc_count"
1616+
prep_fn = BranchDataWithIPCPrep
1617+
prep_wa_fn = BranchDataWithIPCPrepWA
1618+
else:
1619+
select_ipc = ""
1620+
prep_fn = BranchDataPrep
1621+
prep_wa_fn = BranchDataPrepWA
15751622
sql = ("SELECT samples.id, time, cpu, comm, pid, tid, branch_types.name,"
15761623
" CASE WHEN in_tx = '0' THEN 'No' ELSE 'Yes' END,"
15771624
" ip, symbols.name, sym_offset, dsos.short_name,"
15781625
" to_ip, to_symbols.name, to_sym_offset, to_dsos.short_name"
1626+
+ select_ipc +
15791627
" FROM samples"
15801628
" INNER JOIN comms ON comm_id = comms.id"
15811629
" INNER JOIN threads ON thread_id = threads.id"
@@ -1589,9 +1637,9 @@ def __init__(self, glb, event_id, where_clause, parent=None):
15891637
" ORDER BY samples.id"
15901638
" LIMIT " + str(glb_chunk_sz))
15911639
if pyside_version_1 and sys.version_info[0] == 3:
1592-
prep = BranchDataPrepWA
1640+
prep = prep_fn
15931641
else:
1594-
prep = BranchDataPrep
1642+
prep = prep_wa_fn
15951643
self.fetcher = SQLFetcher(glb, sql, prep, self.AddSample)
15961644
self.fetcher.done.connect(self.Update)
15971645
self.fetcher.Fetch(glb_chunk_sz)
@@ -1600,13 +1648,23 @@ def GetRoot(self):
16001648
return BranchRootItem()
16011649

16021650
def columnCount(self, parent=None):
1603-
return 8
1651+
if self.have_ipc:
1652+
return 11
1653+
else:
1654+
return 8
16041655

16051656
def columnHeader(self, column):
1606-
return ("Time", "CPU", "Command", "PID", "TID", "Branch Type", "In Tx", "Branch")[column]
1657+
if self.have_ipc:
1658+
return ("Time", "CPU", "Command", "PID", "TID", "Branch Type", "In Tx", "Insn Cnt", "Cyc Cnt", "IPC", "Branch")[column]
1659+
else:
1660+
return ("Time", "CPU", "Command", "PID", "TID", "Branch Type", "In Tx", "Branch")[column]
16071661

16081662
def columnFont(self, column):
1609-
if column != 7:
1663+
if self.have_ipc:
1664+
br_col = 10
1665+
else:
1666+
br_col = 7
1667+
if column != br_col:
16101668
return None
16111669
return QFont("Monospace")
16121670

@@ -2114,10 +2172,10 @@ def GetEventList(db):
21142172

21152173
# Is a table selectable
21162174

2117-
def IsSelectable(db, table, sql = ""):
2175+
def IsSelectable(db, table, sql = "", columns = "*"):
21182176
query = QSqlQuery(db)
21192177
try:
2120-
QueryExec(query, "SELECT * FROM " + table + " " + sql + " LIMIT 1")
2178+
QueryExec(query, "SELECT " + columns + " FROM " + table + " " + sql + " LIMIT 1")
21212179
except:
21222180
return False
21232181
return True
@@ -2854,6 +2912,12 @@ def setActiveSubWindow(self, nr):
28542912
sudo ./mfile.py --prefix=/usr/local install
28552913
sudo ldconfig
28562914
</pre>
2915+
<h3>Instructions per Cycle (IPC)</h3>
2916+
If available, IPC information is displayed in columns 'insn_cnt', 'cyc_cnt' and 'IPC'.
2917+
<p><b>Intel PT note:</b> The information applies to the blocks of code ending with, and including, that branch.
2918+
Due to the granularity of timing information, the number of cycles for some code blocks will not be known.
2919+
In that case, 'insn_cnt', 'cyc_cnt' and 'IPC' are zero, but when 'IPC' is displayed it covers the period
2920+
since the previous displayed 'IPC'.
28572921
<h3>Find</h3>
28582922
Ctrl-F displays a Find bar which finds substrings by either an exact match or a regular expression match.
28592923
Refer to Python documentation for the regular expression syntax.

0 commit comments

Comments
 (0)