Mercurial > kallithea
annotate rhodecode/lib/timerproxy.py @ 1237:f7bb54f8c20f
fixed archive names, added setup command to contributing docs.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Apr 2011 20:15:18 +0200 |
parents | 73434499fa72 |
children | bf263968da47 |
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 |
1228
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
3 import logging |
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
4 log = logging.getLogger('timerproxy') |
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
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' |
1228
73434499fa72
merges for stable
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): |
1228
73434499fa72
merges for stable
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__() |
1228
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
18 |
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
19 def cursor_execute(self, execute, cursor, statement, parameters, |
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
20 context, executemany): |
73434499fa72
merges for stable
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: |
1228
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
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 |
1228
73434499fa72
merges for stable
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
28 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total)) |