72 self.
data = [
"",
"",
"",
"",
"",
"",
""]
83 query = QSqlQuery(self.
db)
84 ret = query.exec_(
'SELECT id, comm FROM comms')
86 raise Exception(
"Query failed: " + query.lastError().text())
88 if not query.value(0):
93 child_item.setUpLevel1(query.value(0), query.value(1))
101 query = QSqlQuery(self.
db)
102 ret = query.exec_(
'SELECT thread_id, ( SELECT pid FROM threads WHERE id = thread_id ), ( SELECT tid FROM threads WHERE id = thread_id ) FROM comm_threads WHERE comm_id = ' +
str(comm_id))
104 raise Exception(
"Query failed: " + query.lastError().text())
109 child_item.setUpLevel2(comm_id, query.value(0), query.value(1), query.value(2))
128 x = (b * Decimal(100)) / self.
time 129 return str(x.quantize(Decimal(
'.1'), rounding=ROUND_HALF_UP))
135 return str(x.quantize(Decimal(
'.1'), rounding=ROUND_HALF_UP))
137 def addChild(self, call_path_id, name, dso, count, time, branch_count):
139 child_item.comm_id = self.
comm_id 141 child_item.call_path_id = call_path_id
142 child_item.branch_count = branch_count
143 child_item.time = time
144 child_item.data[0] = name
145 if dso ==
"[kernel.kallsyms]":
147 child_item.data[1] = dso
148 child_item.data[2] =
str(count)
149 child_item.data[3] =
str(time)
151 child_item.data[5] =
str(branch_count)
158 query = QSqlQuery(self.
db)
159 ret = query.exec_(
'SELECT id, call_path_id, branch_count, call_time, return_time, ' 160 '( SELECT name FROM symbols WHERE id = ( SELECT symbol_id FROM call_paths WHERE id = call_path_id ) ), ' 161 '( SELECT short_name FROM dsos WHERE id = ( SELECT dso_id FROM symbols WHERE id = ( SELECT symbol_id FROM call_paths WHERE id = call_path_id ) ) ), ' 162 '( SELECT ip FROM call_paths where id = call_path_id ) ' 164 ' ORDER BY call_path_id')
166 raise Exception(
"Query failed: " + query.lastError().text())
167 last_call_path_id = 0
172 total_branch_count = 0
176 if query.value(1) == last_call_path_id:
178 branch_count += query.value(2)
179 time += query.value(4) - query.value(3)
182 self.
addChild(last_call_path_id, name, dso, count, time, branch_count)
183 last_call_path_id = query.value(1)
184 name = query.value(5)
187 total_branch_count += branch_count
189 branch_count = query.value(2)
190 time = query.value(4) - query.value(3)
192 self.
addChild(last_call_path_id, name, dso, count, time, branch_count)
193 total_branch_count += branch_count
200 child_item.data[6] = self.
branchPercent(child_item.branch_count)
201 if total_time > self.
time:
202 self.
time = total_time
205 child_item.data[4] = self.
timePercent(child_item.time)
216 headers = [
"Call Path",
"Object",
"Count ",
"Time (ns) ",
"Time (%) ",
"Branch Count ",
"Branch Count (%) "]
217 return headers[column]
220 return self.
data[column]
225 super(TreeModel, self).
__init__(parent)
234 parent_item = parent.internalPointer()
236 parent_item = self.
root 237 return parent_item.childCount()
240 if role == Qt.TextAlignmentRole:
243 if role != Qt.DisplayRole:
245 if orientation != Qt.Horizontal:
247 return self.
root.columnHeader(section)
250 child_item = child.internalPointer()
251 if child_item
is self.
root:
253 parent_item = child_item.getParentItem()
254 return self.createIndex(parent_item.getRow(), 0, parent_item)
256 def index(self, row, column, parent):
258 parent_item = parent.internalPointer()
260 parent_item = self.
root 261 child_item = parent_item.getChildItem(row)
262 return self.createIndex(row, column, child_item)
265 if role == Qt.TextAlignmentRole:
266 if index.column() > 1:
268 if role != Qt.DisplayRole:
270 index_item = index.internalPointer()
271 return index_item.getData(index.column())
276 super(MainWindow, self).
__init__(parent)
278 self.setObjectName(
"MainWindow")
279 self.setWindowTitle(
"Call Graph: " + dbname)
281 self.resize(800, 600)
283 icon = style.standardIcon(QStyle.SP_MessageBoxInformation)
284 self.setWindowIcon(icon);
291 self.setCentralWidget(self.
view)
293 if __name__ ==
'__main__':
294 if (len(sys.argv) < 2):
295 print >> sys.stderr,
"Usage is: call-graph-from-sql.py <database name>" 296 raise Exception(
"Too few arguments")
303 if f.read(15) ==
"SQLite format 3":
310 db = QSqlDatabase.addDatabase(
'QSQLITE')
312 db = QSqlDatabase.addDatabase(
'QPSQL')
313 opts = dbname.split()
317 if opt[0] ==
'hostname':
318 db.setHostName(opt[1])
319 elif opt[0] ==
'port':
320 db.setPort(int(opt[1]))
321 elif opt[0] ==
'username':
322 db.setUserName(opt[1])
323 elif opt[0] ==
'password':
324 db.setPassword(opt[1])
325 elif opt[0] ==
'dbname':
330 db.setDatabaseName(dbname)
332 raise Exception(
"Failed to open database " + dbname +
" error: " + db.lastError().text())
334 app = QApplication(sys.argv)
def branchPercent(self, b)
def setUpLevel1(self, comm_id, comm)
def __init__(self, db, dbname, parent=None)
def getData(self, column)
def __init__(self, db, parent=None)
def addChild(self, call_path_id, name, dso, count, time, branch_count)
def columnHeader(self, column)
def setUpLevel2(self, comm_id, thread_id, pid, tid)
static int str(yyscan_t scanner, int token)
def columnCount(self, parent)
def getChildItem(self, row)
def data(self, index, role)
def index(self, row, column, parent)
def __init__(self, db, row, parent_item)
def rowCount(self, parent)
def headerData(self, section, orientation, role)