Mercurial > kallithea
annotate rhodecode/lib/timerproxy.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl
old style: show the full link box on summary page - no overlap or truncation
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:23 -0400 |
parents | ffd45b185016 |
children |
rev | line source |
---|---|
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
1 # -*- coding: utf-8 -*- |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
5 # (at your option) any later version. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
6 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
10 # GNU General Public License for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
11 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
14 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
15 import time |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
16 import logging |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
17 from sqlalchemy.interfaces import ConnectionProxy |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
1512
diff
changeset
|
18 |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
19 log = logging.getLogger('timerproxy') |
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
20 |
153
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
21 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
|
22 |
1307 | 23 |
153
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
24 def color_sql(sql): |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
25 COLOR_SEQ = "\033[1;%dm" |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
26 COLOR_SQL = YELLOW |
a5a3bcc5ee89
Added colored formatter to project, and configs
Marcin Kuzminski <marcin@python-works.com>
parents:
90
diff
changeset
|
27 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
|
28 return ''.join([COLOR_SEQ % COLOR_SQL, sql, normal]) |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
29 |
1307 | 30 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
31 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
|
32 |
492
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
33 def __init__(self): |
a5a17000e45b
timeproxy logging memory leak fix.
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
34 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
|
35 |
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
|
36 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
|
37 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
|
38 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
39 now = time.time() |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
40 try: |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
41 log.info(color_sql(">>>>> STARTING QUERY >>>>>")) |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
42 return execute(cursor, statement, parameters, context) |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
43 finally: |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
44 total = time.time() - now |
1191
1fb97030b9b7
let timerproxy use logging module
Marcin Kuzminski <marcin@python-works.com>
parents:
1186
diff
changeset
|
45 log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total)) |