diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2018-10-01 02:28:40 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-23 13:23:13 -0400 |
commit | b2556c46a69b4c0e6bbf690ac4ca2913cbe90e1e (patch) | |
tree | afcd90a43bc058fd8da562a37376641881df0842 /tools/perf/scripts/python/call-graph-from-sql.py | |
parent | 7e4fc93e2ade2b0c453a97e307203ffe3f930c98 (diff) |
perf scripts python: call-graph-from-sql.py: Separate the database details into a class
Separate the database details into a class that can provide different
connections using the same connection information. That paves the way
for sub-processes that require their own connection.
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-7-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.py | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/tools/perf/scripts/python/call-graph-from-sql.py b/tools/perf/scripts/python/call-graph-from-sql.py index 2b74b94eeccc..9d056deab2b1 100644 --- a/tools/perf/scripts/python/call-graph-from-sql.py +++ b/tools/perf/scripts/python/call-graph-from-sql.py | |||
@@ -284,6 +284,42 @@ class MainWindow(QMainWindow): | |||
284 | 284 | ||
285 | self.setCentralWidget(self.view) | 285 | self.setCentralWidget(self.view) |
286 | 286 | ||
287 | # Database reference | ||
288 | |||
289 | class DBRef(): | ||
290 | |||
291 | def __init__(self, is_sqlite3, dbname): | ||
292 | self.is_sqlite3 = is_sqlite3 | ||
293 | self.dbname = dbname | ||
294 | |||
295 | def Open(self, connection_name): | ||
296 | dbname = self.dbname | ||
297 | if self.is_sqlite3: | ||
298 | db = QSqlDatabase.addDatabase("QSQLITE", connection_name) | ||
299 | else: | ||
300 | db = QSqlDatabase.addDatabase("QPSQL", connection_name) | ||
301 | opts = dbname.split() | ||
302 | for opt in opts: | ||
303 | if "=" in opt: | ||
304 | opt = opt.split("=") | ||
305 | if opt[0] == "hostname": | ||
306 | db.setHostName(opt[1]) | ||
307 | elif opt[0] == "port": | ||
308 | db.setPort(int(opt[1])) | ||
309 | elif opt[0] == "username": | ||
310 | db.setUserName(opt[1]) | ||
311 | elif opt[0] == "password": | ||
312 | db.setPassword(opt[1]) | ||
313 | elif opt[0] == "dbname": | ||
314 | dbname = opt[1] | ||
315 | else: | ||
316 | dbname = opt | ||
317 | |||
318 | db.setDatabaseName(dbname) | ||
319 | if not db.open(): | ||
320 | raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text()) | ||
321 | return db, dbname | ||
322 | |||
287 | # Main | 323 | # Main |
288 | 324 | ||
289 | def Main(): | 325 | def Main(): |
@@ -302,31 +338,8 @@ def Main(): | |||
302 | except: | 338 | except: |
303 | pass | 339 | pass |
304 | 340 | ||
305 | if is_sqlite3: | 341 | dbref = DBRef(is_sqlite3, dbname) |
306 | db = QSqlDatabase.addDatabase('QSQLITE') | 342 | db, dbname = dbref.Open("main") |
307 | else: | ||
308 | db = QSqlDatabase.addDatabase('QPSQL') | ||
309 | opts = dbname.split() | ||
310 | for opt in opts: | ||
311 | if '=' in opt: | ||
312 | opt = opt.split('=') | ||
313 | if opt[0] == 'hostname': | ||
314 | db.setHostName(opt[1]) | ||
315 | elif opt[0] == 'port': | ||
316 | db.setPort(int(opt[1])) | ||
317 | elif opt[0] == 'username': | ||
318 | db.setUserName(opt[1]) | ||
319 | elif opt[0] == 'password': | ||
320 | db.setPassword(opt[1]) | ||
321 | elif opt[0] == 'dbname': | ||
322 | dbname = opt[1] | ||
323 | else: | ||
324 | dbname = opt | ||
325 | |||
326 | db.setDatabaseName(dbname) | ||
327 | if not db.open(): | ||
328 | raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text()) | ||
329 | |||
330 | app = QApplication(sys.argv) | 343 | app = QApplication(sys.argv) |
331 | window = MainWindow(db, dbname) | 344 | window = MainWindow(db, dbname) |
332 | window.show() | 345 | window.show() |