U
    h@
                     @   sr   d dl Z d dlZd dlZddlmZmZmZ ddlmZ dd Z	dd Z
d	d
 Zdd Zdd Zedkrne  dS )    N   )startfinalize_select_backend)set_command_linec                  C   s   t jddt jd} | jddtdd | jdd	td
d dgd | jddtddddgd | jddtdddgd | jddtdd d dgd |  \}}||fS )NzBThe proton command utility for profiling scripts and pytest tests.z
    proton [options] script.py [script_args] [script_options]
    proton [options] pytest [pytest_args] [script_options]
    python -m triton.profiler.proton [options] script.py [script_args] [script_options]
)descriptionusageformatter_classz-nz--namezName of the profiling session)typehelpz-bz	--backendzProfiling backendZcupti)r
   r   defaultchoicesz-cz	--contextzProfiling contextZshadowpythonz-dz--datazProfiling datatreez-kz--hookzProfiling hookZtriton)argparseArgumentParserRawTextHelpFormatteradd_argumentstrparse_known_args)parserargstarget_args r   H/var/www/html/venv/lib/python3.8/site-packages/triton/profiler/proton.pyparse_arguments   s     r   c                 C   s   t j| dkS )Npytest)ospathbasename)scriptr   r   r   	is_pytest   s    r!   c              
   C   s   t j| }ddd|dttjti}tj}| g| t_zjz4t|d}t|	 |d}W 5 Q R X t
|| W n0 tk
r } ztd|  W 5 d }~X Y nX W 5 |t_X d S )N__name____main____file____builtins__rbexecz.An error occurred while executing the script: )r   r   abspathr%   sysr"   argvopencompilereadr'   	Exceptionprint)r    r   Zscript_pathZclean_globalsZoriginal_argvfilecodeer   r   r   execute_as_main   s&        $r3   c                 C   s   | j r| j nt }t| j| j| j|| jd t  |d }t|dkrR|dd  ng }t	|rrdd l
}|| n
t|| t  d S )N)contextdatabackendhookr   r   )r6   r   r   namer4   r5   r7   r   lenr!   r   mainr3   r   )r   r   r6   r    script_argsr   r   r   r   run_profiling5   s    
r<   c                  C   s   t  \} }t| | d S )N)r   r<   )r   r   r   r   r   r:   H   s    
r:   r#   )r   r)   r   Zprofiler   r   r   flagsr   r   r!   r3   r<   r:   r"   r   r   r   r   <module>   s   