B ռʣ@slddlZddlZddlZdddgZGdddZdddZdd dZGd ddZd d Ze d krhedS)NrunrunctxProfilec@s,eZdZddZddZddZddZd S) _UtilscCs ||_dS)N)profiler)selfrr*/opt/alt/python37/lib/python3.7/profile.py__init__/sz_Utils.__init__c CsF|}z(y||Wntk r,YnXWd||||XdS)N)rr SystemExit_show)r statementfilenamesortprofrrr r2s  z _Utils.runc CsJ|}z,y||||Wntk r0YnXWd||||XdS)N)rrr r )rr globalslocalsrrrrrr r;s  z _Utils.runctxcCs"|dk r||n ||dS)N) dump_stats print_stats)rrrrrrr r Ds z _Utils._showN)__name__ __module__ __qualname__r rrr rrrr r)s  rcCstt|||S)N)rrr)r rrrrr rPs cCstt|||||S)N)rrr)r rrrrrrr r]sc@seZdZdZd3ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e e e e e e dZ ddZGdddZGdddZddZddZd4d!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd5d/d0Zd1d2ZdS)6rrNcCsi|_d|_d|_d|_|dkr&|j}||_|sHtj|_|_|j |_ nl||_|}y t |}Wn"t k r||_|j |_ Yn0X|dkr|j |_ n|j|_ |tfdd}||_||_|ddS)NcSs ||S)Nr)timersumrrr get_time_timersz(Profile.__init__..get_time_timerr)timingscurcmd c_func_namebiastimeZ process_timerget_timetrace_dispatch_i dispatcherlen TypeErrortrace_dispatchtrace_dispatch_lrt simulate_call)rrr"r+lengthrrrr r s0    zProfile.__init__cCs|j}|}|d|d|j|j}|dkr8|j|_|j||||rd|}|d|d|_n|}|d|d||_dS)Nrc_call)rr+r"rr!dispatch)rframeeventargrr+rrrr r)szProfile.trace_dispatchcCsT|j}||j|j}|dkr(|j|_|j||||rD||_n |||_dS)Nr/)rr+r"rr!r0)rr1r2r3rr+rrr r%s zProfile.trace_dispatch_icCs`|j}|d|j|j}|dkr,|j|_|j||||rL|d|_n|d||_dS)NgN@r/)rr+r"rr!r0)rr1r2r3rr+rrr trace_dispatch_macszProfile.trace_dispatch_maccCsT|j}||j|j}|dkr(|j|_|j||||rD||_n |||_dS)Nr/)r$r+r"rr!r0)rr1r2r3r$r+rrr r*s zProfile.trace_dispatch_lc CsD|j\}}}}}}||k r*|r*|||S|||||||f|_dS)Nr.)rtrace_dispatch_return) rr1r+rptritretrfnrframercurrrr 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| | <dS)Nrr.) rf_back isinstancer fake_framer6f_code co_filenameco_firstlinenoco_namer)rr1r+r7r8r9r:r;r<Zfcodefnrccnsttctcallersrrr trace_dispatch_calls  zProfile.trace_dispatch_callc Csndd|jf}|dd|||jf|_|j}||krX||\}}}}} ||d||| f||<nddddif||<dS)Nrrr.)r!rr) rr1r+rFrrGrHrIrJrKrrr trace_dispatch_c_calls zProfile.trace_dispatch_c_callcCs||jdk r ||jdd|j\}}}}}}||}||}|\} } } } } }| | || || | |f|_|j}||\}}}}}|s||}|d}| |kr|| d|| <nd|| <||d||||f||<dS)Nr>rr.)rr6r)rr1r+r7r8r9r:r<Z frame_totalZpptZpitZpetZpfnpframeZpcurrrGrHrIrJrKrrr r6!s"zProfile.trace_dispatch_return)callZ exceptionreturnr/Z c_exceptionZc_returncCs"|jdrdS||_||dS)Nr)rr r,)rr rrr set_cmdWs zProfile.set_cmdc@seZdZddZddZdS)zProfile.fake_codecCs||_||_||_d|_dS)Nr)rCco_linerErD)rrlinenamerrr r ]szProfile.fake_code.__init__cCst|j|j|jfS)N)reprrCrRrE)rrrr __repr__cszProfile.fake_code.__repr__N)rrrr rVrrrr fake_code\srWc@seZdZddZdS)zProfile.fake_framecCs||_||_dS)N)rBr?)rcodeZpriorrrr r gszProfile.fake_frame.__init__N)rrrr rrrr rAfsrAcCsF|dd|}|jr |jd}nd}|||}|jd||ddS)NZprofilerr>rO)rWrrAr0)rrTrXrNr1rrr r,ks   zProfile.simulate_callcCsN|j}||j}x*|jdr<|jd||jd|d}qW|||_dS)NrrPr>r)r$r+rr0)rr$r+rrr simulate_cmd_completews   zProfile.simulate_cmd_completercCs$ddl}|||dS)Nr)pstatsZStatsZ strip_dirsZ sort_statsr)rrrZrrr rszProfile.print_statsc Cs0t|d}|t|j|WdQRXdS)Nwb)open create_statsmarshaldumpstats)rfilefrrr rs zProfile.dump_statscCs||dS)N)rYsnapshot_stats)rrrr r]szProfile.create_statsc Csfi|_xZ|jD]L\}\}}}}}|}d}x|D] }||7}q:W|||||f|j|<qWdS)Nr)r`ritemscopyvalues) rfuncrGrHrIrJrKZncZcallcntrrr rcs zProfile.snapshot_statscCsddl}|j}||||S)Nr)__main____dict__r)rr rhdictrrr rsz Profile.runc Cs8||t|jzt|||WdtdX|S)N)rQsys setprofiler&exec)rr rrrrr rs    zProfile.runctxc Ost|dkr|^}}}n>|s&tdn0d|krB|d}|^}}ntdt|d|t|t|jz |||StdXdS)Nrz:descriptor 'runcall' of 'Profile' object needs an argumentrgz7runcall expected at least 1 positional argument, got %dr.)r'r(poprQrUrkrlr&)argskwrrgrrr runcalls       zProfile.runcallcCs8|jtk rtd|j}d|_z |||S||_XdS)Nz&Subclasses must override .calibrate().r) __class__rr(r"_calibrate_inner)rmverboseZ saved_biasrrr calibrates  zProfile.calibratecCs"|j}dd}|fdd}|||}|||}||}|rLtd|t} |}| dtt|}||} |rtd| d} d} x>| jD]0\\} }}\}}}}}|d kr| |7} | |7} qW|rtd | td | | |d krtd | | |d| }|rtd||S)NcSsxt|D]}d}q WdS)Nr.)range)nixrrr f1sz$Profile._calibrate_inner..f1cSsxt|D] }|dq WdS)Nd)rw)rtr{ryrrr rbsz#Profile._calibrate_inner..fz elapsed time without profiling =zf(m)zelapsed time with profiling =g)rbr{z!'CPU seconds' profiler reported =ztotal # calls =r.z internal error: total calls = %dg@z+mean stopwatch overhead per profile event =) r$printrrrrrrd ValueError)rrtrur$r{rbZt0Zt1Zelapsed_noprofilepZelapsed_profileZ total_callsZ reported_timerrSfuncnamerGrHrIrJrKZmeanrrr rssB   "      zProfile._calibrate_inner)NN)r)r)rrrr"r r)r%r5r*r=rLrMr6r0rQrWrAr,rYrrr]rcrrrqrvrsrrrr rfs<' ' '      = c Cs ddl}ddlm}d}||d}d|_|jdddd dd |jd d d ddd tjddsp|td| \}}|tjdd<t |dkr|d}tj d|j |t|d}t||d}WdQRX|dddd} t|| d|j|jn||S)Nr) OptionParserz?profile.py [-o output_file_path] [-s sort] scriptfile [arg] ...)usageFz-oz --outfileoutfilezSave stats to )desthelpdefaultz-sz--sortrz?Sort order when printing to stdout, based on pstats.Stats classrr.rrbrmrh)__file__r __package__ __cached__)osZoptparserZallow_interspersed_argsZ add_optionrkargv print_usageexit parse_argsr'pathinsertdirnamer\compilereadrrr) rrrparseroptionsroZprognamefprXZglobsrrr main4s6         rrh)Nr)Nr) rkr#r^__all__rrrrrrrrrr s ' Q%