From a6e074f74bcff92aef358d7a6ce4221616f8226d Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 25 Sep 2009 02:12:53 -0700 Subject: [PATCH] Turn of profiling by default, rename macro. --- Cython/Compiler/Nodes.py | 33 +++++++++++++++------------------ Cython/Compiler/Options.py | 4 ++-- tests/bugs.txt | 2 +- tests/run/profile_test.pyx | 6 +++--- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 17e63c89..a1abe76a 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1062,14 +1062,11 @@ class FuncDefNode(StatNode, BlockNode): is_getbuffer_slot = (self.entry.name == "__getbuffer__" and self.entry.scope.is_c_class_scope) - if code.globalstate.directives['profile'] is None: - profile = 'inline' not in self.modifiers and not lenv.nogil - else: - profile = code.globalstate.directives['profile'] - if profile and lenv.nogil: - error(self.pos, "Cannot profile nogil function.") + profile = code.globalstate.directives['profile'] if profile: - code.globalstate.use_utility_code(trace_utility_code) + if lenv.nogil: + error(self.pos, "Cannot profile nogil function.") + code.globalstate.use_utility_code(profile_utility_code) # Generate C code for header and body of function code.enter_cfunc_scope() @@ -5791,22 +5788,22 @@ proto=""" # Note that cPython ignores PyTrace_EXCEPTION, # but maybe some other profilers don't. -trace_utility_code = UtilityCode(proto=""" -#ifndef CYTHON_TRACING -#define CYTHON_TRACING 1 +profile_utility_code = UtilityCode(proto=""" +#ifndef CYTHON_PROFILE +#define CYTHON_PROFILE 1 #endif -#ifndef CYTHON_TRACING_REUSE_FRAME -#define CYTHON_TRACING_REUSE_FRAME 0 +#ifndef CYTHON_PROFILE_REUSE_FRAME +#define CYTHON_PROFILE_REUSE_FRAME 0 #endif -#if CYTHON_TRACING +#if CYTHON_PROFILE #include "compile.h" #include "frameobject.h" #include "traceback.h" -#if CYTHON_TRACING_REUSE_FRAME +#if CYTHON_PROFILE_REUSE_FRAME #define CYTHON_FRAME_MODIFIER static #define CYTHON_FRAME_DEL #else @@ -5846,7 +5843,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, c #define __Pyx_TraceCall(funcname, srcfile, firstlineno) #define __Pyx_TraceException() #define __Pyx_TraceReturn(result) -#endif /* CYTHON_TRACING */ +#endif /* CYTHON_PROFILE */ """ % { "FRAME": Naming.frame_cname, @@ -5854,14 +5851,14 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, c }, impl = """ -#if CYTHON_TRACING +#if CYTHON_PROFILE static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno) { - if (*frame == NULL || !CYTHON_TRACING_REUSE_FRAME) { + if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) { if (*code == NULL) { *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno); if (*code == NULL) return 0; @@ -5921,7 +5918,7 @@ bad: return py_code; } -#endif /* CYTHON_TRACING */ +#endif /* CYTHON_PROFILE */ """ % { 'EMPTY_TUPLE' : Naming.empty_tuple, 'EMPTY_BYTES' : Naming.empty_bytes, diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 60a2cab0..869a26c3 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -67,11 +67,11 @@ option_defaults = { 'wraparound' : True, 'c99_complex' : False, # Don't use macro wrappers for complex arith, not sure what to name this... 'callspec' : "", - 'profile': None, + 'profile': False, } # Override types possibilities above, if needed -option_types = { 'profile': bool } +option_types = {} for key, val in option_defaults.items(): if key not in option_types: diff --git a/tests/bugs.txt b/tests/bugs.txt index 2d1b21b8..e7c4b586 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -13,4 +13,4 @@ bad_c_struct_T252 missing_baseclass_in_predecl_T262 # Not yet enabled -profile_test +# profile_test diff --git a/tests/run/profile_test.pyx b/tests/run/profile_test.pyx index db433a5e..f231b3e7 100644 --- a/tests/run/profile_test.pyx +++ b/tests/run/profile_test.pyx @@ -1,3 +1,5 @@ +# cython: profile = True + __doc__ = u""" >>> import os, tempfile, cProfile as profile, pstats >>> statsfile = tempfile.mkstemp()[1] @@ -9,9 +11,7 @@ __doc__ = u""" >>> short_stats['f_cdef'] 100 >>> short_stats['f_inline'] - Traceback (most recent call last): - ... - KeyError: 'f_inline' + 100 >>> short_stats['f_inline_prof'] 100 >>> short_stats['f_noprof'] -- 2.26.2