Example #1
0
 def record_stats(self, stats):
     toolbar = DebugToolbarMiddleware.get_current()
     panel_stats = toolbar.stats.get(self.slug)
     if panel_stats:
         panel_stats.update(stats)
     else:
         toolbar.stats[self.slug] = stats
Example #2
0
 def record_stats(self, stats):
     toolbar = DebugToolbarMiddleware.get_current()
     panel_stats = toolbar.stats.get(self.slug)
     if panel_stats:
         panel_stats.update(stats)
     else:
         toolbar.stats[self.slug] = stats
Example #3
0
def execute_command(func,self,*args,**options):

    command = args[0]
    start = datetime.now()
    result = func(self,*args,**options)

    stop = datetime.now()
    duration = ms_from_timedelta(stop - start)

    #TODO find more better way to get the calling func info
    calframe = _get_func_info()

    params = {
        'func':calframe[4][3],
        'func_path':"{}:{}".format(calframe[4][1],calframe[4][2]),
        'command':command,
        'result':result,
        'start_time':start,
        'stop_time':stop,
        'duration':duration,
        'is_slow':None,

    }

    #TODO more better way to loggging?
    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result
    logger = djdt.get_panel(RedisDebugPanel)
    logger.record(**params)

    return result
def cursor(func, self):
    result = func(self)

    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result

    return CursorWrapper(result, self, logger=_logger())
Example #5
0
def cursor(func, self):
    result = func(self)

    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result
    logger = djdt.get_panel(SQLDebugPanel)

    return CursorWrapper(result, self, logger=logger)
Example #6
0
def cursor(func, self):
    result = func(self)

    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result
    logger = djdt.get_panel(SQLDebugPanel)
    
    return CursorWrapper(result, self, logger=logger)
 def record_stats(self, stats):
     # import locally to work around recursive imports
     from debug_toolbar.middleware import DebugToolbarMiddleware
     toolbar = DebugToolbarMiddleware.get_current()
     panel_stats = toolbar.stats.get(self.slug)
     if panel_stats:
         panel_stats.update(stats)
     else:
         toolbar.stats[self.slug] = stats
def record(func, *args, **kwargs):
    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return func(*args, **kwargs)

    panel = djdt.get_panel(BasePanel)

    # Get stacktrace
    if ENABLE_STACKTRACES:
        stacktrace = tidy_stacktrace(reversed(get_stack()))
    else:
        stacktrace = []

    # Get template info
    template_info = None
    cur_frame = sys._getframe().f_back
    try:
        while cur_frame is not None:
            if cur_frame.f_code.co_name == 'render':
                node = cur_frame.f_locals['self']
                if isinstance(node, Node):
                    template_info = get_template_info(node.source)
                    break
            cur_frame = cur_frame.f_back
    except:
        pass
    del cur_frame

    # Find args
    cache_args = None
    # first arg is self, do we have another
    if len(args) > 1:
        cache_args = args[1]
        # is it a dictionary (most likely multi)
        if isinstance(cache_args, dict):
            # just use it's keys
            cache_args = cache_args.keys()

    # the clock starts now
    start = datetime.now()
    try:
        return func(*args, **kwargs)
    finally:
        # the clock stops now
        duration = ms_from_timedelta(datetime.now() - start)
        call = {
            'function': func.__name__,
            'args': cache_args,
            'duration': duration,
            'stacktrace': stacktrace,
            'template_info': template_info,
        }
        panel.record(**call)
Example #9
0
def record(func, *args, **kwargs):
    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return func(*args, **kwargs)

    panel = djdt.get_panel(BasePanel)

    # Get stacktrace
    if ENABLE_STACKTRACES:
        stacktrace = tidy_stacktrace(reversed(get_stack()))
    else:
        stacktrace = []

    # Get template info
    template_info = None
    cur_frame = sys._getframe().f_back
    try:
        while cur_frame is not None:
            if cur_frame.f_code.co_name == 'render':
                node = cur_frame.f_locals['self']
                if isinstance(node, Node):
                    template_info = get_template_info(node.source)
                    break
            cur_frame = cur_frame.f_back
    except:
        pass
    del cur_frame

    # Find args
    cache_args = None
    # first arg is self, do we have another
    if len(args) > 1:
        cache_args = args[1]
        # is it a dictionary (most likely multi)
        if isinstance(cache_args, dict):
            # just use it's keys
            cache_args = cache_args.keys()

    # the clock starts now
    start = datetime.now()
    try:
        return func(*args, **kwargs)
    finally:
        # the clock stops now
        duration = ms_from_timedelta(datetime.now() - start)
        call = {
            'function': func.__name__,
            'args': cache_args,
            'duration': duration,
            'stacktrace': stacktrace,
            'template_info': template_info,
        }
        panel.record(**call)
Example #10
0
 def get_stats(self):
     toolbar = DebugToolbarMiddleware.get_current()
     return toolbar.stats.get(self.slug, {})
 def get_stats(self):
     # import locally to work around recursive imports
     from debug_toolbar.middleware import DebugToolbarMiddleware
     toolbar = DebugToolbarMiddleware.get_current()
     return toolbar.stats.get(self.slug, {})
Example #12
0
 def get_stats(self):
     toolbar = DebugToolbarMiddleware.get_current()
     return toolbar.stats.get(self.slug, {})