Beispiel #1
0
def thread_profiler(frame, event, arg):
    global _state
    assert _state, "Global variable '_state' not set"

    now = clock()  # measure once and reuse it

    current_greenlet = greenlet.getcurrent()  # pylint: disable=no-member
    current_state = ensure_thread_state(current_greenlet, frame)

    if _state.last != current_state:
        current_state.context_switch += 1
        _state.last = current_state

    if event in ("c_call", "c_return", "c_exception"):
        # The frame is of the python callee
        call = {
            "function": arg.__name__,
            "module": arg.__module__ or "__builtin__",
            "lineno": "",
            "abs_path": "",
            "filename": "",
            "runtime_id": id(arg),
        }
    else:
        call = get_trace_info(frame)

    if event in ("call", "c_call"):
        current_state.call_enter(call, now)
    elif event in ("return", "c_return", "c_exception"):
        current_state.call_exit(call, now)

    return thread_profiler
Beispiel #2
0
def thread_profiler(frame, event, arg):
    global _state

    now = clock()  # measure once and reuse it

    current_greenlet = greenlet.getcurrent()  # pylint: disable=no-member
    current_state = ensure_thread_state(current_greenlet, frame)

    if _state.last != current_state:
        current_state.context_switch += 1
        _state.last = current_state

    if event in ('c_call', 'c_return', 'c_exception'):
        # The frame is of the python callee
        call = {
            'function': arg.__name__,
            'module': arg.__module__ or '__builtin__',
            'lineno': '',
            'abs_path': '',
            'filename': '',
            'runtime_id': id(arg),
        }
    else:
        call = get_trace_info(frame)

    if event in ('call', 'c_call'):
        current_state.call_enter(call, now)
    elif event in ('return', 'c_return', 'c_exception'):
        current_state.call_exit(call, now)

    return thread_profiler
Beispiel #3
0
def thread_profiler(frame, event, arg):
    global _state

    now = clock()  # measure once and reuse it

    current_greenlet = greenlet.getcurrent()  # pylint: disable=no-member
    current_state = ensure_thread_state(current_greenlet, frame)

    if _state.last != current_state:
        current_state.context_switch += 1
        _state.last = current_state

    if event in ('c_call', 'c_return', 'c_exception'):
        # The frame is of the python callee
        call = {
            'function': arg.__name__,
            'module': arg.__module__ or '__builtin__',
            'lineno': '',
            'abs_path': '',
            'filename': '',
            'runtime_id': id(arg),
        }
    else:
        call = get_trace_info(frame)

    if event in ('call', 'c_call'):
        current_state.call_enter(call, now)
    elif event in ('return', 'c_return', 'c_exception'):
        current_state.call_exit(call, now)

    return thread_profiler