annotate rhodecode/lib/timerproxy.py @ 1191:1fb97030b9b7 beta

let timerproxy use logging module
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 01 Apr 2011 16:35:03 +0200
parents b9ea10d3e419
children c1516b35f91d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
1 from sqlalchemy.interfaces import ConnectionProxy
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
2 import time
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
3 import logging
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
4 log = logging.getLogger('timerproxy')
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
5
153
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
6 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
7
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
8 def color_sql(sql):
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
9 COLOR_SEQ = "\033[1;%dm"
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
10 COLOR_SQL = YELLOW
a5a3bcc5ee89 Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents: 90
diff changeset
11 normal = '\x1b[0m'
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
12 return COLOR_SEQ % COLOR_SQL + sql + normal
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
13
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
14 class TimerProxy(ConnectionProxy):
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
15
492
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
16 def __init__(self):
a5a17000e45b timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
17 super(TimerProxy, self).__init__()
1186
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
18
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
19 def cursor_execute(self, execute, cursor, statement, parameters,
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
20 context, executemany):
b9ea10d3e419 timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
21
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
22 now = time.time()
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
23 try:
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
24 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
25 return execute(cursor, statement, parameters, context)
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
26 finally:
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
27 total = time.time() - now
1191
1fb97030b9b7 let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents: 1186
diff changeset
28 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total))