
    ci                     z    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 Z	d Z
d Zd Zd	 Zd
 Zedk(  r e        yy)    N   )startfinalize_select_backend)set_command_linec            	         t        j                  ddt         j                        } | j                  ddt        d       | j                  dd	t        d
d g d       | j                  ddt        ddddg       | j                  ddt        dd        | j                  ddt        ddddg       | j                  ddt        dd d dg       | j                  dt         j
                  d !       | j                         }||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launchtarget_argszSubcommand and its arguments)nargsr   )argparseArgumentParserRawTextHelpFormatteradd_argumentstr	REMAINDER
parse_argsr   )parserargss     P/var/www/html/engine/venv/lib/python3.12/site-packages/triton/profiler/proton.pyparse_argumentsr$      s(   $$X a 224F hS7VW
k:MW[ I  K
k:MW_!)8 4  6
hS7GQUV
hS7GQWbhjqars
hS7GQU`dfn_op
X-?-?FdeD!!!!    c                 F    t         j                  j                  |       dk(  S )Npytest)ospathbasename)scripts    r#   	is_pytestr,      s    77F#x//r%   c                 r   t         j                  j                  |       }ddd|dt        t        j
                  t        i}t        j                  }| g|z   t        _        t        j                  j                  t         j                  j                  |             	 t        |d      5 }t        |j                         |d      }d d d        t        |       |t        _        y # 1 sw Y   !xY w# t        $ r-}t        d|        t	        j                  d       Y d }~Id }~ww xY w# |t        _        w xY w)	N__name____main____file____builtins__rbexecz.An error occurred while executing the script: r   )r(   r)   abspathr1   sysr.   argvappenddirnameopencompilereadr3   	Exceptionprintexit)r+   r"   script_pathclean_globalsoriginal_argvfilecodees           r#   execute_as_mainrE       s    ''//&)K 	JKc	M HHMx$CHHHOOBGGOOK01!+t$ 	=499;V<D	=T=!
 !	= 	=  >qcBC !sB   C0 (C$C0 $C-)C0 0	D&9#D!D) !D&&D) )D6c                     t                | d   }t        |       dkD  r| dd  ng }t        |      rdd l}|j	                  |       y t        ||       y )Nr   r   )r   lenr,   r'   mainrE   )r   r+   script_argsr'   s       r#   do_setup_and_executerJ   ;   sK    ^F%(%5%9+ab/rKK ,r%   c                     | j                   r| j                   n	t               }t        | j                  | j                  | j
                  || j                         t        |       t                y )N)contextdatabackendhook)	rN   r   r   namerL   rM   rO   rJ   r   )r"   r   rN   s      r#   run_profilingrQ   H   sF    "lldll0AG	$))T\\		7QUQZQZ[%Jr%   c                  6    t               \  } }t        | |       y )N)r$   rQ   )r"   r   s     r#   rH   rH   R   s    ')D+$$r%   r/   )r   r5   r(   profiler   r   r   flagsr   r$   r,   rE   rJ   rQ   rH   r.    r%   r#   <module>rV      sI     
 	 5 5 #"(0!6
-%
 zF r%   