Skip to content

Commit c2dae08

Browse files
committed
-
1 parent 235f267 commit c2dae08

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

python_toolbox/cute_profile/cute_profile.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,33 @@
88
'''
99

1010
import functools
11+
import marshal
1112

1213
from python_toolbox import decorator_tools
1314

1415
from . import base_profile
1516

1617

17-
def profile_ready(condition=None, off_after=True, sort=2):
18+
def profile(statement, globals_, locals_):
19+
profile_ = base_profile.Profile()
20+
result = None
21+
try:
22+
profile_ = profile_.runctx(statement, globals_, locals_)
23+
except SystemExit:
24+
pass
25+
profile_.create_stats()
26+
profile_result = marshal.dumps(self.stats, f)
27+
return profile_result
28+
29+
30+
def profile_expression(expression, globals_, locals_):
31+
profile_result = profile('result = %s' % expression, globals(), locals())
32+
return (locals()['result'], profile_result)
33+
34+
35+
def profile_ready(condition=None, off_after=True, profile_handler=None):
1836
'''
37+
blocktododoc
1938
Decorator for setting a function to be ready for profiling.
2039
2140
For example:
@@ -73,12 +92,14 @@ def inner(function_, *args, **kwargs):
7392
# This line puts it in locals, weird:
7493
decorated_function.original_function
7594

76-
base_profile.runctx(
77-
'result = '
95+
result, profile_result = profile_expression(
7896
'decorated_function.original_function(*args, **kwargs)',
79-
globals(), locals(), sort=decorated_function.sort
80-
)
81-
return locals()['result']
97+
globals(), locals()
98+
)
99+
100+
Z Z Z Do shit depending on `profile_handler`. Allow filename, folder, email address, or index for printing (sort). In any case do everything on a thread.
101+
102+
return result
82103

83104
else: # decorated_function.profiling_on is False
84105

0 commit comments

Comments
 (0)