MCPcopy Index your code
hub / github.com/pythonprofilers/memory_profiler / exec_with_profiler

Function exec_with_profiler

memory_profiler.py:1234–1255  ·  view source on GitHub ↗
(filename, profiler, backend, passed_args=[])

Source from the content-addressed store, hash-verified

1232# for all cases, e.g. a script that imports another
1233# script where @profile is used)
1234def exec_with_profiler(filename, profiler, backend, passed_args=[]):
1235 from runpy import run_module
1236 builtins.__dict__['profile'] = profiler
1237 ns = dict(_CLEAN_GLOBALS,
1238 profile=profiler,
1239 # Make sure the __file__ variable is usable
1240 # by the script we're profiling
1241 __file__=filename)
1242 # Make sure the script's directory in on sys.path
1243 # credit to line_profiler
1244 sys.path.insert(0, os.path.dirname(script_filename))
1245
1246 _backend = choose_backend(backend)
1247 sys.argv = [filename] + passed_args
1248 try:
1249 if _backend == 'tracemalloc' and has_tracemalloc:
1250 tracemalloc.start()
1251 with io.open(filename, encoding='utf-8') as f:
1252 exec(compile(f.read(), filename, 'exec'), ns, ns)
1253 finally:
1254 if has_tracemalloc and tracemalloc.is_tracing():
1255 tracemalloc.stop()
1256
1257
1258def run_module_with_profiler(module, profiler, backend, passed_args=[]):

Callers 1

memory_profiler.pyFile · 0.85

Calls 1

choose_backendFunction · 0.85

Tested by

no test coverage detected