
    vh                    N   d dl mZ 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	 	 d dl
mZ d dl
mZ dZ ej                   e      Zej%                  d	dd
e       ej%                  dde       ej%                  dde       ej%                  ddd       ej%                  ddde       ej%                  ddde       ej%                  ddde       ej%                  ddde       	 	 	 	 	 	 	 	 	 	 d#d Zd! Zed"k(  r eej1                                yy# e$ r	  ed      w xY w)$    )annotationsN)profiler)_pywrap_profiler_plugin)raw_to_tool_dataz-This script requires `xprof` to be installed.a  
To profile running JAX programs, you first need to start the profiler server
in the program of interest. You can do this via
`jax.profiler.start_server(<port>)`. Once the program is running and the
profiler server has started, you can run `collect_profile` to trace the execution
for a provided duration. The trace file will be dumped into a directory
(determined by `--log_dir`) and by default, a Perfetto UI link will be generated
to view the resulting trace.
)descriptionz	--log_dirzJDirectory to store log files. Uses a temporary directory if none provided.)defaulthelptypeportzPort to collect trace)r	   r
   duration_in_msz)Duration to collect trace in millisecondsz--no_perfetto_linkz Disable creating a perfetto link
store_true)r	   actionz--hostz	127.0.0.1z,Host to collect trace. Defaults to 127.0.0.1z--host_tracer_level   zProfiler host tracer levelz--device_tracer_level   zProfiler device tracer levelz--python_tracer_levelzProfiler Python tracer levelc                   |||d}t        j                  ||nt        j                               }	t	        j
                  | d|  t        |	      ||       t        d|	        |	j                         }
|
dz  dz  }|j                         D cg c]  }||z  	 }}t        |t        j                  j                        }t        |j                  d            }t!        j"                  |gd	i       \  }}t%        j&                  t        |d
z        d      5 }|j)                  |j+                  d             d d d        |s+t-        j.                  |	      }t-        j0                  |       y y c c}w # 1 sw Y   <xY w)N)host_tracer_leveldevice_tracer_levelpython_tracer_level:)optionsz!Dumped profiling information in: pluginsprofile)keyz*.xplane.pbtrace_viewerzremote.trace.json.gzwbzutf-8)pathlibPathtempfilemkdtempr   tracestrprintresolveiterdirmaxospathgetmtimenextglobconvertxspace_to_tool_datagzipopenwriteencodejax_profiler_write_perfetto_trace_file_host_perfetto_trace_file)r   r   hostlog_dirr   r   r   no_perfetto_linkr   log_dir_	curr_pathroot_trace_foldertrace_foldertrace_folderslatest_folderxplaneresult_fpr'   s                       N/opt/face_recognition/venv/lib/python3.12/site-packages/jax/collect_profile.pycollect_profilerB   @   sn   
 -00'
 \\W%8'h>N>N>PQ(	av	(m	
 
+H:67
  ))+i7'//13$|3 3- 3m)9)9:-""=12&))6(NBG)&!yy]%;;<dC %rHHV]]7#$% 
228<D**40 
3% %s   E2!E77F c           
         t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                         y )N)	rB   r   r   r4   r5   r   r   r   r6   )argss    rA   mainrE   c   sG    $))T00$))T\\(($*B*B**D,A,AC    __main__)r   intr   rH   r4   r!   r5   zos.PathLike | str | Noner   rH   r   rH   r   rH   r6   bool)
__future__r   argparser-   r&   r   r   jax._srcr   r1   xprof.convertr   r   r+   ImportError_DESCRIPTIONArgumentParserparseradd_argumentr!   rH   rB   rE   __name__
parse_args rF   rA   <module>rV      s   #   	   .737 
!	 	 \	:   KI     F!8s  C   $D3  P   (;'  )   HkG     )15C  A   +Q7c  C   +Q7c  C!15!1JM!1),!1CF!1 '+!1FC
 zv Y  75	7 77s   D D$