Skip to content

Commit 5e8f0aa

Browse files
committed
-
1 parent 3b6537e commit 5e8f0aa

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

python_toolbox/cute_profile/cute_profile.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def profile(statement, globals_, locals_):
2525
except SystemExit:
2626
pass
2727
profile_.create_stats()
28-
profile_result = marshal.dumps(self.stats, f)
28+
profile_result = marshal.dumps(profile_.stats)
2929
return profile_result
3030

3131

3232
def profile_expression(expression, globals_, locals_):
33-
profile_result = profile('result = %s' % expression, globals(), locals())
33+
profile_result = profile('result = %s' % expression, globals_, locals_)
3434
return (locals()['result'], profile_result)
3535

3636

@@ -98,15 +98,9 @@ def inner(function_, *args, **kwargs):
9898
'decorated_function.original_function(*args, **kwargs)',
9999
globals(), locals()
100100
)
101-
102-
103-
profile_handler = \
104-
profile_handling.get_profile_handler(profile_handler)
105-
106-
profile_handler(profile_result)
107-
108-
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.
109101

102+
decorated_function.profile_handler(profile_result)
103+
110104
return result
111105

112106
else: # decorated_function.profiling_on is False
@@ -119,7 +113,8 @@ def inner(function_, *args, **kwargs):
119113
decorated_function.profiling_on = None
120114
decorated_function.condition = condition
121115
decorated_function.off_after = off_after
122-
decorated_function.sort = sort
116+
decorated_function.profile_handler = \
117+
profile_handling.get_profile_handler(profile_handler)
123118

124119
return decorated_function
125120

python_toolbox/cute_profile/profile_handling.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import threading
55
import datetime as datetime_module
6+
import abc
67
import os.path
78
import pstats
89

@@ -93,15 +94,16 @@ def __call__(self, profile_data):
9394

9495

9596
def get_profile_handler(profile_handler_string):
96-
if misc_tools.is_legal_email_address(profile_handler_string.split('\n')
97-
[0]):
98-
return EmailProfileHandler(*profile_handler_string.split('\n'))
99-
elif os.path.isdir(profile_handler_string):
100-
return FolderProfileHandler(profile_handler_string)
101-
else:
102-
assert profile_handler_string == '' or int(profile_handler_string)
97+
if not profile_handler_string or profile_handler_string in \
98+
map(str, range(-1, 5)):
10399
try:
104100
sort_order = int(profile_handler_string)
105-
except ValueError:
101+
except (ValueError, TypeError):
106102
sort_order = -1
107-
return PrintProfileHandler(sort_order)
103+
return PrintProfileHandler(sort_order)
104+
elif misc_tools.is_legal_email_address(profile_handler_string.split('\n')
105+
[0]):
106+
return EmailProfileHandler(*profile_handler_string.split('\n'))
107+
else:
108+
assert os.path.isdir(profile_handler_string)
109+
return FolderProfileHandler(profile_handler_string)

0 commit comments

Comments
 (0)