diff options
author | Fred Drake <fdrake@acm.org> | 2001-10-04 14:48:42 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-10-04 14:48:42 (GMT) |
commit | 8f51f54319fdf1511d080785a73a331489775e8f (patch) | |
tree | c15d40e53c2f75d2f37df4b551375d2d1918e405 /Python | |
parent | c4b09b4417a41163eb0c0f7df985d6b39ea1f552 (diff) | |
download | cpython-8f51f54319fdf1511d080785a73a331489775e8f.zip cpython-8f51f54319fdf1511d080785a73a331489775e8f.tar.gz cpython-8f51f54319fdf1511d080785a73a331489775e8f.tar.bz2 |
Rationalize the events passed to the profiler (no changes for the tracer).
The profiler does not need to know anything about the exception state,
so we no longer call it when an exception is raised. We do, however,
make sure we *always* call the profiler when we exit a frame. This
ensures that timing events are more easily isolated by a profiler and
finally clauses that do a lot of work don't have their time
mis-allocated.
When an exception is propogated out of the frame, the C callback for
the profiler now receives a PyTrace_RETURN event with an arg of NULL;
the Python-level profile hook function will see a 'return' event with
an arg of None. This means that from Python it is impossible for the
profiler to determine if the frame exited with an exception or if it
returned None, but this doesn't matter for profiling. A C-based
profiler could tell the difference, but this doesn't seem important.
ceval.c:eval_frame(): Simplify the code in two places so that the
profiler is called for every exit from a frame
and not for exceptions.
sysmodule.c:profile_trampoline(): Make sure we don't expose Python
code to NULL; use None instead.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 14 | ||||
-rw-r--r-- | Python/sysmodule.c | 2 |
2 files changed, 6 insertions, 10 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 132fb72..99822e8 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2198,14 +2198,9 @@ eval_frame(PyFrameObject *f) f->f_lasti -= 2; PyTraceBack_Here(f); - if (tstate->use_tracing) { - if (tstate->c_tracefunc) - call_exc_trace(tstate->c_tracefunc, - tstate->c_traceobj, f); - if (tstate->c_profilefunc) - call_exc_trace(tstate->c_profilefunc, - tstate->c_profileobj,f); - } + if (tstate->c_tracefunc != NULL) + call_exc_trace(tstate->c_tracefunc, + tstate->c_traceobj, f); } /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */ @@ -2301,8 +2296,7 @@ eval_frame(PyFrameObject *f) why = WHY_EXCEPTION; } } - if (tstate->c_profilefunc - && (why == WHY_RETURN || why == WHY_YIELD)) { + if (tstate->c_profilefunc) { if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, f, PyTrace_RETURN, retval)) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 82d2999..deead3a 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -260,6 +260,8 @@ profile_trampoline(PyObject *self, PyFrameObject *frame, PyThreadState *tstate = frame->f_tstate; PyObject *result; + if (arg == NULL) + arg = Py_None; result = call_trampoline(tstate, self, frame, what, arg); if (result == NULL) { PyEval_SetProfile(NULL, NULL); |