1818
1919
2020def profile (statement , globals_ , locals_ ):
21+ '''Profile a statement and return the `Profile`.'''
2122 profile_ = base_profile .Profile ()
2223 result = None
2324 try :
@@ -29,13 +30,13 @@ def profile(statement, globals_, locals_):
2930
3031
3132def profile_expression (expression , globals_ , locals_ ):
33+ '''Profile an expression, and return a tuple of `(result, profile)`.'''
3234 profile_ = profile ('result = %s' % expression , globals_ , locals_ )
3335 return (locals_ ['result' ], profile_ )
3436
3537
3638def profile_ready (condition = None , off_after = True , profile_handler = None ):
3739 '''
38- blocktododoc
3940 Decorator for setting a function to be ready for profiling.
4041
4142 For example:
@@ -50,6 +51,8 @@ def f(x, y):
5051
5152 2. You can set the function to be profiled *when* you want, on the fly.
5253
54+ 3. You can have the profile results handled in various useful ways.
55+
5356 How can you set the function to be profiled? There are a few ways:
5457
5558 You can set `f.profiling_on=True` for the function to be profiled on the
@@ -65,7 +68,18 @@ def f(x, y):
6568 turned off afterwards as well. (Unless, again, `f.off_after` is set to
6669 `False`.)
6770
68- `sort` is an `int` specifying which column the results will be sorted by.
71+ Using `profile_handler` you can say what will be done with profile results.
72+ If `profile_handler` is an `int`, the profile results will be printed, with
73+ the sort order determined by `profile_handler`. If `profile_handler` is a
74+ directory path, profiles will be saved to files in that directory. If
75+ `profile_handler` is details on how to send email, the profile will be sent
76+ as an attached file via email, on a separate thread.
77+
78+ To send email, supply a `profile_handler` like so, with values separated by
79+ newlines:
80+
81+ 'ram@rachum.com\n smtp.gmail.com\n smtp_username\n smtppassword'
82+
6983 '''
7084
7185
0 commit comments