diff options
Diffstat (limited to 'tools/perf/scripts/python/call-graph-from-sql.py')
-rw-r--r-- | tools/perf/scripts/python/call-graph-from-sql.py | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/tools/perf/scripts/python/call-graph-from-sql.py b/tools/perf/scripts/python/call-graph-from-sql.py index f18406d3faf7..b494a67a1c67 100644 --- a/tools/perf/scripts/python/call-graph-from-sql.py +++ b/tools/perf/scripts/python/call-graph-from-sql.py | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/usr/bin/python2 | 1 | #!/usr/bin/python2 |
2 | # call-graph-from-sql.py: create call-graph from postgresql database | 2 | # call-graph-from-sql.py: create call-graph from sql database |
3 | # Copyright (c) 2014-2017, Intel Corporation. | 3 | # Copyright (c) 2014-2017, Intel Corporation. |
4 | # | 4 | # |
5 | # This program is free software; you can redistribute it and/or modify it | 5 | # This program is free software; you can redistribute it and/or modify it |
@@ -11,16 +11,17 @@ | |||
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
12 | # more details. | 12 | # more details. |
13 | 13 | ||
14 | # To use this script you will need to have exported data using the | 14 | # To use this script you will need to have exported data using either the |
15 | # export-to-postgresql.py script. Refer to that script for details. | 15 | # export-to-sqlite.py or the export-to-postgresql.py script. Refer to those |
16 | # scripts for details. | ||
16 | # | 17 | # |
17 | # Following on from the example in the export-to-postgresql.py script, a | 18 | # Following on from the example in the export scripts, a |
18 | # call-graph can be displayed for the pt_example database like this: | 19 | # call-graph can be displayed for the pt_example database like this: |
19 | # | 20 | # |
20 | # python tools/perf/scripts/python/call-graph-from-sql.py pt_example | 21 | # python tools/perf/scripts/python/call-graph-from-sql.py pt_example |
21 | # | 22 | # |
22 | # Note this script supports connecting to remote databases by setting hostname, | 23 | # Note that for PostgreSQL, this script supports connecting to remote databases |
23 | # port, username, password, and dbname e.g. | 24 | # by setting hostname, port, username, password, and dbname e.g. |
24 | # | 25 | # |
25 | # python tools/perf/scripts/python/call-graph-from-sql.py "hostname=myhost username=myuser password=mypassword dbname=pt_example" | 26 | # python tools/perf/scripts/python/call-graph-from-sql.py "hostname=myhost username=myuser password=mypassword dbname=pt_example" |
26 | # | 27 | # |
@@ -296,24 +297,35 @@ if __name__ == '__main__': | |||
296 | 297 | ||
297 | dbname = sys.argv[1] | 298 | dbname = sys.argv[1] |
298 | 299 | ||
299 | db = QSqlDatabase.addDatabase('QPSQL') | 300 | is_sqlite3 = False |
300 | 301 | try: | |
301 | opts = dbname.split() | 302 | f = open(dbname) |
302 | for opt in opts: | 303 | if f.read(15) == "SQLite format 3": |
303 | if '=' in opt: | 304 | is_sqlite3 = True |
304 | opt = opt.split('=') | 305 | f.close() |
305 | if opt[0] == 'hostname': | 306 | except: |
306 | db.setHostName(opt[1]) | 307 | pass |
307 | elif opt[0] == 'port': | 308 | |
308 | db.setPort(int(opt[1])) | 309 | if is_sqlite3: |
309 | elif opt[0] == 'username': | 310 | db = QSqlDatabase.addDatabase('QSQLITE') |
310 | db.setUserName(opt[1]) | 311 | else: |
311 | elif opt[0] == 'password': | 312 | db = QSqlDatabase.addDatabase('QPSQL') |
312 | db.setPassword(opt[1]) | 313 | opts = dbname.split() |
313 | elif opt[0] == 'dbname': | 314 | for opt in opts: |
314 | dbname = opt[1] | 315 | if '=' in opt: |
315 | else: | 316 | opt = opt.split('=') |
316 | dbname = opt | 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': | ||
326 | dbname = opt[1] | ||
327 | else: | ||
328 | dbname = opt | ||
317 | 329 | ||
318 | db.setDatabaseName(dbname) | 330 | db.setDatabaseName(dbname) |
319 | if not db.open(): | 331 | if not db.open(): |