
    0FieL                       d dl mZ d dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlZd d	lmZ d d
lmZ d dl m!Z! d dl"m#Z# d dl$m%Z% ej&        '                    d          rd dl(m)Z) ndZ)ej&        '                    d          Z*ej+        ,                    e*d          Z* G d de!          Z- G d de!          Z. G d de!          Z/ G d de!          Z0 G d de!          Z1dS )    )annotationsN)without_property_validation)columnrow)	ButtonColumnDataSourceDataRange1d	HoverToolLabelSetNumeralTickFormatterRange1dSelectTitle)	Spectral9)figure)gen)profile)WINDOWS)DashboardComponentupdate)
log_errorsz!distributed.dashboard.export-tool)
ExportToolz#distributed.worker.profile.intervalms)defaultc                  d    e Zd ZdZd Zeed                         Zeed                         Z	dS )
ProcessingzProcessing and distribution per core

    This shows how many tasks are actively running on each worker and how many
    tasks are enqueued for each worker and how many are in the common pool
    c                   |                      i i d          }t          |          | _        t          dd          }t	          ddd|d|}|                    | j        ddt          d         d	d
           d|j        _        d|j	        _
        d|j        _
        t                      }|                    |           |                    t                    }d|_        d|_        || _        d S )N)
processingnthreads   zProcessing and Pending )titletoolsx_ranger   righttopbottom)sourceleftr'   colorr(   r)   Fa  
        <div>
            <span style="font-size: 14px; font-weight: bold;">Host:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Processing:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@processing</span>
        </div>
        follow_mouse )processing_updater   r*   r   r   quadr   xaxisminor_tick_line_alphayaxisvisibleygridr
   	add_toolsselecttooltipspoint_policyroot)selfkwargsdatar&   fighovers         Glib/python3.11/site-packages/distributed/dashboard/components/shared.py__init__zProcessing.__init__1   s   %%RR&H&HII&t,,"a.. 
*
 
 	
 
 	;A, 	 	
 	
 	
 +,	'!	!	e

9%%	 ,			    c                |   |d         }|                     d          sd S |                     |          }| j        j        }t	          |d                   }t	          |d                   }|j        |k     r|dz   |_        n&|j        d|z  |z   k    r|j        dz  |dz  z   |_        t          | j        |           d S )Nr   r    r'      gffffff?g?)getr/   r:   r&   maxendr   r*   )r;   messagesmsgr=   r&   	max_rightcoress          r@   r   zProcessing.updateZ   s     |$wwz"" 	F%%c**)#W&&	D$%%;""#a-GKK[1y=5000!+,y4/??GKt{D!!!!!rB   c                   t          | d                   }t          |          }| d         fd|D             | d         fd|D             t          |          }t          |          t                    t          t          |dd                    t          t          |dz
  dd                    d}d	g|z  |d
<   |S )Nr   c                     g | ]
}|         S r.   r.   ).0namer   s     r@   
<listcomp>z0Processing.processing_update.<locals>.<listcomp>q   s    9994j&999rB   r    c                     g | ]
}|         S r.   r.   )rN   rO   r    s     r@   rP   z0Processing.processing_update.<locals>.<listcomp>s   s    555tHTN555rB   r   r!   r"   )rO   r   r'   r(   r)   r    gffffff?alpha)sortedlenlistrange)rI   namesndr    r   s       @@r@   r/   zProcessing.processing_updatek   s     s<())u&
99995999
z?5555u555JJKK$*%%aB((5QB//00 
 
 UQY'
rB   N)
__name__
__module____qualname____doc__rA   r   r   r   staticmethodr/   r.   rB   r@   r   r   *   sy         ' ' 'R !" " Z ! "   Z \  rB   r   c                  >    e Zd ZdZd Zeed                         ZdS )ProfilePlotTime plots of the current resource usage on the cluster

    This is two plots, one for CPU and Memory and another for Network I/O
    c                R    t          j                    }t          j        |t                    }|                    d           _        t          j        |fi |\   _         _        t          t           fd                        } j        j                            d|           d S )Nstatesc                B   	 |j         d         }n# t          $ r Y d S w xY wt          j        j        |         t
                    }j        d d = j                            |                    d                     t          j	        |           |j	        _
        d S )Nr   rc   )indices
IndexErrorr   	plot_datarc   profile_intervalextendpopr   r*   selected)attroldnewindr=   r;   s        r@   cbz ProfilePlot.__init__.<locals>.cb   s    k!n   $T[%57GHHDAAAKtxx112224;%%%#&DK   s    
re   )r   createrg   rh   rj   rc   plot_figurer:   r*   r   r   rk   	on_change)r;   r<   stater=   rp   s   `    r@   rA   zProfilePlot.__init__   s       (899hhx((!(!4T!D!DV!D!D	4;	$			' 		' 		' 		' 
 
%	$		' 	&&y"55555rB   c                    || _         t          j        | j         t                    }|                    d          | _        t          | j        |           d S Nrc   rt   r   rg   rh   rj   rc   r   r*   r;   rt   r=   s      r@   r   zProfilePlot.update   K     
 -=>>hhx((t{D!!!!!rB   N)rZ   r[   r\   r]   rA   r   r   r   r.   rB   r@   r`   r`      sS         
6 6 6* !" " Z ! " " "rB   r`   c                  Z    e Zd ZdZddZeedd                        Zedd            ZdS )	ProfileTimePlotra   Nc           	         |t          j        |           _        	 |j        j        j                            dd            _        n# t          $ r
 d  _        Y nw xY wt           j        t                    r j        d          _        t           j        t                    r j                                         _         j        r	d j        gndg _        nd  _        dg _        | _        d  _        d  _        g g d _        t%          j                     _        t%          j         j        t,                    }|                    d           _        t%          j        |fi |\   _         _        dgt8           fd            } j        j                            d|           t?          g g d	           _         tC          d
dddddd           _"         j"        #                    dd j                     j"        $                    dd j         d d           d j"        j%        _&        d j"        j'        _&        tP           fd            } j         j                            d|           tS          dd           _*         j*        +                     fd           tS          dd           _,         j,        +                     j-                   t]           j        d          j                   _/         fd} j/                            d |           ta          tc           j/         j*         j,        d!d"#           j         j"        fi | _2        tg          d$d%&           _4         j        5                     j4        d           tl          j7                            d'          s2d( j4        _8        d) j/        _9        d) j*        _9        d) j,        _9        d S d S )*Nkeyr   Allcounttimerc   Fc                   d         st          |          dk    rd S t                      5  t          j        j        |d                  t
                    }j        d d = j                            |                    d                     dd<   t          j	        |           |j	        j
        _        dd<   d d d            d S # 1 swxY w Y   d S Nr   rc   TF)rT   r   r   rg   rc   rh   ri   rj   r   r*   rk   re   rl   rm   rn   r=   changingr;   s       r@   rp   z$ProfileTimePlot.__init__.<locals>.cb   s   { c#hh!mm $ $(SV)<>NOOKN""488H#5#5666"t{D)))/2$,#$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   BCCCre   r   r   Activity over time   datetimexbox_select"xpan,xwheel_zoom,xbox_select,resetstretch_widthabover$   heightx_axis_typeactive_dragr%   sizing_modetoolbar_locationr   r   r*   oranger*   r,   selection_colorc                n   j         j        j        }|r|j         j        d         t	          |                   dz  }j         j        d         t          |                   dz  }t	          ||          t          ||          c_        _        nd x_        _                            d           d S )Nr     Fupdate_metadata		ts_sourcerk   re   r=   minrF   startstoptrigger_updaterl   rm   rn   rk   r   r   r;   s         r@   	ts_changez+ProfileTimePlot.__init__.<locals>.ts_change   s    ~.6H .+F3CMMBTI~*623x==ADH(+E4(8(8#eT:J:J%
DII)--
TY66666rB   Resetsuccesslabelbutton_typec                 8                           j                  S Nr   rt   r;   s   r@   <lambda>z*ProfileTimePlot.__init__.<locals>.<lambda>       4;;tz+B+B rB   Updater!   )valueoptionsc                R    |dk    rd }|_                             d           d S )Nr~   Fr   )r}   r   )rl   rm   rn   r;   s      r@   	select_cbz+ProfileTimePlot.__init__.<locals>.select_cb   s5    e||DH66666rB   r   scale_width   )r   r    italictexttext_font_style"distributed.worker.profile.enabledProfiling is disabled.T):weakrefrefdocsession_contextrequest	argumentsrE   r}   AttributeError
isinstancerU   bytesdecode
task_namesserverr   r   tsr   rq   rt   rg   rh   rj   rc   rr   profile_plotr*   r   rk   rs   r   r   r   ts_plotlinecircler3   r4   gridr   r   reset_buttonon_clickupdate_buttonr   r   r7   r   r   r:   r   subtitle
add_layoutdaskconfigr   disabled)	r;   r   r   r<   r=   rp   r   r   r   s	   `       @r@   rA   zProfileTimePlot.__init__   s    ?{3''DH .6@DDUDQQ!       $(D)) '8A;$(E** -8??,,378Hudh//%DOODH$gDO
	++^%%
 -=>>hhx(()0)<T)L)LV)L)L&4;7	$
	$ 
	$ 
	$ 
	$ 
	$ 
%	$
	$ 	&&y"555)2*C*CDD&"%6'$
 
 
 	&'$.AAAGDN$PX 	 	
 	
 	
 &+"$)!		7 	7 	7 	7 
	7 	)))Y???"iHHH""#B#B#B#BCCC#(	JJJ##D$78884?2#6PPP	7 	7 	7 	7 	7 	gy111!")   L
 
 
 
	 3AAA$$T]G<<<{CDD 	/!9DM#'DK )-D&*.D'''		/ 	/s   *A
 
AAc                   || _         t          j        | j         t                    }|                    d          | _        t          | j        |           ||d         rdgt          |d                   z   | _	        | j	        | j
        _        | j        r#| j        |d         v r|d         | j                 }n|d         }t          | \  }}|d |D             d| _        | j        j                            | j                   d S d S d S )Nrc   countsr~   keysc                    g | ]}|d z  S r   r.   )rN   ts     r@   rP   z*ProfileTimePlot.update.<locals>.<listcomp>)  s    0I0I0IaT0I0I0IrB   r   )rt   r   rg   rh   rj   rc   r   r*   rS   r   r7   r   r}   zipr   r   r=   )r;   rt   metadatar=   r   timesr   s          r@   r   zProfileTimePlot.update  s    
 -=>>hhx((t{D!!!HX$6$gx/?(@(@@DO"&/DKx (DH(888f%dh/h'HME6 &0I0I50I0I0IJJDGN&&tw/////  rB   Tc                n     t            fd            } j        j                            |           d S )Nc                    K   j                             j        j        j                   d {V r j                                          d {V  nd  t          t          j                  rt          j
                    d {V \                                                        fd           d S )N)r}   r   r   c                 0                                    S r   r   )r   profr;   s   r@   r   z<ProfileTimePlot.trigger_update.<locals>.cb.<locals>.<lambda>:  s    dkk$6Q6Q rB   )r   get_profiler}   r   r   get_profile_metadatar   r   Futureasynciogatherr   add_next_tick_callback)r   r   r;   r   s   @@r@   rp   z*ProfileTimePlot.trigger_update.<locals>.cb/  s      00HDJTY 1        D   !%!A!A!C!CCCCCCC$
++ F'.~dH'E'E!E!E!E!E!E!EhHHJJ--.Q.Q.Q.Q.Q.QRRRRRrB   )r   r   loopadd_callback)r;   r   rp   s   `` r@   r   zProfileTimePlot.trigger_update-  sS    	
	S 
	S 
	S 
	S 
	S 

	S 	%%b)))))rB   r   )T	rZ   r[   r\   r]   rA   r   r   r   r   r.   rB   r@   r{   r{      s         
j/ j/ j/ j/X !0 0 0 Z ! 0$ !* * * ! * * *rB   r{   c                  V    e Zd ZdZddZeed                         Zed             ZdS )ProfileServerra   Nc           	         |t          j        |           _        | _         j        j        j         _        d  _        d  _        g g d _	        t          j
         j                   _        t          j         j        t                    }|                    d           _        t          j        |fi |\   _         _        dgt&          t(           fd                        } j        j                            d|           t/          g g d           _        t3          ddd	d
ddd           _         j                            dd j                    j                            dd j        d d           d j        j        _        d j        j        _        t(           fd            } j        j                            d|           tA          dd           _!         j!        "                     fd           tA          dd           _#         j#        "                     j$                   tK          tM           j!         j#        d           j         j        fi | _'        tQ          dd           _)         j        *                     j)        d           tV          j,        -                    d          s&d  j)        _.        d! j!        _/        d! j#        _/        d S d S )"Nr   rc   Fc                f   d         st          |          dk    rd S t          j        j        |d                  t                    }j        d d = j                            |                    d                     dd<   t          j        |           |j        j	        _
        dd<   d S r   )rT   r   rg   rc   rh   ri   rj   r   r*   rk   re   r   s       r@   rp   z"ProfileServer.__init__.<locals>.cbT  s     { c#hh!mm$T[Q%8:JKKDAAAKtxx11222HQK4;%%%+.DK (HQKKKrB   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                j   j         j        j        }|r|j         j        d         t	          |                   dz  }j         j        d         t          |                   dz  }t	          ||          t          ||          c_        _        nd x_        _                                         d S )Nr   r   r   r   s         r@   r   z)ProfileServer.__init__.<locals>.ts_changeu  s    ~.6H .+F3CMMBTI~*623x==ADH(+E4(8(8#eT:J:J%
DII)--
TY!!!!!rB   r   r   r   c                 8                           j                  S r   r   r   s   r@   r   z(ProfileServer.__init__.<locals>.<lambda>  r   rB   r   r   )r   r   r   r   r   r   T)0r   r   r   r   io_loopr   logr   r   r   r   rt   rg   rh   rj   rc   rr   r   r*   r   r   rk   rs   r   r   r   r   r   r   r3   r4   r   r   r   r   r   r   r   r   r:   r   r   r   r   r   rE   r   r   )r;   r   r   r<   r=   rp   r   r   s   `      @r@   rA   zProfileServer.__init__E  s   ?{3''DH;&.
	++(22
 -=>>hhx(()0)<T)L)LV)L)L&4;7	$	
	  
	  
	  
	  
	  
 
%	$
	  	&&y"555)2*C*CDD&"%6'$
 
 
 	&'$.AAAGDN$PX 	 	
 	
 	
 &+"$)!		" 	" 	" 	" 
	" 	)))Y???"iHHH""#B#B#B#BCCC#(	JJJ##D$7888!4#5=QQQL
 
 	
 
	 3AAA$$T]G<<<{CDD 	/!9DM)-D&*.D'''	/ 	/rB   c                    || _         t          j        | j         t                    }|                    d          | _        t          | j        |           d S rv   rw   rx   s      r@   r   zProfileServer.update  ry   rB   c           	        t          j        | j        | j        | j                  | _        t          j        | j        t                    }|                    d          | _	        t          | j        |           d | j        D             }t          t          j        dt          j        d| j                                      }| j        j        
                    ||d           d S )N)r   r   rc   c                    g | ]
\  }}|d z  S r   r.   )rN   r   _s      r@   rP   z0ProfileServer.trigger_update.<locals>.<listcomp>  s     ///daT///rB   r   r"   r   )r   r   r   r   r   rt   rg   rh   rj   rc   r   r*   rU   toolzpluckr   r=   )r;   r=   r   r   s       r@   r   zProfileServer.trigger_update  s    ($)TTT
 -=>>hhx((t{D!!!//dh///ek'5;q$(+C+CDDEE""EF#C#CDDDDDrB   r   r   r.   rB   r@   r   r   ?  s~         
O/ O/ O/ O/b !" " Z ! " !E E ! E E ErB   r   c                  B    e Zd ZddZd Zeed                         ZdS )SystemMonitorr   Nc                   || _         |j        j        }d| _        |"|j                            |          }|| _        t          d |D                       | _        t          dgdz  g dg dg dd	          | _        t          | j        | 	                                           t          d
dd          }d}t          d-dd||d|d|| _        | j                            | j        dd           d| j        j        _        | j                            t#          dddddd| j                             t          d-dd||d|d|| _        | j                            | j        dd           d| j        j        _        | j                            t#          dddddd| j                             t          d-dd|||dd|| _        | j                            | j        dd d!d"#           | j                            | j        dd$d%d&#           d'| j        j        _        t)          d()          | j        j        d         _        t)          d()          | j        j        d         _        | j        | j        | j        g}t,          sTt          d-d*d|||dd|| _        | j                            | j        dd+           |                    | j                   d,|v rd,|d,         i}	ni }	t,          sd| j        j        _        d| j        j        _        d| j        j        _        d| j        j        _        t7          |i |	| _        | j         j                                         d S ).Nr   r   c                    i | ]}|g S r.   r.   )rN   rO   s     r@   
<dictcomp>z*SystemMonitor.__init__.<locals>.<dictcomp>  s    'C'C'CTb'C'C'CrB         )F   7   (   )zmax: 45%zmin: 45%z	mean: 45%)zmax: 133.5MiBzmin: 23.6MiBzmean: 115.4MiB)xycpumemoryrG   i N  )followfollow_intervalrange_paddingzreset,xpan,xwheel_zoomCPUr   r   )r$   r   r   r%   r   r&   r   r  )r*   r  r  
Percentager  r  screen1em)r  r  x_unitsy_unitsr   text_font_sizer*   Memoryr	  Bytes	Bandwidth)r$   r   r   r&   r%   r   zhost_net_io.read_bpsredread)r*   r  r  r,   legend_labelzhost_net_io.write_bpsbluewritezBytes / secondz0.0b)formatzNumber of File Descriptorsnum_fdsr   r.   )workermonitor
quantities
last_countrange_queryr   r*   label_sourcer   get_datar	   r   r  r   r3   
axis_labelr   r   mem	bandwidthr   	formatterr   r  appendy_ranger   r   r:   )
r;   r  r   r!  r<   rW   r&   r%   plotskws
             r@   rA   zSystemMonitor.__init__  s   )!N..Z.@@E(DO&'C'CU'C'C'CDD,S1W!\\<<<MMM	 
 
 	t{DMMOO,,,UEQRSSS( 
"$
 
 
 
 	T[Fe<<<$0!  $(  
	
 
	
 
	
  
"$
 
 
 
 	T[Fh???$+!  $(  
	
 
	
 
	
   
"$
 
 
 
 	;$ 	 	
 	
 	
 	;%  	 	
 	
 	
 +;' -A,O,O,OQ)&:&&I&I&Iq#48T^4 	'! 2&!(   DL LT[FiHHHLL&&&F""!67BBB 	+)*DL &!"!"'($E(R((	""$$$$$rB   c                    | j         j                            | j                  }d |d         D             |d<   | j         j        j        | _        |S )Nr   c                    g | ]}|d z  S r   r.   )rN   r  s     r@   rP   z*SystemMonitor.get_data.<locals>.<listcomp>*  s    111!QX111rB   r   )r  r  r"  r!  r   )r;   rY   s     r@   r$  zSystemMonitor.get_data(  sN    K++$/+BB11qy111&	+-3rB   c                    d } j                                                              d            fdt          t          |fD              j        j        d<    fdt          t          |fD              j        j        d<   d S )Nc                @    t          |           t          |           z  S r   )sumrT   )r  s    r@   meanz"SystemMonitor.update.<locals>.mean1  s    q66CFF?"rB   r   c           	     x    g | ]6}d                      |j         |j        j        d                             7S )z{}: {:.1f}%r  )r  rZ   r*   r=   rN   fr;   s     r@   rP   z(SystemMonitor.update.<locals>.<listcomp>5  sO     )
 )
 )
   QQt{/?/F-G-GHH)
 )
 )
rB   r  c                    g | ]S}d                      |j        t          j                             |j        j        d                                       TS )z{}: {}r	  )r  rZ   r   utilsformat_bytesr*   r=   r4  s     r@   rP   z(SystemMonitor.update.<locals>.<listcomp>9  sd     ,
 ,
 ,
  OO
DJ33AAdk6Fx6P4Q4QRR ,
 ,
 ,
rB   r	  )r*   streamr$  r   rF   r#  r=   )r;   r2  s   ` r@   r   zSystemMonitor.update.  s    	# 	# 	# 	4==??D111)
 )
 )
 )
3%)
 )
 )
u%,
 ,
 ,
 ,
 3%	,
 ,
 ,
x(((rB   )r   N)rZ   r[   r\   rA   r$  r   r   r   r.   rB   r@   r   r     sb        |% |% |% |%|   !
 
 Z ! 
 
 
rB   r   )2
__future__r   r   r   tlzr   bokeh.core.propertiesr   bokeh.layoutsr   r   bokeh.modelsr   r   r	   r
   r   r   r   r   r   bokeh.palettesr   bokeh.plottingr   tornador   r   distributedr   distributed.compatibilityr    distributed.dashboard.componentsr   distributed.dashboard.utilsr   distributed.utilsr   r   rE   !distributed.dashboard.export_toolr   rh   r7  parse_timedeltar   r`   r{   r   r   r.   rB   r@   <module>rI     s   " " " " " "       = = = = = = % % % % % % % %
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 % $ $ $ $ $ ! ! ! ! ! !              - - - - - - ? ? ? ? ? ? . . . . . . ( ( ( ( ( (;??677 <<<<<<<J ;??#HII :--.>-MM V V V V V# V V Vr!" !" !" !" !"$ !" !" !"HU* U* U* U* U*( U* U* U*pgE gE gE gE gE& gE gE gETU
 U
 U
 U
 U
& U
 U
 U
 U
 U
rB   