§
    J�’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 d dlmZ d dl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)Ú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       úVC:\Projects\DSCons\.venv\Lib\site-packages\torch\_strobelight\compile_time_profiler.pyÚ	get_fburlr      sª   € Ø€IðMÝ”Ø�cˆN¨4µzÔ7Ið
ñ 
ô 
ˆð Ô Ò!Ð!Øœ×,Ò,¨WÑ5Ô5ˆIøøÝð Mð Mð MÝ�ŠÐBÅDÈÁGÄGÑ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_urlrV   *   sv  € ð Ø˜ð àÐ3ð ð 	˜"˜ð ð 	˜"˜ð	 ð
 	�Ð!7Ð8ð ð 	�6ð ð 	Ø%¨UÐ>QÀ:Ð>QÐ>QÐ>QÐ=RÐSÐSÐTð
ð ð 	�rð ð 	ˆuð ð 	�Bð ð 	�ið ð 	˜Gð ð 	$ Wð ð  	˜ð! ð" 	�bð# ð$ 	�'ð% ð& 	�Rð' ð( Øà$¨F¸SÈCÐPÐPð
ð Ø#ØØØØ)Øð? ð  ð  €JðB zÐØO€NØ¥$¤*¨ZÑ"8Ô"8Ñ8¸>ÑI€HÝ�XÑÔÐó    c                   óz  — 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d	z  ed
<   d	Zed	z  ed<   d	Zed	z  ed<   d	Zed	z  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_FILTERNÚframe_id_filterr   Ú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._guardsrj   ÚstrÚcurrent_trace_id)Úclsrj   s     r   Ú	get_framez(StrobelightCompileTimeProfiler.get_frameo   s.   € à0Ð0Ð0Ð0Ð0Ð0å�^×4Ò4Ñ6Ô6Ñ7Ô7Ð7rW   Ú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Ú )rh   Úmax_profile_duration_secÚstack_max_lenÚasync_stack_max_lenÚrun_user_namer*   )r^   r   Úinfor   ÚshutilÚwhichÚ	_cls_initrh   rf   rd   ÚosÚenvironÚgetr   rb   )rn   rp   r{   s      r   Úenablez%StrobelightCompileTimeProfiler.enableu   sÿ   € àŒ;ð 	Ý�KŠKÐLÑMÔMÐMØˆFå�ŠÐ@ÑAÔAÐAàÕ;Ð;Ð;ØˆMˆMˆMà—<’< Ñ/Ô/ð Ý—’ð8ñô ð ð �àˆŒØ�Š‰Œˆð
 &�~ØœØ%(Ô%9ØÔ.Ø #Ô 4Ø)ÝŒj�nŠn˜V¥R¤Z§^¢^°JÀÑ%CÔ%CÑDÔDñEàœÐ(ð
ñ 
ô 
ˆŒˆˆrW   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   r1   Ústrftimer~   Úgetpidr   r   r   rz   rV   ©rn   s    r   r}   z(StrobelightCompileTimeProfiler._cls_init—   s�   € à0×7Ò7Ý”‘”×(Ò(Ð)<Ñ=Ô=Ý”	‘”Ý ‘]”]ð 8ñ 
ô 
ˆŒõ 	�ŠÐ;¸S¼^ÑLÔLÐLÝ�ŠØMÝ ¤Ñ/Ô/ñ	
ô 	
ð 	
ð 	
ð 	
rW   c                 ób   — t                                d| j        | j        | j        z   ¦  «         d S )NzG%s strobelight success runs out of %s non-recursive compilation events.)r   rz   rZ   r[   r‰   s    r   Ú
_log_statsz)StrobelightCompileTimeProfiler._log_stats¥   s9   € å�ŠØUØÔ%ØÔ%¨Ô(@Ñ@ñ	
ô 	
ð 	
ð 	
ð 	
rW   Ú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˜Ð( Ð(Ð(Ð(rW   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^   rb   r   Úerrorro   r]   r\   rz   ra   r`   ÚreÚmatchÚprofileÚprofile_resultrZ   r[   r‹   )	rn   rŒ   r�   rŽ   r�   r“   Úframe_idÚ
should_runÚwork_results	    ` ``    r   Úprofile_compile_timez3StrobelightCompileTimeProfiler.profile_compile_time®   sÄ  øøø€ ð	)•cð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð Œ{ð 	Ø�4‘6”6ˆMàŒ<ÐÝ�LŠLÐ.Ñ/Ô/Ð/ØˆFà—=’=‘?”?ˆàÔ*ð 
	ØÐ$Ô$¨Ñ)Ð$Ô$Ý�KŠKð3àØØÔ!Øñô ð ð �4‘6”6ˆMàÔÐ*Ýœ #Ô"5°xÑ@Ô@ÈÐLˆJØð Ý—’ØMØØÔ'ñô ð ð
 �t‘v”v�à*.ˆÔ'Ø&ˆÔÝ�ŠÐ(¨(Ñ3Ô3Ð3Ø*�c”lÔ*¨4ÐA°$ÐAÐAÐA¸&ÐAÐAˆàŒ<Ô&Ð2ØÐ%Ô%¨Ñ*Ð%Ô%Ð%àÐ$Ô$¨Ñ)Ð$Ô$à�ŠÑÔÐØ*/ˆÔ'ØÐrW   )r	   N)Ú__name__Ú
__module__Ú__qualname__rZ   ÚintÚ__annotations__r[   r\   r]   Úboolr^   r~   r   r€   r`   rl   r   ra   rb   r   rd   rf   Úfloatrh   Úclassmethodro   r   r�   r}   r‹   r�   r’   rW   r   rY   rY   R   se  € € € € € € Ø!"Ð˜3Ð"Ð"Ñ"Ø !Ð˜#Ð!Ð!Ñ!Ø !Ð˜#Ð!Ð!Ñ!Ø(-Ð Ð-Ð-Ñ-Ø€GˆTÐÐÑð #%¤*§.¢.Ð1SÑ"TÔ"T€O�S˜4‘ZÐTÐTÑTð "€J��d‘
Ð!Ð!Ñ!à $€M�3˜‘:Ð$Ð$Ñ$à€Hˆc�D‰jÐÐÑà˜CØ
Œ
�ŠÐ=¸sÑCÔCñô Ð�cð ð ñ ð  ˜CØ
Œ
�ŠÐ=¸wÑGÔGñô Ð�cð ð ñ ð �sØˆˆbŒj�nŠnÐ>ÀÑ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rW   rY   )rP   Úloggingr~   r–   r   r   Úsocketr   Útypingr   Ú(torch._strobelight.cli_function_profilerr   Ú	getLoggerr   ÚStreamHandlerÚconsole_handlerÚ	FormatterÚ	formatterÚsetFormatterÚ
addHandlerÚsetLevelÚINFOÚ	propagaterl   r   rV   rY   r’   rW   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rW   