
    %Vjie                        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	m
Z
 d dlmZ  ej        d          Z ej                    Z ej        d          Ze                    e           e                    e           e                    ej                   de_        d	ed
efdZded
efdZ G d d          ZdS )    N)datetime)gethostname)AnyOptional)StrobelightCLIFunctionProfiler!strobelight_compile_time_profilerzB%(name)s, line %(lineno)d, %(asctime)s, %(levelname)s: %(message)sFurlreturnc                    | }	 t          j        d| gdt           j                  }|j        dk    r|j                            d          }n?# t          $ r2}t                              dt          |                     Y d }~nd }~ww xY w|S )NfburlT)capture_outputstdinr   zutf-8z)URL shortening failed: %s, using long URL)

subprocessrunDEVNULL
returncodestdoutdecode	Exceptionloggerwarningrepr)r	   	short_urlresultes       b/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/_strobelight/compile_time_profiler.py	get_fburlr      s    IMcN4z7I
 
 
 !!,,W55I M M MBDGGLLLLLLLLMs   AA 
B	(BB	
identifierc                 
   i dg dddg gdg gdddgd	d
dddd|  dgdggdg dddg dddddddddg dddg dd d!d"d#d#d$gg dd%dd&d'd(d)
}d*}d+}|t          j        |          z   |z   }t          |          S ),NaggregateListaggregation_fieldasync_stack_completeb_constraintsc_constraintscolsnamespace_idnamespace_process_idcomparenoneconstraintssample_tagsallz["z"])columnopvaluederivedColsendnowenumCols
filterModeDEFAULThideEmptyColumnsfalseignoreGroupByInComparisonis_timeseries
mappedColsmetriccount	modifiersweighttruepy_async_stackedge0)dimr.   paramanchor1z-30 dayszAmerica/Los_Angelesi'  )
order
order_descparam_dimensionspurposesreturn_remaindersamplingRatioshould_pivotstarttimezonetopz`https://www.internalfb.com/intern/scuba/query/?dataset=pyperf_experimental/on_demand&drillstate=z8&view=GraphProfilerView&&normalized=1726332703&pool=uber)jsondumpsr   )r   
scuba_jsonscuba_url_prefixscuba_url_sufflong_urls        r   get_strobelight_urlrW   *   sv     3  	"  	"	 
 	!78  	6  	%U>Q:>Q>Q>Q=RSST
  	r  	u  	B  	i  	G  	$W   	! " 	b# $ 	'% & 	R' ( $FSCPP
 #)?     JB zON$*Z"8"88>IHX    c                      e Zd ZU dZeed<   dZeed<   dZeed<   dZe	ed<   dZ
e	ed<   ej                            d          Zee         ed	<   d
Zee         ed<   d
Zee         ed<   d
Zee         ed<    eej                            dd                    Zeed<    eej                            dd                    Zeed<    e eej                            dd                              Zeed<   edefd            Zeefdedd
fd            Zed"d            Zed"d            Zedededed edef
d!            Zd
S )#StrobelightCompileTimeProfilerr   success_profile_countfailed_profile_countignored_profile_runsFinside_profile_compile_timeenabled COMPILE_STROBELIGHT_FRAME_FILTERframe_id_filterNr   current_phaseprofiler$COMPILE_STROBELIGHT_MAX_STACK_LENGTHi  max_stack_length$COMPILE_STROBELIGHT_MAX_PROFILE_TIMEi  max_profile_timeCOMPILE_STROBELIGHT_SAMPLE_RATEg    cAsample_eachr
   c                 P    ddl m} t          |                                          S )Nr   )CompileContext)torch._guardsrk   strcurrent_trace_id)clsrk   s     r   	get_framez(StrobelightCompileTimeProfiler.get_frameo   s.    000000^4466777rX   profiler_classc                    | j         rt                              d           d S t                              d           |t          u r5dd l}|                    d          st                              d           d S d| _         |                                   || j        | j        | j	        | j	        dt          j                            dt          j                            d	d
                    z   | j        h          | _        d S )Nz2compile time strobelight profiling already enabledz*compile time strobelight profiling enabledr   strobeclientzostrobeclient not found, can't enable compile time strobelight profiling, seemslike you are not on a FB machine.Tzpt2-profiler/USERUSERNAME )ri   max_profile_duration_secstack_max_lenasync_stack_max_lenrun_user_namer+   )r_   r   infor   shutilwhich	_cls_initri   rg   re   osenvirongetr   rc   )ro   rq   r|   s      r   enablez%StrobelightCompileTimeProfiler.enableu   s    ; 	KKLMMMF@AAA;;;MMM<<// 8   
 &~%(%9. # 4)jnnVRZ^^J%C%CDDE(
 
 
rX   c                 \   d                     t          j                                        d          t	          j                    t                                | _        t          	                    d| j                   t          	                    dt          | j                             d S )Nz{date}{pid}{hostname}z%Y-%m-%d-%H:%M:%S)datepidhostnamez%Unique sample tag for this run is: %sz?URL to access the strobelight profile at the end of the run: %s)formatr   r2   strftimer   getpidr   r   r   r{   rW   ro   s    r   r~   z(StrobelightCompileTimeProfiler._cls_init   s    077(()<==	 ]] 8 
 
 	;S^LLLM//	
 	
 	
 	
 	
rX   c                 b    t                               d| j        | j        | j        z              d S )NzG%s strobelight success runs out of %s non-recursive compilation events.)r   r{   r[   r\   r   s    r   
_log_statsz)StrobelightCompileTimeProfiler._log_stats   s9    U%%(@@	
 	
 	
 	
 	
rX   func
phase_nameargskwargsc                    dt           ffd}| j        s
 |            S | j        t                              d           d S |                                 }| j        r=| xj        dz  c_        t                              d||| j	        |            |            S | j
        It          j        | j
        |          d u}|s+t                              d|| j
                    |            S d| _        || _	        t                              d|            | j        j        gR i }| j        j        | xj        dz  c_        n| xj        dz  c_        |                                  d	| _        |S )
Nr
   c                        i S )N )r   r   r   s   r   skipzAStrobelightCompileTimeProfiler.profile_compile_time.<locals>.skip   s    4((((rX   zprofiler is not set   z~profile_compile_time is requested for phase: %s, frame %s, while already in running phase: %s,frame %s, recursive call ignoredz7profiling frame %s is skipped due to frame_id_filter %sTzprofiling frame %sF)r   r_   rc   r   errorrp   r^   r]   r{   rb   ra   rematchprofileprofile_resultr[   r\   r   )	ro   r   r   r   r   r   frame_id
should_runwork_results	    ` ``    r   profile_compile_timez3StrobelightCompileTimeProfiler.profile_compile_time   s   	)c 	) 	) 	) 	) 	) 	) 	) 	) { 	466M<LL.///F==??* 
	$$)$$KK3!   466M*#"5x@@LJ M'  
 tvv*.'&((333*cl*4A$AAA&AA<&2%%*%%%$$)$$*/'rX   )r
   N) __name__
__module____qualname__r[   int__annotations__r\   r]   r^   boolr_   r   r   r   ra   r   rm   r   rb   rc   r   re   rg   floatri   classmethodrp   r   r   r~   r   r   r   rX   r   rZ   rZ   R   se        !"3""" !#!!! !#!!!(----GT &(Z^^4V%W%WOXc]WWW !%J$$$#'M8C='''"Hhsm"""C

=sCC c     C

=wGG c    sbjnn>DDEE K    8# 8 8 8 [8
 *H 
 
C 
T 
 
 
 [
B 
 
 
 [
 
 
 
 [
 11$'1031?B1	1 1 1 [1 1 1rX   rZ   )rQ   loggingr   r   r   r   socketr   typingr   r   (torch._strobelight.cli_function_profilerr   	getLoggerr   StreamHandlerconsole_handler	Formatter	formattersetFormatter
addHandlersetLevelINFO	propagaterm   r   rW   rZ   r   rX   r   <module>r      s     				 				                                 S S S S S S 
	>	?	?'''))GH 	   Y ' ' '   / " " "     3 3    %C %C % % % %PN N N N N N N N N NrX   