File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from asyncio import coroutine , iscoroutinefunction
2+ from contextlib import contextmanager
3+ from functools import wraps
4+
5+ from memory_profiler import LineProfiler , show_results
6+
7+
8+ class CoroLineProfiler (LineProfiler ):
9+ @contextmanager
10+ def count_contextmgr (self ):
11+ self .enable_by_count ()
12+ try :
13+ yield
14+ finally :
15+ self .disable_by_count ()
16+
17+ def wrap_function (self , func ):
18+ if iscoroutinefunction (func ):
19+ @coroutine
20+ def f (* args , ** kwargs ):
21+ with self .count_contextmgr ():
22+ yield from func (* args , ** kwargs )
23+ return f
24+ else :
25+ return super (CoroLineProfiler , self ).wrap_function (func )
26+
27+
28+ def _get_coro_wrapper (coro , backend , stream , precision ):
29+ @wraps (coro )
30+ @coroutine
31+ def wrapper (* args , ** kwargs ):
32+ prof = CoroLineProfiler (backend = backend )
33+ val = yield from prof (coro )(* args , ** kwargs )
34+ show_results (prof , stream = stream , precision = precision )
35+ return val
You can’t perform that action at this time.
0 commit comments