
    	^cD"                         d dl Z ddlmZ ddlmZmZ ddlmZmZm	Z	mZm
Z
 d Ze j        d             Ze j        d             Ze j        d	             Z G d
 d          ZdS )    N   )_)getattropen)encodingerror
extensionspycompatutilc                     |}t          j        | |g           	 t          j        |          }t          |dd          S # t          $ r Y dS w xY w)zBload profiler extension. return profile method, or None on failure)	whitelistprofileN)r	   loadallfindr   KeyError)uiprofilerextnamemods       5/usr/lib/python3/dist-packages/mercurial/profiling.py_loadprofilerr      sk    GrgY////-og&& sIt,,,    tts   A   
AAc              #     K   |                      dd          }|                      dd          }|                     dd          }|                     dd          }|dvr'|                     t          d          |z             d}	 d	d
lm} n/# t          $ r" t          j        t          d                    w xY w|	                                }|
                    d           	 d V  |                                 |dk    r2d	dlm} |                    |          }	|	                    |           d S |                    |                                          }
|
                    t%          j        |                     |
                    |||           d S # |                                 |dk    r1d	dlm} |                    |          }	|	                    |           w |                    |                                          }
|
                    t%          j        |                     |
                    |||           w xY w)N	   profilings   formats   sorts   limits   nested)   text   kcachegrinds-   unrecognized profiling format '%s' - Ignored
r   r   )lsprofsY   lsprof not available - install from http://codespeak.net/svn/user/arigo/hack/misc/lsprof/T)subcallsr   )lsprofcalltree)limitfileclimit)config	configintwarnr    r   ImportErrorr   AbortProfilerenabledisabler   KCacheGrindoutputStatsgetstatssortr
   sysstrpprint)r   fpformatfieldr   r!   r   pr   calltreestatss              r   	lsprofiler8   %   sf     YY|Y//FIIlG,,ELLx00E\\,	22F...
CDDvMNNN
 
 
 
kI 
 
 	

 	AHHdH>			^##((((((%11!44HOOB LL..EJJxu--...LLu2fL===== 	
		^##((((((%11!44HOOB LL..EJJxu--...LLu2fL====s   B ,B:(F   B3Ic           
   #      K   	 ddl m } n/# t          $ r" t          j        t	          d                    w xY w|                     dd          }d }d}|                    |d|z  ||          }t          j                    }	 |	                                 d V  |
                                 |                                 t          dt          j                    |z
  |                                |                    d	          fz             d S # |
                                 |                                 t          dt          j                    |z
  |                                |                    d	          fz             w xY w)
Nr   )
flamegraphsW   flamegraph not available - install from https://github.com/evanhempel/python-flamegraphr      freqTg      ?s7   Collected %d stack frames (%d unique) in %2.2f seconds.)unique)r:   r&   r   r'   r   r#   ProfileThreadr   timerstartstopjoinprint
num_frames)r   r2   r:   freqfilter_collapse_recursionthread
start_times           r   flameprofilerI   L   s     
))))))) 
 
 
kC 
 
 	

 <<g..DG%%
C$J!3 F J
F
z)!!##!!!..	
 	
 	
 	
 	
 	F
z)!!##!!!..	
 	
 	
 	
s    ,7D A9Fc              #   |  K   ddl m} |                     dd          }|dk    r&|j        j        dk    r|                    |           n%|                     t          d          |z             |                     ddt          j
        rdpd	          }|                    d
|           	 d V  |                                }|                     dd          }|j        j        |j        j        |j        j        |j        j        |j        j        d}||v r	||         }n1|                     t          d          |z             |j        j        }i }	d }
|dk    rG|                     |
ddd          }|                     |
dd          }|	                    ||           n>|dk    r8|                     |
ddd          }||	d<   |                     dd          }||	d<    |j        |f||d|	 d S # |                                }|                     dd          }|j        j        |j        j        |j        j        |j        j        |j        j        d}||v r	||         }n1|                     t          d          |z             |j        j        }i }	d }
|dk    rG|                     |
ddd          }|                     |
dd          }|	                    ||           n>|dk    r8|                     |
ddd          }||	d<   |                     dd          }||	d<    |j        |f||d|	 w xY w)Nr   )statprofr   r;   r   s+   invalid sampling frequency '%s' - ignoring
s
   time-tracks   cpus   reals   thread)	mechanismtracks
   statformat)s   bylines   bymethod   hotpaths   json   chromes#   unknown profiler output format: %s
c                    t          | t          t          f          rt          |           S |                     d          rt          | d d                   dz  }nt          |           }d|cxk    rdk    rn n|S t	          |           )N   %d   r   r   )
isinstancefloatintendswith
ValueError)svs     r   fractionzstatprofile.<locals>.fraction   s    !eS\**  Qxxzz$ !CRC&MMC'!HHA{{{{{{{{{Q--    rO   s   showming{Gzt?s   showmax)minthresholdmaxthresholdrN   g?r   s   showtimeshowtime)datar3   )r%   rK   r#   stateprofile_levelresetr$   r   r"   r
   	iswindowsr?   r@   DisplayFormatsByLineByMethodHotpathJsonChrome
configwithupdate
configbooldisplay)r   r2   rK   rD   rM   r`   
profformatformatsdisplayformatkwargsr[   showminshowmaxr   r_   s                  r   statprofileru   o   s     <<g..Daxx>'1,,NN4   
ABBTIJJJIImX%7%BF%Mg E NNYeN444-H}}YY|];;
  .5!09 /7,1.5
 
   #J/MMGGA=>>KLLL$3;M		  		  		  ""mmHlJNNGmmHlJGGGMMwWMEEEE:%%MM(L*dKKE#F7O}}\;??H!)F:G$}GGGGGGGU }}YY|];;
  .5!09 /7,1.5
 
   #J/MMGGA=>>KLLL$3;M		  		  		  ""mmHlJNNGmmHlJGGGMMwWMEEEE:%%MM(L*dKKE#F7O}}\;??H!)F:G$}GGGGGGs   -G6 6EL;c                   8    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	S )r   zStart 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| _        d S )NTF)	_ui_output_fp
_fpdoclose_flushfp	_profiler_enabled_entered_started)selfr   enableds      r   __init__zprofile.__init__   sE    r\   c                 J    d| _         | j        r|                                  | S )NT)r   r~   r?   r   s    r   	__enter__zprofile.__enter__   s%    = 	JJLLLr\   c                    | j         st          j        d          | j        rdS d| _        t          j                            d          }d}|| j                            dd          }|dvrCt          | j        |          }|,| j        
                    t          d          |z             d	}| j                            dd
          | _        	 | j        dk    rt          j                    | _        n| j        r/t          j        | j                  }t#          |d          | _        n_t$          j        r* G d d          }d| _         || j                  | _        n)d| _        | j        j        | _        | j        j        | _        |n#|dk    rt0          }n|dk    rt2          }nt4          } || j        | j                  | _        | j                                         dS #  |                                   xY w)zStart profiling.

        The profiling will stop at the context exit.

        If the profiler was already started, this has no effect.s   use a context manager to startNTs   HGPROFr   s   type)   ls   stat   flames%   unrecognized profiler '%s' - ignored
r   s   output   blackboxs   wbc                        e Zd Zd Zd Zd ZdS )profile.start.<locals>.uifpc                     || _         d S N)rx   )r   r   s     r   r   z$profile.start.<locals>.uifp.__init__   s    #%r\   c                 :    | j                             |           d S r   )rx   	write_err)r   r`   s     r   writez!profile.start.<locals>.uifp.write   s    **400000r\   c                 8    | j                                          d S r   )rx   flushr   s    r   r   z!profile.start.<locals>.uifp.flush   s    (((((r\   N)__name__
__module____qualname__r   r   r    r\   r   uifpr      sA        & & &1 1 1) ) ) ) )r\   r   Fr   r   )r   r   ProgrammingErrorr   r   environgetrx   r"   r   r$   r   ry   r   stringiorz   
expandpathr   r
   rd   r{   ferrfoutr|   r8   rI   ru   r}   r   _closefp)r   r   proffnpathr   s        r   r?   zprofile.start   s    } 	L()JKKK= 	F#''	22x|W==H555"48X66F~?@@8K   #x|Y??'	|{**=?? .t|44e,,# .) ) ) ) ) ) ) ) #(4>>"'8= $!U"""X%%%$#VDHdh77DNN$$&&&&&	MMOOOs   DG' 'G>c                 P   d }| j         |                                  | j                             |||          }| j        dk    rMd| j                                        z  }|                    dd          }| j                            d|           | 	                                 |S )Nr   s   Profile:
%srQ   s   %%s   profile)
r}   _uiflush__exit__ry   rz   getvaluereplacerx   logr   )r   exception_typeexception_value	traceback	propagatevals         r   r   zprofile.__exit__  s    	>%MMOOO// I |{**%(9(9(;(;; kk$..Z---r\   c                 \    | j         r"| j        | j                                         d S d S d S r   )r{   rz   closer   s    r   r   zprofile._closefp  s;    ? 	tx3HNN	 	33r\   c                 J    | j         r| j                                          d S d S r   )r|   r   r   s    r   r   zprofile._uiflush  s0    = 	"M!!!!!	" 	"r\   N)T)
r   r   r   __doc__r   r   r?   r   r   r   r   r\   r   r   r      s         	 	 	 	  A A AF     " " " " "r\   r   )
contextlibi18nr   r
   r   r   r%   r   r   r	   r   r   contextmanagerr8   rI   ru   r   r   r\   r   <module>r      sA                                	- 	- 	- #> #> #>L 
 
 
D =H =H =H@q" q" q" q" q" q" q" q" q" q"r\   