o
    Uݢg                     @   s|   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r<e
  dS 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   m/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/external/anaconda/lib/python3.10/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_dirs
sort_statsprint_stats)selfr   r   r   r   r   r   (   s   zProfile.print_statsc                 C   sN   dd l }t|d}|   || j| W d    d S 1 s w   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 ](}t|j}|j}||j }|j}|j}i }	|	|t|j< |||||	f| j|< q|D ]Y}|j	rt|j}|j	D ]K}
z	|t|
j }	W n	 t
yW   Y qCw |
j}||
j }|
j}|
j}||	v r|	| }||d 7 }||d 7 }||d 7 }||d 7 }||||f|	|< qCq6d S )Nr            )Zgetstatsr   labelcodeZ	callcountZreccallcountZ
inlinetimeZ	totaltimeidZcallsKeyError)r   entriesZcallersdictsentryfuncZncZccZttZctZcallersZsubentryZprevr   r   r   r    6   sD   




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   s.   |    zt||| W |   | S |   w r   )enableexecr   )r   r.   r   r   r   r   r   r   a   s   
zProfile.runctxc                O   s,   |    z||i |W |   S |   w r   )r0   r   )r   r+   argsZ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   r3   r4   r6   r   r   r   r   r      s    
&	r   c                 C   s$   t | tr
dd| fS | j| j| jfS )N~r   )
isinstancestrco_filenameco_firstlinenoco_name)r&   r   r   r   r%   z   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  sS|  |d | \}}||jd d < |jd urm| j|j|_t|dkr|jrd}	|j|d d}
n3|d }|jd| j| t|d}t| |d}	W d    n1 sw   Y  |dd d d}
zt|	|
d |j|j W |S  ty } zd |_||j W Y d }~|S d }~ww |  |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   )rD   rE   rF   Zchoicesz-mmoduleZ
store_truezProfile a library module)rD   ZactionrE   rF   r"   r#   z(run_module(modname, run_name='__main__'))
run_modulemodnamerbr1   r,   )__file__r7   __package__
__cached__)ossysrunpyr   ZoptparserA   Zallow_interspersed_argsZ
add_optionsortedr   Zsort_arg_dict_defaultargvZprint_usageexitZ
parse_argsrC   pathabspathlenrG   rH   insertdirnamer   compilereadr   r   BrokenPipeErrorstdouterrno)rN   rO   rP   r   rA   rB   ZparserZoptionsr2   r&   ZglobsZprognamefpexcr   r   r   main   sj   






r`   r,   )Nr   )r:   __all__Z_lsprofZprofiler   r   r   ZProfilerr   r%   r`   r7   r   r   r   r   <module>   s   



_;
