History

perf scripts python: exported-sql-viewer.py: Add IPC information to Call Tree

Enhance the call tree to display IPC information if it is available. Committer testing: [acme@quaco adrian.hunter]$ python ~acme/libexec/perf-core/scripts/python/exported-sql-viewer.py ~/c/adrian.hunter/simple-retpoline.db Reports -> Call Tree, then expand a few trees, then select with the mouse and press control+C (copy): Call Path Object Call Time Time Time(%) Insn Insn Cyc Cyc IPC Branch Branch ▼ simple-retpolin (ns) Cnt Cnt(%) Cnt Cnt(%) Count Count(%) ▼ 23003:23003 ▼ _start ld-2.28.so 112195670 218295 100.0 127746 100.0 207320 100.0 0.62 13046 100.0 ▶ unknown unknown 112195987 3202 1.5 0 0.0 0 0.0 0 1 0.0 ▶ _dl_start ld-2.28.so 112199189 188471 86.3 123394 96.6 180007 86.8 0.69 12529 96.0 ▼ _dl_init ld-2.28.so 112387660 13406 6.1 3207 2.5 14868 7.2 0.22 327 2.5 ▶ call_init.part.0 ld-2.28.so 112387773 117 0.9 70 2.2 639 4.3 0.11 3 0.9 ▶ call_init.part.0 ld-2.28.so 112387890 13129 97.9 3103 96.8 14100 94.8 0.22 315 96.3 ▶ call_init.part.0 ld-2.28.so 112401020 0 0.0 0 0.0 0 0.0 0 2 0.6 ▼ _start simple-retpol 112401066 12899 5.9 1142 0.9 11561 5.6 0.10 184 1.4 ▶ unknown unknown 112401388 846 6.6 0 0.0 0 0.0 0 1 0.5 ▼ __libc_start_main libc-2.28.so 112402344 11621 90.1 1129 98.9 10350 89.5 0.11 181 98.4 ▶ __cxa_atexit libc-2.28.so 112402360 2302 19.8 101 8.9 1817 17.6 0.06 13 7.2 ▶ __libc_csu_init simple-retpol 112404673 121 1.0 43 3.8 340 3.3 0.13 8 4.4 ▶ _setjmp libc-2.28.so 112404794 74 0.6 46 4.1 206 2.0 0.22 4 2.2 ▼ main simple-retpol 112404892 44 0.4 23 2.0 126 1.2 0.18 12 6.6 ▼ foo simple-retpol 112404892 19 43.2 12 52.2 55 43.7 0.22 5 41.7 bar simple-retpol 112404896 12 63.2 3 25.0 34 61.8 0.09 1 20.0 ▼ foo simple-retpol 112404911 25 56.8 11 47.8 71 56.3 0.15 5 41.7 ▶ bar simple-retpol 112404924 10 40.0 3 27.3 27 38.0 0.11 1 20.0 ▶ exit libc-2.28.so 112404936 9029 77.7 878 77.8 7765 75.0 0.11 139 76.8

Adrian Hunter committed 7 years ago

Commit b3b66071 parent 38a846d1 file · +56 −13Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/exported-sql-viewer.py+56−13
@@ -781,11 +781,13 @@ class CallGraphModel(CallGraphModelBase): · 780 unmodified lines
781781
782782 class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
783783
784− def __init__(self, glb, params, row, comm_id, thread_id, calls_id, time, branch_count, parent_item):
784+ def __init__(self, glb, params, row, comm_id, thread_id, calls_id, time, insn_cnt, cyc_cnt, branch_count, parent_item):
785785 super(CallTreeLevelTwoPlusItemBase, self).__init__(glb, params, row, parent_item)
786786 self.comm_id = comm_id
787787 self.thread_id = thread_id
788788 self.calls_id = calls_id
789+ self.insn_cnt = insn_cnt
790+ self.cyc_cnt = cyc_cnt
789791 self.branch_count = branch_count
790792 self.time = time
791793
@@ -795,8 +797,12 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): · 3 unmodified lines
795797 comm_thread = " AND comm_id = " + str(self.comm_id) + " AND thread_id = " + str(self.thread_id)
796798 else:
797799 comm_thread = ""
800+ if self.params.have_ipc:
801+ ipc_str = ", insn_count, cyc_count"
802+ else:
803+ ipc_str = ""
798804 query = QSqlQuery(self.glb.db)
799− QueryExec(query, "SELECT calls.id, name, short_name, call_time, return_time - call_time, branch_count"
805+ QueryExec(query, "SELECT calls.id, name, short_name, call_time, return_time - call_time" + ipc_str + ", branch_count"
800806 " FROM calls"
801807 " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
802808 " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
@@ -804,7 +810,15 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): · 1 unmodified line
804810 " WHERE calls.parent_id = " + str(self.calls_id) + comm_thread +
805811 " ORDER BY call_time, calls.id")
806812 while query.next():
807− child_item = CallTreeLevelThreeItem(self.glb, self.params, self.child_count, self.comm_id, self.thread_id, query.value(0), query.value(1), query.value(2), query.value(3), int(query.value(4)), int(query.value(5)), self)
813+ if self.params.have_ipc:
814+ insn_cnt = int(query.value(5))
815+ cyc_cnt = int(query.value(6))
816+ branch_count = int(query.value(7))
817+ else:
818+ insn_cnt = 0
819+ cyc_cnt = 0
820+ branch_count = int(query.value(5))
821+ child_item = CallTreeLevelThreeItem(self.glb, self.params, self.child_count, self.comm_id, self.thread_id, query.value(0), query.value(1), query.value(2), query.value(3), int(query.value(4)), insn_cnt, cyc_cnt, branch_count, self)
808822 self.child_items.append(child_item)
809823 self.child_count += 1
810824
@@ -812,10 +826,17 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): · 1 unmodified line
812826
813827 class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase):
814828
815− def __init__(self, glb, params, row, comm_id, thread_id, calls_id, name, dso, count, time, branch_count, parent_item):
816− super(CallTreeLevelThreeItem, self).__init__(glb, params, row, comm_id, thread_id, calls_id, time, branch_count, parent_item)
829+ def __init__(self, glb, params, row, comm_id, thread_id, calls_id, name, dso, count, time, insn_cnt, cyc_cnt, branch_count, parent_item):
830+ super(CallTreeLevelThreeItem, self).__init__(glb, params, row, comm_id, thread_id, calls_id, time, insn_cnt, cyc_cnt, branch_count, parent_item)
817831 dso = dsoname(dso)
818− self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
832+ if self.params.have_ipc:
833+ insn_pcnt = PercentToOneDP(insn_cnt, parent_item.insn_cnt)
834+ cyc_pcnt = PercentToOneDP(cyc_cnt, parent_item.cyc_cnt)
835+ br_pcnt = PercentToOneDP(branch_count, parent_item.branch_count)
836+ ipc = CalcIPC(cyc_cnt, insn_cnt)
837+ self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(insn_cnt), insn_pcnt, str(cyc_cnt), cyc_pcnt, ipc, str(branch_count), br_pcnt ]
838+ else:
839+ self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
819840 self.dbid = calls_id
820841
821842 # Call tree data model level two item
@@ -823,18 +844,28 @@ class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase): · 1 unmodified line
823844 class CallTreeLevelTwoItem(CallTreeLevelTwoPlusItemBase):
824845
825846 def __init__(self, glb, params, row, comm_id, thread_id, pid, tid, parent_item):
826− super(CallTreeLevelTwoItem, self).__init__(glb, params, row, comm_id, thread_id, 0, 0, 0, parent_item)
827− self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
847+ super(CallTreeLevelTwoItem, self).__init__(glb, params, row, comm_id, thread_id, 0, 0, 0, 0, 0, parent_item)
848+ if self.params.have_ipc:
849+ self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", "", "", "", "", "", ""]
850+ else:
851+ self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
828852 self.dbid = thread_id
829853
830854 def Select(self):
831855 super(CallTreeLevelTwoItem, self).Select()
832856 for child_item in self.child_items:
833857 self.time += child_item.time
858+ self.insn_cnt += child_item.insn_cnt
859+ self.cyc_cnt += child_item.cyc_cnt
834860 self.branch_count += child_item.branch_count
835861 for child_item in self.child_items:
836862 child_item.data[4] = PercentToOneDP(child_item.time, self.time)
837− child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
863+ if self.params.have_ipc:
864+ child_item.data[6] = PercentToOneDP(child_item.insn_cnt, self.insn_cnt)
865+ child_item.data[8] = PercentToOneDP(child_item.cyc_cnt, self.cyc_cnt)
866+ child_item.data[11] = PercentToOneDP(child_item.branch_count, self.branch_count)
867+ else:
868+ child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
838869
839870 # Call tree data model level one item
840871
@@ -842,7 +873,10 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase): · 1 unmodified line
842873
843874 def __init__(self, glb, params, row, comm_id, comm, parent_item):
844875 super(CallTreeLevelOneItem, self).__init__(glb, params, row, parent_item)
845− self.data = [comm, "", "", "", "", "", ""]
876+ if self.params.have_ipc:
877+ self.data = [comm, "", "", "", "", "", "", "", "", "", "", ""]
878+ else:
879+ self.data = [comm, "", "", "", "", "", ""]
846880 self.dbid = comm_id
847881
848882 def Select(self):
@@ -885,14 +919,23 @@ class CallTreeModel(CallGraphModelBase): · 36 unmodified lines
885919 return CallTreeRootItem(self.glb, self.params)
886920
887921 def columnCount(self, parent=None):
888− return 7
922+ if self.params.have_ipc:
923+ return 12
924+ else:
925+ return 7
889926
890927 def columnHeader(self, column):
891− headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
928+ if self.params.have_ipc:
929+ headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Insn Cnt", "Insn Cnt (%)", "Cyc Cnt", "Cyc Cnt (%)", "IPC", "Branch Count ", "Branch Count (%) "]
930+ else:
931+ headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
892932 return headers[column]
893933
894934 def columnAlignment(self, column):
895− alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
935+ if self.params.have_ipc:
936+ alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
937+ else:
938+ alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
896939 return alignment[column]
897940
898941 def DoFindSelect(self, query, match):

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t