
    Ǆg5                     N   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_         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)sFc                      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<   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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enabledN
identifiercurrent_phaseprofiler$COMPILE_STROBELIGHT_MAX_STACK_LENGTH   max_stack_length$COMPILE_STROBELIGHT_MAX_PROFILE_TIMEi  max_profile_timeCOMPILE_STROBELIGHT_SAMPLE_RATEg    cAsample_eachprofiler_classreturnc                    | 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 )r   max_profile_duration_secstack_max_lenasync_stack_max_lenrun_user_namesample_tags)r   loggerinfor   shutilwhich	_cls_initr   r   r   osenvirongetr   r   )clsr   r(   s      p/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/_strobelight/compile_time_profiler.pyenablez%StrobelightCompileTimeProfiler.enable2   s    ;;KKLM@A;;<</8  &%(%9%9.. # 4 4)jjnnVRZZ^^J%CDE(
    c                 4   dj                  t        j                         j                  d      t	        j
                         t                     | _        t        j                  d| j                         t        j                  dd| j                   d       y )Nz{date}{pid}{hostname}z%Y-%m-%d-%H:%M:%S)datepidhostnamez%Unique sample tag for this run is: %szZYou can use the following link to access the strobelight profile at the end of the run: %sa*  https://www.internalfb.com/intern/scuba/query/?dataset=pyperf_experimental%2Fon_demand&drillstate=%7B%22purposes%22%3A[]%2C%22end%22%3A%22now%22%2C%22start%22%3A%22-30%20days%22%2C%22filterMode%22%3A%22DEFAULT%22%2C%22modifiers%22%3A[]%2C%22sampleCols%22%3A[]%2C%22cols%22%3A[%22namespace_id%22%2C%22namespace_process_id%22]%2C%22derivedCols%22%3A[]%2C%22mappedCols%22%3A[]%2C%22enumCols%22%3A[]%2C%22return_remainder%22%3Afalse%2C%22should_pivot%22%3Afalse%2C%22is_timeseries%22%3Afalse%2C%22hideEmptyColumns%22%3Afalse%2C%22timezone%22%3A%22America%2FLos_Angeles%22%2C%22compare%22%3A%22none%22%2C%22samplingRatio%22%3A%221%22%2C%22metric%22%3A%22count%22%2C%22aggregation_field%22%3A%22async_stack_complete%22%2C%22top%22%3A10000%2C%22aggregateList%22%3A[]%2C%22param_dimensions%22%3A[%7B%22dim%22%3A%22py_async_stack%22%2C%22op%22%3A%22edge%22%2C%22param%22%3A%220%22%2C%22anchor%22%3A%220%22%7D]%2C%22order%22%3A%22weight%22%2C%22order_desc%22%3Atrue%2C%22constraints%22%3A[[%7B%22column%22%3A%22sample_tags%22%2C%22op%22%3A%22all%22%2C%22value%22%3A[%22[%5C%22z%5C%22]%22]%7D]]%2C%22c_constraints%22%3A[[]]%2C%22b_constraints%22%3A[[]]%2C%22ignoreGroupByInComparison%22%3Afalse%7D&view=GraphProfilerView&&normalized=1712358002&pool=uber)
formatr   nowstrftimer+   getpidr   r   r&   r'   r.   s    r/   r*   z(StrobelightCompileTimeProfiler._cls_initR   s}    077(()<=		 ] 8 
 	;S^^Lh# $'>>"2 3HH	
r1   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_statss   s.    U%%%%(@(@@	
r1   func
phase_nameargskwargsc                    | j                   s ||i |S | j                  t        j                  d       y | j                  r>| xj
                  dz  c_        t        j                  d|| j                          ||i |S d| _        || _         | j                  j                  |g|i |}| j                  j                  | xj                  dz  c_
        n| xj                  dz  c_        | j                          d| _        |S )Nzprofiler is not set   zjprofile_compile_time is requested for phase: %s while already in running phase: %s, recursive call ignoredTF)r   r   r&   errorr   r   r'   r   profileprofile_resultr   r   r<   )r.   r=   r>   r?   r@   work_results         r/   profile_compile_timez3StrobelightCompileTimeProfiler.profile_compile_time|   s     {{(((<<LL./**$$)$KK|!!
 (((*.'&*cll**4A$A&A<<&&2%%*%$$)$*/'r1   )r   N)__name__
__module____qualname__r   int__annotations__r   r   r   boolr   r   r   strr   r   r   r+   r,   r-   r   r   floatr   classmethodr   r0   r*   r<   rG    r1   r/   r
   r
      se   !"3" !#! !#!(--GT !%J$#'M8C='"Hhsm"


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


=wGc  bjjnn>DEK  *H 
C 
T 
 
> 
 
@ 
 
 $'03?B	 r1   r
   )loggingr+   r   socketr   typingr   r   (torch._strobelight.cli_function_profilerr   	getLoggerr&   StreamHandlerconsole_handler	Formatter	formattersetFormatter
addHandlersetLevelINFO	propagater
   rQ   r1   r/   <module>r`      s     	     S 
		>	?'''')GH	   Y '   / "   C Cr1   