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

Function profile

memory_profiler.py:1163–1198  ·  view source on GitHub ↗

Decorator that will run the function and print a line-by-line profile

(func=None, stream=None, precision=1, backend='psutil')

Source from the content-addressed store, hash-verified

1161
1162
1163def profile(func=None, stream=None, precision=1, backend='psutil'):
1164 """
1165 Decorator that will run the function and print a line-by-line profile
1166 """
1167 backend = choose_backend(backend)
1168 if backend == 'tracemalloc' and has_tracemalloc:
1169 if not tracemalloc.is_tracing():
1170 tracemalloc.start()
1171 if func is not None:
1172 get_prof = partial(LineProfiler, backend=backend)
1173 show_results_bound = partial(
1174 show_results, stream=stream, precision=precision
1175 )
1176 if iscoroutinefunction(func):
1177 @wraps(wrapped=func)
1178 @coroutine
1179 def wrapper(*args, **kwargs):
1180 prof = get_prof()
1181 val = yield from prof(func)(*args, **kwargs)
1182 show_results_bound(prof)
1183 return val
1184 else:
1185 @wraps(wrapped=func)
1186 def wrapper(*args, **kwargs):
1187 prof = get_prof()
1188 val = prof(func)(*args, **kwargs)
1189 show_results_bound(prof)
1190 return val
1191
1192 return wrapper
1193 else:
1194 def inner_wrapper(f):
1195 return profile(f, stream=stream, precision=precision,
1196 backend=backend)
1197
1198 return inner_wrapper
1199
1200
1201def choose_backend(new_backend=None):

Callers 3

mprunMethod · 0.85
inner_wrapperFunction · 0.85
test_mprofile.pyFile · 0.85

Calls 1

choose_backendFunction · 0.85

Tested by

no test coverage detected