Created
May 31, 2012 23:45
-
-
Save AevaOnline/2847258 to your computer and use it in GitHub Desktop.
override sqlalchemy orm.query._compile_context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /home/stack/nova/nova/db/sqlalchemy/session.py 2012-06-01 09:39:14.595304669 -0700 | |
+++ /opt/stack/nova/nova/db/sqlalchemy/session.py 2012-06-01 11:58:32.384748730 -0700 | |
@@ -29,6 +29,8 @@ | |
import nova.flags as flags | |
import nova.log as logging | |
+import traceback | |
+import MySQLdb.cursors | |
FLAGS = flags.FLAGS | |
LOG = logging.getLogger(__name__) | |
@@ -36,6 +38,36 @@ | |
_ENGINE = None | |
_MAKER = None | |
+old_do_query = MySQLdb.cursors.BaseCursor._do_query | |
+def debug_do_query(self, q): | |
+ stack = '' | |
+ for file, line, method, function in traceback.extract_stack(): | |
+ # don't include this function in the trace | |
+ if method == 'debug_do_query': continue | |
+ # don't print all the api.py wrapper calls | |
+ if file.endswith('api.py') and method == 'wrapper': continue | |
+ # don't print LoopingCall either | |
+ if file.endswith('utils.py') and method == '_inner': continue | |
+ # or our exception wrapper | |
+ if file.endswith('exception.py') and method == '_wrap': continue | |
+ # only print relative path | |
+ index = file.rfind('nova') | |
+ # don't print traces outside of nova | |
+ if index == -1: continue | |
+ stack += "File:%s:%s Method:%s() Line:%s | " \ | |
+ % (file[index:], line, method, function) | |
+ | |
+ # strip trailing " | " from stack | |
+ if stack: | |
+ stack = stack[:-3] | |
+ qq = "%s /* %s */" % (q, stack) | |
+ else: | |
+ qq = q | |
+ | |
+ old_do_query(self, qq) | |
+ | |
+setattr(MySQLdb.cursors.BaseCursor, '_do_query', debug_do_query) | |
+ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
User@Host: stack[stack] @ localhost []
Query_time: 0.000052 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1338576831;
select 1 /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:55 Method:save() Line:session = get_session() | File:nova/db/sqlalchemy/session.py:124 Method:get_session() Line:engine = get_engine() | File:nova/db/sqlalchemy/session.py:208 Method:get_engine() Line:_ENGINE.connect() | File:nova/db/sqlalchemy/session.py:153 Method:checkout() Line:dbapi_con.cursor().execute('select 1') */;
User@Host: stack[stack] @ localhost []
Query_time: 0.000016 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1338576831;
select 1 /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:58 Method:save() Line:session.flush() | File:nova/db/sqlalchemy/session.py:153 Method:checkout() Line:dbapi_con.cursor().execute('select 1') */;
User@Host: stack[stack] @ localhost []
Query_time: 0.000131 Lock_time: 0.000054 Rows_sent: 0 Rows_examined: 0
SET timestamp=1338576831;
INSERT INTO floating_ips (created_at, updated_at, deleted_at, deleted, address, fixed_ip_id, project_id, host, auto_assigned, pool, interface) VALUES ('2012-06-01 18:53:51', NULL, NULL, 0, '10.10.1.193', NULL, NULL, NULL, 0, 'nova', 'eth0') /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:58 Method:save() Line:session.flush() */;
User@Host: stack[stack] @ localhost []
Query_time: 0.017091 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1338576831;
commit;
User@Host: stack[stack] @ localhost []
Query_time: 0.000120 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1338576831;
select 1 /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:58 Method:save() Line:session.flush() | File:nova/db/sqlalchemy/session.py:153 Method:checkout() Line:dbapi_con.cursor().execute('select 1') */;
User@Host: stack[stack] @ localhost []
Query_time: 0.000274 Lock_time: 0.000108 Rows_sent: 0 Rows_examined: 0
SET timestamp=1338576831;
INSERT INTO floating_ips (created_at, updated_at, deleted_at, deleted, address, fixed_ip_id, project_id, host, auto_assigned, pool, interface) VALUES ('2012-06-01 18:53:51', NULL, NULL, 0, '10.10.1.194', NULL, NULL, NULL, 0, 'nova', 'eth0') /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:58 Method:save() Line:session.flush() */;
User@Host: stack[stack] @ localhost []
Query_time: 0.027198 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1338576831;
commit;
User@Host: stack[stack] @ localhost []
Query_time: 0.000117 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1338576831;
select 1 /* File:nova-manage:1754 Method:() Line:main() | File:nova-manage:1741 Method:main() Line:fn(_fn_args, *_fn_kwargs) | File:nova-manage:662 Method:create() Line:'interface': interface}) | File:nova/db/api.py:251 Method:floating_ip_create() Line:return IMPL.floating_ip_create(context, values) | File:nova/db/sqlalchemy/api.py:685 Method:floating_ip_create() Line:floating_ip_ref.save() | File:nova/db/sqlalchemy/models.py:58 Method:save() Line:session.flush() | File:nova/db/sqlalchemy/session.py:153 Method:checkout() Line:dbapi_con.cursor().execute('select 1') */;