2 # SPDX-License-Identifier: GPL-2.0
3 # exported-sql-viewer.py: view data from sql database
4 # Copyright (c) 2014-2018, Intel Corporation.
6 # To use this script you will need to have exported data using either the
7 # export-to-sqlite.py or the export-to-postgresql.py script. Refer to those
10 # Following on from the example in the export scripts, a
11 # call-graph can be displayed for the pt_example database like this:
13 # python tools/perf/scripts/python/exported-sql-viewer.py pt_example
15 # Note that for PostgreSQL, this script supports connecting to remote databases
16 # by setting hostname, port, username, password, and dbname e.g.
18 # python tools/perf/scripts/python/exported-sql-viewer.py "hostname=myhost username=myuser password=mypassword dbname=pt_example"
20 # The result is a GUI window with a tree representing a context-sensitive
21 # call-graph. Expanding a couple of levels of the tree and adjusting column
22 # widths to suit will display something like:
24 # Call Graph: pt_example
25 # Call Path Object Count Time(ns) Time(%) Branch Count Branch Count(%)
28 # v- _start ld-2.19.so 1 10074071 100.0 211135 100.0
29 # |- unknown unknown 1 13198 0.1 1 0.0
30 # >- _dl_start ld-2.19.so 1 1400980 13.9 19637 9.3
31 # >- _d_linit_internal ld-2.19.so 1 448152 4.4 11094 5.3
32 # v-__libc_start_main@plt ls 1 8211741 81.5 180397 85.4
33 # >- _dl_fixup ld-2.19.so 1 7607 0.1 108 0.1
34 # >- __cxa_atexit libc-2.19.so 1 11737 0.1 10 0.0
35 # >- __libc_csu_init ls 1 10354 0.1 10 0.0
36 # |- _setjmp libc-2.19.so 1 0 0.0 4 0.0
37 # v- main ls 1 8182043 99.6 180254 99.9
40 # The top level is a command name (comm)
41 # The next level is a thread (pid:tid)
42 # Subsequent levels are functions
43 # 'Count' is the number of calls
44 # 'Time' is the elapsed time until the function returns
45 # Percentages are relative to the level above
46 # 'Branch Count' is the total number of branches for that function and all
47 # functions that it calls
53 from PySide.QtCore import *
54 from PySide.QtGui import *
55 from PySide.QtSql import *
58 # Data formatting helpers
61 if name == "[kernel.kallsyms]":
65 # Percent to one decimal place
67 def PercentToOneDP(n, d):
70 x = (n * Decimal(100)) / d
71 return str(x.quantize(Decimal(".1"), rounding=ROUND_HALF_UP))
73 # Helper for queries that must not fail
75 def QueryExec(query, stmt):
76 ret = query.exec_(stmt)
78 raise Exception("Query failed: " + query.lastError().text())
82 class Thread(QThread):
86 def __init__(self, task, param=None, parent=None):
87 super(Thread, self).__init__(parent)
93 if self.param is None:
94 done, result = self.task()
96 done, result = self.task(self.param)
97 self.done.emit(result)
103 class TreeModel(QAbstractItemModel):
105 def __init__(self, root, parent=None):
106 super(TreeModel, self).__init__(parent)
108 self.last_row_read = 0
110 def Item(self, parent):
112 return parent.internalPointer()
116 def rowCount(self, parent):
117 result = self.Item(parent).childCount()
120 self.dataChanged.emit(parent, parent)
123 def hasChildren(self, parent):
124 return self.Item(parent).hasChildren()
126 def headerData(self, section, orientation, role):
127 if role == Qt.TextAlignmentRole:
128 return self.columnAlignment(section)
129 if role != Qt.DisplayRole:
131 if orientation != Qt.Horizontal:
133 return self.columnHeader(section)
135 def parent(self, child):
136 child_item = child.internalPointer()
137 if child_item is self.root:
139 parent_item = child_item.getParentItem()
140 return self.createIndex(parent_item.getRow(), 0, parent_item)
142 def index(self, row, column, parent):
143 child_item = self.Item(parent).getChildItem(row)
144 return self.createIndex(row, column, child_item)
146 def DisplayData(self, item, index):
147 return item.getData(index.column())
149 def columnAlignment(self, column):
152 def columnFont(self, column):
155 def data(self, index, role):
156 if role == Qt.TextAlignmentRole:
157 return self.columnAlignment(index.column())
158 if role == Qt.FontRole:
159 return self.columnFont(index.column())
160 if role != Qt.DisplayRole:
162 item = index.internalPointer()
163 return self.DisplayData(item, index)
167 model_cache = weakref.WeakValueDictionary()
168 model_cache_lock = threading.Lock()
170 def LookupCreateModel(model_name, create_fn):
171 model_cache_lock.acquire()
173 model = model_cache[model_name]
178 model_cache[model_name] = model
179 model_cache_lock.release()
186 def __init__(self, parent, finder, is_reg_expr=False):
189 self.last_value = None
190 self.last_pattern = None
192 label = QLabel("Find:")
193 label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
195 self.textbox = QComboBox()
196 self.textbox.setEditable(True)
197 self.textbox.currentIndexChanged.connect(self.ValueChanged)
199 self.progress = QProgressBar()
200 self.progress.setRange(0, 0)
204 self.pattern = QCheckBox("Regular Expression")
206 self.pattern = QCheckBox("Pattern")
207 self.pattern.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
209 self.next_button = QToolButton()
210 self.next_button.setIcon(parent.style().standardIcon(QStyle.SP_ArrowDown))
211 self.next_button.released.connect(lambda: self.NextPrev(1))
213 self.prev_button = QToolButton()
214 self.prev_button.setIcon(parent.style().standardIcon(QStyle.SP_ArrowUp))
215 self.prev_button.released.connect(lambda: self.NextPrev(-1))
217 self.close_button = QToolButton()
218 self.close_button.setIcon(parent.style().standardIcon(QStyle.SP_DockWidgetCloseButton))
219 self.close_button.released.connect(self.Deactivate)
221 self.hbox = QHBoxLayout()
222 self.hbox.setContentsMargins(0, 0, 0, 0)
224 self.hbox.addWidget(label)
225 self.hbox.addWidget(self.textbox)
226 self.hbox.addWidget(self.progress)
227 self.hbox.addWidget(self.pattern)
228 self.hbox.addWidget(self.next_button)
229 self.hbox.addWidget(self.prev_button)
230 self.hbox.addWidget(self.close_button)
233 self.bar.setLayout(self.hbox);
241 self.textbox.setFocus()
243 def Deactivate(self):
247 self.textbox.setEnabled(False)
249 self.next_button.hide()
250 self.prev_button.hide()
254 self.textbox.setEnabled(True)
257 self.next_button.show()
258 self.prev_button.show()
260 def Find(self, direction):
261 value = self.textbox.currentText()
262 pattern = self.pattern.isChecked()
263 self.last_value = value
264 self.last_pattern = pattern
265 self.finder.Find(value, direction, pattern, self.context)
267 def ValueChanged(self):
268 value = self.textbox.currentText()
269 pattern = self.pattern.isChecked()
270 index = self.textbox.currentIndex()
271 data = self.textbox.itemData(index)
272 # Store the pattern in the combo box to keep it with the text value
274 self.textbox.setItemData(index, pattern)
276 self.pattern.setChecked(data)
279 def NextPrev(self, direction):
280 value = self.textbox.currentText()
281 pattern = self.pattern.isChecked()
282 if value != self.last_value:
283 index = self.textbox.findText(value)
284 # Allow for a button press before the value has been added to the combo box
286 index = self.textbox.count()
287 self.textbox.addItem(value, pattern)
288 self.textbox.setCurrentIndex(index)
291 self.textbox.setItemData(index, pattern)
292 elif pattern != self.last_pattern:
293 # Keep the pattern recorded in the combo box up to date
294 index = self.textbox.currentIndex()
295 self.textbox.setItemData(index, pattern)
299 QMessageBox.information(self.bar, "Find", "'" + self.textbox.currentText() + "' not found")
301 # Context-sensitive call graph data model item base
303 class CallGraphLevelItemBase(object):
305 def __init__(self, glb, row, parent_item):
308 self.parent_item = parent_item
309 self.query_done = False;
311 self.child_items = []
313 def getChildItem(self, row):
314 return self.child_items[row]
316 def getParentItem(self):
317 return self.parent_item
322 def childCount(self):
323 if not self.query_done:
325 if not self.child_count:
327 return self.child_count
329 def hasChildren(self):
330 if not self.query_done:
332 return self.child_count > 0
334 def getData(self, column):
335 return self.data[column]
337 # Context-sensitive call graph data model level 2+ item base
339 class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase):
341 def __init__(self, glb, row, comm_id, thread_id, call_path_id, time, branch_count, parent_item):
342 super(CallGraphLevelTwoPlusItemBase, self).__init__(glb, row, parent_item)
343 self.comm_id = comm_id
344 self.thread_id = thread_id
345 self.call_path_id = call_path_id
346 self.branch_count = branch_count
350 self.query_done = True;
351 query = QSqlQuery(self.glb.db)
352 QueryExec(query, "SELECT call_path_id, name, short_name, COUNT(calls.id), SUM(return_time - call_time), SUM(branch_count)"
354 " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
355 " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
356 " INNER JOIN dsos ON symbols.dso_id = dsos.id"
357 " WHERE parent_call_path_id = " + str(self.call_path_id) +
358 " AND comm_id = " + str(self.comm_id) +
359 " AND thread_id = " + str(self.thread_id) +
360 " GROUP BY call_path_id, name, short_name"
361 " ORDER BY call_path_id")
363 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)
364 self.child_items.append(child_item)
365 self.child_count += 1
367 # Context-sensitive call graph data model level three item
369 class CallGraphLevelThreeItem(CallGraphLevelTwoPlusItemBase):
371 def __init__(self, glb, row, comm_id, thread_id, call_path_id, name, dso, count, time, branch_count, parent_item):
372 super(CallGraphLevelThreeItem, self).__init__(glb, row, comm_id, thread_id, call_path_id, time, branch_count, parent_item)
374 self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ]
375 self.dbid = call_path_id
377 # Context-sensitive call graph data model level two item
379 class CallGraphLevelTwoItem(CallGraphLevelTwoPlusItemBase):
381 def __init__(self, glb, row, comm_id, thread_id, pid, tid, parent_item):
382 super(CallGraphLevelTwoItem, self).__init__(glb, row, comm_id, thread_id, 1, 0, 0, parent_item)
383 self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""]
384 self.dbid = thread_id
387 super(CallGraphLevelTwoItem, self).Select()
388 for child_item in self.child_items:
389 self.time += child_item.time
390 self.branch_count += child_item.branch_count
391 for child_item in self.child_items:
392 child_item.data[4] = PercentToOneDP(child_item.time, self.time)
393 child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count)
395 # Context-sensitive call graph data model level one item
397 class CallGraphLevelOneItem(CallGraphLevelItemBase):
399 def __init__(self, glb, row, comm_id, comm, parent_item):
400 super(CallGraphLevelOneItem, self).__init__(glb, row, parent_item)
401 self.data = [comm, "", "", "", "", "", ""]
405 self.query_done = True;
406 query = QSqlQuery(self.glb.db)
407 QueryExec(query, "SELECT thread_id, pid, tid"
409 " INNER JOIN threads ON thread_id = threads.id"
410 " WHERE comm_id = " + str(self.dbid))
412 child_item = CallGraphLevelTwoItem(self.glb, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self)
413 self.child_items.append(child_item)
414 self.child_count += 1
416 # Context-sensitive call graph data model root item
418 class CallGraphRootItem(CallGraphLevelItemBase):
420 def __init__(self, glb):
421 super(CallGraphRootItem, self).__init__(glb, 0, None)
423 self.query_done = True;
424 query = QSqlQuery(glb.db)
425 QueryExec(query, "SELECT id, comm FROM comms")
427 if not query.value(0):
429 child_item = CallGraphLevelOneItem(glb, self.child_count, query.value(0), query.value(1), self)
430 self.child_items.append(child_item)
431 self.child_count += 1
433 # Context-sensitive call graph data model
435 class CallGraphModel(TreeModel):
437 def __init__(self, glb, parent=None):
438 super(CallGraphModel, self).__init__(CallGraphRootItem(glb), parent)
441 def columnCount(self, parent=None):
444 def columnHeader(self, column):
445 headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "]
446 return headers[column]
448 def columnAlignment(self, column):
449 alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ]
450 return alignment[column]
452 def FindSelect(self, value, pattern, query):
454 # postgresql and sqlite pattern patching differences:
455 # postgresql LIKE is case sensitive but sqlite LIKE is not
456 # postgresql LIKE allows % and _ to be escaped with \ but sqlite LIKE does not
457 # postgresql supports ILIKE which is case insensitive
458 # sqlite supports GLOB (text only) which uses * and ? and is case sensitive
459 if not self.glb.dbref.is_sqlite3:
461 s = value.replace("%", "\%")
462 s = s.replace("_", "\_")
463 # Translate * and ? into SQL LIKE pattern characters % and _
464 trans = string.maketrans("*?", "%_")
465 match = " LIKE '" + str(s).translate(trans) + "'"
467 match = " GLOB '" + str(value) + "'"
469 match = " = '" + str(value) + "'"
470 QueryExec(query, "SELECT call_path_id, comm_id, thread_id"
472 " INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
473 " INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
474 " WHERE symbols.name" + match +
475 " GROUP BY comm_id, thread_id, call_path_id"
476 " ORDER BY comm_id, thread_id, call_path_id")
478 def FindPath(self, query):
479 # Turn the query result into a list of ids that the tree view can walk
480 # to open the tree at the right place.
482 parent_id = query.value(0)
484 ids.insert(0, parent_id)
485 q2 = QSqlQuery(self.glb.db)
486 QueryExec(q2, "SELECT parent_id"
488 " WHERE id = " + str(parent_id))
491 parent_id = q2.value(0)
492 # The call path root is not used
495 ids.insert(0, query.value(2))
496 ids.insert(0, query.value(1))
499 def Found(self, query, found):
501 return self.FindPath(query)
504 def FindValue(self, value, pattern, query, last_value, last_pattern):
505 if last_value == value and pattern == last_pattern:
506 found = query.first()
508 self.FindSelect(value, pattern, query)
510 return self.Found(query, found)
512 def FindNext(self, query):
515 found = query.first()
516 return self.Found(query, found)
518 def FindPrev(self, query):
519 found = query.previous()
522 return self.Found(query, found)
524 def FindThread(self, c):
525 if c.direction == 0 or c.value != c.last_value or c.pattern != c.last_pattern:
526 ids = self.FindValue(c.value, c.pattern, c.query, c.last_value, c.last_pattern)
527 elif c.direction > 0:
528 ids = self.FindNext(c.query)
530 ids = self.FindPrev(c.query)
533 def Find(self, value, direction, pattern, context, callback):
535 def __init__(self, *x):
536 self.value, self.direction, self.pattern, self.query, self.last_value, self.last_pattern = x
537 def Update(self, *x):
538 self.value, self.direction, self.pattern, self.last_value, self.last_pattern = x + (self.value, self.pattern)
540 context[0].Update(value, direction, pattern)
542 context.append(Context(value, direction, pattern, QSqlQuery(self.glb.db), None, None))
543 # Use a thread so the UI is not blocked during the SELECT
544 thread = Thread(self.FindThread, context[0])
545 thread.done.connect(lambda ids, t=thread, c=callback: self.FindDone(t, c, ids), Qt.QueuedConnection)
548 def FindDone(self, thread, callback, ids):
551 # Vertical widget layout
555 def __init__(self, w1, w2, w3=None):
556 self.vbox = QWidget()
557 self.vbox.setLayout(QVBoxLayout());
559 self.vbox.layout().setContentsMargins(0, 0, 0, 0)
561 self.vbox.layout().addWidget(w1)
562 self.vbox.layout().addWidget(w2)
564 self.vbox.layout().addWidget(w3)
569 # Context-sensitive call graph window
571 class CallGraphWindow(QMdiSubWindow):
573 def __init__(self, glb, parent=None):
574 super(CallGraphWindow, self).__init__(parent)
576 self.model = LookupCreateModel("Context-Sensitive Call Graph", lambda x=glb: CallGraphModel(x))
578 self.view = QTreeView()
579 self.view.setModel(self.model)
581 for c, w in ((0, 250), (1, 100), (2, 60), (3, 70), (4, 70), (5, 100)):
582 self.view.setColumnWidth(c, w)
584 self.find_bar = FindBar(self, self)
586 self.vbox = VBox(self.view, self.find_bar.Widget())
588 self.setWidget(self.vbox.Widget())
590 AddSubWindow(glb.mainwindow.mdi_area, self, "Context-Sensitive Call Graph")
592 def DisplayFound(self, ids):
595 parent = QModelIndex()
598 n = self.model.rowCount(parent)
599 for row in xrange(n):
600 child = self.model.index(row, 0, parent)
601 if child.internalPointer().dbid == dbid:
603 self.view.setCurrentIndex(child)
610 def Find(self, value, direction, pattern, context):
613 self.model.Find(value, direction, pattern, context, self.FindDone)
615 def FindDone(self, ids):
617 if not self.DisplayFound(ids):
621 self.find_bar.NotFound()
625 def CreateAction(label, tip, callback, parent=None, shortcut=None):
626 action = QAction(label, parent)
628 action.setShortcuts(shortcut)
629 action.setStatusTip(tip)
630 action.triggered.connect(callback)
633 # Typical application actions
635 def CreateExitAction(app, parent=None):
636 return CreateAction("&Quit", "Exit the application", app.closeAllWindows, parent, QKeySequence.Quit)
638 # Typical MDI actions
640 def CreateCloseActiveWindowAction(mdi_area):
641 return CreateAction("Cl&ose", "Close the active window", mdi_area.closeActiveSubWindow, mdi_area)
643 def CreateCloseAllWindowsAction(mdi_area):
644 return CreateAction("Close &All", "Close all the windows", mdi_area.closeAllSubWindows, mdi_area)
646 def CreateTileWindowsAction(mdi_area):
647 return CreateAction("&Tile", "Tile the windows", mdi_area.tileSubWindows, mdi_area)
649 def CreateCascadeWindowsAction(mdi_area):
650 return CreateAction("&Cascade", "Cascade the windows", mdi_area.cascadeSubWindows, mdi_area)
652 def CreateNextWindowAction(mdi_area):
653 return CreateAction("Ne&xt", "Move the focus to the next window", mdi_area.activateNextSubWindow, mdi_area, QKeySequence.NextChild)
655 def CreatePreviousWindowAction(mdi_area):
656 return CreateAction("Pre&vious", "Move the focus to the previous window", mdi_area.activatePreviousSubWindow, mdi_area, QKeySequence.PreviousChild)
658 # Typical MDI window menu
662 def __init__(self, mdi_area, menu):
663 self.mdi_area = mdi_area
664 self.window_menu = menu.addMenu("&Windows")
665 self.close_active_window = CreateCloseActiveWindowAction(mdi_area)
666 self.close_all_windows = CreateCloseAllWindowsAction(mdi_area)
667 self.tile_windows = CreateTileWindowsAction(mdi_area)
668 self.cascade_windows = CreateCascadeWindowsAction(mdi_area)
669 self.next_window = CreateNextWindowAction(mdi_area)
670 self.previous_window = CreatePreviousWindowAction(mdi_area)
671 self.window_menu.aboutToShow.connect(self.Update)
674 self.window_menu.clear()
675 sub_window_count = len(self.mdi_area.subWindowList())
676 have_sub_windows = sub_window_count != 0
677 self.close_active_window.setEnabled(have_sub_windows)
678 self.close_all_windows.setEnabled(have_sub_windows)
679 self.tile_windows.setEnabled(have_sub_windows)
680 self.cascade_windows.setEnabled(have_sub_windows)
681 self.next_window.setEnabled(have_sub_windows)
682 self.previous_window.setEnabled(have_sub_windows)
683 self.window_menu.addAction(self.close_active_window)
684 self.window_menu.addAction(self.close_all_windows)
685 self.window_menu.addSeparator()
686 self.window_menu.addAction(self.tile_windows)
687 self.window_menu.addAction(self.cascade_windows)
688 self.window_menu.addSeparator()
689 self.window_menu.addAction(self.next_window)
690 self.window_menu.addAction(self.previous_window)
691 if sub_window_count == 0:
693 self.window_menu.addSeparator()
695 for sub_window in self.mdi_area.subWindowList():
696 label = str(nr) + " " + sub_window.name
699 action = self.window_menu.addAction(label)
700 action.setCheckable(True)
701 action.setChecked(sub_window == self.mdi_area.activeSubWindow())
702 action.triggered.connect(lambda x=nr: self.setActiveSubWindow(x))
703 self.window_menu.addAction(action)
706 def setActiveSubWindow(self, nr):
707 self.mdi_area.setActiveSubWindow(self.mdi_area.subWindowList()[nr - 1])
709 # Unique name for sub-windows
711 def NumberedWindowName(name, nr):
713 name += " <" + str(nr) + ">"
716 def UniqueSubWindowName(mdi_area, name):
719 unique_name = NumberedWindowName(name, nr)
721 for sub_window in mdi_area.subWindowList():
722 if sub_window.name == unique_name:
731 def AddSubWindow(mdi_area, sub_window, name):
732 unique_name = UniqueSubWindowName(mdi_area, name)
733 sub_window.setMinimumSize(200, 100)
734 sub_window.resize(800, 600)
735 sub_window.setWindowTitle(unique_name)
736 sub_window.setAttribute(Qt.WA_DeleteOnClose)
737 sub_window.setWindowIcon(sub_window.style().standardIcon(QStyle.SP_FileIcon))
738 sub_window.name = unique_name
739 mdi_area.addSubWindow(sub_window)
744 class MainWindow(QMainWindow):
746 def __init__(self, glb, parent=None):
747 super(MainWindow, self).__init__(parent)
751 self.setWindowTitle("Exported SQL Viewer: " + glb.dbname)
752 self.setWindowIcon(self.style().standardIcon(QStyle.SP_ComputerIcon))
753 self.setMinimumSize(200, 100)
755 self.mdi_area = QMdiArea()
756 self.mdi_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
757 self.mdi_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
759 self.setCentralWidget(self.mdi_area)
761 menu = self.menuBar()
763 file_menu = menu.addMenu("&File")
764 file_menu.addAction(CreateExitAction(glb.app, self))
766 edit_menu = menu.addMenu("&Edit")
767 edit_menu.addAction(CreateAction("&Find...", "Find items", self.Find, self, QKeySequence.Find))
769 reports_menu = menu.addMenu("&Reports")
770 reports_menu.addAction(CreateAction("Context-Sensitive Call &Graph", "Create a new window containing a context-sensitive call graph", self.NewCallGraph, self))
772 self.window_menu = WindowMenu(self.mdi_area, menu)
775 win = self.mdi_area.activeSubWindow()
778 win.find_bar.Activate()
782 def NewCallGraph(self):
783 CallGraphWindow(self.glb, self)
789 def __init__(self, dbref, db, dbname):
794 self.mainwindow = None
800 def __init__(self, is_sqlite3, dbname):
801 self.is_sqlite3 = is_sqlite3
804 def Open(self, connection_name):
807 db = QSqlDatabase.addDatabase("QSQLITE", connection_name)
809 db = QSqlDatabase.addDatabase("QPSQL", connection_name)
810 opts = dbname.split()
814 if opt[0] == "hostname":
815 db.setHostName(opt[1])
816 elif opt[0] == "port":
817 db.setPort(int(opt[1]))
818 elif opt[0] == "username":
819 db.setUserName(opt[1])
820 elif opt[0] == "password":
821 db.setPassword(opt[1])
822 elif opt[0] == "dbname":
827 db.setDatabaseName(dbname)
829 raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
835 if (len(sys.argv) < 2):
836 print >> sys.stderr, "Usage is: exported-sql-viewer.py <database name>"
837 raise Exception("Too few arguments")
844 if f.read(15) == "SQLite format 3":
850 dbref = DBRef(is_sqlite3, dbname)
851 db, dbname = dbref.Open("main")
852 glb = Glb(dbref, db, dbname)
853 app = QApplication(sys.argv)
855 mainwindow = MainWindow(glb)
856 glb.mainwindow = mainwindow
862 if __name__ == "__main__":