diff options
| author | Adrian Hunter <adrian.hunter@intel.com> | 2017-08-03 04:31:30 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-08-15 16:03:38 -0400 |
| commit | 1fe03b5f2d70b48c4a10785edf2678ff05506e59 (patch) | |
| tree | a76f504b2580d80c1cf8c80e119bc29ab7ced86d /tools/perf/scripts/python/call-graph-from-sql.py | |
| parent | 69e6e410f1a1e69cb656e8ebddaae0ba2138b235 (diff) | |
perf script python: Add support for sqlite3 to call-graph-from-sql.py
Add support for SQLite 3 to the call-graph-from-sql.py script. The SQL
statements work as is, so just detect the database type by checking if the
SQLite 3 file exists.
Committer notes:
Tested collecting the PT data on a RHEL7.4, generating the SQLite3
database there and then moving it to a Fedora 26 system where the
call-graph-from-sql.py script was run, using python-pyside version
1.2.2-7fc26 to see the callgraphs using Qt4.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/r/1501749090-20357-6-git-send-email-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 | 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(): |
