]> Git Repo - linux.git/blobdiff - tools/perf/scripts/python/exported-sql-viewer.py
Merge tag 'driver-core-5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / tools / perf / scripts / python / exported-sql-viewer.py
index a607235c8cd9cd2f1c061afec0bebcca06b7abca..6e7934f2ac9a31549cddfd1a669e6cc7f61b613e 100755 (executable)
@@ -200,9 +200,10 @@ class Thread(QThread):
 
 class TreeModel(QAbstractItemModel):
 
-       def __init__(self, glb, parent=None):
+       def __init__(self, glb, params, parent=None):
                super(TreeModel, self).__init__(parent)
                self.glb = glb
+               self.params = params
                self.root = self.GetRoot()
                self.last_row_read = 0
 
@@ -399,6 +400,7 @@ class FindBar():
 
        def Activate(self):
                self.bar.show()
+               self.textbox.lineEdit().selectAll()
                self.textbox.setFocus()
 
        def Deactivate(self):
@@ -463,8 +465,9 @@ class FindBar():
 
 class CallGraphLevelItemBase(object):
 
-       def __init__(self, glb, row, parent_item):
+       def __init__(self, glb, params, row, parent_item):
                self.glb = glb
+               self.params = params
                self.row = row
                self.parent_item = parent_item
                self.query_done = False;
@@ -503,18 +506,24 @@ class CallGraphLevelItemBase(object):
 
 class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, call_path_id, time, branch_count, parent_item):
-               super(CallGraphLevelTwoPlusItemBase, self).__init__(glb, row, parent_item)
+       def __init__(self, glb, params, row, comm_id, thread_id, call_path_id, time, insn_cnt, cyc_cnt, branch_count, parent_item):
+               super(CallGraphLevelTwoPlusItemBase, self).__init__(glb, params, row, parent_item)
                self.comm_id = comm_id
                self.thread_id = thread_id
                self.call_path_id = call_path_id
+               self.insn_cnt = insn_cnt
+               self.cyc_cnt = cyc_cnt
                self.branch_count = branch_count
                self.time = time
 
        def Select(self):
                self.query_done = True;
                query = QSqlQuery(self.glb.db)
-               QueryExec(query, "SELECT call_path_id, name, short_name, COUNT(calls.id), SUM(return_time - call_time), SUM(branch_count)"
+               if self.params.have_ipc:
+                       ipc_str = ", SUM(insn_count), SUM(cyc_count)"
+               else:
+                       ipc_str = ""
+               QueryExec(query, "SELECT call_path_id, name, short_name, COUNT(calls.id), SUM(return_time - call_time)" + ipc_str + ", SUM(branch_count)"
                                        " FROM calls"
                                        " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
                                        " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
@@ -525,7 +534,15 @@ class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase):
                                        " GROUP BY call_path_id, name, short_name"
                                        " ORDER BY call_path_id")
                while query.next():
-                       child_item = CallGraphLevelThreeItem(self.glb, 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)
+                       if self.params.have_ipc:
+                               insn_cnt = int(query.value(5))
+                               cyc_cnt = int(query.value(6))
+                               branch_count = int(query.value(7))
+                       else:
+                               insn_cnt = 0
+                               cyc_cnt = 0
+                               branch_count = int(query.value(5))
+                       child_item = CallGraphLevelThreeItem(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)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
@@ -533,37 +550,57 @@ class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
 class CallGraphLevelThreeItem(CallGraphLevelTwoPlusItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, call_path_id, name, dso, count, time, branch_count, parent_item):
-               super(CallGraphLevelThreeItem, self).__init__(glb, row, comm_id, thread_id, call_path_id, time, branch_count, parent_item)
+       def __init__(self, glb, params, row, comm_id, thread_id, call_path_id, name, dso, count, time, insn_cnt, cyc_cnt, branch_count, parent_item):
+               super(CallGraphLevelThreeItem, self).__init__(glb, params, row, comm_id, thread_id, call_path_id, time, insn_cnt, cyc_cnt, branch_count, parent_item)
                dso = dsoname(dso)
-               self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
+               if self.params.have_ipc:
+                       insn_pcnt = PercentToOneDP(insn_cnt, parent_item.insn_cnt)
+                       cyc_pcnt = PercentToOneDP(cyc_cnt, parent_item.cyc_cnt)
+                       br_pcnt = PercentToOneDP(branch_count, parent_item.branch_count)
+                       ipc = CalcIPC(cyc_cnt, insn_cnt)
+                       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 ]
+               else:
+                       self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
                self.dbid = call_path_id
 
 # Context-sensitive call graph data model level two item
 
 class CallGraphLevelTwoItem(CallGraphLevelTwoPlusItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, pid, tid, parent_item):
-               super(CallGraphLevelTwoItem, self).__init__(glb, row, comm_id, thread_id, 1, 0, 0, parent_item)
-               self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
+       def __init__(self, glb, params, row, comm_id, thread_id, pid, tid, parent_item):
+               super(CallGraphLevelTwoItem, self).__init__(glb, params, row, comm_id, thread_id, 1, 0, 0, 0, 0, parent_item)
+               if self.params.have_ipc:
+                       self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", "", "", "", "", "", ""]
+               else:
+                       self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
                self.dbid = thread_id
 
        def Select(self):
                super(CallGraphLevelTwoItem, self).Select()
                for child_item in self.child_items:
                        self.time += child_item.time
+                       self.insn_cnt += child_item.insn_cnt
+                       self.cyc_cnt += child_item.cyc_cnt
                        self.branch_count += child_item.branch_count
                for child_item in self.child_items:
                        child_item.data[4] = PercentToOneDP(child_item.time, self.time)
-                       child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
+                       if self.params.have_ipc:
+                               child_item.data[6] = PercentToOneDP(child_item.insn_cnt, self.insn_cnt)
+                               child_item.data[8] = PercentToOneDP(child_item.cyc_cnt, self.cyc_cnt)
+                               child_item.data[11] = PercentToOneDP(child_item.branch_count, self.branch_count)
+                       else:
+                               child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
 
 # Context-sensitive call graph data model level one item
 
 class CallGraphLevelOneItem(CallGraphLevelItemBase):
 
-       def __init__(self, glb, row, comm_id, comm, parent_item):
-               super(CallGraphLevelOneItem, self).__init__(glb, row, parent_item)
-               self.data = [comm, "", "", "", "", "", ""]
+       def __init__(self, glb, params, row, comm_id, comm, parent_item):
+               super(CallGraphLevelOneItem, self).__init__(glb, params, row, parent_item)
+               if self.params.have_ipc:
+                       self.data = [comm, "", "", "", "", "", "", "", "", "", "", ""]
+               else:
+                       self.data = [comm, "", "", "", "", "", ""]
                self.dbid = comm_id
 
        def Select(self):
@@ -574,7 +611,7 @@ class CallGraphLevelOneItem(CallGraphLevelItemBase):
                                        " INNER JOIN threads ON thread_id = threads.id"
                                        " WHERE comm_id = " + str(self.dbid))
                while query.next():
-                       child_item = CallGraphLevelTwoItem(self.glb, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self)
+                       child_item = CallGraphLevelTwoItem(self.glb, self.params, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
@@ -582,8 +619,8 @@ class CallGraphLevelOneItem(CallGraphLevelItemBase):
 
 class CallGraphRootItem(CallGraphLevelItemBase):
 
-       def __init__(self, glb):
-               super(CallGraphRootItem, self).__init__(glb, 0, None)
+       def __init__(self, glb, params):
+               super(CallGraphRootItem, self).__init__(glb, params, 0, None)
                self.dbid = 0
                self.query_done = True;
                query = QSqlQuery(glb.db)
@@ -591,16 +628,23 @@ class CallGraphRootItem(CallGraphLevelItemBase):
                while query.next():
                        if not query.value(0):
                                continue
-                       child_item = CallGraphLevelOneItem(glb, self.child_count, query.value(0), query.value(1), self)
+                       child_item = CallGraphLevelOneItem(glb, params, self.child_count, query.value(0), query.value(1), self)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
+# Call graph model parameters
+
+class CallGraphModelParams():
+
+       def __init__(self, glb, parent=None):
+               self.have_ipc = IsSelectable(glb.db, "calls", columns = "insn_count, cyc_count")
+
 # Context-sensitive call graph data model base
 
 class CallGraphModelBase(TreeModel):
 
        def __init__(self, glb, parent=None):
-               super(CallGraphModelBase, self).__init__(glb, parent)
+               super(CallGraphModelBase, self).__init__(glb, CallGraphModelParams(glb), parent)
 
        def FindSelect(self, value, pattern, query):
                if pattern:
@@ -682,17 +726,26 @@ class CallGraphModel(CallGraphModelBase):
                super(CallGraphModel, self).__init__(glb, parent)
 
        def GetRoot(self):
-               return CallGraphRootItem(self.glb)
+               return CallGraphRootItem(self.glb, self.params)
 
        def columnCount(self, parent=None):
-               return 7
+               if self.params.have_ipc:
+                       return 12
+               else:
+                       return 7
 
        def columnHeader(self, column):
-               headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
+               if self.params.have_ipc:
+                       headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Insn Cnt", "Insn Cnt (%)", "Cyc Cnt", "Cyc Cnt (%)", "IPC", "Branch Count ", "Branch Count (%) "]
+               else:
+                       headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
                return headers[column]
 
        def columnAlignment(self, column):
-               alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
+               if self.params.have_ipc:
+                       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 ]
+               else:
+                       alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
                return alignment[column]
 
        def DoFindSelect(self, query, match):
@@ -729,11 +782,13 @@ class CallGraphModel(CallGraphModelBase):
 
 class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, calls_id, time, branch_count, parent_item):
-               super(CallTreeLevelTwoPlusItemBase, self).__init__(glb, row, parent_item)
+       def __init__(self, glb, params, row, comm_id, thread_id, calls_id, time, insn_cnt, cyc_cnt, branch_count, parent_item):
+               super(CallTreeLevelTwoPlusItemBase, self).__init__(glb, params, row, parent_item)
                self.comm_id = comm_id
                self.thread_id = thread_id
                self.calls_id = calls_id
+               self.insn_cnt = insn_cnt
+               self.cyc_cnt = cyc_cnt
                self.branch_count = branch_count
                self.time = time
 
@@ -743,8 +798,12 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
                        comm_thread = " AND comm_id = " + str(self.comm_id) + " AND thread_id = " + str(self.thread_id)
                else:
                        comm_thread = ""
+               if self.params.have_ipc:
+                       ipc_str = ", insn_count, cyc_count"
+               else:
+                       ipc_str = ""
                query = QSqlQuery(self.glb.db)
-               QueryExec(query, "SELECT calls.id, name, short_name, call_time, return_time - call_time, branch_count"
+               QueryExec(query, "SELECT calls.id, name, short_name, call_time, return_time - call_time" + ipc_str + ", branch_count"
                                        " FROM calls"
                                        " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
                                        " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
@@ -752,7 +811,15 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
                                        " WHERE calls.parent_id = " + str(self.calls_id) + comm_thread +
                                        " ORDER BY call_time, calls.id")
                while query.next():
-                       child_item = CallTreeLevelThreeItem(self.glb, 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)
+                       if self.params.have_ipc:
+                               insn_cnt = int(query.value(5))
+                               cyc_cnt = int(query.value(6))
+                               branch_count = int(query.value(7))
+                       else:
+                               insn_cnt = 0
+                               cyc_cnt = 0
+                               branch_count = int(query.value(5))
+                       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)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
@@ -760,37 +827,57 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
 class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, calls_id, name, dso, count, time, branch_count, parent_item):
-               super(CallTreeLevelThreeItem, self).__init__(glb, row, comm_id, thread_id, calls_id, time, branch_count, parent_item)
+       def __init__(self, glb, params, row, comm_id, thread_id, calls_id, name, dso, count, time, insn_cnt, cyc_cnt, branch_count, parent_item):
+               super(CallTreeLevelThreeItem, self).__init__(glb, params, row, comm_id, thread_id, calls_id, time, insn_cnt, cyc_cnt, branch_count, parent_item)
                dso = dsoname(dso)
-               self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
+               if self.params.have_ipc:
+                       insn_pcnt = PercentToOneDP(insn_cnt, parent_item.insn_cnt)
+                       cyc_pcnt = PercentToOneDP(cyc_cnt, parent_item.cyc_cnt)
+                       br_pcnt = PercentToOneDP(branch_count, parent_item.branch_count)
+                       ipc = CalcIPC(cyc_cnt, insn_cnt)
+                       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 ]
+               else:
+                       self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
                self.dbid = calls_id
 
 # Call tree data model level two item
 
 class CallTreeLevelTwoItem(CallTreeLevelTwoPlusItemBase):
 
-       def __init__(self, glb, row, comm_id, thread_id, pid, tid, parent_item):
-               super(CallTreeLevelTwoItem, self).__init__(glb, row, comm_id, thread_id, 0, 0, 0, parent_item)
-               self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
+       def __init__(self, glb, params, row, comm_id, thread_id, pid, tid, parent_item):
+               super(CallTreeLevelTwoItem, self).__init__(glb, params, row, comm_id, thread_id, 0, 0, 0, 0, 0, parent_item)
+               if self.params.have_ipc:
+                       self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", "", "", "", "", "", ""]
+               else:
+                       self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
                self.dbid = thread_id
 
        def Select(self):
                super(CallTreeLevelTwoItem, self).Select()
                for child_item in self.child_items:
                        self.time += child_item.time
+                       self.insn_cnt += child_item.insn_cnt
+                       self.cyc_cnt += child_item.cyc_cnt
                        self.branch_count += child_item.branch_count
                for child_item in self.child_items:
                        child_item.data[4] = PercentToOneDP(child_item.time, self.time)
-                       child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
+                       if self.params.have_ipc:
+                               child_item.data[6] = PercentToOneDP(child_item.insn_cnt, self.insn_cnt)
+                               child_item.data[8] = PercentToOneDP(child_item.cyc_cnt, self.cyc_cnt)
+                               child_item.data[11] = PercentToOneDP(child_item.branch_count, self.branch_count)
+                       else:
+                               child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
 
 # Call tree data model level one item
 
 class CallTreeLevelOneItem(CallGraphLevelItemBase):
 
-       def __init__(self, glb, row, comm_id, comm, parent_item):
-               super(CallTreeLevelOneItem, self).__init__(glb, row, parent_item)
-               self.data = [comm, "", "", "", "", "", ""]
+       def __init__(self, glb, params, row, comm_id, comm, parent_item):
+               super(CallTreeLevelOneItem, self).__init__(glb, params, row, parent_item)
+               if self.params.have_ipc:
+                       self.data = [comm, "", "", "", "", "", "", "", "", "", "", ""]
+               else:
+                       self.data = [comm, "", "", "", "", "", ""]
                self.dbid = comm_id
 
        def Select(self):
@@ -801,7 +888,7 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase):
                                        " INNER JOIN threads ON thread_id = threads.id"
                                        " WHERE comm_id = " + str(self.dbid))
                while query.next():
-                       child_item = CallTreeLevelTwoItem(self.glb, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self)
+                       child_item = CallTreeLevelTwoItem(self.glb, self.params, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
@@ -809,8 +896,8 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase):
 
 class CallTreeRootItem(CallGraphLevelItemBase):
 
-       def __init__(self, glb):
-               super(CallTreeRootItem, self).__init__(glb, 0, None)
+       def __init__(self, glb, params):
+               super(CallTreeRootItem, self).__init__(glb, params, 0, None)
                self.dbid = 0
                self.query_done = True;
                query = QSqlQuery(glb.db)
@@ -818,7 +905,7 @@ class CallTreeRootItem(CallGraphLevelItemBase):
                while query.next():
                        if not query.value(0):
                                continue
-                       child_item = CallTreeLevelOneItem(glb, self.child_count, query.value(0), query.value(1), self)
+                       child_item = CallTreeLevelOneItem(glb, params, self.child_count, query.value(0), query.value(1), self)
                        self.child_items.append(child_item)
                        self.child_count += 1
 
@@ -830,17 +917,26 @@ class CallTreeModel(CallGraphModelBase):
                super(CallTreeModel, self).__init__(glb, parent)
 
        def GetRoot(self):
-               return CallTreeRootItem(self.glb)
+               return CallTreeRootItem(self.glb, self.params)
 
        def columnCount(self, parent=None):
-               return 7
+               if self.params.have_ipc:
+                       return 12
+               else:
+                       return 7
 
        def columnHeader(self, column):
-               headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
+               if self.params.have_ipc:
+                       headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Insn Cnt", "Insn Cnt (%)", "Cyc Cnt", "Cyc Cnt (%)", "IPC", "Branch Count ", "Branch Count (%) "]
+               else:
+                       headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
                return headers[column]
 
        def columnAlignment(self, column):
-               alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
+               if self.params.have_ipc:
+                       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 ]
+               else:
+                       alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
                return alignment[column]
 
        def DoFindSelect(self, query, match):
@@ -1606,7 +1702,7 @@ class BranchModel(TreeModel):
        progress = Signal(object)
 
        def __init__(self, glb, event_id, where_clause, parent=None):
-               super(BranchModel, self).__init__(glb, parent)
+               super(BranchModel, self).__init__(glb, None, parent)
                self.event_id = event_id
                self.more = True
                self.populated = 0
This page took 0.047818 seconds and 4 git commands to generate.