Ńň §ÚęLc @sVdZddkZddkZddkZddkZddklZddddgZedd„Z ed „Z d „Z ei d joddk Z e id „Zneed ƒoeid„ZndZy+ddkZd„Zed„ZdZWnej onXdfd„ƒYZd„Zd„Zedjo eƒndS(s Class for profiling Python code.i˙˙˙˙N(t OptionParsertruntrunctxthelptProfilecCsatƒ}y|i|ƒ}Wntj onX|dj o|i|ƒn|i|ƒSdS(sRun 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(RRt SystemExittNonet dump_statst print_stats(t statementtfilenametsorttprof((s/usr/lib64/python2.6/profile.pyR9s  cCsdtƒ}y|i|||ƒ}Wntj onX|dj o|i|ƒn |iƒSdS(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(RRRRRR(R tglobalstlocalsR R ((s/usr/lib64/python2.6/profile.pyRNs  cCsdGHdGHdS(Ns2Documentation for the profile module can be found s?in the Python Library Reference, section 'The Python Profiler'.((((s/usr/lib64/python2.6/profile.pyR`stmaccCs |ƒdS(NgN@((ttimer((s/usr/lib64/python2.6/profile.pyt _get_time_macfsttimescCs|ƒ}|d|dS(Nii((Rtt((s/usr/lib64/python2.6/profile.pyt_get_time_timesjs icCstitiƒS((tresourcet getrusaget RUSAGE_SELF(((s/usr/lib64/python2.6/profile.pytuscCs|ƒ}|d|dS(Nii((RR((s/usr/lib64/python2.6/profile.pyt_get_time_resourcevs icBs3eZdZdZd"d"d„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z he d 6e d 6e d 6e d6e d6e d6Zd„Zdd#d„ƒYZdd$d„ƒYZd„Zd„Zdd„Zd„Zd„Zd„Zd„Zd„Zd„Zdd „Zd!„ZRS(%sProfiler 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. icCsčh|_d|_d|_d|_|djo |i}n||_|péto"t|_|i |_ t |_ qČt idjo%ti|_|i|_ t|_ qČttdƒo#ti|_|_ |i|_ qČtt dƒo%t i|_|i |_ t|_ qČti|_|_ |i|_ n’||_|iƒ}yt|ƒ}Wn(tj o||_ |i|_ nCX|djo|i |_ n |i|_ |td„}||_ |i ƒ|_|idƒdS(NtRtclockRicSs ||ƒƒS(N((Rtsum((s/usr/lib64/python2.6/profile.pytget_time_timerŐstprofiler(ttimingsRtcurtcmdt c_func_nametbiast_has_rest resgetrusageRttrace_dispatcht dispatcherRtget_timetostnametMacOStGetTicksttrace_dispatch_macRthasattrttimeRttrace_dispatch_iRRtlent TypeErrorttrace_dispatch_lRRt simulate_call(tselfRR#RtlengthR((s/usr/lib64/python2.6/profile.pyt__init__ŚsN                      cCsą|i}|ƒ}|d|d|i|i}|djo|i|_n|i||||ƒo"|ƒ}|d|d|_n#|ƒ}|d|d||_dS(Niitc_call(RRR#t__name__R"tdispatch(R5tframeteventtargRRtr((s/usr/lib64/python2.6/profile.pyR&Ýs      cCs{|i}|ƒ|i|i}|djo|i|_n|i||||ƒo|ƒ|_n|ƒ||_dS(NR8(RRR#R9R"R:(R5R;R<R=RR((s/usr/lib64/python2.6/profile.pyR0ďs  cCs‡|i}|ƒd|i|i}|djo|i|_n|i||||ƒo|ƒd|_n|ƒd||_dS(NgN@R8(RRR#R9R"R:(R5R;R<R=RR((s/usr/lib64/python2.6/profile.pyR-ţs  cCs{|i}|ƒ|i|i}|djo|i|_n|i||||ƒo|ƒ|_n|ƒ||_dS(NR8(R(RR#R9R"R:(R5R;R<R=R(R((s/usr/lib64/python2.6/profile.pyR3 s  c Csc|i\}}}}}}||j o|o|i||ƒS|||||||f|_dS(Ni(R ttrace_dispatch_return( R5R;Rtrpttrittrettrfntrframetrcur((s/usr/lib64/python2.6/profile.pyttrace_dispatch_exceptions cCs†|ioĐ|i|idj oš|i\}}}}}}t|tiƒp‡|i|ijp"td|||i||if‚|i|dƒ|idjp.|i|idjptd|idf‚qÚn|i} | i | i | i f} |dd| ||if|_|i } | | jo:| | \} } }}}| | d|||f| | tdefaults-ss--sortR s?Sort order when printing to stdout, based on pstats.Stats classi˙˙˙˙iiis execfile(%r)(RtFalsetallow_interspersed_argst add_optionRR†targvt print_usagetexitt parse_argsR1tpathtinsertR)tdirnameRR¤R (R˘tparsertoptionsRˆ((s/usr/lib64/python2.6/profile.pytmainRs"     &( Rƒ(RĄR†R)R/RvtoptparseRt__all__RRRRR*R+R,RR.RRR$RR%Rt ImportErrorRRpR˛R9(((s/usr/lib64/python2.6/profile.pyts8           ˙Ó