Always print SQL counters.
bzr revid: p_christ@hol.gr-20090106131746-mwdgfx2l1z9hd02b
This commit is contained in:
parent
7aa561987b
commit
3487f659ec
|
@ -59,6 +59,8 @@ def log(msg, lvl=netsvc.LOG_DEBUG):
|
||||||
logger = netsvc.Logger()
|
logger = netsvc.Logger()
|
||||||
logger.notifyChannel('sql', lvl, msg)
|
logger.notifyChannel('sql', lvl, msg)
|
||||||
|
|
||||||
|
sql_counter = 0
|
||||||
|
|
||||||
class Cursor(object):
|
class Cursor(object):
|
||||||
IN_MAX = 1000
|
IN_MAX = 1000
|
||||||
sql_from_log = {}
|
sql_from_log = {}
|
||||||
|
@ -72,7 +74,7 @@ class Cursor(object):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
if not hasattr(self, '_obj'):
|
if not hasattr(self, '_obj'):
|
||||||
raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
|
raise psycopg2.ProgrammingError('Unable to use the cursor after having closed it')
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ class Cursor(object):
|
||||||
self.count+=1
|
self.count+=1
|
||||||
if '%d' in query or '%f' in query:
|
if '%d' in query or '%f' in query:
|
||||||
log(query, netsvc.LOG_WARNING)
|
log(query, netsvc.LOG_WARNING)
|
||||||
log("SQL queries mustn't containt %d or %f anymore. Use only %s", netsvc.LOG_WARNING)
|
log("SQL queries cannot contain %d or %f anymore. Use only %s", netsvc.LOG_WARNING)
|
||||||
if params:
|
if params:
|
||||||
query = query.replace('%d', '%s').replace('%f', '%s')
|
query = query.replace('%d', '%s').replace('%f', '%s')
|
||||||
|
|
||||||
|
@ -134,19 +136,20 @@ class Cursor(object):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def print_log(self):
|
def print_log(self):
|
||||||
|
global sql_counter
|
||||||
|
sql_counter += self.count
|
||||||
def process(type):
|
def process(type):
|
||||||
sqllogs = {'from':self.sql_from_log, 'into':self.sql_into_log}
|
sqllogs = {'from':self.sql_from_log, 'into':self.sql_into_log}
|
||||||
if not sqllogs[type]:
|
|
||||||
return
|
|
||||||
sqllogitems = sqllogs[type].items()
|
|
||||||
sqllogitems.sort(key=lambda k: k[1][1])
|
|
||||||
sum = 0
|
sum = 0
|
||||||
log("SQL LOG %s:" % (type,))
|
if sqllogs[type]:
|
||||||
for r in sqllogitems:
|
sqllogitems = sqllogs[type].items()
|
||||||
log("table: %s: %s/%s" %(r[0], str(r[1][1]), r[1][0]))
|
sqllogitems.sort(key=lambda k: k[1][1])
|
||||||
sum+= r[1][1]
|
log("SQL LOG %s:" % (type,))
|
||||||
log("SUM:%s/%d" % (sum, self.count))
|
for r in sqllogitems:
|
||||||
sqllogs[type].clear()
|
log("table: %s: %s/%s" %(r[0], str(r[1][1]), r[1][0]))
|
||||||
|
sum+= r[1][1]
|
||||||
|
sqllogs[type].clear()
|
||||||
|
log("SUM:%s/%d [%d]" % (sum, self.count,sql_counter))
|
||||||
process('from')
|
process('from')
|
||||||
process('into')
|
process('into')
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
Loading…
Reference in New Issue