a
    c_/                     @   sx   d Z g d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rte
  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   2   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   6   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   a   s
    zProfile.runctxc                O   s0   |    z||i |W |   S |   0 d S r   )r0   r   )r   r*   argskwr   r   r   runcallj   s    zProfile.runcallc                 C   s   |    | S r   )r0   r    r   r   r   	__enter__q   s    zProfile.__enter__c                 G   s   |    d S r   )r   )r   exc_infor   r   r   __exit__u   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$   z   s    

r$   c                  C   st  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 < t|dkrh|jrd}	|j|d d}
nh|d }|jd| j| t|d }t| |d}	W d    n1 s:0    Y  |dd d d}
t|	|
d |j|j 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modnamerbr1   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_argslenrI   rL   pathinsertdirnamer   compilereadr   rD   r   )rR   rS   rT   r   rB   rC   parserZoptionsr2   r%   ZglobsZprognamefpr   r   r   main   sT    





0ra   r,   )Nr   )Nr   )r;   __all__Z_lsprofZprofiler   r   r   ZProfilerr   r$   ra   r8   r   r   r   r   <module>   s   



_1