
    Foj                         S SK r S SKrS SKrS SKrS SKrSSKJrJrJr  SSK	J	r	  S r
S rS rS rS	 rS
 r\S:X  a  \" 5         gg)    N   )startfinalize_select_backend)flagsc            	         [         R                  " SS[         R                  S9n U R                  SS[        SS9  U R                  SS	[        S
S / SQS9  U R                  SS[        SSSS/S9  U R                  SS[        SS S9  U R                  SS[        SSSS/S9  U R                  SS[        SS S S/S9  U R                  S[         R
                  S S!9  U R                  5       nXR                  4$ )"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argss     P/mnt/workspace/venv-train/lib/python3.13/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    [         R                  R                  U 5      S:H  $ )Npytest)ospathbasename)scripts    r#   	is_pytestr,      s    77F#x//r%   c                 `   [         R                  R                  U 5      n[        R                  nU /U-   [        l        [        R                  R                  [         R                  R                  U5      5         [        R                  " U SS9   U[        l        g! [         a6  n[        S5        [        R                  " U5         S nAU[        l        gS nAf[         a!  nUR                  s S nAU[        l        $ S nAf[         a     U[        l        gf = f! U[        l        f = f)N__main__)run_namez-An error occurred while executing the script:r   r   )r(   r)   abspathsysargvappenddirnamerunpyrun_path	Exceptionprint	tracebackprint_exception
SystemExitcodeKeyboardInterrupt)r+   r"   script_pathoriginal_argves        r#   execute_as_mainrA   "   s    ''//&)KHHMx$CHHHOOBGGOOK01!v
3 !  =>!!!$ !  vv !    !sN   <B 
D(!C	D  D&D1D2D  DD  DD   D-c                     S[         l        U S   n[        U 5      S:  a  U SS  O/ n[        U5      (       a  SS KnUR                  U5      $ [        X5      $ )NTr   r   )r   command_linelenr,   r'   mainrA   )r   r+   script_argsr'   s       r#   do_setup_and_executerG   :   sT    E^F%(%5%9+ab/rK{{;''v33r%   c                    U R                   (       a  U R                   O	[        5       n[        U R                  U R                  U R
                  X R                  S9  [        U5      n[        5         [        R                  " U5        g )N)contextdatabackendhook)rK   r   r   namerI   rJ   rL   rG   r   r1   exit)r"   r   rK   exitcodes       r#   run_profilingrP   G   sQ    "lldll0AG	$))T\\		7QZQZ[#K0HJHHXr%   c                  2    [        5       u  p[        X5        g )N)r$   rP   )r"   r   s     r#   rE   rE   R   s    ')D$$r%   r.   )r   r1   r(   r5   r9   profiler   r   r   r   r$   r,   rA   rG   rP   rE   __name__ r%   r#   <module>rU      sO     
 	   5 5 "(00
4%
 zF r%   