
    shd                        S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
  S SKJr  \R                  " S5      r\R                  " 5       r\R"                  " S5      r\R'                  \5        \R)                  \5        \R+                  \R,                  5        S\l        S	\S
\4S jrS\S
\4S jr " S S5      rg)    N)datetime)gethostname)AnyOptional)StrobelightCLIFunctionProfiler!strobelight_compile_time_profilerzB%(name)s, line %(lineno)d, %(asctime)s, %(levelname)s: %(message)sFurlreturnc                    U n [         R                  " SU /S[         R                  S9nUR                  S:X  a  UR                  R                  S5      nU$ ! [         a*  n[        R                  S[        U5      5         S nAU$ S nAff = f)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       |/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/_strobelight/compile_time_profiler.py	get_fburlr      s    IMcN4z7I7I
 !,,W5I   MBDGLLMs   AA 
B!BB
identifierc                    0 S/ _SS_S/ /_S/ /_SSS/_S	S
_SSSSU  S3/S.//_S/ _SS_S/ _SS_SS_SS_SS_S/ _SS_S/ _SS S!S"S#S#S$.// SS%SS&S'S(S).
EnS*nS+nU[         R                  " U5      -   U-   n[        U5      $ ),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' ( $FSCP
 #)? JB zON$**Z"88>IHX    c                   ^   \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\
\S'   Sr\
\S'   \R                  R                  S	5      r\\   \S
'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   \" \R                  R                  SS5      5      r\\S'   \" \R                  R                  SS5      5      r\\S'   \" \" \R                  R                  SS5      5      5      r\\S'   \S\4S j5       r\\4S\SS4S jj5       r\S$S j5       r\S$S j5       r\S\S\S \S!\S\4
S" j5       r S#r!g)%StrobelightCompileTimeProfilerR   r   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                 @    SSK Jn  [        UR                  5       5      $ )Nr   )CompileContext)torch._guardsrl   strcurrent_trace_id)clsrl   s     r   	get_frame(StrobelightCompileTimeProfiler.get_frameo   s    0^44677rX   profiler_classc                     U R                   (       a  [        R                  S5        g [        R                  S5        U[        L a0  SS KnUR                  S5      (       d  [        R                  S5        g SU l         U R                  5         U" U R                  U R                  U R                  U R                  S[        R                  R                  S[        R                  R                  S	S
5      5      -   U R                  1S9U l        g )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 )rj   max_profile_duration_secstack_max_lenasync_stack_max_lenrun_user_namer+   )r`   r   infor   shutilwhich	_cls_initrj   rh   rf   osenvirongetr   rd   )rp   rs   r~   s      r   enable%StrobelightCompileTimeProfiler.enableu   s    ;;KKLM@A;;<<//8 
 &%(%9%9.. # 4 4)jjnnVRZZ^^J%CDE(
rX   c                 <   SR                  [        R                  " 5       R                  S5      [        R
                  " 5       [        5       S9U l        [        R                  SU R                  5        [        R                  S[        U R                  5      5        g )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   rp   s    r   r   (StrobelightCompileTimeProfiler._cls_init   sl    077(()<=		 ] 8 
 	;S^^LM/	
rX   c                 t    [         R                  SU R                  U R                  U R                  -   5        g )NzG%s strobelight success runs out of %s non-recursive compilation events.)r   r}   r\   r]   r   s    r   
_log_stats)StrobelightCompileTimeProfiler._log_stats   s.    U%%%%(@(@@	
rX   func
phase_nameargskwargsc                 X  ^^^ S[         4UUU4S jjnU R                  (       d  U" 5       $ U R                  c  [        R	                  S5        g U R                  5       nU R                  (       a?  U =R                  S-  sl        [        R                  SUUU R                  U5        U" 5       $ U R                  bR  [        R                  " U R                  U5      S LnU(       d(  [        R                  SUU R                  5        U" 5       $ SU l        X l	        [        R                  SU5        U R                  R                  " T/TQ70 TD6nU R                  R                  b  U =R                  S-  sl        OU =R                   S-  sl        U R#                  5         S	U l        U$ )
Nr
   c                     > T" T 0 TD6$ )N )r   r   r   s   r   skipAStrobelightCompileTimeProfiler.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`   rd   r   errorrq   r_   r^   r}   rc   rb   rematchprofileprofile_resultr\   r]   r   )	rp   r   r   r   r   r   frame_id
should_runwork_results	    ` ``    r   profile_compile_time3StrobelightCompileTimeProfiler.profile_compile_time   sb   	)c 	) 	) {{6M<<LL./==?**$$)$KK3!! 6M*#"5"5x@LJM''
 v*.'&((3ll**4A$A&A<<&&2%%*%$$)$*/'rX   r   )r
   N)"__name__
__module____qualname____firstlineno__r\   int__annotations__r]   r^   r_   boolr`   r   r   r   rb   r   rn   r   rc   rd   r   rf   rh   floatrj   classmethodrq   r   r   r   r   r   __static_attributes__r   rX   r   rZ   rZ   R   s   !"3" !#! !#!(--GT &(ZZ^^4V%WOXc]W !%J$#'M8C='"Hhsm"


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


=wGc  bjjnn>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	propagatern   r   rW   rZ   r   rX   r   <module>r      s      	 	      S 
		>	?'')H	   Y '   / "   3 3 %C %C %PN NrX   