
    nVh                         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 dl
Z
d Zd ZddZd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dg       | 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cupti_pcsampling	roctracer)r   r   defaultchoicesz-cz	--contextzProfiling contextshadowpythonz-dz--datazProfiling datatreez-kz--hookzProfiling hooktritonz-iz--instrumentzInstrumentation analysis typeprint-mem-spacestarget_argszSubcommand and its arguments)nargsr   )argparseArgumentParserRawTextHelpFormatteradd_argumentstr	REMAINDER
parse_argsr   )parserargss     F/home/dcms/DCMS/lib/python3.12/site-packages/triton/profiler/proton.pyparse_argumentsr$   
   s2   $$X a 224F hS7VW
k:MW[ J  L
k:MW_!)8 4  6
hS7GQWbhaij
hS7GQU`dfn_op
n3=\fj!%'9 :  <
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                  |       }ddd|dt        t        j
                  t        i}t        j                  }| g|z   t        _        t        j                  j                  t         j                  j                  |             t         j                  j                  t        j                        }|dk(  rpt        t        t        j                  |      j                  d      d             }dt         j                   d<   d	t         j                   d
<   |t         j                   d<   	 t#        |d      5 }t%        |j'                         |d      }	d d d        t)        	|       |t        _        y # 1 sw Y   !xY w# t*        $ r}
t-        d|
        Y d }
~
4d }
~
ww xY w# |t        _        w xY w)N__name____main____file____builtins__r   zlibPrintLoadStoreMemSpaces.so1TRITON_ALWAYS_COMPILE0TRITON_DISABLE_LINE_INFOLLVM_PASS_PLUGIN_PATHrbexecz.An error occurred while executing the script: )r(   r)   abspathr1   sysr.   argvappenddirnamer   r0   r   nextpathlibPathrglobenvironopencompilereadr8   	Exceptionprint)r+   r"   instrumentation_passscript_pathclean_globalsoriginal_argvtop_level_triton_pathinstrumentation_pass_pathfilecodees              r#   execute_as_mainrQ   #   sa   ''//&)K 	JKc	M HHMx$CHHHOOBGGOOK01GGOOFOO<11$'34::;Z[]ab%d!.1

*+14

-..G

*+!+t$ 	=499;V<D	=T=! !	= 	=  D>qcBCCD !sB   >F 
F&F FF 	F3F.)F6 .F33F6 6G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'   mainrQ   )r   rH   r+   script_argsr'   s        r#   do_setup_and_executerV   E   sN    ^F%(%5%9+ab/rKK -ABr%   c                     | j                   r| j                   n	t               }t        | j                  | j                  | j
                  || j                         t        |       t                y )N)contextdatabackendhook)	rZ   r   r   namerX   rY   r[   rV   r   )r"   r   rZ   s      r#   run_profilingr]   R   sF    "lldll0AG	$))T\\		7QUQZQZ[%Jr%   c                 0    t        || j                         y N)rV   
instrumentr"   r   s     r#   run_instrumentationrb   \   s    doo6r%   c                  h    t               \  } }| j                  rt        | |       y t        | |       y r_   )r$   r`   rb   r]   ra   s     r#   rT   rT   `   s-    ')D+D+.$$r%   r/   r_   )r   r:   r(   r?   profiler   r   r   flagsr   r   r$   r,   rQ   rV   r]   rb   rT   r.    r%   r#   <module>rg      sV     
 	  5 5 # "*0!D
C7% zF r%   