Mercurial > kallithea
annotate rhodecode/lib/timerproxy.py @ 1186:b9ea10d3e419 beta
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
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 28 Mar 2011 22:13:21 +0200 |
parents | 1e757ac98988 |
children | 1fb97030b9b7 |
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 |
492
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
3 from sqlalchemy import log |
153
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
4 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
|
5 |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
6 def color_sql(sql): |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
7 COLOR_SEQ = "\033[1;%dm" |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
8 COLOR_SQL = YELLOW |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
9 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
|
10 return COLOR_SEQ % COLOR_SQL + sql + normal |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
11 |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
12 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
|
13 |
492
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
14 def __init__(self): |
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
15 super(TimerProxy, self).__init__() |
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
16 self.logging_name = 'timerProxy' |
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
17 self.log = log.instance_logger(self, True) |
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: |
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
|
24 self.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 |
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
|
28 self.log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total)) |