ž Š˙fČSc@s´dZddlZddlZddlZddlZddlmZdddgZed dd„Z ed d d„Z Gd d„dƒZ d d „Z e d kr°e ƒndS(u Class for profiling Python code.iN(u OptionParserurunurunctxuProfileic Cs^tƒ}y|j|ƒ}Wntk r0YnX|dk rM|j|ƒn |j|ƒSdS(uRun 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(uProfileurunu SystemExituNoneu dump_statsu print_stats(u statementufilenameusortuprof((u,/opt/alt/python33/lib64/python3.3/profile.pyurun0s   c Csdtƒ}y|j|||ƒ}Wntk r6YnX|dk rS|j|ƒn |j|ƒSdS(uˇ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(uProfileurunctxu SystemExituNoneu dump_statsu print_stats(u statementuglobalsulocalsufilenameusortuprof((u,/opt/alt/python33/lib64/python3.3/profile.pyurunctxEs   cBs~|EeZdZdZdZd8d8dd„Zdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zie d6e d6ed6e d6ed6ed6Zdd„ZGdd„dƒZGdd „d ƒZd!d"„Zd#d$„Zd9d&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zdd4d5„Zd6d7„Zd8S(:uProfileuProfiler 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. ic Csi|_d|_d|_d|_|dkr<|j}n||_|smtj|_|_ |j |_ n‘||_|jƒ}yt |ƒ}Wn't k rť||_ |j |_ YnCX|dkr×|j|_ n |j|_ |tdd„}||_ |j ƒ|_|jdƒdS(NuicSs ||ƒƒS(N((utimerusum((u,/opt/alt/python33/lib64/python3.3/profile.pyuget_time_timeržsu(Profile.__init__..get_time_timeruprofiler(utimingsuNoneucurucmdu c_func_nameubiasutimeu process_timeutimeruget_timeutrace_dispatch_iu dispatcherulenu TypeErrorutrace_dispatchutrace_dispatch_lusumutu simulate_call(uselfutimerubiasutulengthuget_time_timer((u,/opt/alt/python33/lib64/python3.3/profile.pyu__init__s0              uProfile.__init__cCs­|j}|ƒ}|d|d|j|j}|dkrM|j|_n|j||||ƒr‡|ƒ}|d|d|_n"|ƒ}|d|d||_dS(Niiuc_call(utimerutubiasu__name__u c_func_nameudispatch(uselfuframeueventuargutimerutur((u,/opt/alt/python33/lib64/python3.3/profile.pyutrace_dispatchŚs      uProfile.trace_dispatchcCsw|j}|ƒ|j|j}|dkr;|j|_n|j||||ƒrc|ƒ|_n|ƒ||_dS(Nuc_call(utimerutubiasu__name__u c_func_nameudispatch(uselfuframeueventuargutimerut((u,/opt/alt/python33/lib64/python3.3/profile.pyutrace_dispatch_i¸s  uProfile.trace_dispatch_icCsƒ|j}|ƒd|j|j}|dkr?|j|_n|j||||ƒrk|ƒd|_n|ƒd||_dS(NgN@uc_call(utimerutubiasu__name__u c_func_nameudispatch(uselfuframeueventuargutimerut((u,/opt/alt/python33/lib64/python3.3/profile.pyutrace_dispatch_macÇs  uProfile.trace_dispatch_maccCsw|j}|ƒ|j|j}|dkr;|j|_n|j||||ƒrc|ƒ|_n|ƒ||_dS(Nuc_call(uget_timeutubiasu__name__u c_func_nameudispatch(uselfuframeueventuarguget_timeut((u,/opt/alt/python33/lib64/python3.3/profile.pyutrace_dispatch_lŐs  uProfile.trace_dispatch_lc Cs`|j\}}}}}}||k r=|r=|j||ƒS|||||||f|_dS(Ni(ucurutrace_dispatch_return( uselfuframeuturpturitureturfnurframeurcur((u,/opt/alt/python33/lib64/python3.3/profile.pyutrace_dispatch_exceptiončs u Profile.trace_dispatch_exceptioncCs€|jrÖ|j|jdk rÖ|j\}}}}}}t|tjƒsÖ|j|jks‚td|||j||jfƒ‚|j|dƒ|jdksÓ|j|jdksÓtd|jdfƒ‚qÖn|j} | j | j | j f} |dd| ||jf|_|j } | | krc| | \} } }}}| | d|||f| | .f1cSs%xt|ƒD]}|dƒq WdS(Nid(urange(umuf1ui((u,/opt/alt/python33/lib64/python3.3/profile.pyufćsu#Profile._calibrate_inner..fu elapsed time without profiling =uf(m)uelapsed time with profiling =gufuf1u!'CPU seconds' profiler reported =utotal # calls =iu internal error: total calls = %dg@u+mean stopwatch overhead per profile event =(ufuf1( uget_timeuprintuProfileurunctxuglobalsulocalsutimingsuitemsu ValueError(uselfumuverboseuget_timeuf1ufut0ut1uelapsed_noprofileupuelapsed_profileu total_callsu reported_timeufilenameulineufuncnameuccunsuttuctucallersumean((u,/opt/alt/python33/lib64/python3.3/profile.pyu_calibrate_innerŮsB           1   uProfile._calibrate_innerNi˙˙˙˙(u__name__u __module__u __qualname__u__doc__ubiasuNoneu__init__utrace_dispatchutrace_dispatch_iutrace_dispatch_macutrace_dispatch_lutrace_dispatch_exceptionutrace_dispatch_callutrace_dispatch_c_callutrace_dispatch_returnudispatchuset_cmdu fake_codeu fake_frameu simulate_callusimulate_cmd_completeu print_statsu dump_statsu create_statsusnapshot_statsurunurunctxuruncallu calibrateu_calibrate_inner(u __locals__((u,/opt/alt/python33/lib64/python3.3/profile.pyuProfileVs@%'       &       1 c Csnd}td|ƒ}d|_|jddddddd dƒ|jd d dd dd d dƒtjdd…s|jƒtjdƒn|j ƒ\}}|tjdd…udefaultu-su--sortusortu?Sort order when printing to stdout, based on pstats.Stats classiiiurbuexecu__file__u__main__u__name__u __package__u __cached__Fi˙˙˙˙(u OptionParseruFalseuallow_interspersed_argsu add_optionuNoneusysuargvu print_usageuexitu parse_argsulenupathuinsertuosudirnameuopenucompileureadurunctxuoutfileusort(uusageuparseruoptionsuargsuprognameufpucodeuglobs((u,/opt/alt/python33/lib64/python3.3/profile.pyumains4      umainu__main__(u__doc__usysuosutimeumarshaluoptparseu OptionParseru__all__uNoneurunurunctxuProfileumainu__name__(((u,/opt/alt/python33/lib64/python3.3/profile.pyu s    ˙Ä "