
    ^j                         d dl Z d dl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)flagsc            	         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tritontarget_argszSubcommand and its arguments)nargsr   )argparseArgumentParserRawTextHelpFormatteradd_argumentstr	REMAINDER
parse_argsr   )parserargss     a/var/www/ramen.bs-engineer-server.com/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                 \   t         j                  j                  |       }t        j                  }| g|z   t        _        t        j                  j                  t         j                  j                  |             	 t        j                  | d       	 |t        _        y# t        $ r5}t        d       t        j                  |       Y d }~|t        _        yd }~wt        $ r!}|j                  cY d }~|t        _        S d }~wt        $ r Y |t        _        yw xY w# |t        _        w xY w)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0D1D DD DD D+c                     dt         _        | d   }t        |       dkD  r| dd  ng }t        |      rdd l}|j                  |      S t        ||      S )NTr   r   )r   command_linelenr,   r'   mainrA   )r   r+   script_argsr'   s       r#   do_setup_and_executerG   :   sS    E^F%(%5%9+ab/rK{{;''v{33r%   c                    | j                   r| j                   n	t               }t        | j                  | j                  | j
                  || j                         t        |      }t                t        j                  |       y )N)contextdatabackendhook)rK   r   r   namerI   rJ   rL   rG   r   r1   exit)r"   r   rK   exitcodes       r#   run_profilingrP   G   sT    "lldll0AG	$))T\\		7QUQZQZ[#K0HJHHXr%   c                  6    t               \  } }t        | |       y )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%   