
    Vpfq                       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 n# e$ r  ed          w xY w	 d dlmZ n# e$ r  ed          w xY wd	Z ej        e
          Ze                    ddde           e                    dde           e                    dde           e                    ddd           e                    ddde           e                    ddde           e                    ddde           e                    d dd!e           d/d,Zd- Zed.k    r ee                                           dS dS )0    )annotationsN)profiler)profiler_v2)profiler_clientz2This script requires `tensorflow` to be installed.)raw_to_tool_datazBThis script requires `tensorboard_plugin_profile` 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 levelinthoststrlog_dir
str | Nonehost_tracer_leveldevice_tracer_levelpython_tracer_levelno_perfetto_linkboolc                l   t          j        |||          }t          j        ||nt	          j                              }	t          j        | d|  t          |	          ||           t          d|	            |	
                                }
|
dz  dz  fd                                D             }t          |t          j        j                  }t!          |                    d	                    }t%          j        |gd
i           \  }}t)          j        t          |dz            d          5 }|                    |                    d                     d d d            n# 1 swxY w Y   |s7t1          j        t          |	                    }t1          j        |           d S d S )N)r   r   r   :)optionsz!Dumped profiling information in: pluginsprofilec                    g | ]}|z  S  r"   ).0trace_folderroot_trace_folders     S/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/collect_profile.py
<listcomp>z#collect_profile.<locals>.<listcomp>Z   s+     3 3 3$|3 3 3 3    )keyz*.xplane.pbztrace_viewer^zremote.trace.json.gzwbzutf-8)r   ProfilerOptionspathlibPathtempfilemkdtempr   tracer   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   r   r   r   r   r   r   r   log_dir_	curr_pathtrace_folderslatest_folderxplaneresult_fpr6   r%   s                     @r&   collect_profilerK   D   s    $)--  '
 \W%8''h>N>P>PQQ(		(mm	   
 6H66777
   ))+i73 3 3 3'//113 3 3-m)9:::-""=1122&)6(ORHH)&!y]%;;<<dCC %rHHV]]7##$$$% % % % % % % % % % % % % % % 
 123x==AAD*4000001 1s   ;)E00E47E4c           
         t          | j        | j        | j        | j        | j        | j        | j        | j                   d S )N)	rK   r   r   r   r   r   r   r   r   )argss    r&   mainrN   g   sJ    $)T0$)T\($*B*D,AC C C C Cr(   __main__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
__future__r   argparser<   r5   r,   r.   jax._srcr   r@   tensorflow.python.profilerr   r   ImportError"tensorboard_plugin_profile.convertr   r:   _DESCRIPTIONArgumentParserparseradd_argumentr   r   rK   rN   __name__
parse_argsr"   r(   r&   <module>r\      s   # " " " " "   				   . - - - - -J@@@@@@8888888 J J JHIIIJLLLLLLLL L L LJ	L 	L LL 
!	 \	:	:	:   KI       F!8s  C C C   $D3  P P P   (;'  ) ) )   HkG       )15C  A A A   +Q7c  C C C   +Q7c  C C C!1 !1 !1 !1FC C C
 z$v s   / A A A