Beispiel #1
0
def _trace_data(start, obj, cmd, vids, **kwargs):
    if not _get_trace_local():
        return None

    if not _trace_check_limits(obj, cmd, vids):
        return None

    elapse = time.time() - start

    if not coro.has_local(CORO_LOCAL_TDATA):
        coro.set_local(CORO_LOCAL_TDATA, {})
        
    data = coro.get_local(CORO_LOCAL_TDATA)
    data = data.setdefault(obj, {})

    look = not isinstance(vids, (list, tuple)) and 1 or len(vids)

    data[cmd] = sum_tuple(data.get(cmd, (0, 0, 0)), (elapse, look, 1))

    if _get_trace_local() > ACCESS_TRACE_DEBUG:
        stack = pyinfo.rawstack()
        stack = stack[:-5] # remove 5 levels of mod_python, publisher
        while stack and stack[0][0].startswith('access'):
            stack.pop(0)
        stack = ' @ %s' % '|'.join(['%s:%s:%s' % x for x in stack])
    else:
        stack = ''

    if _get_trace_local() < ACCESS_TRACE_DEBUG:
        return None

    print 'Access | %.4f | obj: %s cmd: %s vid: %s args: %s kwargs: %s%s' % (
        elapse, obj, cmd, vids,
        kwargs.get('args', ()), kwargs.get('kwargs', {}),
        stack)
Beispiel #2
0
    def _save_info(self, o):
        '''_save_info

        When an item is fetched from the queue, save information about
        the item request and the requester.
        '''
        data    = {'caller': pyinfo.rawstack(depth = 2), 'time':   time.time()}
        current = coro.current_thread()

        if current is not None:
            data.update({'thread': current.thread_id()})
            current.trace(True)

        self._item_save[id(o)] = data
        return o