Ejemplo n.º 1
0
def execute_sql(self, *args, **kwargs):
    client = get_client()
    if client is None:
        return self.__execute_sql(*args, **kwargs)
    try:
        q, params = self.as_sql()
        if not q:
            raise EmptyResultSet
    except EmptyResultSet:
        if kwargs.get('result_type', MULTI) == MULTI:
            return iter([])
        else:
            return
    start = datetime.now()
    try:
        return self.__execute_sql(*args, **kwargs)
    finally:
        d = (datetime.now() - start)
        client.insert({
            'query': q,
            'view': _get_current_view(),
            'type': 'sql'
        }, {
            'time': 0.0 + d.seconds * 1000 + d.microseconds / 1000,
            'count': 1
        })
Ejemplo n.º 2
0
 def process_response(self, request, response):
     request.profiler_view = _get_current_view()
     _set_current_view(None)
     if True:
         _tac('view')
         _tic('mid2')
     return response
Ejemplo n.º 3
0
 def process_response(self, request, response):
     request.profiler_view = _get_current_view()
     _set_current_view(None)
     if True:
         _tac('view')
         _tic('mid2')
     return response
Ejemplo n.º 4
0
def execute_sql(self, *args, **kwargs):
    client = get_client()
    if client is None:
        return self.__execute_sql(*args, **kwargs)
    try:
        q, params = self.as_sql()
        if not q:
            raise EmptyResultSet
    except EmptyResultSet:
        if kwargs.get('result_type', MULTI) == MULTI:
            return iter([])
        else:
            return
    start = datetime.now()
    try:
        return self.__execute_sql(*args, **kwargs)
    finally:
        d = (datetime.now() - start)
        # TODO: make this more generalized. good enough for what we need now.
        # tries to find where the sql call was made from
        our_stack = [
            '{module}.{func} #{num}'.format(module=format_path(f[1]), num=f[2], func=f[3])
            for f in inspect.stack() if 'eventsquare' in f[1]
        ]

        if our_stack:
            q = ' -> '.join(our_stack) + ' | ' + q

        client.insert({'query': q, 'view': _get_current_view(), 'type': 'sql'},
                      {'time': 0.0 + d.seconds * 1000 + d.microseconds/1000, 'count': 1})
Ejemplo n.º 5
0
def instrumented_execute(self, *args, **kwargs):
    start = datetime.now()
    try:
        return self._real_execute(*args, **kwargs)
    finally:
        client = get_client()
        d = (datetime.now() - start)
        client.insert({'query' : args[0], 'view' : _get_current_view(),
                       'type' : 'sql'},
                      {'time' : 0.0 + d.seconds * 1000 + \
                       float(d.microseconds)/1000, 'count' : 1})
Ejemplo n.º 6
0
def instrumented_execute(self, *args, **kwargs):
    start = datetime.now()
    try:
        return self._real_execute(*args, **kwargs)
    finally:
        client = get_client()
        d = (datetime.now() - start)
        client.insert({'query' : args[0], 'view' : _get_current_view(),
                       'type' : 'sql'},
                      {'time' : 0.0 + d.seconds * 1000 + \
                       float(d.microseconds)/1000, 'count' : 1})
Ejemplo n.º 7
0
 def wrapper(self, *args, **kwargs):
     client = get_client()
     if client is None:
         return orig(self, *args, **kwargs)
     try:
         start = datetime.now()
         result = orig(self, *args, **kwargs)
         return result
     finally:
         d = datetime.now() - start
         # None return value is key to not log
         log_q = query(self, delay=d, *args, **kwargs) if callable(query) else query
         if log_q is not None:
             log_key = dict(query=log_q,
                         view=_get_current_view(),
                         type='mongo')
             log_val = dict(time=(0.0 + d.seconds * 1000 + d.microseconds/1000), count=1)
             client.insert(log_key, log_val)
def execute_sql(self, *args, **kwargs):
    client = get_client()
    if client is None:
        return self.__execute_sql(*args, **kwargs)
    try:
        q, params = self.as_sql()
        if not q:
            raise EmptyResultSet
    except EmptyResultSet:
        if kwargs.get('result_type', MULTI) == MULTI:
            return iter([])
        else:
            return
    start = datetime.now()
    try:
        return self.__execute_sql(*args, **kwargs)
    finally:
        d = (datetime.now() - start)
        client.insert({'query' : q, 'view' : _get_current_view(), 'type' : 'sql'},
                      {'time' : 0.0 + d.seconds * 1000 + d.microseconds/1000, 'count' : 1})
 def wrapper(self, *args, **kwargs):
     client = get_client()
     if client is None:
         return orig(self, *args, **kwargs)
     try:
         start = datetime.now()
         result = orig(self, *args, **kwargs)
         return result
     finally:
         d = datetime.now() - start
         # None return value is key to not log
         log_q = query(self, delay=d, *args, **
                       kwargs) if callable(query) else query
         if log_q is not None:
             log_key = dict(query=log_q,
                            view=_get_current_view(),
                            type='mongo')
             log_val = dict(time=(0.0 + d.seconds * 1000 +
                                  d.microseconds / 1000),
                            count=1)
             client.insert(log_key, log_val)
Ejemplo n.º 10
0
def execute_sql(self, *args, **kwargs):
    client = get_client()
    if client is None:
        return self.__execute_sql(*args, **kwargs)
    try:
        q, params = self.as_sql()
        if not q:
            raise EmptyResultSet
    except EmptyResultSet:
        if kwargs.get("result_type", MULTI) == MULTI:
            return iter([])
        else:
            return
    start = datetime.now()
    try:
        return self.__execute_sql(*args, **kwargs)
    finally:
        d = datetime.now() - start
        client.insert(
            {"query": q, "view": _get_current_view(), "type": "sql"},
            {"time": 0.0 + d.seconds * 1000 + d.microseconds / 1000, "count": 1},
        )