
    
3j                         % S SK r S SKrS SKJr  S SKJrJr  S SKJr	  S SK
Jr  SSKJr   " S S	\5      r\" 5       q\\\4   \S
'   Sr " S S5      r " S S5      r\\/rg)    N)OrderedDict)Any	TypedDict)IO)PromptServer   )logc                   :    \ rS rSr% \\S'   \\S'   \S-  \S'   Srg)Clock   namestartNend )__name__
__module____qualname____firstlineno__str__annotations__float__static_attributes__r       B/home/wildlama/comfy/ComfyUI/custom_nodes/comfy_mtb/nodes/clock.pyr   r      s    
IL	r   r   active_timers2   c            	           \ rS rSrSrS r\S 5       r\R                  S4r
SrSrSrS	S
.S\S\S	-  4S jjr\SS	S.S\S\S\S	-  4S jj5       rSrg	)MTB_StartClock   zc
Starts a profiling clock with a given name.

Outputs a unique ID that must be passed to EndClock.
c                     g Nr   selfs    r   __init__MTB_StartClock.__init__       r   c                 F    SSS04SSSS.4S.S	[         R                  40S
.$ )NSTRINGdefaultzClock ABOOLEANFzCache the clock ID, this means the node will follow Comfy's default invalidation system. If False it will always invalidate / mark the node as 'dirty')r)   tooltip)r   cachepassthrough)requiredoptionalCIOANYclss    r   INPUT_TYPESMTB_StartClock.INPUT_TYPES"   sH     "Iy#9:#( $|	 z
 	
r   r(   )r-   clock_idstart_timer	mtb/utilsN)r-   r   r-   c          	      n   [        [        5      [        :  a  S n[        R                  5        H  u  pVUS   c  M  Un  O   U(       a=  [        R	                  U5      n[
        R                  " SUS    SU S[         S35        O<[        R                  SS9u  pG[
        R                  " S	US    SU S[         S35        [        [        R                  " 5       5      n[        R                  " 5       n	U	US S
.[        U'   [        R                  U5        [
        R                  " SU SU S35        UU4$ )Nr   z$[Profiling] Evicted finished clock 'r   ' (ID: z) due to limit (z).F)lastz#[Profiling] Evicted running clock ')r   r   r   [Profiling] Clock 'z
) started.)lenr   
MAX_CLOCKSitemspopr	   infopopitemwarningr   uuiduuid4timeperf_countermove_to_enddebug)
r#   r   r-   kwargsremoved_keykey
clock_dataremoved_clockr7   
start_times
             r   r8   MTB_StartClock.start_timer?   s\   
 }+K#0#6#6#8e$0"%K $9  - 1 1+ >:=;P:QQXYdXeeu  wA  vB  BD  E .;-B-B-B-N*9-:O9PPWXcWddtu  uA  AC  D tzz|$&&(
  #
h 	!!(+		'vWXJjIJ 
 	
r   F)r,   r-   r,   c                0    U(       d  [        S5      $ XUS.$ )NNan)r   r,   r-   )r   )r4   r   r,   r-   s       r   
IS_CHANGEDMTB_StartClock.IS_CHANGEDh   s     <[IIr   r   )r   r   r   r   __doc__r$   classmethodr5   r1   r2   RETURN_TYPESRETURN_NAMESFUNCTIONCATEGORYr   r   r8   boolrT   r   r   r   r   r   r      s     
 
$ 	LL HH 7;'
'
),t'
R ).$JJ"&J=@4ZJ Jr   r   c                   l    \ rS rSrSrS r\S 5       r\R                  SSS4r
SrS	rS
rSS\4S jjrSrg)MTB_EndClockr   z
Stops a profiling clock identified by its ID and returns the elapsed time in milliseconds.

Errors if the clock ID is not found or already stopped.
c                     g r!   r   r"   s    r   r$   MTB_EndClock.__init__y   r&   r   c                 @    SSSS040S[         R                  40SS0S.$ )	Nr7   r(   
forceInputTr-   	unique_id	UNIQUE_ID)r.   r/   hiddenr0   r3   s    r   r5   MTB_EndClock.INPUT_TYPES|   sD     !4( z [
 	
r   r(   FLOATINT)r-   r   secondsmilliseconds	end_timerr9   Nr7   c           	         U[         ;  a  [        SU S35      e[         U   nUR                  S5      b
  X$S   US   4$ US   n[        R                  " 5       nXe-
  n[        US-  5      nXS'   [         R                  U5        [        R                  " SUS    SU S	U S
35        U(       a+  [        R                  R                  SUS    SUS S3U5        X$S   Xx4$ )NzError: Clock with ID 'zX' not found. Ensure StartClock was executed for this ID and proper passthrough chaining.r   r   r   i  r=   r;   z) stopped. Elapsed: mszClock 'z' took z.4fz seconds)r   
ValueErrorgetrG   rH   intrI   r	   rJ   r   instancesend_progress_text)	r#   r7   r-   rd   clockrP   end_timeduration_secondsduration_mss	            r   rl   MTB_EndClock.end_timer   s    =((
 3^ ^ 
 h'99U've==7^
$$&#0*T12"e!!(+		!%-zAUVaUbbde	
 !!44%-0@/EXN
 6],<JJr   r   r!   )r   r   r   r   rV   r$   rW   r5   r1   r2   rX   rY   rZ   r[   r   rl   r   r   r   r   r^   r^   r   s`     
 
" 		LL HHK# K Kr   r^   )rG   rE   collectionsr   typingr   r   comfy.comfy_types.node_typingr   r1   serverr   r	   r   r   r   r   r?   r   r^   	__nodes__r   r   r   <module>r~      sn      # ! 3  I  *5{3:& 6 
WJ WJtIK IKX \*	r   