1 | import time |
---|
2 | import inspect |
---|
3 | import os |
---|
4 | |
---|
5 | from galaxy.model.orm import * |
---|
6 | |
---|
7 | import logging |
---|
8 | |
---|
9 | log = logging.getLogger( __name__ ) |
---|
10 | |
---|
11 | wd = os.getcwd() |
---|
12 | def stripwd( s ): |
---|
13 | if s.startswith( wd ): |
---|
14 | return s[len(wd):] |
---|
15 | return s |
---|
16 | |
---|
17 | def pretty_stack(): |
---|
18 | rval = [] |
---|
19 | for frame, fname, line, funcname, _, _ in inspect.stack()[2:]: |
---|
20 | rval.append( "%s:%s@%d" % ( stripwd( fname ), funcname, line ) ) |
---|
21 | return " > ".join( rval ) |
---|
22 | |
---|
23 | class LoggingProxy(ConnectionProxy): |
---|
24 | def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): |
---|
25 | start = time.clock() |
---|
26 | rval = execute(cursor, statement, parameters, context) |
---|
27 | duration = time.clock() - start |
---|
28 | log.debug( "statement: %r parameters: %r executemany: %r duration: %r stack: %r", |
---|
29 | statement, parameters, executemany, duration, pretty_stack() ) |
---|
30 | return rval |
---|