a
    If                     @   s   d Z g dZddlZddlZddlZdddZdddZejj e_ ejj e_ G d	d
 d
ejZ	dd Z
dd Zedkr|e  dS )zUPython interface for the 'lsprof' profiler.
   Compatible with the 'profile' module.
)runrunctxProfile    Nc                 C   s   t t| ||S N)
_pyprofile_Utilsr   r   )	statementfilenamesort r   lib/python3.9/cProfile.pyr      s    r   c                 C   s   t t| ||||S r   )r   r   r   r   )r	   globalslocalsr
   r   r   r   r   r      s    r   c                   @   sZ   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )r   a`  Profile(timer=None, timeunit=None, subcalls=True, builtins=True)

    Builds a profiler object using the specified timer function.
    The default timer is a fast built-in one based on real time.
    For custom timer functions returning integers, timeunit can
    be a float specifying a scale (i.e. how long each integer unit
    is, in seconds).
    r   c                 C   s$   dd l }||  |  d S Nr   )pstatsStatsZ
strip_dirsZ
sort_statsprint_stats)selfr   r   r   r   r   r   )   s    zProfile.print_statsc                 C   sL   dd l }t|d&}|   || j| W d    n1 s>0    Y  d S )Nr   wb)marshalopencreate_statsdumpstats)r   filer   fr   r   r   
dump_stats-   s    zProfile.dump_statsc                 C   s   |    |   d S r   )disablesnapshot_statsr   r   r   r   r   3   s    zProfile.create_statsc              
   C   s*  |   }i | _i }|D ]P}t|j}|j}||j }|j}|j}i }	|	|t|j< |||||	f| j|< q|D ]}|j	rlt|j}|j	D ]}
z|t|
j }	W n t
y   Y qY n0 |
j}||
j }|
j}|
j}||	v r|	| }||d 7 }||d 7 }||d 7 }||d 7 }||||f|	|< qqld S )Nr            )Zgetstatsr   labelcodeZ	callcountZreccallcountZ
inlinetimeZ	totaltimeidZcallsKeyError)r   entriesZcallersdictsentryfuncZncZccZttZctZcallersZsubentryprevr   r   r   r   7   s>    






zProfile.snapshot_statsc                 C   s   dd l }|j}| |||S r   )__main____dict__r   )r   cmdr,   dictr   r   r   r   ]   s    zProfile.runc                 C   s0   |    zt||| W |   n
|   0 | S r   )enableexecr   )r   r.   r   r   r   r   r   r   b   s
    zProfile.runctxc                O   s0   |    z||i |W |   S |   0 d S r   )r0   r   )r   r*   argskwr   r   r   runcallk   s    zProfile.runcallc                 C   s   |    | S r   )r0   r    r   r   r   	__enter__r   s    zProfile.__enter__c                 G   s   |    d S r   )r   )r   exc_infor   r   r   __exit__v   s    zProfile.__exit__N)r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r4   r5   r7   r   r   r   r   r      s   
&	r   c                 C   s(   t | trdd| fS | j| j| jfS d S )N~r   )
isinstancestrco_filenameco_firstlinenoco_name)r%   r   r   r   r$   {   s    

r$   c               
   C   s  dd l } dd l}dd l}dd l}ddlm} d}||d}d|_|jdddd	d d
 |jdddddt|j	j
d |jdddddd |jdd  s|  |d | \}}||jd d < |jd ur| j|j|_t|dkr|jrd}	|j|d d}
nh|d }|jd| j| t| }t| |d}	W d    n1 sV0    Y  |dd d d}
zt|	|
d |j|j W n8 ty } zd |_||j W Y d }~n
d }~0 0 n|  |S )Nr   )OptionParserzNcProfile.py [-o output_file_path] [-s sort] [-m module | scriptfile] [arg] ...)usageFz-oz	--outfileoutfilezSave stats to <outfile>)desthelpdefaultz-sz--sortr   z?Sort order when printing to stdout, based on pstats.Stats classr   )rE   rF   rG   choicesz-mmodule
store_truezProfile a library module)rE   actionrF   rG   r!   r"   z(run_module(modname, run_name='__main__'))
run_modulemodnamer1   r,   )__file__r8   __package__
__cached__) ossysrunpyr   ZoptparserB   Zallow_interspersed_argsZ
add_optionsortedr   Zsort_arg_dict_defaultargvZprint_usageexit
parse_argsrD   pathabspathlenrI   rL   insertdirnameio	open_codecompilereadr   r   BrokenPipeErrorstdouterrno)rQ   rR   rS   r   rB   rC   parserZoptionsr2   r%   ZglobsZprognamefpexcr   r   r   main   s`    






0$rg   r,   )Nr   )Nr   )r;   __all__Z_lsprofr]   Zprofiler   r   r   ZProfilerr   r$   rg   r8   r   r   r   r   <module>   s   



_;