U
    yh5                     @   s   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 
dZe  Ze dZee ee ee j de_G d	d
 d
ZdS )    N)datetime)gethostname)AnyOptional)StrobelightCLIFunctionProfilerZ!strobelight_compile_time_profilerzB%(name)s, line %(lineno)d, %(asctime)s, %(levelname)s: %(message)sFc                   @   s"  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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efeddddZeddddZeddddZeeeeeedddZdS ) StrobelightCompileTimeProfilerr   success_profile_countfailed_profile_countignored_profile_runsFinside_profile_compile_timeenabledN
identifiercurrent_phaseprofilerZ$COMPILE_STROBELIGHT_MAX_STACK_LENGTH   max_stack_lengthZ$COMPILE_STROBELIGHT_MAX_PROFILE_TIMEi  max_profile_timeZCOMPILE_STROBELIGHT_SAMPLE_RATEg    cAsample_each)profiler_classreturnc                 C   s   | j rtd d S td |tkrFdd l}|dsFtd d S d| _ |   || j| j| j	| j	dt
jdt
jd	d
 | jhd| _d S )Nz2compile time strobelight profiling already enabledz*compile time strobelight profiling enabledr   Zstrobeclientznstrobeclient not found, cant enable compile time strobelight profiling, seemslike you are not on a FB machine.Tzpt2-profiler/USERUSERNAME )r   Zmax_profile_duration_secZstack_max_lenZasync_stack_max_lenZrun_user_nameZsample_tags)r   loggerinfor   shutilwhich	_cls_initr   r   r   osenvirongetr   r   )clsr   r    r"   Z/var/www/html/venv/lib/python3.8/site-packages/torch/_strobelight/compile_time_profiler.pyenable2   s.    


z%StrobelightCompileTimeProfiler.enable)r   c                 C   sJ   dj t dt t d| _t	d| j t	dd| j d d S )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!   r"   r"   r#   r   R   s    z(StrobelightCompileTimeProfiler._cls_initc                 C   s   t d| j| j| j  d S )NzG%s strobelight success runs out of %s non-recursive compilation events.)r   r   r   r	   r,   r"   r"   r#   
_log_statss   s
    
z)StrobelightCompileTimeProfiler._log_stats)func
phase_nameargskwargsr   c                 O   s   | j s|||S | jd kr(td d S | jrV|  jd7  _td|| j |||S d| _|| _| jj|f||}| jj	d k	r|  j
d7  _
n|  jd7  _|   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   ZprofileZprofile_resultr   r	   r-   )r!   r.   r/   r0   r1   Zwork_resultr"   r"   r#   profile_compile_time|   s,    



z3StrobelightCompileTimeProfiler.profile_compile_time)__name__
__module____qualname__r   int__annotations__r	   r
   r   boolr   r   r   strr   r   r   r   r   r    r   r   floatr   classmethodr   r$   r   r-   r4   r"   r"   r"   r#   r      s<   
    r   )loggingr   r   socketr   typingr   r   Z(torch._strobelight.cli_function_profilerr   	getLoggerr   StreamHandlerZconsole_handler	Formatter	formattersetFormatter
addHandlersetLevelINFO	propagater   r"   r"   r"   r#   <module>   s   


