U if\@stddlZddlZddlZddlZdddgZGdddZdddZdd dZGd ddZd d Z e d krpe dS)NrunrunctxProfilec@s,eZdZddZddZddZddZd S) _UtilscCs ||_dSN)profiler)selfrr ,/opt/alt/python38/lib64/python3.8/profile.py__init__0sz_Utils.__init__c CsF|}z(z||Wntk r,YnXW5||||XdSr)r_showr SystemExit)r statementfilenamesortprofr r r r3s  z _Utils.runc CsJ|}z,z||||Wntk r0YnXW5||||XdSr)rr rr )rrglobalslocalsrrrr r r r<s  z _Utils.runctxcCs"|dk r||n ||dSr) dump_stats print_stats)rrrrr r r r Es z _Utils._showN)__name__ __module__ __qualname__r rrr r r r r r*s  rcCstt|||Sr)rrr)rrrr r r rQs cCstt|||||Sr)rrr)rrrrrr r r r^sc@seZdZdZd4ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e e e e e e dZ ddZGdddZGdddZddZddZd5d!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/e_d6d0d1Zd2d3ZdS)7rrNcCsi|_d|_d|_d|_|dkr&|j}||_|sHtj|_|_|j |_ nl||_|}z t |}Wn"t k r||_|j |_ Yn0X|dkr|j |_ n|j|_ |tfdd}||_||_|ddS)NcSs ||Srr )timersumr r r get_time_timersz(Profile.__init__..get_time_timerr)timingscurcmd c_func_namebiastime process_timerget_timetrace_dispatch_i dispatcherlen TypeErrortrace_dispatchtrace_dispatch_lrt simulate_call)rrr#r-Zlengthrr r r r s0    zProfile.__init__cCs|j}|}|d|d|j|j}|dkr8|j|_|j||||rd|}|d|d|_n|}|d|d||_dS)Nrc_callrr-r#rr"dispatch)rframeeventargrr-rr r r r+szProfile.trace_dispatchcCsT|j}||j|j}|dkr(|j|_|j||||rD||_n |||_dSNr0r1rr3r4r5rr-r r r r's zProfile.trace_dispatch_icCs`|j}|d|j|j}|dkr,|j|_|j||||rL|d|_n|d||_dS)NgN@r0r1r8r r r trace_dispatch_macszProfile.trace_dispatch_maccCsT|j}||j|j}|dkr(|j|_|j||||rD||_n |||_dSr7)r&r-r#rr"r2)rr3r4r5r&r-r r r r,s zProfile.trace_dispatch_lc CsD|j\}}}}}}||k r*|r*|||S|||||||f|_dSNr/)r trace_dispatch_return) rr3r-rptritretrfnrframercurr r r trace_dispatch_exceptions   z Profile.trace_dispatch_exceptioncCs|jr@|j|jdk r@|j\}}}}}}t|tjs@||d|j} | j| j| j f} |dd| ||jf|_|j } | | kr| | \} } }}}| | d|||f| | <nddddif| | <dSNrr/) r f_back isinstancer fake_framer;f_code co_filenameco_firstlinenoco_namer)rr3r-r<r=r>r?r@rAZfcodefnrccnsttctcallersr r r trace_dispatch_calls  zProfile.trace_dispatch_callc Csndd|jf}|dd|||jf|_|j}||krX||\}}}}} ||d||| f||<nddddif||<dS)Nrrr/)r"r r) rr3r-rLrrMrNrOrPrQr r r trace_dispatch_c_calls zProfile.trace_dispatch_c_callcCs||jdk r ||jdd|j\}}}}}}||}||}|\} } } } } }| | || || | |f|_|j}||\}}}}}|s||}|d}| |kr|| d|| <nd|| <||d||||f||<dSrC)r r;r)rr3r-r<r=r>r?rAZ frame_totalZpptZpitZpetZpfnpframeZpcurrrMrNrOrPrQr r r r;"s"zProfile.trace_dispatch_return)callZ exceptionreturnr0Z c_exceptionZc_returncCs"|jdrdS||_||dS)Nr)r r!r.)rr!r r r set_cmdXs zProfile.set_cmdc@seZdZddZddZdS)zProfile.fake_codecCs||_||_||_d|_dSNr)rIco_linerKrJ)rrlinenamer r r r ^szProfile.fake_code.__init__cCst|j|j|jfSr)reprrIrYrKrr r r __repr__dszProfile.fake_code.__repr__N)rrrr r^r r r r fake_code]sr_c@seZdZddZdS)zProfile.fake_framecCs||_||_dSr)rHrE)rcodeZpriorr r r r hszProfile.fake_frame.__init__N)rrrr r r r r rGgsrGcCsF|dd|}|jr |jd}nd}|||}|jd||ddS)NZprofilerrDrU)r_r rGr2)rr[r`rTr3r r r r.ls   zProfile.simulate_callcCsJ|j}||j}|jdr:|jd||jd|d}q|||_dS)NrrVrDr)r&r-r r2)rr&r-r r r simulate_cmd_completexs   zProfile.simulate_cmd_completercCs$ddl}|||dSrX)pstatsZStatsZ strip_dirsZ sort_statsr)rrrbr r r rszProfile.print_statsc Cs0t|d}|t|j|W5QRXdS)Nwb)open create_statsmarshaldumpstats)rfilefr r r rs zProfile.dump_statscCs||dSr)rasnapshot_statsr]r r r reszProfile.create_statsc Cs^i|_|jD]H\}\}}}}}|}d}|D] }||7}q6|||||f|j|<qdSrX)rhritemscopyvalues) rfuncrMrNrOrPrQZncZcallcntr r r rks  zProfile.snapshot_statscCsddl}|j}||||SrX)__main____dict__r)rr!rpdictr r r rsz Profile.runc Cs8||t|jzt|||W5tdX|Sr)rWsys setprofiler(exec)rr!rrr r r rs    zProfile.runctxc Ost|dkr|^}}}nV|s&tdnHd|krZ|d}|^}}ddl}|jdtddntdt|d|t|t |j z|||WSt dXdS) Nrz:descriptor 'runcall' of 'Profile' object needs an argumentrorz0Passing 'func' as keyword argument is deprecated) stacklevelz7runcall expected at least 1 positional argument, got %dr/) r)r*popwarningswarnDeprecationWarningrWr\rsrtr()argskwrrorxr r r runcalls(      zProfile.runcallz($self, func, /, *args, **kw)cCs<|jtk rtd|j}d|_z|||WS||_XdS)Nz&Subclasses must override .calibrate().r) __class__rr*r#_calibrate_inner)rmverboseZ saved_biasr r r calibrates zProfile.calibratecCs|j}dd}|fdd}|||}|||}||}|rLtd|t} |}| dtt|}||} |rtd| d} d} | jD]0\\} }}\}}}}}|d kr| |7} | |7} q|rtd | td | | |d krtd | | |d| }|rtd||S)NcSst|D]}d}qdSr:range)nixr r r f1s z$Profile._calibrate_inner..f1cSst|D] }|dqdS)Ndr)rrrr r r rjs z#Profile._calibrate_inner..fz elapsed time without profiling =zf(m)zelapsed time with profiling =g)rjrz!'CPU seconds' profiler reported =ztotal # calls =r/z internal error: total calls = %dg@z+mean stopwatch overhead per profile event =) r&printrrrrrrl ValueError)rrrr&rrjZt0t1Zelapsed_noprofilepZelapsed_profileZ total_callsZ reported_timerrZfuncnamerMrNrOrPrQZmeanr r r rsB         zProfile._calibrate_inner)NN)r)r)rrrr#r r+r'r9r,rBrRrSr;r2rWr_rGr.rarrrerkrrr}__text_signature__rrr r r r rgs@' ' '     + c Csddl}ddlm}d}||d}d|_|jdddd dd |jd d d ddd|jdddddd tjdds|td| \}}|tjdd<|j dk r|j |j |_ t |dkr|jrddl}d}|j|dd}nR|d} tj d|j | t| } t| | d}W5QRX| dddd}zt||d|j |jWn6tk r} zdt_t| jW5d} ~ XYnXn||S)Nr) OptionParserzMprofile.py [-o output_file_path] [-s sort] [-m module | scriptfile] [arg] ...)usageFz-oz --outfileoutfilezSave stats to )desthelpdefaultz-mmodule store_truezProfile a library module.)ractionrrz-sz--sortrz?Sort order when printing to stdout, based on pstats.Stats classrr/rz(run_module(modname, run_name='__main__')) run_modulemodnamerurp)__file__r __package__ __cached__)osZoptparserZallow_interspersed_argsZ add_optionrsargvZ print_usageexit parse_argsrpathabspathr)rrunpyrinsertdirnameio open_codecompilereadrrBrokenPipeErrorstdouterrno) rrrparserZoptionsr{rr`ZglobsZprognamefpexcr r r main9s^          rrp)Nr)Nr) rrsr$rf__all__rrrrrrr r r r s ' U9