Commit b2556c46 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7e4fc93e
...@@ -284,41 +284,33 @@ class MainWindow(QMainWindow): ...@@ -284,41 +284,33 @@ class MainWindow(QMainWindow):
self.setCentralWidget(self.view) self.setCentralWidget(self.view)
# Main # Database reference
def Main(): class DBRef():
if (len(sys.argv) < 2):
print >> sys.stderr, "Usage is: call-graph-from-sql.py <database name>"
raise Exception("Too few arguments")
dbname = sys.argv[1] def __init__(self, is_sqlite3, dbname):
self.is_sqlite3 = is_sqlite3
self.dbname = dbname
is_sqlite3 = False def Open(self, connection_name):
try: dbname = self.dbname
f = open(dbname) if self.is_sqlite3:
if f.read(15) == "SQLite format 3": db = QSqlDatabase.addDatabase("QSQLITE", connection_name)
is_sqlite3 = True
f.close()
except:
pass
if is_sqlite3:
db = QSqlDatabase.addDatabase('QSQLITE')
else: else:
db = QSqlDatabase.addDatabase('QPSQL') db = QSqlDatabase.addDatabase("QPSQL", connection_name)
opts = dbname.split() opts = dbname.split()
for opt in opts: for opt in opts:
if '=' in opt: if "=" in opt:
opt = opt.split('=') opt = opt.split("=")
if opt[0] == 'hostname': if opt[0] == "hostname":
db.setHostName(opt[1]) db.setHostName(opt[1])
elif opt[0] == 'port': elif opt[0] == "port":
db.setPort(int(opt[1])) db.setPort(int(opt[1]))
elif opt[0] == 'username': elif opt[0] == "username":
db.setUserName(opt[1]) db.setUserName(opt[1])
elif opt[0] == 'password': elif opt[0] == "password":
db.setPassword(opt[1]) db.setPassword(opt[1])
elif opt[0] == 'dbname': elif opt[0] == "dbname":
dbname = opt[1] dbname = opt[1]
else: else:
dbname = opt dbname = opt
...@@ -326,7 +318,28 @@ def Main(): ...@@ -326,7 +318,28 @@ def Main():
db.setDatabaseName(dbname) db.setDatabaseName(dbname)
if not db.open(): if not db.open():
raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text()) raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
return db, dbname
# Main
def Main():
if (len(sys.argv) < 2):
print >> sys.stderr, "Usage is: call-graph-from-sql.py <database name>"
raise Exception("Too few arguments")
dbname = sys.argv[1]
is_sqlite3 = False
try:
f = open(dbname)
if f.read(15) == "SQLite format 3":
is_sqlite3 = True
f.close()
except:
pass
dbref = DBRef(is_sqlite3, dbname)
db, dbname = dbref.Open("main")
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow(db, dbname) window = MainWindow(db, dbname)
window.show() window.show()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment