aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/default_settings.py1
-rw-r--r--wqflask/dbFunction/webqtlDatabaseFunction.py6
-rw-r--r--wqflask/utility/benchmark.py29
-rw-r--r--wqflask/utility/logger.py2
-rw-r--r--wqflask/utility/tools.py1
5 files changed, 22 insertions, 17 deletions
diff --git a/etc/default_settings.py b/etc/default_settings.py
index 296ffcb0..4bb1b80c 100644
--- a/etc/default_settings.py
+++ b/etc/default_settings.py
@@ -39,6 +39,7 @@ WEBSERVER_DEPLOY = None # Deployment specifics (nyi)
LOG_LEVEL = 'WARNING' # Logger mode (DEBUG|INFO|WARNING|ERROR|CRITICAL)
LOG_LEVEL_DEBUG = 1 # Debug log level (0-5) (nyi)
LOG_SQL = 'False' # Log SQL/backend calls
+LOG_BENCH = True # Log bench marks
USE_REDIS = True # REDIS caching (note that redis will be phased out)
USE_GN_SERVER = True # Use GN_SERVER SQL calls
diff --git a/wqflask/dbFunction/webqtlDatabaseFunction.py b/wqflask/dbFunction/webqtlDatabaseFunction.py
index 4a0fb40f..b14c9312 100644
--- a/wqflask/dbFunction/webqtlDatabaseFunction.py
+++ b/wqflask/dbFunction/webqtlDatabaseFunction.py
@@ -28,7 +28,7 @@ import string
import urllib2
import json
from base import webqtlConfig
-from utility.tools import USE_GN_SERVER
+from utility.tools import USE_GN_SERVER, LOG_SQL
from utility.benchmark import Bench
from utility.logger import getLogger
@@ -51,7 +51,7 @@ def fetchone(query):
"""Return tuple containing one row by calling SQL directly
"""
- with Bench("SQL took"):
+ with Bench("SQL took",LOG_SQL):
def helper(query):
res = g.db.execute(query)
return res.fetchone()
@@ -62,7 +62,7 @@ def gn_server(path):
"""Return JSON record by calling GN_SERVER
"""
- with Bench("GN_SERVER took"):
+ with Bench("GN_SERVER took",LOG_SQL):
res = urllib2.urlopen("http://localhost:8880/"+path)
rest = res.read()
res2 = json.loads(rest)
diff --git a/wqflask/utility/benchmark.py b/wqflask/utility/benchmark.py
index d5b32703..887b3d88 100644
--- a/wqflask/utility/benchmark.py
+++ b/wqflask/utility/benchmark.py
@@ -3,34 +3,37 @@ from __future__ import print_function, division, absolute_import
import collections
import inspect
import time
+from utility.tools import LOG_BENCH
class Bench(object):
entries = collections.OrderedDict()
- def __init__(self, name=None):
+ def __init__(self, name=None, write_output=True):
self.name = name
+ self.write_output = write_output
def __enter__(self):
- if self.name:
- print("Starting benchmark: %s" % (self.name))
- else:
- print("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2]))
+ if self.write_output:
+ if self.name:
+ print("Starting benchmark: %s" % (self.name))
+ else:
+ print("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2]))
self.start_time = time.time()
def __exit__(self, type, value, traceback):
- if self.name:
- name = self.name
- else:
- name = "That"
-
time_taken = time.time() - self.start_time
- print(" %s took: %f seconds" % (name, (time_taken)))
+ if self.write_output:
+ if self.name:
+ name = self.name
+ else:
+ name = "That"
+
+ print(" %s took: %f seconds" % (name, (time_taken)))
if self.name:
Bench.entries[self.name] = Bench.entries.get(self.name, 0) + time_taken
-
@classmethod
def report(cls):
total_time = sum((time_taken for time_taken in cls.entries.itervalues()))
@@ -42,4 +45,4 @@ class Bench(object):
def reset(cls):
"""Reset the entries"""
- cls.entries = collections.OrderedDict() \ No newline at end of file
+ cls.entries = collections.OrderedDict()
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index d56b134c..d1324dd5 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -81,7 +81,7 @@ class GNLogger:
if fun:
result = fun(sqlcommand)
if LOG_SQL:
- self.debug(result)
+ self.info(result)
return result
def collect(self,fun,*args):
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index fca5917e..c1b635e0 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -171,6 +171,7 @@ WEBSERVER_MODE = get_setting('WEBSERVER_MODE')
LOG_LEVEL = get_setting('LOG_LEVEL')
LOG_LEVEL_DEBUG = get_setting_int('LOG_LEVEL_DEBUG')
LOG_SQL = get_setting_bool('LOG_SQL')
+LOG_BENCH = get_setting_bool('LOG_BENCH')
USE_REDIS = get_setting_bool('USE_REDIS')
USE_GN_SERVER = get_setting_bool('USE_GN_SERVER')