Mercurial > kallithea
annotate rhodecode/lib/timerproxy.py @ 2300:edfff9f37916 rhodecode-0.0.1.3.6
merge with beta
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 17 May 2012 14:27:51 +0200 |
parents | bf263968da47 |
children | ffd45b185016 |
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 |
1307 | 8 |
153
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
9 def color_sql(sql): |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
10 COLOR_SEQ = "\033[1;%dm" |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
11 COLOR_SQL = YELLOW |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
12 normal = '\x1b[0m' |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
13 return ''.join([COLOR_SEQ % COLOR_SQL, sql, normal]) |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
14 |
1307 | 15 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
16 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
|
17 |
492
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
18 def __init__(self): |
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
19 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
|
20 |
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 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
|
22 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
|
23 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
24 now = time.time() |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
25 try: |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
26 log.info(color_sql(">>>>> STARTING QUERY >>>>>")) |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
27 return execute(cursor, statement, parameters, context) |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
28 finally: |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
29 total = time.time() - now |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
30 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total)) |