ó EŃŐfc@s$dZddlZddlZddlZddlZddlmZddddgZedd„Z edd „Z d „Z e ed ƒr ej d „Znd Zy+ddlZd„Zed„ZdZWnek ränXdfd„ƒYZd„Zd„Zedkr eƒndS(s Class for profiling Python code.i˙˙˙˙N(t OptionParsertruntrunctxthelptProfilecCs]tƒ}y|j|ƒ}Wntk r/nX|dk rL|j|ƒn |j|ƒ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.7/profile.pyR0s   cCsctƒ}y|j|||ƒ}Wntk r5nX|dk rR|j|ƒn |j|ƒ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 R ((s/usr/lib64/python2.7/profile.pyREs   cCsdGHdGHdS(Ns2Documentation for the profile module can be found s?in the Python Library Reference, section 'The Python Profiler'.((((s/usr/lib64/python2.7/profile.pyRWsttimescCs|ƒ}|d|dS(Nii((ttimertt((s/usr/lib64/python2.7/profile.pyt_get_time_times\s icCstjtjƒS(N(tresourcet getrusaget RUSAGE_SELF(((s/usr/lib64/python2.7/profile.pytgscCs|ƒ}|d|dS(Nii((RR((s/usr/lib64/python2.7/profile.pyt_get_time_resourcehs icBs3eZdZdZd"d"d„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z ie 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Ľi|_d|_d|_d|_|dkr<|j}n||_|sřtrrt|_|j |_ t |_ q…t tdƒrŁtj|_|_ |j|_ q…t tdƒrÖtj|_|j |_ t|_ q…tj|_|_ |j|_ n||_|jƒ}yt|ƒ}Wn&tk rE||_ |j|_ n@X|dkra|j |_ n |j|_ |td„}||_ |j ƒ|_|jdƒdS(NttclockRicSs ||ƒƒS(N((Rtsum((s/usr/lib64/python2.7/profile.pytget_time_timerĂstprofiler(ttimingsRtcurtcmdt c_func_nametbiast_has_rest resgetrusageRttrace_dispatcht dispatcherRtget_timethasattrttimeRttrace_dispatch_itosRRtlent TypeErrorttrace_dispatch_lRRt simulate_call(tselfRR!RtlengthR((s/usr/lib64/python2.7/profile.pyt__init__˜sF                    cCs­|j}|ƒ}|d|d|j|j}|dkrM|j|_n|j||||ƒr‡|ƒ}|d|d|_n"|ƒ}|d|d||_dS(Niitc_call(RRR!t__name__R tdispatch(R/tframeteventtargRRtr((s/usr/lib64/python2.7/profile.pyR$Ës      cCsw|j}|ƒ|j|j}|dkr;|j|_n|j||||ƒrc|ƒ|_n|ƒ||_dS(NR2(RRR!R3R R4(R/R5R6R7RR((s/usr/lib64/python2.7/profile.pyR)Ýs  cCsƒ|j}|ƒd|j|j}|dkr?|j|_n|j||||ƒrk|ƒd|_n|ƒd||_dS(NgN@R2(RRR!R3R R4(R/R5R6R7RR((s/usr/lib64/python2.7/profile.pyttrace_dispatch_macěs  cCsw|j}|ƒ|j|j}|dkr;|j|_n|j||||ƒrc|ƒ|_n|ƒ||_dS(NR2(R&RR!R3R R4(R/R5R6R7R&R((s/usr/lib64/python2.7/profile.pyR-ús  c Cs`|j\}}}}}}||k r=|r=|j||ƒS|||||||f|_dS(Ni(Rttrace_dispatch_return( R/R5Rtrpttrittrettrfntrframetrcur((s/usr/lib64/python2.7/profile.pyttrace_dispatch_exception s cCs |jrb|j|jdk rb|j\}}}}}}t|tjƒsb|j|dƒqbn|j} | j| j| j f} |dd| ||jf|_|j } | | krď| | \} } }}}| | d|||f| | R?R@tfcodetfnRtcctnsttttcttcallers((s/usr/lib64/python2.7/profile.pyttrace_dispatch_calls    c Cs›dd|jf}|dd|||jf|_|j}||kr~||\}}}}} ||d||| f||R@t frame_totaltppttpittpettpfntpframetpcurRRKRLRMRNRO((s/usr/lib64/python2.7/profile.pyR:6s"  #     !tcallt exceptiontreturnR2t c_exceptiontc_returncCs+|jdrdS||_|j|ƒdS(Ni˙˙˙˙(RRR.(R/R((s/usr/lib64/python2.7/profile.pytset_cmdls  t fake_codecBseZd„Zd„ZRS(cCs(||_||_||_d|_dS(Ni(RFtco_lineRHRG(R/R tlinetname((s/usr/lib64/python2.7/profile.pyR1rs   cCst|j|j|jfƒS(N(treprRFR`RH(R/((s/usr/lib64/python2.7/profile.pyt__repr__xs(R3t __module__R1Rd(((s/usr/lib64/python2.7/profile.pyR_qs RDcBseZd„ZRS(cCs||_||_dS(N(RERB(R/tcodetprior((s/usr/lib64/python2.7/profile.pyR1|s (R3ReR1(((s/usr/lib64/python2.7/profile.pyRD{scCsa|jdd|ƒ}|jr.|jd}nd}|j||ƒ}|jd||dƒdS(Ntprofileiiţ˙˙˙RY(R_RRRDR4(R/RbRfRWR5((s/usr/lib64/python2.7/profile.pyR.€s  cCse|j}|ƒ|j}x5|jdrP|jd||jd|ƒd}qW|ƒ||_dS(Ni˙˙˙˙R[iţ˙˙˙i(R&RRR4(R/R&R((s/usr/lib64/python2.7/profile.pytsimulate_cmd_completeŒs   i˙˙˙˙cCs2ddl}|j|ƒjƒj|ƒjƒdS(Ni˙˙˙˙(tpstatstStatst strip_dirst sort_statsR(R/R Rj((s/usr/lib64/python2.7/profile.pyR—s cCs:t|dƒ}|jƒtj|j|ƒ|jƒdS(Ntwb(topent create_statstmarshaltdumptstatstclose(R/tfiletf((s/usr/lib64/python2.7/profile.pyRœs cCs|jƒ|jƒdS(N(Ritsnapshot_stats(R/((s/usr/lib64/python2.7/profile.pyRp˘s c Cs‹i|_x{|jjƒD]j\}\}}}}}|jƒ}d}x|jƒD]}||7}qSW|||||f|j|tdefaults-ss--sortR s?Sort order when printing to stdout, based on pstats.Stats classi˙˙˙˙iiitrbtexect__file__R~R3t __package__(RtFalsetallow_interspersed_argst add_optionRRtargvt print_usagetexitt parse_argsR+tpathtinsertR*tdirnameRotcompiletreadRRŸR (RtparsertoptionsRƒtprognametfpRftglobs((s/usr/lib64/python2.7/profile.pytmain@s2        R~(RœRR*R(RqtoptparseRt__all__RRRRR'RRR"RR#Rt ImportErrorRRkRśR3(((s/usr/lib64/python2.7/profile.pyt s2          ˙Ď  !