o
    Di                     @   s~   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dd Zedkr=e  dS dS )    N   )startfinalize_select_backend)flagsc                  C   s   t jddt jd} | jddtdd | jdd	td
d g dd | jddtddddgd | jddtdd d | jddtddddgd | jddtdd d dgd | jdt jd d! |  }||j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 backend)cupti	roctracerinstrumentation)r
   r   defaultchoicesz-cz	--contextzProfiling contextshadowpythonz-mz--modezProfiling mode)r
   r   r   z-dz--datazProfiling datatreetracez-kz--hookzProfiling hooktritontarget_argszSubcommand and its arguments)nargsr   )argparseArgumentParserRawTextHelpFormatteradd_argumentstr	REMAINDER
parse_argsr   )parserargs r!   `/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/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_tjt j| zOz$t	|d}t
| |d}W d    n1 s>w   Y  t|| W n tyg } ztd|  td W Y d }~nd }~ww W |t_d S W |t_d S |t_w )	N__name____main____file____builtins__rbexecz.An error occurred while executing the script: r   )r%   r&   abspathr-   sysr*   argvappenddirnameopencompilereadr/   	Exceptionprintexit)r(   r    script_pathclean_globalsoriginal_argvfilecodeer!   r!   r"   execute_as_main    s.   
rA   c                 C   sV   dt _| d }t| dkr| dd  ng }t|r$dd l}|| d S t|| d S )NTr   r   )r   command_linelenr)   r$   mainrA   )r   r(   script_argsr$   r!   r!   r"   do_setup_and_execute;   s   rF   c                 C   s>   | j r| j nt }t| j| j| j|| jd t| t  d S )N)contextdatabackendhook)	rI   r   r   namerG   rH   rJ   rF   r   )r    r   rI   r!   r!   r"   run_profilingH   s   
rL   c                  C   s   t  \} }t| | d S )N)r#   rL   )r    r   r!   r!   r"   rD   R   s   
rD   r+   )r   r1   r%   profiler   r   r   r   r#   r)   rA   rF   rL   rD   r*   r!   r!   r!   r"   <module>   s    

