History

perf scripts python: exported-sql-viewer.py: Factor out CallGraphModelBase

Factor out a base class CallGraphModelBase from CallGraphModel, so that CallGraphModelBase can be reused.

Adrian Hunter committed 7 years ago

Commit 254c0d81 parent a448ba21 file · +55 −45Browse 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+55−45
@@ -558,26 +558,12 @@ class CallGraphRootItem(CallGraphLevelItemBase): · 557 unmodified lines
558558 self.child_items.append(child_item)
559559 self.child_count += 1
560560
561−# Context-sensitive call graph data model
561+# Context-sensitive call graph data model base
562562
563−class CallGraphModel(TreeModel):
563+class CallGraphModelBase(TreeModel):
564564
565565 def __init__(self, glb, parent=None):
566− super(CallGraphModel, self).__init__(glb, parent)
567−
568− def GetRoot(self):
569− return CallGraphRootItem(self.glb)
570−
571− def columnCount(self, parent=None):
572− return 7
573−
574− def columnHeader(self, column):
575− headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
576− return headers[column]
577−
578− def columnAlignment(self, column):
579− alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
580− return alignment[column]
566+ super(CallGraphModelBase, self).__init__(glb, parent)
581567
582568 def FindSelect(self, value, pattern, query):
583569 if pattern:
@@ -597,34 +583,7 @@ class CallGraphModel(TreeModel): · 13 unmodified lines
597583 match = " GLOB '" + str(value) + "'"
598584 else:
599585 match = " = '" + str(value) + "'"
600− QueryExec(query, "SELECT call_path_id, comm_id, thread_id"
601− " FROM calls"
602− " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
603− " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
604− " WHERE symbols.name" + match +
605− " GROUP BY comm_id, thread_id, call_path_id"
606− " ORDER BY comm_id, thread_id, call_path_id")
607−
608− def FindPath(self, query):
609− # Turn the query result into a list of ids that the tree view can walk
610− # to open the tree at the right place.
611− ids = []
612− parent_id = query.value(0)
613− while parent_id:
614− ids.insert(0, parent_id)
615− q2 = QSqlQuery(self.glb.db)
616− QueryExec(q2, "SELECT parent_id"
617− " FROM call_paths"
618− " WHERE id = " + str(parent_id))
619− if not q2.next():
620− break
621− parent_id = q2.value(0)
622− # The call path root is not used
623− if ids[0] == 1:
624− del ids[0]
625− ids.insert(0, query.value(2))
626− ids.insert(0, query.value(1))
627− return ids
586+ self.DoFindSelect(query, match)
628587
629588 def Found(self, query, found):
630589 if found:
@@ -678,6 +637,57 @@ class CallGraphModel(TreeModel): · 47 unmodified lines
678637 def FindDone(self, thread, callback, ids):
679638 callback(ids)
680639
640+# Context-sensitive call graph data model
641+
642+class CallGraphModel(CallGraphModelBase):
643+
644+ def __init__(self, glb, parent=None):
645+ super(CallGraphModel, self).__init__(glb, parent)
646+
647+ def GetRoot(self):
648+ return CallGraphRootItem(self.glb)
649+
650+ def columnCount(self, parent=None):
651+ return 7
652+
653+ def columnHeader(self, column):
654+ headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
655+ return headers[column]
656+
657+ def columnAlignment(self, column):
658+ alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
659+ return alignment[column]
660+
661+ def DoFindSelect(self, query, match):
662+ QueryExec(query, "SELECT call_path_id, comm_id, thread_id"
663+ " FROM calls"
664+ " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
665+ " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
666+ " WHERE symbols.name" + match +
667+ " GROUP BY comm_id, thread_id, call_path_id"
668+ " ORDER BY comm_id, thread_id, call_path_id")
669+
670+ def FindPath(self, query):
671+ # Turn the query result into a list of ids that the tree view can walk
672+ # to open the tree at the right place.
673+ ids = []
674+ parent_id = query.value(0)
675+ while parent_id:
676+ ids.insert(0, parent_id)
677+ q2 = QSqlQuery(self.glb.db)
678+ QueryExec(q2, "SELECT parent_id"
679+ " FROM call_paths"
680+ " WHERE id = " + str(parent_id))
681+ if not q2.next():
682+ break
683+ parent_id = q2.value(0)
684+ # The call path root is not used
685+ if ids[0] == 1:
686+ del ids[0]
687+ ids.insert(0, query.value(2))
688+ ids.insert(0, query.value(1))
689+ return ids
690+
681691 # Vertical widget layout
682692
683693 class VBox():