<s> from __future__ import absolute_import <EOL> try : <EOL> from django . db . backends . base . base import BaseDatabaseWrapper <EOL> except ImportError : <EOL> from django . db . backends import BaseDatabaseWrapper <EOL> try : <EOL> from django . db . backends . utils import CursorWrapper <EOL> except ImportError : <EOL> from django . db . backends . util import CursorWrapper <EOL> from . base import BaseModule , RequestTrace <EOL> from . monkey_patching import monkeypatch_method <EOL> class SqlModule ( BaseModule ) : <EOL> key = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> super ( SqlModule , self ) . __init__ ( ) <EOL> self . queries = [ ] <EOL> def get_metrics ( self ) : <EOL> return RequestTrace . instance ( ) . stacktracer . get_node_metrics ( '<STR_LIT>' ) <EOL> def get_details ( self ) : <EOL> sql_nodes = RequestTrace . instance ( ) . stacktracer . get_nodes ( '<STR_LIT>' ) <EOL> return [ { '<STR_LIT>' : node . label , '<STR_LIT:time>' : int ( node . duration * <NUM_LIT:1000> ) } for node in sql_nodes ] <EOL> class _DetailedTracingCursorWrapper ( CursorWrapper ) : <EOL> def execute ( self , sql , params = ( ) ) : <EOL> request_trace = RequestTrace . instance ( ) <EOL> if request_trace : <EOL> stack_entry = request_trace . stacktracer . push_stack ( '<STR_LIT>' , sql ) <EOL> try : <EOL> return self . cursor . execute ( sql , params ) <EOL> finally : <EOL> if request_trace : <EOL> request_trace . stacktracer . pop_stack ( ) <EOL> sql = self . db . ops . last_executed_query ( self . cursor , sql , params ) <EOL> stack_entry . label = sql <EOL> def executemany ( self , sql , param_list ) : <EOL> request_trace = RequestTrace . instance ( ) <EOL> if request_trace : <EOL> request_trace . stacktracer . push_stack ( '<STR_LIT>' , sql ) <EOL> try : <EOL> return self . cursor . executemany ( sql , param_list ) <EOL> finally : <EOL> if request_trace : <EOL> request_trace . stacktracer . pop_stack ( ) <EOL> def init ( ) : <EOL> @ monkeypatch_method ( BaseDatabaseWrapper ) <EOL> def cursor ( original , self , * args , ** kwargs ) : <EOL> result = original ( * args , ** kwargs ) <EOL> return _DetailedTracingCursorWrapper ( result , self ) <EOL> return SqlModule </s>
