o ]Lb"@sddlmZmZddlZddlmZddlmZmZddl m Z m Z m Z mZm Z ddZejd d Zejd d Zejd dZGdddeZdS))absolute_importprint_functionN)_)getattropen)encodingerror extensionspycompatutilcCsD|}tj||gdzt|}Wn tyYdSwt|ddS)zBload profiler extension. return profile method, or None on failure) whitelistNprofile)r loadallfindKeyErrorr)uiprofilerextnamemodr5/usr/lib/python3/dist-packages/mercurial/profiling.py _loadprofilers  rc csd|dd}|dd}|dd}|dd}|dvr(|td|d}zd d lm}Wnty>ttd w| }|j d d z7dVW| |dkrhd dlm }| |} | |dS||} | t|| j|||ddS| |dkrd dlm }| |} | |w||} | t|| j|||dw)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 ImportErrorr AbortProfilerenabledisabler KCacheGrindoutputStatsgetstatssortr sysstrpprint) rfpformatfieldrr!rprcalltreestatsrrr lsprofile&sJ           r8c cszddlm}Wntyttdw|dd}d}d}||d|||}t}z%| dVW| | t dt|| |j dd fdS| | t dt|| |j dd fw) Nr) flamegraphsWflamegraph not available - install from https://github.com/evanhempel/python-flamegraphrfreqTg?s7Collected %d stack frames (%d unique) in %2.2f seconds.)unique)r9r&r r'rr# ProfileThreadr timerstartstopjoinprint num_frames)rr2r9freqfilter_collapse_recursionthread start_timerrr flameprofileMsP       rHc csjddlm}|dd}|dkr|jjdkr||n |td||ddt j r/dp0d }|j d |d zdVW| }|dd }|j j|j j|j j|j j|j jd }||vrc||}n |td||j j}i} dd} |dkr|| ddd} || dd} | j| | dn|dkr|| ddd} | | d<|dd}|| d<|j|f||d| dS| }|dd }|j j|j j|j j|j j|j jd }||vr||}n |td||j j}i} dd} |dkr || ddd} || dd} | j| | dn|dkr(|| ddd} | | d<|dd}|| d<|j|f||d| w)Nr)statprofrr:rs+invalid sampling frequency '%s' - ignoring s time-trackscpusrealsthread) mechanismtracks statformat)sbylinesbymethodhotpathsjsonchromes#unknown profiler output format: %s cSsft|ttfr t|S|drt|ddd}nt|}d|kr*dkr/|St|t|)N%drr) isinstancefloatintendswith ValueError)svrrrfractions zstatprofile..fractionrMsshowming{Gzt?sshowmax) minthreshold maxthresholdrLg?rsshowtimeshowtime)datar3)r%rIr#state profile_levelresetr$rr"r iswindowsr>r?DisplayFormatsByLineByMethodHotpathJsonChrome configwithupdate configbooldisplay)rr2rIrCrKr\ profformatformats displayformatkwargsrXshowminshowmaxrr[rrr statprofileps|             rqc@sBeZdZdZdddZddZddZd d Zd d Zd dZ dS)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. TcCs:||_d|_d|_d|_d|_d|_||_d|_d|_dS)NTF) _ui_output_fp _fpdoclose_flushfp _profiler_enabled_entered_started)selfrenabledrrr__init__s zprofile.__init__cCsd|_|jr ||S)NT)ryrxr>r{rrr __enter__szprofile.__enter__cCs`|jstd|jr dSd|_tjd}d}|dur#|jdd}|dvr=t |j|}|dur=|j t d|d }|jdd |_ zb|j d krQt |_n2|j rat |j }t|d |_n"tjrvGd ddt}d|_||j|_n d|_|jj|_|jj|_|durn|dkrt}n |dkrt}nt}||j|j|_|jWdS|)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@s$eZdZddZddZddZdS)zprofile.start..uifpcSs ||_dSN)rr)r{rrrrr}s z$profile.start..uifp.__init__cSs|j|dSr)rr write_err)r{r\rrrwritesz!profile.start..uifp.writecSs|jdSr)rrflushr~rrrrsz!profile.start..uifp.flushN)__name__ __module__ __qualname__r}rrrrrruifps rFrr)ryr ProgrammingErrorrzrenvirongetrrr"rr$rrsr stringiort expandpathrr r`objectruferrfoutrvr8rHrqrwr_closefp)r{rproffnpathrrrrr>sT          z profile.startcCsdd}|jdur,||j|||}|jdkr,d|j}|dd}|jd|| |S)Nrs Profile: %srNs%%sprofile) rw_uiflush__exit__rsrtgetvaluereplacerrlogr)r{exception_typeexception_value traceback propagatevalrrrr s   zprofile.__exit__cCs&|jr|jdur|jdSdSdSr)rurtcloser~rrrrszprofile._closefpcCs|jr |jdSdSr)rvrr~rrrr szprofile._uiflushN)T) rrr__doc__r}rr>rrrrrrrrs  C r) __future__rr contextlibi18nrr rrr%rr r r rcontextmanagerr8rHrqrrrrrrs   & " @