Ñò
§ÚêLc
@ sV d Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d d d g Z e d d „ Z e d „ Z
d
„ Z e i d j o d d k
Z
e
i d „ Z n e e d
ƒ o e i d „ Z n d Z y+ d d k Z d „ Z e d „ Z d Z Wn e j
o n Xd f d „ ƒ YZ d „ Z d „ Z e d j o e ƒ n d S( s Class for profiling Python code.iÿÿÿÿN( t OptionParsert runt runctxt helpt Profilec C sa t ƒ } y | i | ƒ } Wn t j
o n X| d j o | i | ƒ n | i | ƒ Sd S( s Run statement under profiler optionally saving results in filename
This function takes a single argument that can be passed to the
"exec" statement, and an optional file name. In all cases this
routine attempts to "exec" its first argument and gather profiling
statistics from the execution. If no file name is present, then this
function automatically prints a simple profiling report, sorted by the
standard name string (file/line/function-name) that is presented in
each line.
N( R R t
SystemExitt Nonet
dump_statst print_stats( t statementt filenamet sortt prof( ( s /usr/lib64/python2.6/profile.pyR 9 s
c C sd t ƒ } y | i | | | ƒ } Wn t j
o n X| d j o | i | ƒ n | i ƒ Sd S( s· Run statement under profiler, supplying your own globals and locals,
optionally saving results in filename.
statement and filename have the same semantics as profile.run
N( R R R R R R ( R t globalst localsR
R ( ( s /usr/lib64/python2.6/profile.pyR N s
c C s d GHd GHd S( Ns2 Documentation for the profile module can be found s? in the Python Library Reference, section 'The Python Profiler'.( ( ( ( s /usr/lib64/python2.6/profile.pyR ` s t macc C s | ƒ d S( Ng N@( ( t timer( ( s /usr/lib64/python2.6/profile.pyt
_get_time_macf s t timesc C s | ƒ } | d | d S( Ni i ( ( R t t( ( s /usr/lib64/python2.6/profile.pyt _get_time_timesj s i c C s t i t i ƒ S( ( t resourcet getrusaget RUSAGE_SELF( ( ( s /usr/lib64/python2.6/profile.pyt u s c C s | ƒ } | d | d S( Ni i ( ( R R ( ( s /usr/lib64/python2.6/profile.pyt _get_time_resourcev s i c B s3 e Z d Z d Z d" d" d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z
d „ Z d „ Z d
„ Z
h e d 6e
d 6e
d
6e d 6e
d 6e
d 6Z d „ Z d d# d „ ƒ YZ d d$ d „ ƒ YZ d „ Z d „ Z d d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d d „ Z d! „ Z RS(% s Profiler class.
self.cur is always a tuple. Each such tuple corresponds to a stack
frame that is currently active (self.cur[-2]). The following are the
definitions of its members. We use this external "parallel stack" to
avoid contaminating the program that we are profiling. (old profiler
used to write into the frames local dictionary!!) Derived classes
can change the definition of some entries, as long as they leave
[-2:] intact (frame and previous tuple). In case an internal error is
detected, the -3 element is used as the function name.
[ 0] = Time that needs to be charged to the parent frame's function.
It is used so that a function call will not have to access the
timing data for the parent frame.
[ 1] = Total time spent in this frame's function, excluding time in
subfunctions (this latter is tallied in cur[2]).
[ 2] = Total time spent in subfunctions, excluding time executing the
frame's function (this latter is tallied in cur[1]).
[-3] = Name of the function that corresponds to this frame.
[-2] = Actual frame that we correspond to (used to sync exception handling).
[-1] = Our parent 6-tuple (corresponds to frame.f_back).
Timing data for each function is stored as a 5-tuple in the dictionary
self.timings[]. The index is always the name stored in self.cur[-3].
The following are the definitions of the members:
[0] = The number of times this function was called, not counting direct
or indirect recursion,
[1] = Number of times this function appears on the stack, minus one
[2] = Total time spent internal to this function
[3] = Cumulative time that this function was present on the stack. In
non-recursive functions, this is the total execution time from start
to finish of each invocation of a function, including time spent in
all subfunctions.
[4] = A dictionary indicating for each function name, the number of times
it was called by us.
i c C sè h | _ d | _ d | _ d | _ | d j o
| i } n | | _ | pé t o" t | _ | i | _
t | _ qÈt
i d j o% t i | _ | i | _
t | _ qÈt t d ƒ o# t i | _ | _ | i | _
qÈt t
d ƒ o% t
i | _ | i | _
t | _ qÈt i | _ | _ | i | _
n’ | | _ | i ƒ } y t | ƒ } Wn( t j
o | | _ | i | _
nC X| d j o | i | _
n
| i | _
| t d „ } | | _ | i ƒ | _ | i d ƒ d S( Nt R t clockR i c S s
| | ƒ ƒ S( N( ( R t sum( ( s /usr/lib64/python2.6/profile.pyt get_time_timerÕ s t profiler( t timingsR t curt cmdt c_func_namet biast _has_rest resgetrusageR t trace_dispatcht
dispatcherR t get_timet ost namet MacOSt GetTickst trace_dispatch_macR t hasattrt timeR t trace_dispatch_iR R t lent TypeErrort trace_dispatch_lR R t
simulate_call( t selfR R# R t lengthR ( ( s /usr/lib64/python2.6/profile.pyt __init__¦ sN
c C s± | i } | ƒ } | d | d | i | i } | d j o | i | _ n | i | | | | ƒ o" | ƒ } | d | d | _ n# | ƒ } | d | d | | _ d S( Ni i t c_call( R R R# t __name__R" t dispatch( R5 t framet eventt argR R t r( ( s /usr/lib64/python2.6/profile.pyR&