From 067f95b1f6eec1a274ada2a3a756258d25ce29e8 Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Sat, 12 Mar 2016 23:11:25 +0100 Subject: [PATCH] Log debug open times --- src/Db/Db.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Db/Db.py b/src/Db/Db.py index e6c64bec..e5f0b06e 100644 --- a/src/Db/Db.py +++ b/src/Db/Db.py @@ -7,6 +7,7 @@ import os import gevent from DbCursor import DbCursor +from Config import config opened_dbs = [] @@ -45,7 +46,7 @@ class Db(object): def connect(self): if self not in opened_dbs: opened_dbs.append(self) - + s = time.time() self.log.debug("Connecting to %s (sqlite version: %s)..." % (self.db_path, sqlite3.version)) if not os.path.isdir(self.db_dir): # Directory not exist yet os.makedirs(self.db_dir) @@ -53,6 +54,8 @@ class Db(object): if not os.path.isfile(self.db_path): self.log.debug("Db file not exist yet: %s" % self.db_path) self.conn = sqlite3.connect(self.db_path) + if config.verbose: + self.log.debug("Connected to Db in %.3fs" % (time.time()-s)) self.conn.row_factory = sqlite3.Row self.conn.isolation_level = None self.cur = self.getCursor() @@ -62,6 +65,8 @@ class Db(object): self.cur.execute("PRAGMA synchronous = OFF") if self.foreign_keys: self.execute("PRAGMA foreign_keys = ON") + if config.verbose: + self.log.debug("Db is ready to use in %.3fs" % (time.time()-s)) # Execute query using dbcursor @@ -312,4 +317,4 @@ if __name__ == "__main__": cur.execute("COMMIT") print "Done in %.3fs" % (time.time() - s) for query, stats in sorted(dbjson.query_stats.items()): - print "-", query, stats + print "-", query, stats \ No newline at end of file