aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/call-graph-from-sql.py
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2018-10-01 02:28:43 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-10-23 13:23:52 -0400
commit70d831e85c1bdd87d193e85666bf3aa39aab7f21 (patch)
tree61d50f10351b3364e339d4f5a47098e8f79686b5 /tools/perf/scripts/python/call-graph-from-sql.py
parente99ef8141a6d97abaf47647cfd0034769144d080 (diff)
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>
Diffstat (limited to 'tools/perf/scripts/python/call-graph-from-sql.py')
-rw-r--r--tools/perf/scripts/python/call-graph-from-sql.py90
1 files changed, 61 insertions, 29 deletions
diff --git a/tools/perf/scripts/python/call-graph-from-sql.py b/tools/perf/scripts/python/call-graph-from-sql.py
index 65c18e351bc4..ada486048ad8 100644
--- a/tools/perf/scripts/python/call-graph-from-sql.py
+++ b/tools/perf/scripts/python/call-graph-from-sql.py
@@ -201,42 +201,47 @@ class TreeItem():
201 self.selectCalls() 201 self.selectCalls()
202 return self.child_count 202 return self.child_count
203 203
204 def columnCount(self): 204 def hasChildren(self):
205 return 7 205 if not self.query_done:
206 206 return True
207 def columnHeader(self, column): 207 return self.child_count > 0
208 headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
209 return headers[column]
210 208
211 def getData(self, column): 209 def getData(self, column):
212 return self.data[column] 210 return self.data[column]
213 211
212# Tree data model
213
214class TreeModel(QAbstractItemModel): 214class TreeModel(QAbstractItemModel):
215 215
216 def __init__(self, db, parent=None): 216 def __init__(self, root, parent=None):
217 super(TreeModel, self).__init__(parent) 217 super(TreeModel, self).__init__(parent)
218 self.db = db 218 self.root = root
219 self.root = TreeItem(db, 0, None) 219 self.last_row_read = 0
220 220
221 def columnCount(self, parent): 221 def Item(self, parent):
222 return self.root.columnCount()
223
224 def rowCount(self, parent):
225 if parent.isValid(): 222 if parent.isValid():
226 parent_item = parent.internalPointer() 223 return parent.internalPointer()
227 else: 224 else:
228 parent_item = self.root 225 return self.root
229 return parent_item.childCount() 226
227 def rowCount(self, parent):
228 result = self.Item(parent).childCount()
229 if result < 0:
230 result = 0
231 self.dataChanged.emit(parent, parent)
232 return result
233
234 def hasChildren(self, parent):
235 return self.Item(parent).hasChildren()
230 236
231 def headerData(self, section, orientation, role): 237 def headerData(self, section, orientation, role):
232 if role == Qt.TextAlignmentRole: 238 if role == Qt.TextAlignmentRole:
233 if section > 1: 239 return self.columnAlignment(section)
234 return Qt.AlignRight
235 if role != Qt.DisplayRole: 240 if role != Qt.DisplayRole:
236 return None 241 return None
237 if orientation != Qt.Horizontal: 242 if orientation != Qt.Horizontal:
238 return None 243 return None
239 return self.root.columnHeader(section) 244 return self.columnHeader(section)
240 245
241 def parent(self, child): 246 def parent(self, child):
242 child_item = child.internalPointer() 247 child_item = child.internalPointer()
@@ -246,21 +251,48 @@ class TreeModel(QAbstractItemModel):
246 return self.createIndex(parent_item.getRow(), 0, parent_item) 251 return self.createIndex(parent_item.getRow(), 0, parent_item)
247 252
248 def index(self, row, column, parent): 253 def index(self, row, column, parent):
249 if parent.isValid(): 254 child_item = self.Item(parent).getChildItem(row)
250 parent_item = parent.internalPointer()
251 else:
252 parent_item = self.root
253 child_item = parent_item.getChildItem(row)
254 return self.createIndex(row, column, child_item) 255 return self.createIndex(row, column, child_item)
255 256
257 def DisplayData(self, item, index):
258 return item.getData(index.column())
259
260 def columnAlignment(self, column):
261 return Qt.AlignLeft
262
263 def columnFont(self, column):
264 return None
265
256 def data(self, index, role): 266 def data(self, index, role):
257 if role == Qt.TextAlignmentRole: 267 if role == Qt.TextAlignmentRole:
258 if index.column() > 1: 268 return self.columnAlignment(index.column())
259 return Qt.AlignRight 269 if role == Qt.FontRole:
270 return self.columnFont(index.column())
260 if role != Qt.DisplayRole: 271 if role != Qt.DisplayRole:
261 return None 272 return None
262 index_item = index.internalPointer() 273 item = index.internalPointer()
263 return index_item.getData(index.column()) 274 return self.DisplayData(item, index)
275
276# Context-sensitive call graph data model
277
278class CallGraphModel(TreeModel):
279
280 def __init__(self, glb, parent=None):
281 super(CallGraphModel, self).__init__(TreeItem(glb.db, 0, None), parent)
282 self.glb = glb
283
284 def columnCount(self, parent=None):
285 return 7
286
287 def columnHeader(self, column):
288 headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
289 return headers[column]
290
291 def columnAlignment(self, column):
292 alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
293 return alignment[column]
294
295# Main window
264 296
265class MainWindow(QMainWindow): 297class MainWindow(QMainWindow):
266 298
@@ -275,7 +307,7 @@ class MainWindow(QMainWindow):
275 self.setWindowIcon(self.style().standardIcon(QStyle.SP_ComputerIcon)) 307 self.setWindowIcon(self.style().standardIcon(QStyle.SP_ComputerIcon))
276 self.setMinimumSize(200, 100) 308 self.setMinimumSize(200, 100)
277 309
278 self.model = TreeModel(glb.db) 310 self.model = CallGraphModel(glb)
279 311
280 self.view = QTreeView() 312 self.view = QTreeView()
281 self.view.setModel(self.model) 313 self.view.setModel(self.model)