perf scripts python: call-graph-from-sql.py: Factor out CallGraphModel from TreeModel
Factor out CallGraphModel from TreeModel, which paves the way to reuse TreeModel in future reports. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/20181001062853.28285-10-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
e99ef8141a
commit
70d831e85c
@@ -201,42 +201,47 @@ class TreeItem():
|
|||||||
self.selectCalls()
|
self.selectCalls()
|
||||||
return self.child_count
|
return self.child_count
|
||||||
|
|
||||||
def columnCount(self):
|
def hasChildren(self):
|
||||||
return 7
|
if not self.query_done:
|
||||||
|
return True
|
||||||
def columnHeader(self, column):
|
return self.child_count > 0
|
||||||
headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
|
|
||||||
return headers[column]
|
|
||||||
|
|
||||||
def getData(self, column):
|
def getData(self, column):
|
||||||
return self.data[column]
|
return self.data[column]
|
||||||
|
|
||||||
|
# Tree data model
|
||||||
|
|
||||||
class TreeModel(QAbstractItemModel):
|
class TreeModel(QAbstractItemModel):
|
||||||
|
|
||||||
def __init__(self, db, parent=None):
|
def __init__(self, root, parent=None):
|
||||||
super(TreeModel, self).__init__(parent)
|
super(TreeModel, self).__init__(parent)
|
||||||
self.db = db
|
self.root = root
|
||||||
self.root = TreeItem(db, 0, None)
|
self.last_row_read = 0
|
||||||
|
|
||||||
def columnCount(self, parent):
|
def Item(self, parent):
|
||||||
return self.root.columnCount()
|
if parent.isValid():
|
||||||
|
return parent.internalPointer()
|
||||||
|
else:
|
||||||
|
return self.root
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
if parent.isValid():
|
result = self.Item(parent).childCount()
|
||||||
parent_item = parent.internalPointer()
|
if result < 0:
|
||||||
else:
|
result = 0
|
||||||
parent_item = self.root
|
self.dataChanged.emit(parent, parent)
|
||||||
return parent_item.childCount()
|
return result
|
||||||
|
|
||||||
|
def hasChildren(self, parent):
|
||||||
|
return self.Item(parent).hasChildren()
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
if role == Qt.TextAlignmentRole:
|
if role == Qt.TextAlignmentRole:
|
||||||
if section > 1:
|
return self.columnAlignment(section)
|
||||||
return Qt.AlignRight
|
|
||||||
if role != Qt.DisplayRole:
|
if role != Qt.DisplayRole:
|
||||||
return None
|
return None
|
||||||
if orientation != Qt.Horizontal:
|
if orientation != Qt.Horizontal:
|
||||||
return None
|
return None
|
||||||
return self.root.columnHeader(section)
|
return self.columnHeader(section)
|
||||||
|
|
||||||
def parent(self, child):
|
def parent(self, child):
|
||||||
child_item = child.internalPointer()
|
child_item = child.internalPointer()
|
||||||
@@ -246,21 +251,48 @@ class TreeModel(QAbstractItemModel):
|
|||||||
return self.createIndex(parent_item.getRow(), 0, parent_item)
|
return self.createIndex(parent_item.getRow(), 0, parent_item)
|
||||||
|
|
||||||
def index(self, row, column, parent):
|
def index(self, row, column, parent):
|
||||||
if parent.isValid():
|
child_item = self.Item(parent).getChildItem(row)
|
||||||
parent_item = parent.internalPointer()
|
|
||||||
else:
|
|
||||||
parent_item = self.root
|
|
||||||
child_item = parent_item.getChildItem(row)
|
|
||||||
return self.createIndex(row, column, child_item)
|
return self.createIndex(row, column, child_item)
|
||||||
|
|
||||||
|
def DisplayData(self, item, index):
|
||||||
|
return item.getData(index.column())
|
||||||
|
|
||||||
|
def columnAlignment(self, column):
|
||||||
|
return Qt.AlignLeft
|
||||||
|
|
||||||
|
def columnFont(self, column):
|
||||||
|
return None
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.TextAlignmentRole:
|
if role == Qt.TextAlignmentRole:
|
||||||
if index.column() > 1:
|
return self.columnAlignment(index.column())
|
||||||
return Qt.AlignRight
|
if role == Qt.FontRole:
|
||||||
|
return self.columnFont(index.column())
|
||||||
if role != Qt.DisplayRole:
|
if role != Qt.DisplayRole:
|
||||||
return None
|
return None
|
||||||
index_item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
return index_item.getData(index.column())
|
return self.DisplayData(item, index)
|
||||||
|
|
||||||
|
# Context-sensitive call graph data model
|
||||||
|
|
||||||
|
class CallGraphModel(TreeModel):
|
||||||
|
|
||||||
|
def __init__(self, glb, parent=None):
|
||||||
|
super(CallGraphModel, self).__init__(TreeItem(glb.db, 0, None), parent)
|
||||||
|
self.glb = glb
|
||||||
|
|
||||||
|
def columnCount(self, parent=None):
|
||||||
|
return 7
|
||||||
|
|
||||||
|
def columnHeader(self, column):
|
||||||
|
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 ]
|
||||||
|
return alignment[column]
|
||||||
|
|
||||||
|
# Main window
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
@@ -275,7 +307,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.setWindowIcon(self.style().standardIcon(QStyle.SP_ComputerIcon))
|
self.setWindowIcon(self.style().standardIcon(QStyle.SP_ComputerIcon))
|
||||||
self.setMinimumSize(200, 100)
|
self.setMinimumSize(200, 100)
|
||||||
|
|
||||||
self.model = TreeModel(glb.db)
|
self.model = CallGraphModel(glb)
|
||||||
|
|
||||||
self.view = QTreeView()
|
self.view = QTreeView()
|
||||||
self.view.setModel(self.model)
|
self.view.setModel(self.model)
|
||||||
|
|||||||
Reference in New Issue
Block a user