^cD"ddlZddlmZddlmZmZddlmZmZm Z mZm Z dZ ej dZ ej dZej d ZGd d ZdS) N)_)getattropen)encodingerror extensionspycompatutilc|}tj||g tj|}t|ddS#t$rYdSwxYw)zBload profiler extension. return profile method, or None on failure) whitelistprofileN)r loadallfindrKeyError)uiprofilerextnamemods 5/usr/lib/python3/dist-packages/mercurial/profiling.py _loadprofilerrskGrgY////-og&&sIt,,, ttsA A Ac#K|dd}|dd}|dd}|dd}|dvr'|td|zd} d d lm}n/#t $r"tjtd wxYw| }| d  dV| |dkr2d dlm }| |} | |dS||} | t%j|| |||dS#| |dkr1d dlm }| |} | |w||} | t%j|| |||wxYw)N profilingsformatssortslimitsnested)text kcachegrinds-unrecognized profiling format '%s' - Ignored rr)lsprofsYlsprof not available - install from http://codespeak.net/svn/user/arigo/hack/misc/lsprof/T)subcallsr)lsprofcalltree)limitfileclimit)config configintwarnrr ImportErrorrAbortProfilerenabledisabler KCacheGrindoutputStatsgetstatssortr sysstrpprint) rfpformatfieldrr!rprcalltreestatss r lsprofiler8%sf YY|Y / /F IIlG , ,E LLx 0 0E \\, 2 2F ... CDDvMNNN     k I       AHHdH>  ^ # # ( ( ( ( ( (%11!44H OOB     LL..E JJxu-- . . . LLu2fL = = = = = ^ # # ( ( ( ( ( (%11!44H OOB    LL..E JJxu-- . . . LLu2fL = = = =sB,B:(F B3Ic # K ddlm}n/#t$r"tjt dwxYw|dd}d}d}||d|z ||}tj} | dV| | tdtj|z | | d fzdS#| | tdtj|z | | d fzwxYw) Nr) flamegraphsWflamegraph not available - install from https://github.com/evanhempel/python-flamegraphrfreqTg?s7Collected %d stack frames (%d unique) in %2.2f seconds.)unique)r:r&rr'rr# ProfileThreadr timerstartstopjoinprint num_frames)rr2r:freqfilter_collapse_recursionthread start_times r flameprofilerILs )))))))    k C       << g . .DG  % % C$J!3FJ       F z)!!##!!!..          F z)!!##!!!..     s ,7DA9F c#|Kddlm}|dd}|dkr&|jjdkr||n%|td|z|ddtj rdpd }| d |  dV| }|dd }|j j|j j|j j|j j|j jd }||vr ||}n1|td|z|j j}i} d} |dkrG|| ddd} || dd} | | | n>|dkr8|| ddd} | | d<|dd}|| d<|j|f||d| dS#| }|dd }|j j|j j|j j|j j|j jd }||vr ||}n1|td|z|j j}i} d} |dkrG|| ddd} || dd} | | | n>|dkr8|| ddd} | | d<|dd}|| d<|j|f||d| wxYw)Nr)statprofrr;rs+invalid sampling frequency '%s' - ignoring s time-trackscpusrealsthread) mechanismtracks statformat)sbylinesbymethodhotpathsjsonchromes#unknown profiler output format: %s ct|ttfrt|S|drt|dddz }nt|}d|cxkrdkrnn|St |)N%drr) isinstancefloatintendswith ValueError)svs rfractionzstatprofile..fractions!eS\** Qxxzz$ !CRC&MMC'!HHA{{{{{{{{{Q-- rOsshowming{Gzt?sshowmax) minthreshold maxthresholdrNg?rsshowtimeshowtime)datar3)r%rKr#state profile_levelresetr$rr"r iswindowsr?r@DisplayFormatsByLineByMethodHotpathJsonChrome configwithupdate configbooldisplay)rr2rKrDrMr` profformatformats displayformatkwargsr[showminshowmaxrr_s r statprofileruos << g . .D axx > '1 , , NN4  ABBTIJJJ IImX%7%BF%Mg  E NNYeN444-H }}YY|];;  .5!09 /7,1.5     #J/MM GGA=>>K L L L$3;M   " "mmHlJNNGmmHlJGGG MMwWM E E E E : % %MM(L*dKKE#F7O}}\;??H!)F: G$}GGGGGGGU}}YY|];;  .5!09 /7,1.5     #J/MM GGA=>>K L L L$3;M   " "mmHlJNNGmmHlJGGG MMwWM E E E E : % %MM(L*dKKE#F7O}}\;??H!)F: G$}GGGGGGs -G66EL;c8eZdZdZd dZdZdZdZdZdZ d S) rzStart profiling. Profiling is active when the context manager is active. When the context manager exits, profiling results will be written to the configured output. Tc||_d|_d|_d|_d|_d|_||_d|_d|_dS)NTF) _ui_output_fp _fpdoclose_flushfp _profiler_enabled_entered_started)selfrenableds r__init__zprofile.__init__sE     r\cJd|_|jr||S)NT)rr~r?rs r __enter__zprofile.__enter__s% =  JJLLL r\c|jstjd|jrdSd|_tjd}d}||jdd}|dvrCt|j|}|,|j td|zd }|jdd |_ |j d krtj|_n|j r/tj|j }t#|d |_n_t$jr*Gd d}d|_||j|_n)d|_|jj|_|jj|_|n#|dkrt0}n|dkrt2}nt4}||j|j|_|jdS#|xYw)zStart profiling. The profiling will stop at the context exit. If the profiler was already started, this has no effect.suse a context manager to startNTsHGPROFrstype)lsstatflames%unrecognized profiler '%s' - ignored rsoutputblackboxswbc eZdZdZdZdZdS)profile.start..uifpc||_dSN)rx)rrs rrz$profile.start..uifp.__init__s #%r\c:|j|dSr)rx write_err)rr`s rwritez!profile.start..uifp.writes**400000r\c8|jdSr)rxflushrs rrz!profile.start..uifp.flushs(((((r\N)__name__ __module__ __qualname__rrrr\ruifprsA&&&111)))))r\rFrr)rrProgrammingErrorrrenvirongetrxr"rr$rryr stringiorz expandpathrr rdr{ferrfoutr|r8rIrur}r_closefp)rrproffnpathrs rr?z profile.starts  } L()JKK K =  F #'' 22  x|W==H 5 5 5"48X66F~ ?@@8K#x|Y?? ' |{**=?? .t|44e,,# .))))))))#(4>>"'8= $  !U"""X%%%$#VDHdh77DN N $ $ & & & & &  MMOOO s DG''G>cPd}|j||j|||}|jdkrMd|jz}|dd}|jd|| |S)Nrs Profile: %srQs%%sprofile) r}_uiflush__exit__ryrzgetvaluereplacerxlogr)rexception_typeexception_value traceback propagatevals rrzprofile.__exit__ s > % MMOOO//I|{**%(9(9(;(;;kk$.. Z--- r\c\|jr"|j|jdSdSdSr)r{rzclosers rrzprofile._closefps; ? tx3 HNN       33r\cJ|jr|jdSdSr)r|rrs rrzprofile._uiflushs0 = " M   ! ! ! ! ! " "r\N)T) rrr__doc__rrr?rrrrr\rrrs     AAAF """""r\r) contextlibi18nrr rrr%rrr r rcontextmanagerr8rIrurrr\rrsA - - - #>#>#>L    D =H=H=H@q"q"q"q"q"q"q"q"q"q"r\