def profile(file, globals_obj, locals_obj, profdll): global profiler, pyprofdll pyprofdll = ctypes.PyDLL(profdll) pyprofdll.CreateProfiler.restype = ctypes.c_void_p pyprofdll.CloseThread.argtypes = [ctypes.c_void_p] pyprofdll.CloseProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.restype = ctypes.c_void_p profiler = pyprofdll.CreateProfiler(ctypes.c_void_p(sys.dllhandle)) if not profiler: raise NotImplementedError("Profiling is currently not supported for " + sys.version) handle = None try: if sys.version_info[0] >= 3: # execfile's not available, and we want to start profiling # after we've compiled the users code. f = srcopen(file) try: code = compile(f.read(), file, 'exec') finally: f.close() handle = start_profiling() exec(code, globals_obj, locals_obj) else: handle = start_profiling() execfile(file, globals_obj, locals_obj) finally: if handle: pyprofdll.CloseThread(handle) pyprofdll.CloseProfiler(profiler)
def profile(file, globals_obj, locals_obj, profdll): global profiler, pyprofdll pyprofdll = ctypes.PyDLL(profdll) pyprofdll.CreateProfiler.restype = ctypes.c_void_p pyprofdll.CloseThread.argtypes = [ctypes.c_void_p] pyprofdll.CloseProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.restype = ctypes.c_void_p profiler = pyprofdll.CreateProfiler(sys.dllhandle) if not profiler: raise NotImplementedError("Profiling is currently not supported for " + sys.version) handle = None try: if sys.version_info[0] >= 3: # execfile's not available, and we want to start profiling # after we've compiled the users code. f = srcopen(file) try: code = compile(f.read(), file, 'exec') finally: f.close() handle = start_profiling() exec(code, globals_obj, locals_obj) else: handle = start_profiling() execfile(file, globals_obj, locals_obj) finally: if handle: pyprofdll.CloseThread(handle) pyprofdll.CloseProfiler(profiler)
def profile(file, globals_obj, locals_obj, profdll, custprofdllname=None): global profiler, pyprofdll if custprofdllname: custprofdll = ctypes.windll.LoadLibrary(custprofdllname) if not custprofdll: raise OSError("Failed to load %s" % custprofdllname) filename = os.path.basename(custprofdll) custprofhandle = ctypes.kernel32.GetModuleHandleA(filename) if not custprofhandle: raise OSError("Failed to get handle for %s" % filename) else: custprofhandle = None pyprofdll = ctypes.PyDLL(profdll) pyprofdll.CreateProfiler.restype = ctypes.c_void_p pyprofdll.CreateCustomProfiler.restype = ctypes.c_void_p pyprofdll.CreateCustomProfiler.argtypes = [ctypes.c_void_p, ctypes.c_void_p] pyprofdll.CloseThread.argtypes = [ctypes.c_void_p] pyprofdll.CloseProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.restype = ctypes.c_void_p if custprofhandle: profiler = pyprofdll.CreateCustomProfiler(custprofhandle, sys.dllhandle) else: profiler = pyprofdll.CreateProfiler(sys.dllhandle) if not profiler: raise NotImplementedError("Profiling is currently not supported for " + sys.version) handle = None try: if sys.version_info[0] >= 3: # execfile's not available, and we want to start profiling # after we've compiled the users code. f = srcopen(file) try: code = compile(f.read(), file, 'exec') finally: f.close() handle = start_profiling() exec(code, globals_obj, locals_obj) else: handle = start_profiling() execfile(file, globals_obj, locals_obj) finally: if handle: pyprofdll.CloseThread(handle) pyprofdll.CloseProfiler(profiler)
def profile(file, globals_obj, locals_obj, profdll, custprofdllname=None): global profiler, pyprofdll if custprofdllname: custprofdll = ctypes.windll.LoadLibrary(custprofdllname) if not custprofdll: raise OSError("Failed to load %s" % custprofdllname) filename = os.path.basename(custprofdll) custprofhandle = ctypes.kernel32.GetModuleHandleA(filename) if not custprofhandle: raise OSError("Failed to get handle for %s" % filename) else: custprofhandle = None pyprofdll = ctypes.PyDLL(profdll) pyprofdll.CreateProfiler.restype = ctypes.c_void_p pyprofdll.CreateCustomProfiler.restype = ctypes.c_void_p pyprofdll.CreateCustomProfiler.argtypes = [ctypes.c_void_p, ctypes.c_void_p] pyprofdll.CloseThread.argtypes = [ctypes.c_void_p] pyprofdll.CloseProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.argtypes = [ctypes.c_void_p] pyprofdll.InitProfiler.restype = ctypes.c_void_p pyprofdll.SetTracing.argtypes = [ctypes.c_void_p] pyprofdll.UnsetTracing.argtypes = [ctypes.c_void_p] pyprofdll.IsTracing.argtypes = [ctypes.c_void_p] pyprofdll.IsTracing.restype = ctypes.c_bool pyprofdll.Debugbreak if custprofhandle: profiler = pyprofdll.CreateCustomProfiler(custprofhandle, sys.dllhandle) else: profiler = pyprofdll.CreateProfiler(sys.dllhandle) import pdb pdb.set_trace() if 'VSPYPROF_DEBUGBREAK_ON_START' in os.environ: pyprofdll.Debugbreak() if 'VSPYPROF_TRACE' in os.environ: pyprofdll.SetTracing(profiler) if not profiler: raise NotImplementedError("Profiling is currently not supported for " + sys.version) handle = None try: if sys.version_info[0] >= 3: # execfile's not available, and we want to start profiling # after we've compiled the users code. f = srcopen(file) try: code = compile(f.read(), file, 'exec') finally: f.close() handle = start_profiling() exec(code, globals_obj, locals_obj) else: handle = start_profiling() execfile(file, globals_obj, locals_obj) finally: if handle: pyprofdll.CloseThread(handle) pyprofdll.CloseProfiler(profiler)