Ë
    g^(hd  ã                   ó†  — 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j'                  e«       ej)                  e«       ej+                  ej,                  «       de_        d	ed
efd„Zded
efd„Z G d„ d«      Zy)é    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                  j                  d«      }|S # t        $ r*}t        j                  dt        |«      «       Y d }~|S d }~ww xY w)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       úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/_strobelight/compile_time_profiler.pyÚ	get_fburlr      sˆ   € Ø€IðMÜ—‘Ø�cˆN¨4´z×7IÑ7Iô
ˆð ×Ñ Ò!ØŸ™×,Ñ,¨WÓ5ˆIð Ðøô ò MÜ�‰ÐBÄDÈÃG×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   *   s_  € ð Ø˜ð àÐ3ð ð 	˜"˜ð ð 	˜"˜ð	 ð
 	�Ð!7Ð8ð ð 	�6ð ð 	Ø%¨UÀÀ:À,ÈbÐ>QÐ=RÑSÐTð
ð ð 	�rð ð 	ˆuð ð 	�Bð ð 	�ið ð 	˜Gð ð 	$ Wð ð  	˜ð! ð" 	�bð# ð$ 	�'ð% ð& 	�Rð' ð( Øà$¨F¸SÈCÑPð
ð Ø#ØØØØ)Øò? €JðB zÐØO€NØ¤$§*¡*¨ZÓ"8Ñ8¸>ÑI€HÜ�XÓÐó    c                   óJ  — 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                  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                  j                  dd«      «      Zeed<    eej                  j                  dd«      «      Zeed<    e eej                  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y
)#Ú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                 ó@   — ddl m} t        |j                  «       «      S )Nr   )ÚCompileContext)Útorch._guardsrk   ÚstrÚcurrent_trace_id)Úclsrk   s     r   Ú	get_framez(StrobelightCompileTimeProfiler.get_frameo   s   € å0ä�^×4Ñ4Ó6Ó7Ð7rX   Úprofiler_classc                 ó  — | j                   rt        j                  d«       y t        j                  d«       |t        u r+dd l}|j                  d«      st        j                  d«       y d| _         | j                  «         || j                  | j                  | j                  | j                  dt        j                  j                  dt        j                  j                  d	d
«      «      z   | j                  h¬«      | _        y )Nz2compile time strobelight profiling already enabledz*compile time strobelight profiling enabledr   Ústrobeclientznstrobeclient not found, cant 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È   € à�;Š;Ü�K‰KÐLÔMØä�‰Ð@ÔAàÔ;Ñ;Ûà—<‘< Ô/Ü—‘ð8ôð àˆŒØ�‰Œñ
 &ØŸ™Ø%(×%9Ñ%9Ø×.Ñ.Ø #× 4Ñ 4Ø)Ü�j‰j�n‰n˜V¤R§Z¡Z§^¡^°JÀÓ%CÓDñEàŸ™Ð(ô
ˆ�rX   c                 ó>  — dj                  t        j                  «       j                  d«      t	        j
                  «       t        «       ¬«      | _        t        j                  d| j                  «       t        j                  dt        | j                  «      «       y )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—   sl   € à0×7Ñ7Ü—‘“×(Ñ(Ð)<Ó=Ü—	‘	“Ü “]ð 8ó 
ˆŒô 	�‰Ð;¸S¿^¹^ÔLÜ�‰ØMÜ §¡Ó/õ	
rX   c                 ót   — t         j                  d| j                  | j                  | j                  z   «       y )NzG%s strobelight success runs out of %s non-recursive compilation events.)r   r{   r[   r\   rŠ   s    r   Ú
_log_statsz)StrobelightCompileTimeProfiler._log_stats¥   s.   € ä�‰ØUØ×%Ñ%Ø×%Ñ%¨×(@Ñ(@Ñ@õ	
rX   ÚfuncÚ
phase_nameÚargsÚkwargsc                 ó0  ‡‡‡— dt         fˆˆˆfd„}| j                  s |«       S | j                  €t        j	                  d«       y | j                  «       }| j                  r?| xj                  dz  c_        t        j                  d||| j                  |«        |«       S | j                  �Lt        j                  | j                  |«      d u}|s(t        j                  d|| j                  «        |«       S d| _        || _	        t        j                  d|«        | j                  j                  ‰g‰¢­i ‰¤Ž}| j                  j                  �| xj                  dz  c_        n| xj                   dz  c_        | j#                  «        d	| _        |S )
Nr
   c                  ó   •—  ‰‰ i ‰¤ŽS )N© )r�   r�   r�   s   €€€r   ÚskipzAStrobelightCompileTimeProfiler.profile_compile_time.<locals>.skip²   s   ø€ Ù˜Ð( Ñ(Ð(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®   sa  ú€ ð	)”c÷ 	)ð �{Š{Ù“6ˆMà�<‰<ÐÜ�L‰LÐ.Ô/Øà—=‘=“?ˆà×*Ò*Ø×$Ò$¨Ñ)Õ$Ü�K‰Kð3àØØ×!Ñ!Øôñ “6ˆMà×ÑÐ*ÜŸ™ #×"5Ñ"5°xÓ@ÈÐLˆJÙÜ—‘ØMØØ×'Ñ'ôñ
 “v�à*.ˆÔ'Ø&ˆÔÜ�‰Ð(¨(Ô3Ø*�c—l‘l×*Ñ*¨4Ð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   sž  … Ø!"Ð˜3Ó"Ø !Ð˜#Ó!Ø !Ð˜#Ó!Ø(-Ð Ó-Ø€GˆTÓð &(§Z¡Z§^¡^Ð4VÓ%W€O�X˜c‘]ÓWð !%€J�˜‘Ó$à#'€M�8˜C‘=Ó'à"€Hˆh�s‰mÓ"áØ
�
‰
�‰Ð=¸sÓCóÐ�có ñ  Ø
�
‰
�‰Ð=¸wÓGóÐ�có ñ Ùˆb�j‰j�n‰nÐ>ÀÓDÓEó€K�ó ð ð8˜#ò 8ó ð8ð
 Ø*Hñ 
 Cð 
ÈTò 
ó ð
ðB ò
ó ð
ð ò
ó ð
ð ð1Øð1Ø$'ð1Ø03ð1Ø?Bð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ð 
ˆ×	Ñ	Ð>Ó	?€à'�'×'Ñ'Ó)€ØˆG×ÑØHó€	ð × Ñ ˜YÔ 'à × Ñ �/Ô "Ø ‡��—‘Ô Ø€Ô ð�3ð ˜3ó ð% Cð %¨Có %÷PNò NrX   