
    0Fie                   t	   d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlZd dlmZm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$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZDmEZEmFZFmGZG d dlHmIZImJZJ d dlKmLZLmMZMmNZN d dlOmPZPmQZQmRZR d dlSmTZT d dlUZUd dlUmVZV d dlWmXZXmYZYmZZZm[Z[m\Z\m]Z] d dl^m_Z_ d dl`maZa d dlbmcZcmdZdmeZemfZf d dlgmhZh d dlimjZjmkZkmlZlmmZmmnZn d dlompZp d dlqmrZr d dlsmtZtmuZu d d lvmwZw d d!lvmtZx d d"lvmyZz d d#l{m|Z| d d$l}m~Z~ d d%lmZ d d&lmZmZ eUjV                            d'          rd d(lmZ ndZ ed)          Z ej        e          Z eI eJej                            ej                            e          d*d*d+d,                    -          Z eBej                            ej                            e          d*d.          /          Zd0g d1d2Zej         d3z  Zd4d5d6d7Z G d8 d9ec          Z G d: d;ec          Z G d< d=          Z G d> d?ece          Z G d@ dAece          Z G dB dCec          Z G dD dEec          Z G dF dGec          Z G dH dIec          Z G dJ dKec          Z G dL dMec          Z G dN dOec          Z G dP dQec          Z G dR dSec          Z G dT dUec          Z G dV dWec          Z G dX dYec          Z G dZ d[ec          Z G d\ d]ec          Z G d^ d_ec          ZddaZ G db dcec          Z G dd deec          Z G df dgec          Z G dh diec          Z G dj dkec          Z G dl dmec          Z G dn doec          Z G dp dqec          Z G dr dsec          Zdtdtdudvdwdxdydzd{Zekj        d|k     rd}eiZnd~eiZ G d d          Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             ZeLdd            Zed             Zed             Zed             Zed             ZdS )    )annotationsN)OrderedDictdefaultdict)Iterable)datetime)Number)AnyTypeVar)valuewithout_property_validation)curdoc)columnrow)AdaptiveTickerArrowBasicTickerBoxSelectToolBoxZoomToolCDSViewColorBarColumnDataSourceCustomJSHoverDataRange1dFactorRangeGroupFilterHelpTool	HoverToolHTMLTemplateFormatterMultiChoiceNumberFormatterNumeralTickFormatterOpenURLPanToolRange1d	ResetToolSelectTabsTapToolTitleVeeHeadWheelZoomTool)	DataTableTableColumn)Div)	Viridis11)figure)Theme)cumsumfactor_cmaplinear_cmapstack)EnvironmentFileSystemLoader)currypipevalmap)concatgroupbymap)escape)config)format_bytesformat_timefuncname	key_splitparse_bytesparse_timedelta)Status)add_periodic_callback)DashboardComponentProfileServerProfileTimePlotSystemMonitor)TabPanel)_DATATABLE_STYLESHEETS_KWARGSBOKEH_VERSION	PROFILING	transposeupdate)GraphLayout)GroupTiming)color_ofprogress_quads)TaskStreamPluginrT   )colors)time)	Scheduler)SpansSchedulerExtension)Log
log_errorsz!distributed.dashboard.export-tool)
ExportToolTz..http	templates)loaderz
theme.yaml)filenamei   )
                   @         i   )base	mantissas	   zstatics/images/numpy.pngzstatics/images/pandas.pngzstatics/images/python.png)numpypandasbuiltinsc                  N    e Zd ZdZed             Zeed                         ZdS )	OccupancyOccupancy (in time) per workerc           
         || _         t          ddgddgddgddgddgdd	gddgd
          | _        t          ddddddd|| _        | j                            | j        ddddd          }d |_        d| j        j        _        d| j        j	        _
        d| j        j        _
        d| j        j        _        t          t          d                    }t!                      }d|_        d|_        | j                            ||           d S )Nr   ab        皙?rd   re   redblue)	occupancyworkerxymscolorescaped_workerrt    abover   2   )titletoolstoolbar_locationx_axis_typemin_border_bottomr   r   r   ?r   )sourcer   widthr   heightr   F"./info/worker/@escaped_worker.htmlurlcallbackz@worker : @occupancy s.follow_mouse )	schedulerr   r   r0   rootrectnonselection_glyphxaxisminor_tick_line_alphayaxisvisibleygridx_rangestartr(   r"   r   tooltipspoint_policy	add_tools)selfr   kwargsr   taphovers         Jlib/python3.11/site-packages/distributed/dashboard/components/scheduler.py__init__zOccupancy.__init__   sC   "&V*3ZV!f#&* 

 

  
$" 
 
 
 
	 y~~;#TSG  
 
 #'01	-"'	"'	"#	w+OPPPQQQ2+	E3'''''    c                   | j         j                                        }t          t	          t          |                              }d |D             }d |D             }d |D             }t          |          }g }|D ]_}|| j         j        v r|                    d           &|| j         j	        v r|                    d           J|                    d           `|r?dt          |           dt          || j         j        z             | j        j        _        nd	| j        j        _        |r5|d
 |D             ||d |D             ||d}	t          | j        |	           d S d S )Nc                    g | ]	}|j         
S r   )r}   .0wss     r   
<listcomp>z$Occupancy.update.<locals>.<listcomp>   s    444bR\444r   c                    g | ]}|d z  S   r   r   occs     r   r   z$Occupancy.update.<locals>.<listcomp>   s    ...ScDj...r   c                    g | ]}|d z  S )  r   r   s     r   r   z$Occupancy.update.<locals>.<listcomp>   s    ,,,3S3Y,,,r   r{   greenr|   zOccupancy -- total time: z wall time: rt   c                    g | ]	}|j         
S r   addressr   s     r   r   z$Occupancy.update.<locals>.<listcomp>   s    888"2:888r   c                @    g | ]}t          j        |j                  S r   r>   
url_escaper   r   s     r   r   z$Occupancy.update.<locals>.<listcomp>   s%    "S"S"SR6#4RZ#@#@"S"S"Sr   )r}   r~   r   r   r   r   r   )r   workersvalueslistrangelensumidleappend	saturatedrA   total_nthreadsr   r   textrQ   r   )
r   r   r   r}   r   r   totalr   r   results
             r   rQ   zOccupancy.update   s    .(//11s7||$$%%44G444	..I...,,),,,I 	% 	%BT^(((U####t~///W%%%%V$$$$ 	/SK,>,> S S)%$.2O*OPPS S IO  
 $/DIO  	(&88888"S"S7"S"S"S F 4;'''''	( 	(r   N__name__
__module____qualname____doc__r]   r   r   rQ   r   r   r   rt   rt   }   sZ        ((&( &( Z&(P !$( $( Z ! $( $( $(r   rt   c                  >    e Zd ZdZed             Zed             ZdS )ProcessingHistogram!How many tasks are on each workerc           	     2   d| _         || _        t          ddgddgddgd          | _        t	          ddddd	d
|| _        d| j        j        _        d| j        j        _	        d | j        _
        | j                            | j        dddddd           d S )Nr   rd   re   
   leftrighttopzTasks Processing (count)
processing	frequencyr   r   namey_axis_labelr   Fr   r   r   deepskyblue      ?r   r   r   bottomr   r   
fill_alphar   )lastr   r   r   r0   r   r   r   r   r   r   quadr   r   r   s      r   r   zProcessingHistogram.__init__   s    	"&Vr2h1v>>
 
  
,$	
 

 
 
	 12	-"'	%)	"	; 	 	
 	
 	
 	
 	
r   c                    d | j         j                                        D             }t          j        |d          \  }}| j        j                            |d d         |dd          |d           d S )Nc                6    g | ]}t          |j                  S r   r   r   r   s     r   r   z.ProcessingHistogram.update.<locals>.<listcomp>   s"    JJJBSJJJr   (   binsrd   r   )r   r   r   np	histogramr   datarQ   )r   Lcountsr   s       r   rQ   zProcessingHistogram.update   sw    JJ$.*@*G*G*I*IJJJL,,,	3B3!ABB% O OPPPPPr   Nr   r   r   r   r   r      sT        ++
 
 Z
< !Q Q ! Q Q Qr   r   c                  6    e Zd ZU dZded<   ded<   d ZddZdS )MemoryColora  Change the color of the memory bars from blue to orange when process memory goes
    above the ``target`` threshold and to red when the worker pauses.
    Workers in ``closing_gracefully`` state will also be orange.

    If ``target`` is disabled, change to orange on ``spill`` instead.
    If spilling is completely disabled, never turn orange.

    If pausing is disabled, change to red when passing the ``terminate`` threshold
    instead. If both pause and terminate are disabled, turn red when passing
    ``memory_limit``.

    Note
    ----
    A worker will start spilling when managed memory alone passes the target threshold.
    However, here we're switching to orange when the process memory goes beyond target,
    which is usually earlier.
    This is deliberate for the sake of simplicity and also because, when the process
    memory passes the spill threshold, it will keep spilling until it falls below the
    target threshold - so it's not completely wrong. Again, we don't want to track
    the hysteresis cycle of the spill system here for the sake of simplicity.

    In short, orange should be treated as "the worker *may* be spilling".
    floatoranger{   c                \   t           j                            d          }t           j                            d          }t           j                            d          }t          |pt          j        |pt          j                  | _        t          |pt          j        d          | _        d S )Nz distributed.worker.memory.targetzdistributed.worker.memory.spillz#distributed.worker.memory.terminate      ?)daskr?   getminmathinfr   r{   )r   targetspill	terminates       r   r   zMemoryColor.__init__  s{    !CDD ABBKOO$IJJ	 &,DHe.?tx@@y,DHc22r   currentintlimitstatusrF   returnstrc                r    |t           j        k    rdS |sdS ||| j        z  k    rdS ||| j        z  k    rdS dS )Nr{   r|   r   )rF   runningr{   r   )r   r  r  r  s       r   _memory_colorzMemoryColor._memory_color   sT    V^##5 	6edh&&&5edk)))8vr   N)r  r  r  r  r  rF   r  r  )r   r   r   r   __annotations__r   r
  r   r   r   r   r      sW          0 MMMJJJ3 3 3	 	 	 	 	 	r   r   c                  X    e Zd ZdZed	d            Zd
dZeed                         ZdS )ClusterMemoryz!Total memory usage on the clusterX  c                   t          j        |            t                              |            || _        t	          dgdz  dgdz  dgdz  g dg ddgdz  dgdz  dgdz  dgdz  dgdz  d
          | _        t          dddt          |dz            d	d
d|| _        | j        	                    | j        dddddd          }d |_
        t          di t          | j        j        d         _        t          d          | j        j        d         _        t$          | j        j        _        d| j        j        _        t+          d          | j        _        d| j        j        _        d| j        j        _        d| j        _        d| j        j        _        t7          dd          }t9          dd          }| j                            ||           d S )Nr   rf   )r|   r|   r|   greyrd   ffffff?皙?rd   )
r   r   r   r   alphaproc_memorymanagedunmanaged_oldunmanaged_recentspilledzBytes stored on clusterr   re   cluster_memoryr   r   r   r   r   r   r   r   r   r   r   r  )r   r   r   r   r   r   r  0.0 bformatr   Fr   r   aZ  
                            <div>
                                <span style="font-size: 12px; font-weight: bold;">Process memory (RSS):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@proc_memory{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Managed:</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@managed{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Unmanaged (old):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_old{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Unmanaged (recent):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_recent{0.00 b}</span>
                            </div>
                            <div>
                                <span style="font-size: 12px; font-weight: bold;">Spilled to disk:</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@spilled{0.00 b}</span>
                            </div>
                            r   r   zPhttps://docs.dask.org/en/stable/dashboard.html#bytes-stored-and-bytes-per-workerz!Description of bytes stored plotsredirectdescriptionr   )rH   r   r   r   r   r   r0   r  r   r   r   r   
TICKS_1024axistickerr!   r   	formatterXLABEL_ORIENTATIONmajor_label_orientationr   r$   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   help_s          r   r   zClusterMemory.__init__/  s   #D)))T""""&qS1WS1W999))) !sQw37"#q%&C!G37 
 
  
+eai..! 
 
 
 
	 y~~;  
 
 #'#.#<#<#<#<	q ';7'K'K'K	$2D	/01	-#!,,,	"'	"'	%,	""'	' 
 
 
2 g;
 
 
 		E5)))))r   r  r  c                      fd j         j                                        D             }|                    h d          sJ d|v rdS d|v rdS dS )Nc           
     |    h | ]8}                     |j        j        t          |d d          |j                  9S )memory_limitr   )r  r  r  )r
  memoryprocessgetattrr  )r   r   r   s     r   	<setcomp>z6ClusterMemory._cluster_memory_color.<locals>.<setcomp>  s\     
 
 
  	)b.!44y   
 
 
r   >   r{   r|   r   r{   r   r|   )r   r   r   issubset)r   rX   s   ` r   _cluster_memory_colorz#ClusterMemory._cluster_memory_color  s    
 
 
 
 n,3355
 
 
 88899999F??586r   c           	        t          d | j        j                                        D                       }| j        j        }|                                 }|j        |j        |j        |j	        gfdt                    D             |||dg|j        gdz  |j        gdz  |j        gdz  |j        gdz  |j	        gdz  d}t          ||j        |j	        z             }|| j        j        _        dt!          |j                   }|j	        r|dt!          |j	                   dz  }|| j        j        _        t'          | j        |           d S )	Nc              3  $   K   | ]}|j         V  d S Nr-  r   s     r   	<genexpr>z'ClusterMemory.update.<locals>.<genexpr>  s$      NNBONNNNNNr   c                P    g | ]"\  }}t          d |                   |dz  z   #S )Nre   r   )r   iwr   s      r   r   z(ClusterMemory.update.<locals>.<listcomp>  s4    FFFTQ#eBQBi..1q5(FFFr   r  rf   )r   r   r   r  r  r  r  r  zBytes stored: z + z spilled to disk)r   r   r   r   r.  r3  r  r  r  r  	enumerater/  maxr   r   endr@   r   r   rQ   r   )r   r  meminfor   r   x_endr   r   s          @r   rQ   zClusterMemory.update  sx    NNdn.D.K.K.M.MNNNNN.'**,, O!$O	
 FFFFYu5E5EFFFUE62#O,q0(1,%34q8!(!9 :Q >(1,	
 	
 E7?W_<== %	@go!>!>@@? 	KJ<88JJJJE$	t{F#####r   Nr  r  r  )	r   r   r   r   r]   r   r3  r   rQ   r   r   r   r  r  ,  sw        ++O* O* O* ZO*b   $ !$ $ Z ! $ $ $r   r  c                  P    e Zd ZdZedd            Zeed                         ZdS )WorkersMemoryzMemory usage for single workersr  c                   t          j        |            t                              |            || _        t	          g g g g g g g g g g g g d          | _        t          dddt          |dz            ddd|| _        | j        	                    | j        dd	d
dddd          }d |_
        t          di t          | j        j        d         _        t          d          | j        j        d         _        t$          | j        j        _        d| j        j        _        t+          d          | j        _        d| j        j        _        d| j        j        _        d | j        _        t7          t9          d                    }| j                            |           t=          dd          }| j                            |           d S )N)r   r   r   r   r  r~   r   r  r  r  r  r  Bytes stored per workerr   re   workers_memoryr   r  r   r   r   r   r   r  r   )r   r   r   r   r   r   r   
line_widthr  r  r  Fr   r   r   r   at  
                            <div>
                                <span style="font-size: 12px; font-weight: bold;">Worker:</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@worker</span>
                            </div>
                            <div>
                                <span style="font-size: 12px; font-weight: bold;">Process memory (RSS):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@proc_memory{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Managed:</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@managed{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Unmanaged (old):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_old{0.00 b}</span>
                            </div>
                            <div style="margin-left: 1em;">
                                <span style="font-size: 12px; font-weight: bold;">Unmanaged (recent):</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_recent{0.00 b}</span>
                            </div>
                            <div>
                                <span style="font-size: 12px; font-weight: bold;">Spilled to disk:</span>&nbsp;
                                <span style="font-size: 10px; font-family: Monaco, monospace;">@spilled{0.00 b}</span>
                            </div>
                            r   r   )rH   r   r   r   r   r   r0   r  r   r   r   r   r$  r%  r&  r!   r   r'  r(  r)  r   r$   r   r   r   r   r   r(   r"   r   r   )r   r   r   r   r   r   r   s          r   r   zWorkersMemory.__init__  s   #D)))T""""&"$!!#$& 
 
"  
+eai..! 
 
 
 
	 y~~;  	
 	
 #'#.#<#<#<#<	q ';7'K'K'K	$2D	/01	-#!,,,	"'	"'	%)	"w+OPPPQQQ	C   ' 
 
 
: 		E"""""r   c                t   dd}| j         j                                        }g g }g }d}g }g }g }g }	g }
|D ]!}|j        }t	          |dd          }t          |||j        |j        z             }|                     |j        ||j	                  }|j
        |j        |j        |j        gz  |fdt          d	d          D             z  }||||d
gz  }|                    |j                   |                    |j
                   |	                    |j                   |
                    |j                   |                    |j                   #||g dt          |          z   |d |D                        |d |D                        |t          t          |                               ||           ||           ||	           ||
           ||          d}fd|                                D             }|| j        j        _        t)          | j        |           d S )Nr;  Iterable[T]r  list[T]c                &    g }| D ]}|||||gz  }|S r6  r   )r;  outiis      r   quadlistz&WorkersMemory.update.<locals>.quadlist  s0    C ( (BB''Jr   r   r-  c                V    g | ]%}t          d |                   |         dz  z   &S )re   r:  )r   r;  r   s     r   r   z(WorkersMemory.update.<locals>.<listcomp>1  s6    HHHa#eBqDk""U1X\1HHHr   rR  r  r  c              3  $   K   | ]}|j         V  d S r6  r   r   s     r   r8  z'WorkersMemory.update.<locals>.<genexpr>@  s$      <<brz<<<<<<r   c              3  H   K   | ]}t          j        |j                  V  d S r6  r   r   s     r   r8  z'WorkersMemory.update.<locals>.<genexpr>A  s/      &W&Wv'8'D'D&W&W&W&W&W&Wr   )r   r   r   r  r~   r   r   r  r  r  r  r  c                L    i | ] \  }}|d  t          |          D             !S )c                    g | ]	\  }}||
S r   r   )r   vir<  s      r   r   z3WorkersMemory.update.<locals>.<dictcomp>.<listcomp>J  s!    999URq9b999r   )zip)r   kvr   s      r   
<dictcomp>z(WorkersMemory.update.<locals>.<dictcomp>J  s6    UUUda!99c!Umm999UUUr   )r;  rK  r  rL  )r   r   r   r.  r0  r>  r/  r  r
  r  r  r  r  r   r   r   itemsr   r   r?  rQ   r   )r   rP  r   r   r   	max_limit
procmemoryr  r  r  r  r   r@  r  color_ir   r   s                   @r   rQ   zWorkersMemory.update  s   	 	 	 	 .(//11	
 	, 	,BiGB22EIugo.OPPI((%KKG%(	 E HHHH5Q<<HHHHAgw88E go...NN7?+++  !6777##G$<===NN7?++++ %%%G4h<<G<<<<<&h&W&Ww&W&W&WWW%G--..#8J//x((%Xm44 ()9 : :x((
 
 VUUUfllnnUUU )	t{F#####r   NrB  r   r   r   r   rE  rE    sc        ))S# S# S# ZS#j !;$ ;$ Z ! ;$ ;$ ;$r   rE  c                  >    e Zd ZdZed             Zed             ZdS )WorkersMemoryHistogramzHistogram of memory usage, showing how many workers there are in each bucket of
    usage. Replaces the per-worker graph when there are >= 50 workers.
    c           	        d| _         || _        t          ddgddgddgd          | _        t	          ddddd	d
|| _        t          d          | j        j        d         _        t          di t          | j        j        _        t          | j        j        _        d| j        j        _        d| j        j        _        d | j        _        | j                            | j        dddddd           d S )Nr   rd   re   r   r   rG  rH  r   r   r   r  r  Fr   r   r   r   r   r   r   )r   r   r   r   r0   r   r!   r   r'  r   r$  r&  r(  r)  r   r   r   r   r   r   s      r   r   zWorkersMemoryHistogram.__init__U  s   	"&Vr2h1v>>
 
  
+!$	
 

 
 
	 (<7'K'K'K	$!/!=!=*!=!=	2D	/01	-"'	%)	"	; 	 	
 	
 	
 	
 	
r   c                   t          j        d | j        j                                        D                       }t          j        |d          \  }}|d d         |dd          |d}t          | j        |           d S )Nc                (    g | ]}|j         d          S )r.  metricsr   s     r   r   z1WorkersMemoryHistogram.update.<locals>.<listcomp>{  s    LLLbRZ!LLLr   r   r   r   rd   r   )r   asarrayr   r   r   r   rQ   r   )r   nbytesr   r   ds        r   rQ   zWorkersMemoryHistogram.updatex  s    LLDN,B,I,I,K,KLLL
 
 Lb111	ssVaeF;;t{Ar   Nr   r   r   r   ra  ra  P  sV           
  
 Z 
D !  !   r   ra  c                  P    e Zd ZdZedd            Zeed                         ZdS )WorkersTransferBytesz<Size of open data transfers from/to other workers per workerr  c           
     `   || _         t          g g g g g g d          | _        t          ddt	          d           dt          |dz            ddd|| _        | j                            d	d
d	d ddd| j                   | j                            dddd ddd| j                   t          di t          | j        j
        d         _        t          d          | j        j        d         _        t          | j        j        _        d| j        j        _        t%          d          | j        _        d| j        j        _        d| j        j        _        d | j        _        t1          t3          d                    }t5          g dd          }| j                            ||           d S )Nr   transfer_incoming_bytestransfer_outgoing_bytesr~   
y_incoming
y_outgoingBytes transferring: r   r   re   workers_transfer_bytesr   r  rn  rp  r   r{   )r   r   r   
line_colorr   r   
fill_colorr   ro  rq  r|   r  r  r  Fr   r   r   ))Workerz@worker)Incomingz @transfer_incoming_bytes{0.00 b})Outgoingz @transfer_outgoing_bytes{0.00 b}r   )r   r   r   )r   r   r   r0   r@   r  r   hbarr   r$  r%  r&  r!   r   r'  r(  r)  r   r$   r   r   r   r   r   r(   r"   r   r   )r   r   r   r   r   r   s         r   r   zWorkersTransferBytes.__init__  s   "&"$+-+-   	
 	
  
:a::eai..) 
 
 
 
	 		*+; 	 		
 		
 		
 		*+; 	 		
 		
 		
 $/#<#<#<#<	q ';7'K'K'K	$2D	/01	-#!,,,	"'	"'	%)	"w+OPPPQQQ  
 (
 
 
 		E3'''''r   c                  
 | j         j                                        }d

fdt          t	          |                    D             }
fdt          t	          |                    D             }d |D             }d |D             }d |D             }d |D             }|rCt          t          |          t          |          t          d |D                                 }nd	}|| j        j        _        ||||||d
}	dt          t          |                     | j        j        _        t          | j        |	           d S )Nrz   c                &    g | ]}|d z   |z  z   S g      ?r   r   r;  hs     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  &    @@@1a$hQ&@@@r   c                &    g | ]}|d z   |z  z   S       ?r   r}  s     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  r  r   c                4    g | ]}|j         d          d         S )transferincoming_bytesre  r   s     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  2     #
 #
 #
9;BJz"#34#
 #
 #
r   c                4    g | ]}|j         d          d         S )r  outgoing_bytesre  r   s     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  r  r   c                    g | ]	}|j         
S r   r   r   s     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  s    ,,,"2:,,,r   c                6    g | ]}t          j        |          S r   )r>   r   )r   r~   s     r   r   z/WorkersTransferBytes.update.<locals>.<listcomp>  s#    KKK6,V44KKKr   c              3  $   K   | ]}|j         V  d S r6  r7  r   s     r   r8  z.WorkersTransferBytes.update.<locals>.<genexpr>  s$      22BO222222r   r   rm  rr  )r   r   r   r   r   r>  r   r   r?  r@   r   r   r   rQ   r   )r   wssrp  rq  rn  ro  r   escaped_workersx_limitr   r~  s             @r   rQ   zWorkersTransferBytes.update  s    n$++--@@@@c#hh@@@
@@@@c#hh@@@
#
 #
?B#
 #
 #
#
 #
?B#
 #
 #
 -,,,,KK7KKK 	+,,+,,22c22222 GG G '	 .'>'>$$
 
 P<4K0L0L#M#MOO 		 	t{F#####r   NrB  r   r   r   r   rk  rk    sc        FF@( @( @( Z@(D !%$ %$ Z ! %$ %$ %$r   rk  c                  .    e Zd ZdZed             Zd ZdS )Hardwareru   c           	     d    | _         t          g g d           _        t          ddddt	          g           d| _         j                            ddd	 j        
           t          ddg          } j                            |           t          d           j        j
        d         _        d j        j        _        t          g g d           _        t          ddddt	          g           d| _         j                            ddd	 j        
           t          ddg          } j                            |           t          d           j        j
        d         _        d j        j        _        t          g g d           _        t          ddddt	          g           d| _         j                            ddd	 j        
           t          ddg          } j                            |           t          d           j        j
        d         _        d j        j        _        t%           j         j         j                   _        g g d _        g g d _        g g d _         fd} j         j                            |           d S )N)size	bandwidthzDisk Bandwidth -- Computing ...r   r   )factorsr   r   r   r   r  r  r   r   r   r   r   vline)	Bandwidthz@bandwidth{0.00 b}/s)moder   r  r  r   Fz!Memory Bandwidth -- Computing ...z"Network Bandwidth -- Computing ...c                   K   j                                          d {V } t          | d         t                    D ]P}| d         |         }j        d                             |           j        d                             |           Qt          | d         t                    D ]P}| d         |         }j        d                             |           j        d                             |           Qt          | d         t                    D ]P}| d         |         }j        d                             |           j        d                             |           Qd S )Ndiskkeyr  r  r.  network)r   benchmark_hardwaresortedrD   	disk_datar   memory_datanetwork_data)r   r  r  r   s      r   fzHardware.__init__.<locals>.fX  sy     ><<>>>>>>>>Fvf~;??? > >"6N40	v&--d333{+229====vh/[AAA @ @"8,T2	 (//555 -44Y????vi0kBBB A A"9-d3	!&)00666!+.55i@@@@A Ar   r   )r   r   disk_sourcer0   r   disk_figurevbarr   r   r!   r   r'  xgridr   memory_sourcememory_figurenetwork_sourcenetwork_figurer   r   r  r  r  loopadd_callback)r   r   r   r   r  s   `    r   r   zHardware.__init__  s   "+ 
 
 " 
3$+++	
 

 
 
 	+S9I 	 	
 	
 	
 $I#J
 
 
 	""5))).B'.R.R.Rq!+).& . 
 
 $ 
5$+++	
 

 
 
 	+S9K 	  	
 	
 	
 $I#J
 
 
 	$$U+++0DG0T0T0T #-+0 ( / 
 
 % 
6$+++	
 

 
 
 	  +S9L 	! 	
 	
 	
 $I#J
 
 
 	%%e,,,1EW1U1U1U!!$.,1!)
 
	 
 

 
 

 
 

	A 	A 	A 	A 	A$ 	((+++++r   c                   | j         d         r| j        j        j        dk    rd S | j        d         | j        j        _        | j         d         | j        j        _        | j        d         | j	        j        _        t          | j        | j                    t          | j        | j                   t          | j        | j                   d| j	        j        _        d| j        j        _        d| j        j        _        d S )Nr  zDisk BandwidthzMemory BandwidthzNetwork Bandwidth)r  r  r   r   r  r  r   r  r  r  rQ   r  r  r  r   s    r   rQ   zHardware.updatel  s    v&	%*.>>>F.2.?.G#++/>&+A (-1-=f-E"*t000t!4#3444t"D$5666(: %&6#)<!&&&r   N)r   r   r   r   r]   r   rQ   r   r   r   r  r    sF        ((t, t, Zt,l= = = = =r   r  c                  N    e Zd ZdZed             Zeed                         ZdS )BandwidthTypesz$Bar chart showing bandwidth per typec                   d| _         || _        t          ddgddgddgddgd	          | _        t	          dd
ddddgd|| _        d| j        j        _        | j                            | j        ddddd          }d| j        j	        _
        t          d          | j        j        d         _        t          di t          | j        j        _        d |_        d| j        j        _        d| j        j        _        d | j        _        t+                      }d|_        d|_        | j                            |           d S )Nr   rd   re   r   rw   rx   12r  bandwidth-halftypebandwidth_textzBandwidth by Typer   bandwidth_type_histogram)r   r   r   y_range      r  r  r  r   r|   r   r   r   r   r   r   r  r  Fz@type: @bandwidth_text / sr   r   )r   r   r   r   r0   r   r   r)  r   r   r   r!   r'  r   r$  r&  r   r   r   r   r   r   r   r   r   r   r   r   r   r   s        r   r   zBandwidthTypes.__init__  s]   	"&V#&(c
#&*	 
 
  
%+#J	
 

 
 
	 37	/y~~;  
 
 #$	';7'K'K'K	$!/!=!=*!=!=	"&01	-"'	%)	"5+	E"""""r   c                   | j         j        }t          t          |                    | j        j        _        t          |                                          d |                                D             t          |                                          d |                                D             d}dt          | j         j
                  z   | j        j        _        t          | j        |           d S )Nc                    g | ]}|d z  S re   r   )r   rx   s     r   r   z)BandwidthTypes.update.<locals>.<listcomp>  s    :::q1u:::r   c                ,    g | ]}t          |          S r   r@   r   r   s     r   r   z)BandwidthTypes.update.<locals>.<listcomp>  s    DDD1|ADDDr   r  Bandwidth: )r   bandwidth_typesr   r  r   r  r  r   keysr@   r  r   r   rQ   r   )r   bwr   s      r   rQ   zBandwidthTypes.update  s     ^+$($4$4	!biikk**::biikk:::OODD		DDD	
 
  -|DN<T/U/UU	t{F#####r   Nr   r   r   r   r  r  ~  sZ        ..)# )# Z)#V !
$ 
$ Z ! 
$ 
$ 
$r   r  c                  N    e Zd ZdZed             Zeed                         ZdS )BandwidthWorkersr   c           	        d| _         || _        t          ddgddgddgddgd          | _        d	 t	          d
d          D             d d d         }t          dd |D             dd          }t          d dddddgddgd|| _        t          | j        j	        _
        | j                            | j        dd|dd           |d         | _        t          | j        dd d          }t          d          |_        t!          d i t"          |_        | j                            |d           d | j        _        t+                      }d|_        d|_        | j                            |           d S )!Nr   rd   re   rw   rx   r  r  )r  r   destinationr  c                <    g | ]}t          |          d d         S )re   N)hexr  s     r   r   z-BandwidthWorkers.__init__.<locals>.<listcomp>  s&    555#a&&*555r   rj   rl   r   r  c                $    g | ]}d |z   |z   dz   S )#FFr   r  s     r   r   z-BandwidthWorkers.__init__.<locals>.<listcomp>  s%    888AS1Wq[4'888r   )
field_namepalettelowhighzBandwidth by Workerr   bandwidth_worker_heatmap)r   r   r   r   r  r   r  )r   r   r   r   r   r   	transform   )r   r   )color_mapperlabel_standoffborder_line_colorlocationr  r  r   z
            <div>
                <p><b>Source:</b> @source </p>
                <p><b>Destination:</b> @destination </p>
                <p><b>Bandwidth:</b> @bandwidth_text / s</p>
            </div>
            r   r   )r   r   r   r   r   r4   r0   r   r(  r   r)  r   	color_mapr   r!   r'  r   r$  r&  
add_layoutr   r   r   r   r   )r   r   r   r   mapper	color_barr   s          r   r   zBandwidthWorkers.__init__  s   	"&V* #Sz#&*	 
 
 65eBnn555ddd;"88888	
 
 
  
'+#J#J
 
 
 
	 3E	/	; 	 	
 	
 	
  ,"	
 
 
	 3'BBB	)77J77		Y000%)	" ,	E"""""r   c           	     8     j         j        }|sd S  fdt          fd|                                D              \  }}}t	          |           j        _        t          t          t          ||z                                 }| j
        j        _        |d d d          j
        j        _        |||t          t          t          |                    d}dt           j         j                  z    j
        j        _        t'           j        |           d S )Nc                    	 j         j        |          }n# t          $ r | cY S w xY w|j        t	          |j                  S | S r6  )r   r   KeyErrorr   r  )r   r   r   s     r   r   z%BandwidthWorkers.update.<locals>.name  sX    ^+G4   w"27||#Ns    %%c              3  R   K   | ]!\  \  }}} |           |          |fV  "d S r6  r   )r   rw   rx   cr   s       r   r8  z*BandwidthWorkers.update.<locals>.<genexpr>  sB      NNifq!aTT!WWdd1ggq1NNNNNNr   r   )r   r  r  r  r  )r   bandwidth_workersrX  r\  r>  r  r  r   r  setr   r   r  r  r=   r@   r  r   r   rQ   r   )r   r  r   r   r   r  r   r   s   `      @r   rQ   zBandwidthWorkers.update  s    ^- 	F	 	 	 	 	 NNNN288::NNNO1e!%jjvc!a%jj))**$+	!$+DDbDM	! "3|U#;#;<<	
 
  -|DN<T/U/UU	t{F#####r   Nr   r   r   r   r  r    sZ        ++<# <# Z<#| !$ $ Z ! $ $ $r   r  c                  N    e Zd ZdZed             Zeed                         ZdS )WorkerNetworkBandwidthzWorker network bandwidth chart

    Plots horizontal bars with the host_net_io.read_bps and host_net_io.write_bps worker
    state
    c           
        || _         t          g g g g g g d          | _        t          ddddd|| _        | j                            ddd dd	d
d| j                   | j                            ddd dd	dd| j                   t          di t          | j        j        d         _	        t          d          | j        j        d         _        t          | j        j        _        d| j        j        _        t!          d          | j        _        d| j        j        _        d| j        j        _        d | j        _        t          ddddd|| _        | j                            ddd dd	d
d| j                   | j                            ddd dd	dd| j                   t          di t          | j        j        d         _	        t          d          | j        j        d         _        t          | j        j        _        d| j        j        _        t!          d          | j        _        d| j        j        _        d| j        j        _        d | j        _        d S )Ny_ready_writex_readx_writex_read_diskx_write_diskzWorker Network Bandwidthr   worker_network_bandwidth)r   r   r   r  r  r   r   r{   read)r   r   rt  r   r   ru  legend_labelr   r  r  r|   writer  r  r  FzWorkers Diskworker_diskr  r  r   )r   r   r   r0   r  ry  r   r$  r%  r&  r!   r   r'  r(  r)  r   r$   r   r   r   r   r   r  r   s      r   r   zWorkerNetworkBandwidth.__init__'  s   "&! " 	
 	
   
,+
 
 	
 
 	; 	 		
 		
 		
 	 ; 	 		
 		
 		
 )4(A(Aj(A(AA%,@,P,P,PQ)7I4562!(q!1!1!1',$',$*.' 
 
 
 	
 
	 		; 	 		
 		
 		
 		  ; 	 		
 		
 		
 $/#<#<#<#<	q ';7'K'K'K	$2D	/01	-#!,,,	"'	"'	%)	"""r   c                p  
 | j         j                                        }d

fdt          t	          |                    D             }
fdt          t	          |                    D             }g }g }g }g }|D ]}|                    |j        d         d                    |                    |j        d         d                    |                    |j                            di                               dd                     |                    |j                            di                               dd                     | j         j        rt          t          |          t          |          d	d
| j	        j
        j        z            | j	        j
        _        t          t          |          t          |          d	d
| j        j
        j        z            | j        j
        _        n"d	| j	        j
        _        d	| j        j
        _        ||||||d}	t          | j        |	           d S )Nrz   c                &    g | ]}|d z   |z  z   S r|  r   r}  s     r   r   z1WorkerNetworkBandwidth.update.<locals>.<listcomp>  s&    @@@q!d(QU"@@@r   c                &    g | ]}|d z   |z  z   S r  r   r}  s     r   r   z1WorkerNetworkBandwidth.update.<locals>.<listcomp>  s&    AAA1t8a!e#AAAr   host_net_ioread_bps	write_bpshost_disk_ior    gffffff?r  )r   r   r   r   r   r   rf  r   r>  r  r   r?  r  rQ   r   )r   r   r  r  r  r  r  r  r   r   r~  s             @r   rQ   zWorkerNetworkBandwidth.update  s     .(//11@@@@E#g,,,?,?@@@AAAAU3w<<-@-@AAA 	X 	XBMM"*]3J?@@@NN2:m4[ABBBrz~~nbAAEEjRSTTUUU
~r B B F F{TU V VWWWW>! 	0),FGt~-11	* *DN"& %(K  L!!ty(,,	% %DI!! *5DN"&$/DI! &(
 
 	t{F#####r   Nr   r   r   r   r  r     sc          [* [* Z[*z !-$ -$ Z ! -$ -$ -$r   r  c                  V    e Zd ZdZedd            Zd Zeed                         ZdS )SystemTimeseriesa  Timeseries for worker network bandwidth, cpu, memory and disk.

    bandwidth
        Plots the average of host_net_io.read_bps and host_net_io.write_bps for the
        workers as a function of time
    cpu
        Plots the average of cpu for the workers as a function of time
    memory
        Plots the average of memory for the workers as a function of time
    disk
        Plots the average of host_disk_io.read_bps and host_disk_io.write_bps for the
        workers as a function of time

    The metrics plotted come from the aggregation of from ws.metrics[key] for ws in
    scheduler.workers.values() divided by number of workers.
     N  c           
     d   || _         t          g g g g g g g d          | _        t          | j        |                                            t          d|d          }d}t          d$dd||dd	|| _        | j                            | j        d
ddd           | j                            | j        d
ddd           d| j        j	        _
        d| j        j        _        t          d          | j        j        d         _        d| j        j        _        d| j        j        _        d| j        j        _        t          d$dd||dd	|| _        | j                            | j        d
d           d| j        j        _        d| j        j        _        d| j        j        _        d| j        j        _        t          d$dd||dd	|| _        | j                            | j        d
d           d| j        j        _        t          d          | j        j        d         _        d| j        j        _        d| j        j        _        d| j        j        _        t          d$d d||d!d	|| _        | j                            | j        d
d"dd           | j                            | j        d
d#dd           d| j        j	        _
        d| j        j        _        t          d          | j        j        d         _        d| j        j        _        d| j        j        _        d| j        j        _        d S )%NrY   host_net_io.read_bpshost_net_io.write_bpscpur.  host_disk_io.read_bpshost_disk_io.write_bpsr?  r   followfollow_intervalrange_paddingzreset, xpan, xwheel_zoomz"Worker Network Bandwidth (average)r   z#worker_network_bandwidth-timeseries)r   r   r   r   r   rY   r  r{   zread (mean))r   r   r   r   r  r  r|   zwrite (mean)top_leftzbytes / secondz0.0br  Fz Worker CPU Utilization (average)zworker_cpu-timeseriesr  )r   r   r   UtilizationzWorker Memory Use (average)zworker_memory-timeseriesr.  ByteszWorker Disk Bandwidth (average)zworker_disk-timeseriesr  r  r   )r   r   r   rQ   get_datar   r0   r  linelegendr  r   
axis_labelr!   r'  r  r   r   r  r   r  r.  r  )r   r   r  r   r   r   s         r   r   zSystemTimeseries.__init__  s   "&(*)+)+*, 

 

 	t{DMMOO,,,/
 
 
 + 
6"6
 
 
 
 	;$& 	 	
 	
 	
 	;%' 	 	
 	
 	
 *4&*:',@,O,O,OQ)'($562',$ 
4"(
 
 
 
 	; 	 	
 	
 	

 %2!!"/0,!& 
/"+
 
 
 
 	; 	 	
 	
 	

 (/$)=V)L)L)L!&$%!23/$)! 
3")
 
 
 
	 		;%& 	 	
 	
 	
 		;&' 	 	
 	
 	
 %/	!%5	"';6'J'J'J	$"#	01	-"'	r   c           
        | j         j                                        }d}d}d}d}d}d}d}|D ]}	||	j        d         d         z  }||	j        d         d         z  }||	j        d         z  }||	j        d         z  }||	j                            di                               dd          z  }||	j                            di                               dd          z  }||	j        d         z  }|t          |          pd	z  d
z  g|t          |          pd	z  g|t          |          pd	z  g|t          |          pd	z  g|t          |          pd	z  g|t          |          pd	z  g|t          |          pd	z  gd}
|
S )Nr   r  r  r  r  r.  r  rY   rd   r   r  )r   r   r   rf  r   r   )r   r   net_read_bpsnet_write_bpsr  r.  disk_read_bpsdisk_write_bpsrY   r   r   s              r   r  zSystemTimeseries.get_dataD  s   .(//11 	' 	'BBJ}5jAALRZ6{CCM2:e$$Cbj**FRZ^^NB??CCJPQRRRMbjnn^R@@DD[RSTTTNBJv&&DD S\\.Q/$67%1S\\5FQ%G$H&3s7||7Hq&I%J3w<<,1-.W!234&3s7||7Hq&I%J'5W9J'K&L	
 	
 r   c                P   | j                             |                                 d           | j        j        rt          d | j        j                                        D                       t          | j        j                                                  z  }t          d | j        j                                        D                       t          | j        j                                                  z  }nd}d}|dz  | j        j	        _
        || j        j	        _
        d S )Nr   c              3  (   K   | ]}|j         pd V  dS rd   Nnthreadsr   s     r   r8  z*SystemTimeseries.update.<locals>.<genexpr>i  s:        %' q     r   c              3  $   K   | ]}|j         V  d S r6  r7  r   s     r   r8  z*SystemTimeseries.update.<locals>.<genexpr>l  s5        $&     r   rd   r  d   )r   streamr  r   r   r   r   r   r  r  r?  r.  )r   	y_end_cpu	y_end_mems      r   rQ   zSystemTimeseries.updatec  s    	4==??D111>! 		$  +/>+A+H+H+J+J    DN*1133445I   *..*@*G*G*I*I    DN*1133445II I#I(3"+r   N)r  )	r   r   r   r   r]   r   r  r   rQ   r   r   r   r   r     sx         " x( x( x( Zx(t  > !, , Z ! , , ,r   r   c                  N    e Zd ZdZed             Zeed                         ZdS )ComputePerKey4Bar chart showing time spend in action by key prefixc                l   d| _         || _        t          j        | j        j        vr,| j                            t          | j                             ddgddgddgt          d         t          d	         gd
dgd}t          |          | _        t          d1dddddgd|}|
                    | j        dddd          }d|j        _        d|j        _        t          d          |j        d         _        t#          d1i t$          |j        _        t(          |j        _        d |_        d|j        _        d|j        _        d |_        t9                      }d|_        d|_        |                    |           |                     tC          dd !          d"           || _"        tG          |d#$          }t          d1ddd%d&d|}|$                    dd'd(tK          d)d*+          tK          d)          d,dd| j        -	  	         d |j&        _        d|j&        _        d |j'        _(        |                     tC          dd !          d"           t9                      }d|_        d|_        |                    |           || _)        tG          |d.$          }	tU          ||	gd/0          | _+        d S )2Nr   皙?rz   0.2 ms2.8 usgQ	@gQ?r  computer   sum_partial)timesformatted_timeanglesr   namesr   zCompute Time Per Taskr   compute_time_per_keyrw   rx   r   r   r   r   r/  r,  r  r   r   r   r   r   r   Time (s)0r  F
            <div>
                <p><b>Name:</b> @names</p>
                <p><b>Time:</b> @formatted_time</p>
            </div>
            r   z1Note: tasks less than 2% of max are not displayeditalicr   text_font_stylebelowz	Bar Chartchildr   zcompute_time_per_key-pier  r   rd   r  r.  Tinclude_zerowhite	r   r   radiusstart_angle	end_anglert  ru  legend_fieldr   z	Pie Chartstretch_both)tabssizing_moder   ),r   r   rV   r   plugins
add_plugints_color_lookupr   compute_sourcer0   r  r  r   r   r  r!   r'  r   r$  r&  r(  r   r)  r   r   r  r   r   r   r   r   r   r  r)   figrL   wedger2   r%  gridgrid_line_color	wedge_figr'   r   )
r   r   r   compute_datarM  r   r   tab1fig2tab2s
             r   r   zComputePerKey.__init__z  s   	" (>>>N%%&6t~&F&FGGG 3Z'2Um%j1?93MN]+
 
 /LAAA 
)'#J	
 

 
 
 xx&  
 
 )	!5S!A!A!A	!)77J77	,>	)"&*+	'!	# ,eH (   	
 	
 	
 c555 
)+	
 

 
 
 	

xd;;;X&& & 	 
	
 
	
 
	
  $	!	$(	!H (   	
 	
 	
  ,ud+666tTlGGG			r   c                @   t          t                    }| j        j                                        D ]I\  }}t          |          }|j                                        D ]\  }}|dk    r||xx         |z  cc<   Jt          |                                d d          }|r|d         d         dz  fd|D             }t                      }t                      }t                      }	d|D ]V\  }}|	                    |           |	                    t          |                     |		                    |           |z  Wfd	|	D             }
|| j        j        _        t          |
|	||d
 |	D                       }t          | j        |           d S d S )Nr*  c                    | d         S Nrd   r   r   s    r   <lambda>z&ComputePerKey.update.<locals>.<lambda>  s
    AaD r   Tr  reverser   rd   g{Gz?c                *    g | ]\  }}|k    ||fS r   r   )r   ntmax_times      r   r   z(ComputePerKey.update.<locals>.<listcomp>  s&    NNN1XaVr   c                :    g | ]}|z  d z  t           j        z  S r  )r   pi)r   r_  
total_times     r   r   z(ComputePerKey.update.<locals>.<listcomp>  s)    IIIqa*nq(472IIIr   c                ,    g | ]}t          |          S r   rA   r   r_  s     r   r   z(ComputePerKey.update.<locals>.<listcomp>  s    EEE1AEEEr   )r.  r,  r   r/  r-  )r   r   r   task_prefixesr\  rC   all_durationsr  r   r   ts_color_ofrM  r   r  dictrQ   rL  )r   compute_timesr  tsr   actionr_  compute_colorscompute_namescompute_timer.  compute_resultr`  rc  s               @@r   rQ   zComputePerKey.update  s    $E**~399;; 	- 	-GCS>>D-3355 - -	Y&&!$'''1,'''-
 }2244..RVWWW  	8$Q'*T1HNNNNNNNM!VVN FFM66LJ(    a$$T***%%k$&7&7888##A&&&a

IIIILIIIF'4DH$!"$#EEEEE  N 4&777773	8 	8r   Nr   r   r   r   r$  r$  w  s`        >>mH mH ZmH^ !&8 &8 Z ! &8 &8 &8r   r$  c                  N    e Zd ZdZed             Zeed                         ZdS )AggregateActionr%  c                   d| _         || _        t          j        | j        j        vr,| j                            t          | j                             ddgddgt          d         t          d         gddgd}t          |	          | _        t          dd
ddddgd|| _
        | j
                            | j        dddd          }d| j
        j        _        t          d          | j
        j        d         _        d| j
        j        _        t%          di t&          | j
        j        _        t*          | j
        j        _        d| j
        j        _        d |_        d| j
        j        _        d| j
        j        _        d | j
        _        t=                      }d|_        d|_         | j
        !                    |           d S )Nr   r'  rz   r(  r)  r  r*  )r,  r-  r   r/  r0  zAggregate Per Actionr   aggregate_per_actionrw   rx   r2  r/  r,  r  r   r3  r5  r  r4  16pxFr6  r   r   )"r   r   rV   r   rI  rJ  rK  r   action_sourcer0   r   r  r  r   r!   r   r'  r  r   r$  r&  r(  r   r)  major_label_text_font_sizer   r   r  r   r   r   r   r   r   )r   r   r   action_datar   r   s         r   r   zAggregateAction.__init__  s   	" (>>>N%%&6t~&F&FGGG 3Z'2%j1?93MN ),	
 
 .;??? 
('#J	
 

 
 
	 y~~%  
 
 #$	';3'G'G'G	$%/	"!/!=!=*!=!=	2D	/5;	2"&01	-"'	%)	" ,	E"""""r   c                   t          t                    }| j        j                                        D ]1}|j                                        D ]\  }}||xx         |z  cc<   2t          |                                d d          }t                      }t                      }t                      }|D ]k\  }}|	                    |           |dk    r|	                    d           n |	                    t          |                    |	                    |           l|| j        j        _        d| j        j        _        t!          |||d |D                       }t#          | j        |           d S )	Nc                    | d         S rX  r   rY  s    r   rZ  z(AggregateAction.update.<locals>.<lambda>Z  s
    AaD r   Tr[  r*  purplezAggregate Time Per Actionc                ,    g | ]}t          |          S r   re  rf  s     r   r   z*AggregateAction.update.<locals>.<listcomp>n  s    ===qKNN===r   )r,  r   r/  r-  )r   r   r   rg  r   rh  r\  r  r   r   rK  r   r   r  r   r   rj  rQ   rw  )	r   	agg_timesrl  rm  r_  
agg_colors	agg_namesagg_timeaction_results	            r   rQ   zAggregateAction.updateP  s     &&	..5577 	' 	'B-3355 ' '	&!!!Q&!!!!' 9??,,..$OOO	VV
FF	66" 	 	IFAV$$$""!!(++++!!/&"9:::OOA$-	!:	==H===	
 
 
 	t!=11111r   Nr   r   r   r   rs  rs    sZ        >>5# 5# Z5#n !2 2 Z ! 2 2 2r   rs  c                  N    e Zd ZdZed             Zeed                         ZdS )MemoryByKeyz*Bar chart showing memory use by key prefixc                v   d| _         || _        t          ddgddgddgddgd	          | _        t	          dd
ddddgd|| _        | j                            | j        dddd          }t          d          | j        j        d         _	        t          di t          | j        j        _        t          | j        j        _        d |_        d| j        j        _        d| j        j        _        d | j        _        t+                      }d|_        d|_        d|_        | j                            |           d S )Nr   rw   rx   r  r   rd   re   r|   )r   rh  countr   z
Memory User   memory_by_keyr2  r   rh  r   r   r3  r  r  Fz@name: @nbytes_textz
            <div>
                <p><b>Name:</b> @name</p>
                <p><b>Bytes:</b> @nbytes_text </p>
                <p><b>Count:</b> @count objects </p>
            </div>
            r   r   )r   r   r   r   r0   r   r  r!   r   r'  r   r$  r&  r(  r   r)  r   r   r   r   r   r   r   r   r   r  s        r   r   zMemoryByKey.__init__w  sU   	"&c
+Q &)	 
 
  
 #J	
 

 
 
	 y~~;&hc  
 
 (<7'K'K'K	$!/!=!=*!=!=	2D	/"&01	-"'	%)	". ,	E"""""r   c                   t          t                    t          t                    | j        j                                        D ]E}|j        D ];}t          |j                  }|xx         dz  cc<   |xx         |j        z  cc<   <Ft          t                              }|| j        j        _        |fd|D             fd|D             fd|D             d |D             d}dt          t                                                              z   | j        j        _        t%          | j        |           d S )Nrd   c                     g | ]
}|         S r   r   )r   r   r   s     r   r   z&MemoryByKey.update.<locals>.<listcomp>  s    555tfTl555r   c                     g | ]
}|         S r   r   r   r   rh  s     r   r   z&MemoryByKey.update.<locals>.<listcomp>  s    666vd|666r   c                :    g | ]}t          |                   S r   r  r  s     r   r   z&MemoryByKey.update.<locals>.<listcomp>  s%    III4L66IIIr   c                ,    g | ]}t          |          S r   rW   r   r   s     r   r   z&MemoryByKey.update.<locals>.<listcomp>  s    777htnn777r   )r   r  rh  nbytes_textr   zTotal Use: )r   r  r   r   r   has_whatrC   r  rh  r   r  r   r   r  r@   r   r   r   rQ   r   )r   r   rl  ksr/  r   r   rh  s         @@r   rQ   zMemoryByKey.update  s^    S!!S!!.(//11 	( 	(Bk ( (rv&&r


a


r


bi'



(
 VF^^$$$)	!5555u5556666666IIII5III77777
 
  -|C<P<P/Q/QQ	t{F#####r   Nr   r   r   r   r  r  t  sZ        44*# *# Z*#X !$ $ Z ! $ $ $r   r  c                  P    e Zd ZdZedd            Zeed                         ZdS )CurrentLoadz"Tasks and CPU usage on each workerr  c                \   d| _         || _        t          g g g g g g g g d          | _        t	          ddddt          |dz            dd|}|                    | j        d	d
ddd          }d|j        _        d |_	        t	          dddt          |dz            dddd|}|                    | j        dd
ddd          }d |_	        ||fD ]l}d|j
        _        d|j        _        d|j        _        t          t!          d                    }|                    |           d |_        d|j        _        mt'                      }	d|	_        d|	_        |                    |	           t'                      }	d|	_        d|	_        |                    |	           || _        || _        d S )Nr   )nprocessingnprocessing-halfnprocessing-colorr  cpu-halfr   r~   r   zTasks Processingr   r   re   r   )r   r   r   r   r   r  r   r  r   r  r  zCPU Utilizationcpu_hist)r   r  )r   r   r   r   r   r   r  r  r|   Fr   r   r   z@worker : @nprocessing tasksr   z@worker : @cpu %r   )r   r   r   r   r0   r  r   r   r   r   r   r   r   r   r   r(   r"   r   r   r   r   r   processing_figure
cpu_figure)
r   r   r   r   r   r   r  rM  r   r   s
             r   r   zCurrentLoad.__init__  s   	"&!$&%'"$	 	
 
  
$eai.. 
 
 
 

 ; %  
 
 $%
 "& 
#eai.. 
 
 
 
 xx;  
 
 #'$ 		& 		&C./CI+ %CI %CI7/S#T#T#TUUUCMM##'C  %CI7+U###++e!+r   c                   | j         j                                        }t                      }t	          d |D                       s|| j        dz   k     rd S || _        d |D             }d |D             }g }|D ]_}|| j         j        v r|                    d           &|| j         j        v r|                    d           J|                    d           `|d |D             |d	 |D             |d
 |D             d |D             t          t          t          |                              d}| j         j        rt          d |D                       }nd}|dz  | j        j        _        t!          | j        |           d S )Nc              3  $   K   | ]}|j         V  d S r6  )r   r   s     r   r8  z%CurrentLoad.update.<locals>.<genexpr>  s$      33R2=333333r   rd   c                B    g | ]}t          |j        d                    S )r  )r  rf  r   s     r   r   z&CurrentLoad.update.<locals>.<listcomp>  s'    888"s2:e$%%888r   c                6    g | ]}t          |j                  S r   r   r   s     r   r   z&CurrentLoad.update.<locals>.<listcomp>  s"    <<<bs2=))<<<r   r{   r   r|   c                    g | ]}|d z  S r  r   )r   r  s     r   r   z&CurrentLoad.update.<locals>.<listcomp>%  s    ,,,1Q,,,r   c                    g | ]}|d z  S r  r   )r   r   s     r   r   z&CurrentLoad.update.<locals>.<listcomp>'  s     > > >Ba > > >r   c                    g | ]	}|j         
S r   r   r   s     r   r   z&CurrentLoad.update.<locals>.<listcomp>)  s    444brz444r   c                @    g | ]}t          j        |j                  S r   r   r   s     r   r   z&CurrentLoad.update.<locals>.<listcomp>*  s%    OOOv0<<OOOr   )r  r  r  r  r  r~   r   r   c              3  (   K   | ]}|j         pd V  dS r  r  r   s     r   r8  z%CurrentLoad.update.<locals>.<genexpr>/  s)      <<b)<<<<<<r   r  )r   r   r   rY   anyr   r   r   r   r   r   r   r>  r  r   r?  rQ   r   )	r   r   nowr  r  nprocessing_colorr   r   xranges	            r   rQ   zCurrentLoad.update  s    .(//11ff33733333 	di!m8K8KF	88888<<G<<< 	1 	1BT^(((!((////t~///!((1111!((0000 ,,,,,& > >+ > > >!244G444OOwOOOeCLL))**	
 	
 >! 	<<G<<<<<FFF&,sl#t{F#####r   NrB  r   r   r   r   r  r    sc        ,,K K K ZKZ !$$ $$ Z ! $$ $$ $$r   r  c                  :    e Zd Zd Zeed                         ZdS )StealingTimeSeriesc                   || _         t          t                      dz  t                      dz  dz   gddgddgd          | _        t	          ddd          }t          ddd	d
|d|| _        | j                            | j        ddd           | j                            | j        ddd           d | j        j        _	        | j        
                    t                      t          d          t          d                     d S )Nr   rd   r   rY   r   r   r?  r  r	  z$Idle and Saturated Workers Over Timer   r   r   r   r   r   rY   r   r{   )r   r   r   r   r   r   r   
dimensionsr   )r   r   rY   r   r   r0   r   r  r   minor_tick_line_colorr   r%   r#   r+   )r   r   r   r   s       r   r   zStealingTimeSeries.__init__8  s&   "&$(9:AV 
 
 UEQRSSS 
8"	
 

 
 
	 		dkVvUKKK	dkV{'RRR04	-	KKG444mw6W6W6W	
 	
 	
 	
 	
r   c                (    t                      dz  gt           j        j                  gt           j        j                  gdt
          r't                                           fd           d S  j        	                    d           d S )Nr   r  c                 :    j                              d          S N'  r   r   )r   r   s   r   rZ  z+StealingTimeSeries.update.<locals>.<lambda>\  s    DK4F4Fvu4U4U r   r  )
rY   r   r   r   r   rO   r   add_next_tick_callbackr   r   )r   r   s   `@r   rQ   zStealingTimeSeries.updateS  s     VVd]O,--.dn6778
 

  	.HH++,U,U,U,U,UVVVVVKvu-----r   Nr   r   r   r   r   r]   rQ   r   r   r   r  r  7  sI        
 
 
6 !	. 	. Z ! 	. 	. 	.r   r  c                  @    e Zd Zd Zd Zeed                         ZdS )StealingEventsc           
     N   || _         |j        d         | _        d| _        t	          t                      dz
  t                      gddgddgddgddgddgddgd          | _        t          d	d
d          }t          dddd|d|| _	        | j	        
                    | j        ddddd           d| j	        j        _        t                      }d|_        d|_        | j	                            |t#                      t%          d          t'          d                     d S )Nstealingr   <      r@  rd   r   )rY   levelr   durationrB  cost_factorr  r?  r  r	  zStealing Eventsr   r   r  rY   r  r   rB  r   )r   r   r   r   r  r  LevelzLLevel: @level, Duration: @duration, Count: @count, Cost factor: @cost_factorr   r   r  r   )r   
extensionsstealr   r   rY   r   r   r0   r   circler   r  r   r   r   r   r%   r#   r+   )r   r   r   r   r   s        r   r   zStealingEvents.__init__b  sf   ")*5
	&"dff-R!7+Fa& !2wQ 

 

 UEQRSSS 
#"	
 

 
 
	 		; 	 	
 	
 	
 &-	"g+	KKw'''W---		
 	
 	
 	
 	
r   c           	     8   d}|D ]}|dd         \  }}}}}}	}
}||z  }	 t           |         }n# t          t          f$ r d}Y nw xY wt          j        t          |d                    dz  dz   }|dz  |t          |          |||| j        j        |         d	}|S )
z Convert a log message to a glyphr   Nrg   blackr      re   r   )rY   r  r  r   r  rB  r  )	r/   r  
IndexErrorr   sqrtr   r   r  cost_multipliers)r   msgstotal_durationmsgrY   r  r  r  satocc_satidlocc_idlr   rB  ri  s                  r   convertzStealingEvents.convert  s     	' 	'CEH!WBD%hWc7h&NN	e$EE*% 	 	 	EEE	 3~r2233b81< 4KYY&:6u=
 
 s   / AAc           	     H     j                             d          t           j         j        d                   }| j        z
  }fdt          d|dz             D             | _        rt          t          t          d                    t          t          j
                  t          t           j                  t          t                    t          r't!                                           fd           d S  j                            d           d S d S )Nr  )topicc                l    g | ]0}|          d          d         dk    |          d          d          1S )rd   r   requestr   r   r;  logs     r   r   z)StealingEvents.update.<locals>.<listcomp>  s?    TTTaRA)9S9SsA2wqz!}9S9S9Sr   rd   c                 :    j                              d          S r  r  newr   s   r   rZ  z'StealingEvents.update.<locals>.<lambda>      8J8J3PU8V8V r   r  )r   
get_eventsr   eventsr   r   r9   r=   r<   rj  r   r;   r  r   rP   rO   r   r  r   r   )r   r  r^  r  r  s   `  @@r   rQ   zStealingEvents.update  s    n''j'99dn+J788diTTTTeAq1uooTTT	 	/GAJJDK  DL!! C  ///0V0V0V0V0VWWWWW""3.....	/ 	/r   N)r   r   r   r   r  r   r]   rQ   r   r   r   r  r  a  sY        -
 -
 -
^  4 !/ / Z ! / / /r   r  c                  <    e Zd ZddZeed                         ZdS )Events   c           	     ,   || _         t                      | _        d| _        || _        t          g g g g g d          | _        t          dd          }t          d|d|d|d|| _	        | j	        
                    | j        d	d
dddd           d| j	        j        _        d| j	        j        _        t                      }d|_        d|_        | j	                            |t'                      t)          d          t+          d                     d S )Nr   rY   rm  r   r   r   r?  i@ )r
  r  r   r   )r   r   r   r   r   rY   r   r   r   r   rm  )r   r   r   r   r  r  rE  Actionr  z@action<br>@hoverr   r   r  r   )r   rj  	action_ysr   r   r   r   r   r0   r   r  r   r  r  r  r   r   r   r   r%   r#   r+   )r   r   r   r   r   r   r   s          r   r   zEvents.__init__  sA   "		&2bII
 
 UFCCC 
"
 
 
 
	 		;! 	 	
 	
 	
 &.	"$.	!,+	KKw'''W---		
 	
 	
 	
 	
r   c                v   
  j         j         j                 
 j         j         j                  j        z
  }
r
fdt          d|dz             D             
 j         j         j                  _        
r?g }g }g }g }g }
D ]\  }}|                    |dz             |d         }	|                    |	           	 |                     j        |	                    nL# t          $ r? t           j                   j        |	<   |                     j        |	                    Y nw xY w|                    t          |	                     |                    d           |||||dt          r't                                           fd           d S  j                            d           d S d S )	Nc                "    g | ]}|          S r   r   r  s     r   r   z!Events.update.<locals>.<listcomp>  s    444q3r7444r   rd   r   rm  TODOr  c                 :    j                              d          S r  r  r  s   r   rZ  zEvents.update.<locals>.<lambda>  r  r   r  )r   r  r   event_countsr   r   r   r  r  r   rT   rO   r   r  r   r   )r   r^  actionsr,  hoversysrX   msg_timer  rm  r  r  s   `         @@r   rQ   zEvents.update  s    n#DI.N'	2TY> 	54444E!QUOO444CN/	:	 	/GEFBF!$ 
& 
&#X_---Xv&&&6IIdnV45555 6 6 6-0-@-@DN6*IIdnV4555556 hv..///f%%%% ! C  ///0V0V0V0V0VWWWWW""3.....;	/ 	/s    C""AD+*D+N)r  r  r   r   r   r  r    sO        )
 )
 )
 )
V !$/ $/ Z ! $/ $/ $/r   r  c                  <    e Zd ZddZeed                         ZdS )
TaskStreamr   20sc                   || _         d| _        t          j        | j         j        vr,| j                             t          | j                              | j         j        t          j                 | _        t          d| j        j        |z
            | _        t                      | _
        || _        t          |d          }|| _        d| _        d| _        t!          |fi |\  | _        | _        dg| _        d S )Nr   r   default)r   offsetrV   r   rI  rJ  pluginr>  indexrj  r   n_rectanglesrE   clear_intervalr   	last_seentask_stream_figurer   r   task_stream_index)r   r   r  r  r   s        r   r   zTaskStream.__init__  s    " (>>>N%%&6t~&F&FGGGn,-=-BCDK-<==
vv((FFF,	!3N!M!Mf!M!MTY #$r   c                     j          j        j         k    rd S  j         rnt           j        j        d                   rOt           j        j        d                   }t           j        j        d                   } j        |z   |z
  dz  }n j        } j                             j          j	        |          t          d                   } j        j          _         d         sd S t                       j         j        z   k    rt          d                    j        z
  }t           j        j        d                   }t          t          t          j         j        j        d          j        j        d                             }t!           j        j        d                   t           j	                  z  ||z
  z  }||z
  ||z
  dz  k    s|dk     rC j        j                            d D                        t          d                    _         fd	d         D             d<   t                       _        |d
k    rSt$          rL                                D ]7\  }	}
t)          |
d         t*                    rt%          j        |
          |	<   8t.          r't1                                           fd           d S  j                             j                   d S )Nr   r  r   )istartr   start_boundaryr   re   g?c                    i | ]}|g S r   r   r   rY  s     r   r[  z%TaskStream.update.<locals>.<dictcomp>Y  s    (C(C(C1B(C(C(Cr   c                $    g | ]}|j         z
  S r   )r  )r   r   r   s     r   r   z%TaskStream.update.<locals>.<listcomp>\  s    LLL1q4;LLLr   r   r   c                 D    j                              j                  S r6  )r   r   r  )
rectanglesr   s   r   rZ  z#TaskStream.update.<locals>.<lambda>g  s    **:t7HII r   )r  r  r   r   r   r   r>  r  r  r   rY   r  r  r=   operatoraddr   rQ   r   r\  
isinstancer   arrayrO   r   r  r   r  )r   r   r  boundaryr^  	new_start	old_startold_enddensityrY  rZ  r  s   `          @r   rQ   zTaskStream.update0  s    :***F: 	##dk.w788 	#(122E4;+J788He+h6$>HH{H[++:t|H , 
 

 
6"##[&
'" 	F 66DNT%8888Jw/004;>IDK,W566ILK$W-K$Z0  G DK$Z011dl##$Y&(  G#)(;q'@@@GdNN ''(C(C
(C(C(CDDD!*W"566LLLL
78KLLL
7 77r7"((** 0 01adF++ 0$&HQKKJqM 	>HH++IIIII     Kz4+<=====r   N)r   r  r  r   r   r   r  r    sN        % % % %* !8> 8> Z ! 8> 8> 8>r   r  r  c                `   t          | d          } t          t          t                      | z
  gdgdgdgdgdgdgdgd	gd
g
  
                  }t	          d          }t	          d          }t          d*dd||dddddd	|}|                    |ddddddddd
  
        }d|_        d|j        _	        d|j        _
        d|j        _        d|j        _        t          dd !          }t          t!          d"#          $          }t#          d%d&'          }	|                    ||t'                      t)                      t+          d()          t-          d()          |	           t.          r8t/                      }
|
                    |           |                    |
           ||fS )+zG
    kwargs are applied to the bokeh.models.plots.Plot constructor
    r   r  rz   r   r@  z100 msfoor   rd   ry   )
r   r  r  r   r   duration_textr~   r   worker_threadr  r0  r  task_streamzTask Streamr   r   Nr   r   )	r   r   r   r  r   r   y_axis_locationr   r   r   r  r  r   333333?r     )
r   r   r   r   r   ru  rt  
line_alphar   rI  Fr   z
            <div>
                <span style="font-size: 12px; font-weight: bold;">@name:</span>&nbsp;
                <span style="font-size: 10px; font-family: Monaco, monospace;">@duration_text</span>
            </div>
            r   z./profile?key=@namer   r   z:https://docs.dask.org/en/stable/dashboard.html#task-streamz6A description of the TaskStream and its color palette.r!  r   r  r   )rE   r   rj  rY   r   r0   r   r   r   major_label_text_alphar   major_tick_line_alphar  r   r   r(   r"   r   r   r   r%   r#   r+   r^   register_plot)r  r   r   r   r  r   r   r   r   r*  exports              r   r  r  m  s$    %^TBBBN66N*+U	)#*7c#%
 
 
  F ***G***G     D 99

   D #D()DJ%'(DJ$'(DJ$DJ#  E 7'<===
>
>
>CML  E 	NN7###)))    T"""v4<r   c                  r    e Zd ZdZd Zeed                         Zed	d            Zed             Z	d Z
dS )
	TaskGraphz
    A dynamic node-link diagram for the task graph on the scheduler

    See also the GraphLayout diagnostic at
    distributed/diagnostics/graph_layout.py
    c           	     v   || _         t          |          | _        |                    | j                   d| _        t          g g g g g g d          | _        t          g g g d          | _        t          dd          }t          j
        dk     rd|gi}nd	|i}t          d%i |}t          d%i |}t          j
        dk     r| j        |_        | j        |_        t          d
g dg d          }t          d%ddi|| _        t!          dd          | _        | j                            | j        d           | j                            dd| j        d|dd           | j                            ddd|| j        |d
          }d | j        j        _        d | j        j        _        d| j        j        _        d| j        j        _        t7          dd|g          }	t9          t;          d !          |g"          }
d |_        | j                            |	|
           tA          j!        d#d$          | _"        d S )&Nr   )r   r   r   stater   r  r   r   r   r   True)column_namegroupr  filtersfilterr  )waitingqueuedr   r.  releasederred)grayyellowr   r{   r|   r  )r  r  r   z
Task Graph r7  r8  r   r   r   rd   r  333333?)xsr  r   rI  viewr   r  r   )r   r   r  r   r   r/  rE  Fr   z<b>@name</b>: @stater   r   	rendererszinfo/task/@key.htmlr   )r   r1  z%distributed.dashboard.graph-max-items  r   )#r   rR   layoutrJ  invisible_countr   node_sourceedge_sourcer   rN   majorr   r   r3   r0   r   r)   subtitler  
multi_linesquarer  rP  r   r   r   r   r   r(   r"   r   r   r?   r   	max_items)r   r   r   r%  filter_kwargs	node_view	edge_viewnode_colorsr   r   r   s              r   r   zTaskGraph.__init__  s   "!),,T[))) +2rB2bQQ
 
 ,"2",M,MNN&AAA""&1MM%v.M,,m,,	,,m,,	 ""#/I#/I!VVVGGG
 
 
 88888	3AAA	T]G444	# 	 	
 	
 	
 y#    
 
 +/	'*.	'"'	"'	'+f
 
 

 w+@AAAdVTTT"&	E3'''$KTRRr   c                |   t          | j        j                  | j        k    r5d| j        _        | j        | j        fD ]}d |j        D             |_	        d S | j
        t          | j        j	        d                   dz  k    r#| j                                         d| _
        d}nd}| j        j        g c}| j        _        | j        j        }g | j        _        |                     |||           |                                  t          | j        j                  dk    rd	| j        _        d S d
| j        _        d S )Nz(Scheduler has too many tasks to display.c                    i | ]}|g S r   r   )r   cols     r   r[  z$TaskGraph.update.<locals>.<dictcomp>	  s    !L!L!Lc#r!L!L!Lr   r   re   r   TF)rQ   Scheduler is empty.r,  )r   r   tasksr;  r8  r   r5  r6  column_namesr   r4  r3  reset_indexr  	new_edgesadd_new_nodes_edgespatch_updates)r   	containerrQ   r  rG  s        r   rQ   zTaskGraph.update	  sG    t~#$$t~55!KDM".0@A M M	!L!LY5K!L!L!L	M M #c$*:*?*D&E&E&III'')))'($#';?B C-I$&DK!$$S)F$CCC   4>'((A--%:"""%("""r   Fc           	     N   |s|rg }g }g }g }g }g }	g }
| j         j        }| j         j        }| j        j        }|D ]}	 ||         }n# t
          $ r Y w xY w||         }||         }|                    t          j        t          |                               |                    |           |                    |           |                    |j
                   |                    |j        j                   |D ]\\  }}	 |	                    ||         ||         g           |
                    ||         ||         g           M# t
          $ r Y Yw xY w|||||dgt          |          z  d}|	|
dgt          |	          z  d}|st          | j        j        d                   s@| j        j                            |           | j        j                            |           d S | j                            |           | j                            |           d S d S )Nr!  )r   r   r  r   r  r   r   r   )r3  r   r   r   rD  r  r   r>   r   r  r  prefixr   r   r5  r   rQ   r6  r   )r   r  rG  rQ   node_keynode_xnode_y
node_state	node_nameedge_xedge_yr   r   rD  r  taskxxyyrw   rx   nodeedges                         r   rH  zTaskGraph.add_new_nodes_edges0	  sw    1	.& 1	.HFFJIFFAAN(E 3 3 :DD   HsVsV 1#c(( ; ;<<<b!!!b!!!!!$*---  !12222!  1MM1Q41,///MM1Q41,////   D #!"8c&kk1 D  f&CKK9OPPD .S!1!6s!;<< . %,,T222 %,,T22222 ''--- ''-----c1	. 1	.s$   A
AAAE
EEc                   t          | j        j        d                   t          | j        j        d                   | j        j        rB| j        j        }g | j        _        fd|D             }| j                            d|i           | j        j        r_| j        j        }fd|D             }g | j        _        | j                            d|i           | xj        t          |          z  c_        | j        j	        rD| j        j	        }fd|D             }g | j        _	        | j                            d|i           dS dS )zV
        Small updates like color changes or lost nodes from task transitions
        r   c                *    g | ]\  }}|k     ||fS r   r   r   r;  r  r^  s      r   r   z+TaskGraph.patch_updates.<locals>.<listcomp>p	  s&    AAA$!Q1q551v555r   r  c                *    g | ]\  }}|k     ||fS r   r   r[  s      r   r   z+TaskGraph.patch_updates.<locals>.<listcomp>u	  &    ;;;$!QQUU1vUUUr   r   c                *    g | ]\  }}|k     ||fS r   r   )r   r;  r  ms      r   r   z+TaskGraph.patch_updates.<locals>.<listcomp>|	  r]  r   N)
r   r5  r   r6  r3  state_updatespatchvisible_updatesr4  visible_edge_updates)r   r`  updatesr_  r^  s      @@r   rI  zTaskGraph.patch_updatese	  sb   
  %c*++ %c*++;$ 	7 K5M(*DK%AAAA-AAAG""GW#5666;& 	1k1G;;;;';;;G*,DK'""Iw#7888  CLL0  ;+ 	9k6G;;;;';;;G/1DK,""Iw#788888		9 	9r   c                P    | j                             | j        j                   d S )Nr   )r   remove_pluginr3  r   r  s    r   __del__zTaskGraph.__del__	  s&    $$$+*:$;;;;;r   NF)r   r   r   r   r   r   r]   rQ   rH  rI  rh  r   r   r   r  r    s         AS AS ASF !) ) Z ! )< !2. 2. 2. ! 2.h !9 9 ! 94< < < < <r   r  c                  Z    e Zd ZdZd Zeed                         Zd Zed             Z	dS )TaskGroupGrapha  
    Task Group Graph

    Creates a graph layout for TaskGroups on the scheduler.  It assigns
    (x, y) locations to all the TaskGroups and lays them out by according
    to their dependencies. The layout gets updated every time that new
    TaskGroups are added.

    Each task group node incodes information about task progress, memory,
    and output type into glyphs, as well as a hover tooltip with more detailed
    information on name, computation time, memory, and tasks status.
    c                   || _         i | _        i | _        d| _        t	          i dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg g g g g g g g g g d	          | _        t	          g g g g d          | _        t          d3ddd|| _        d| j        j	        _
        t          dd          | _        | j                            | j        d           | j                            dddddddd| j        	  	        }| j                            dddd d!d"| j        #           | j                            d	d
ddd d| j        $           | j                            d	ddddd d%| j        &           t#          t%          d'(          dd)d*d+d,d-d.| j        /	  	        | _        | j                            | j                   d | j        j        _        d | j        j        _        d)| j        j        _        d)| j        j        _        t5          d0d1|g2          }| j                            |           d S )4Nr   r   r   w_boxh_boxr   	tot_tasksr   x_startrA  y_starty_endx_end_progress	mem_alphanode_line_width
comp_tasksurl_logox_logo	y_logow_logoh_logoin_processing	in_memoryin_releasedin_erredrp  r.  r.  r  xeyezTask Groups GraphT)r   match_aspectFr,  r7  r8  r   r  )	r   r   r   r   r   r   rt  rI  r   rz  r{  r|  center)r   r   r   r<  r~  anchorr   )r   r   r   r   r   rt  r   r  )r   r   r   r   r   rt  r   r   rg   )r  r   rd   r.  r  r  r  )	r?  rt  r  rI  rp  rq  rA  rr  r   r   a  
                <div>
                    <span style="font-size: 12px; font-weight: bold;">Name:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
                </div>
                <div>
                    <span style="font-size: 12px; font-weight: bold;">Compute time:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@compute_time</span>
                </div>
                <div>
                    <span style="font-size: 12px; font-weight: bold;">Memory:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span>
                </div>
                <div>
                    <span style="font-size: 12px; font-weight: bold;">Tasks:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@tot_tasks</span>
                </div>
                <div style="margin-left: 2em;">
                    <span style="font-size: 12px; font-weight: bold;">Completed:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@comp_tasks</span>
                </div>
                <div style="margin-left: 2em;">
                    <span style="font-size: 12px; font-weight: bold;">Processing:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@in_processing</span>
                </div>
                <div style="margin-left: 2em;">
                    <span style="font-size: 12px; font-weight: bold;">In memory:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@in_memory</span>
                </div>
                <div style="margin-left: 2em;">
                    <span style="font-size: 12px; font-weight: bold;">Erred:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@in_erred</span>
                </div>
                <div style="margin-left: 2em;">
                    <span style="font-size: 12px; font-weight: bold;">Released:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@in_released</span>
                </div>
                r0  r   )r   nodes_layoutarrows_layoutold_counterr   nodes_sourcearrows_sourcer0   r   r%  r   r)   r8  r  r   	image_urlr   r   r*   arrowsr  rP  r   r   r  r  r   r   r  s        r   r   zTaskGroupGraph.__init__	  sR   ",RR  	
  R  2  2  !" R "2 b  B!" "#$ !#! "5  
 
> .RrSU.V.VWWR!44RR6RR	!&	3AAA	T]G444y~~"($  

 

 		$ 	 	
 	
 	
 		$ 	 	
 	
 	
 		"$ 	 		
 		
 		
 Q%

 

 

 		T[)))*.	'*.	'*-	'*-	''%L fQ)
 )
 )
V 		E"""""r   c                   d | j         j                                        D             }dd l}|j                            d | j         j                                        D             |          }t          | j         j        |j                  }i i t                      }i }i }|D ]*}||         rt          fd||         D                       dz   }	t          fd||         D                       }
t          ||                   dk    r*t          fd	||         D                       dk    r|
dz  }
n*d}	r$t          
                                          dz   nd}
|	|
f|v r|
dz  }
|	|
f|v |                    |	|
f           |	|
c|<   |<   |         |         d
||<   ||         |gt          ||                   z  d||<   ,||fS )Nc                >    i | ]\  }fd |j         D             S )c                4    h | ]}|j         k    |j         S r   rf  )r   dsrY  s     r   r1  z:TaskGroupGraph.update_layout.<locals>.<dictcomp>.<setcomp>3
  s"    BBBBRW\\\\\r   )dependencies)r   rl  rY  s     @r   r[  z0TaskGroupGraph.update_layout.<locals>.<dictcomp>2
  sF     
 
 
2 BBBB"/BBB
 
 
r   r   c                $    i | ]\  }}|j         d S )rd   rf  )r   rY  r#  s      r   r[  z0TaskGroupGraph.update_layout.<locals>.<dictcomp>:
  s     RRR81eQRRRr   )dskr  r  c              3  (   K   | ]}|         V  d S r6  r   )r   depr.  s     r   r8  z/TaskGroupGraph.update_layout.<locals>.<genexpr>G
  '      <<C3<<<<<<r   rd   c              3  (   K   | ]}|         V  d S r6  r   r   r  r  s     r   r8  z/TaskGroupGraph.update_layout.<locals>.<genexpr>H
  r  r   c                     h | ]
}|         S r   r   r  s     r   r1  z/TaskGroupGraph.update_layout.<locals>.<setcomp>K
  s    AAARWAAAr   )r   r   )nstartnend)r   task_groupsr\  r   orderr  r   r  r>  r   r   r  )r   r  r   r  ordered	locationsr  r  tgr   r   r.  r  s              @@r   update_layoutzTaskGroupGraph.update_layout-
  sP   

 
399;;
 
 

 	
  RRt~/I/O/O/Q/QRRR% ! 
 

 3CCCEE	 	 	BB 
6<<<<<+;<<<<<q@<<<<<+;<<<<<R())A--AAAAR0@AAABBaGGFA,.5C		$$q((Aa&I%%Q a&I%% MM1a&!!!NBrFBrF &(V"R&99L 'r*s<#3444! !M"
 ]**r   c                6    d}d}||z
  ||z
  z  ||z
  z  |z   }|S )Nr  g?r   )r   r   min_boxmax_boxr   r?  r   s          r   compute_sizezTaskGroupGraph.compute_sized
  s2    5[Ww./1w;?%Gr   c                     j         j         j        k    rd S  j         j         _         j         j        sd j        _        nd j        _         j                                         j         j                                        k    r!                                 \   _         _	        i dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg g g g g g g g g g d	}g g g g d}t                      }t                      } j         j                                        D ]D}|j        r;|j        r4|                    |j                   |                    |j                   Et          |d          }t!          |d          }t          |d          }t!          |d          }	i  j         j                                        D ]\  }
}|j        d         |j        d         z   |j        d         z   }t'          |j                                                  }|j        r|j        r|rt)          |          dk    rrt)          |          dk    r_                     |j        |z  |z  ||z  |z  ||z  |z            }                     |j        |z  |z  ||z  |z  |	|z  |z            }nd}|dz  }||d|
<    j         j                                        D ]%\  }
} j        |
         d         } j        |
         d         }|
         d          }|
         d!         }|d                             |           |d                             |           |d                             |           |d                             |           |j        d         |j        d         z   |j        d         z   }t'          |j                                                  }|d                             |j        j                   |d                             t3          |j        j                             |d	                             |           |d                             |j        d         t'          |j                                                  z  d"z             |j        d#         r|d                             d$           n|d                             d           |d
                             ||dz  z
             |d                             ||dz  z              |d                             ||dz  z
             |d                             ||dz  z
  |d"z  z              |d                             ||dz  z
  ||z  |z  z              |d%xx          fd& j	        |
         d'         D             z  cc<   |d(xx          fd) j	        |
         d'         D             z  cc<   |d*xx          fd+ j	        |
         d,         D             z  cc<   |d-xx          fd. j	        |
         d,         D             z  cc<   t)          |j                  dk    r[t7          t9          |j                                                d/          d         }	 t<          |         }n# t>          $ r d0}Y nw xY wd0}|d                             |           |d                             ||d1z  z              |d2                             ||d1z  z              ||z  }|dk    r@|d3                             |d4z             |d5                             |d4z  |z             n?|d3                             |d4z  |z             |d5                             |d4z             |d6                             tA          |j                             |d                             tC          |j                             |j        d#         }|j        d         }|j        d         }|j        d         }|d                             | d7||z  d8z  d9d:           |d;                             | d7||z  d8z  d9d:           |d<                             | d7||z  d8z  d9d:           |d=                             | d7||z  d8z  d9d:           |d>                             | d7||z  d8z  d9d:           ' j"        j#        $                    |            j%        j#        $                    |           d S )?NrC  r,  r   r   rm  rn  r   r   ro  rp  rA  rq  rr  rs  rt  ru  rv  rw  rx  ry  r  r   r  r(  r.  r)  rd   )r  r  r  re   r   r   r   r   r  r      r.  c                Z    g | ]'}j         |         d          |         d         dz  z   (S r   r   re   r  r   rY  box_dimr   s     r   r   z)TaskGroupGraph.update.<locals>.<listcomp>
  I     " " " !!$S)GAJw,?!,CC" " "r   r  r  c                6    g | ]}j         |         d          S r   r  r   rY  r   s     r   r   z)TaskGroupGraph.update.<locals>.<listcomp>
  3     " " "./!!$S)" " "r   r  c                Z    g | ]'}j         |         d          |         d         dz  z
  (S r  r  r  s     r   r   z)TaskGroupGraph.update.<locals>.<listcomp>  r  r   r  r  c                6    g | ]}j         |         d          S r  r  r  s     r   r   z)TaskGroupGraph.update.<locals>.<listcomp>  r  r   .r   r  rz  r|  r-  r{  rp   (r  .0fz %)r}  r~  r  r  )&r   transition_counterr  r  r8  r   r  r  r  r  r  r   r  nbytes_totalr  r   r>  r\  statesr   r   r  r   rL  r   rT   typesnextitersplit
logos_dictr  rA   r@   r  r   rQ   r  )r   
nodes_dataarrows_data	durationsrh  r  durations_mindurations_max
nbytes_min
nbytes_maxr  rv  ro  	width_box
height_boxr   r   r   r   	logo_typerw  ratiotasks_processingtasks_memorytasks_relasedtasks_erredr  s   `                         @r   rQ   zTaskGroupGraph.updatel
  s4   >,0@@@F><~) 	%!6DM!$DM!!##t~'A'F'F'H'HHH484F4F4H4H1Dt1


 R
 R	

 B
 R
 
 r
 R
 r
 R
 b
 
 r
 "
  !
" b#
$ 5
 
 

< 	
 
 EE	.,3355 	, 	,B{ ,r ,bk***

2?+++Iq111Iq111+++
+++
~17799  	F  	FGC	*%	((;;bi>PP  BI,,..//I +O+ + 	NNQ&&KK!OO !--K*,y8)J6B)J6B .  	 "..Oj09<&3i?&3i? /  

  	&]
%.*EEGCLL~17799 l	 l	GC!#&s+A!#&s+ACL)ES\(+F sO""1%%%sO""1%%%w&&u---w&&v... 	*%	((;;bi>PP  BI,,..//Iv%%bin555w&&x	'?'?@@@{#**9555 {#**8$s29+;+;+=+='>'>>#E  
 y& 8,-44Q7777,-44Q777 y!((UQY777w&&q519}555y!((VaZ888w&&q6A:~'DEEE'(//EAI
 2Y >>  
  " " " " "+C0:" " "   " " " "373Ec3J83T" " "   " " " " "+C08" " "   " " " "373Ec3J63R" " " 
 28}}!! bh0066s;;A>	"))4HH " " "!HHH" z"))(333x ''EAI666x ''FQJ777FNEqyy8$++FSL9998$++ECK%,?@@@@8$++FSL5,@AAA8$++ECK888 ~&--k"+.F.FGGGx ''R_(E(EFFF  "y69X.LIj1M)G,K|$++FFi!7#!=FFFF   '..#QQ'7'BS'HQQQQ   {#**II<#:S#@IIII   }%,, KKM9$<s$BKKKK   z"))HH;	#9C#?HHHH    	%%j111&&{33333s   2[  [[N)
r   r   r   r   r   r   r]   r  r  rQ   r   r   r   rk  rk  	  s         Y# Y# Y#v !3+ 3+ Z ! 3+j   !O4 O4 ! O4 O4 O4r   rk  c                  V    e Zd ZdZd ZddZddZddZee	d	                         Z
d
S )TaskGroupProgressz3Stacked area chart showing task groups through timec                   || _         t                      | _        d| _        t          j        |j        vr#|                    t	          |                     |j        t          j                 | _        | j        	                    t          j        | j        j                  dz  d           t          d          }t          dt          | j        j                            }t#          dddd	d
||ddd d	|| _        d| j        j        _        d| j        j        _        d| j        j        _        d| j        j        _        | j                            t5                      t7                      t9          d          t;          d                     d | _        d | _        t                      | _         |j!        | _"        tG                      | _$        tG                      | _%        d S )N   )r       @@rY   r   r  zTask Group Progresstask_group_progressr   r   r   r   )	r   r   r   r   r   r  r   r   r  Fr   r  r   )&r   r   r   nptsrS   r   rI  rJ  r  r  r   r  rY   r   r$   r>  r  r0   r   r   r  r   r  r  r   r   r   r%   r#   r+   _hover_last_drawn_offsetr  _last_transition_countr   
_renderers_line_renderers)r   r   r   r   r  s        r   r   zTaskGroupProgress.__init__B  s   "&((	9#444  I(>(> ???'(89!122V;VDDDA...!S!56677 
'&$ " 
 
 
 
	 23	.01	-01	-"'		MMKKw'''W---		
 	
 	
 vv&/&B# &--*}}r   r  boolc                8   | j         sdS | j        | j        j        k    s"| j        j                                        dk    rdS t          | j        j        	                                          t          | j
        j        	                                          k     S )a7  
        Whether to add new renderers to the chart.

        When a new set of task groups enters the scheduler we'd like to start rendering
        them. But it can be expensive to add new glyps, so we do it deliberately,
        checking whether we have to do it and whether the scheduler seems busy.
        Tr   F)r  r  r   r  proccpu_percentr  r  r*  r  r   r   r  s    r   _should_add_new_renderersz+TaskGroupProgress._should_add_new_renderersr  s      	4 '4>+LLL~"..002555 t{*//1122c$+:J:O:O:Q:Q6R6RRRRr   c                p    | j         | j        j        k    o!| j        j                                        dk     S )z
        Whether to update the ColumnDataSource. This is cheaper than redrawing,
        but still not free, so we check whether we need it and whether the scheudler
        is busy.
        r   )r  r   r  r  r  r  s    r   _should_updatez TaskGroupProgress._should_update  s7     '4>+LL 7#//11B6	
r   Fc                   	 t          t           j        j                   j        z
  d          	dt           j        j                  rt          	fd j        j                                        D                       }t          |          t          t          j	        |d                    z
  }	|z  	t          t          j	        |d                    t          |          z
  pd	dk    r j        j        	dz
           n j        j        	          j        j
        z
  }t          j         j        j        	                   }t          j        ||          |r.	 fd	 j        j                                        D             }nt          	fd
 j        j                  }| j        z
  dz  |d<   t          j         j        j        	                   |d<   |S )a!  
        Update the ColumnDataSource with our time series data.

        restrict_to_existing determines whether to add new task groups
        which might have been added since the last time we rendered.
        This is important as we want to add new stackers very deliberately.
        r   Nc              3  P   K   | ] }t          j        |d                    V  !d S r6  r   r  )r   rZ  fronts     r   r8  z4TaskGroupProgress._get_timeseries.<locals>.<genexpr>  s5      PPabhqy))PPPPPPr   r  )trimrx   rd   )prependc                r    i | ]3\  }}|j         j        v |t          j        |                   z  4S r   )r   r   r   r  )r   rY  rZ  backdtr  r   s      r   r[  z5TaskGroupProgress._get_timeseries.<locals>.<dictcomp>  sP       Aq((( 28AeDjM**R/(((r   c                B    t          j        |                    z  S r6  r  )r   r  r  r  s    r   rZ  z3TaskGroupProgress._get_timeseries.<locals>.<lambda>  s    "(1U4Z=11B6 r   r  rY   r  )r>  r   r  rY   r  r*  r   r   r   
trim_zerosr  r  diffr\  r:   r  r  )
r   restrict_to_existingaggfront2r  
timestampsnew_datar  r  r  s
   `      @@@r   _get_timeseriesz!TaskGroupProgress._get_timeseries  s    C())DI5q99t{"## 	HPPPP4;3F3M3M3O3OPPPPPCXXBM#C$@$@$@ A AAFVOEr}Ss33344s3xx?G4D zz KUQY''!%(4;>9 	
 Xdk.uTz:;;
WZ111 
	       K/5577  HH 666666# H %  "x(<U4Z(HIIr   c                   |                                  r|                     d          }|| j        _        t	          | j        j                  }| j        j        j	        |k    r|| j        j        _	        t          | j        j                                                  }d |D             }t          t          ||                    D ]
\  }\  }}|| j        v rht!          j        ||                   dk    s%d| j        |         _        d| j        |         _        n$d| j        |         _        d| j        |         _        z| j                            dt+          |d|          t+          |d|dz             |d	| j        
          }|| j        |<   | j                            dt+          |d|dz             |d| j                  }	|	| j        |<   | j        j        rQ| j        Jt1          d          }
t3          ddddd|
i          | _        | j                            | j                   | j        rt1          dt7          t          ||                    z  d| j        i          }
d}t9          | j                                                  D ]}|j        r|} n|g| j        _        d|
i| j        _        tA                      | _!        | j"        j#        | _$        dS | %                                rrt	          | j        j                  }| j        j        j	        |k    r|| j        j        _	        |                     d          | j        _        | j"        j#        | _$        dS dS )zy
        Maybe update the chart. This is somewhat expensive to draw, so we update
        it pretty defensively.
        F)r  c                F    g | ]}t          t          |                    S r   )rT   rC   r  s     r   r   z,TaskGroupProgress.update.<locals>.<listcomp>  s&    ???hy||,,???r   r   TrY   Nrd   r   )r   y1y2r   r  r   r   )r   r   r   r  r   z
return '';)codeaj  
                        <div>
                          <div style="font-size: 1.2em; font-weight: bold">
                            <b>Worker thread occupancy</b>
                          </div>
                          <div>
                            $index{custom}
                          </div>
                        </div>
                        r  nearest
horizontalz$index)r   r  line_policy
attachment
formattersu  
                        const colormap = %s;
                        const divs = [];
                        for (let k of Object.keys(source.data)) {
                          const val = source.data[k][value];
                          const color = colormap[k];
                          if (k === "time" || k === "nthreads" || val < 1.e-3) {
                            continue;
                          }
                          const label = k.length >= 20 ? k.slice(0, 20) + '…' : k;

                          // Unshift so that the ordering of the labels is the same as
                          // the ordering of the stackers.
                          divs.unshift(
                            '<div>'
                              + '<span style="font-weight: bold; color:' + color + ';">'
                                + label
                              + '</span>'
                              + ': '
                              +  val.toFixed(1)
                              + '</div>'
                          )

                        }
                        divs.unshift(
                          '<div>'
                            + '<span style="font-weight: bold; color: darkgrey;">nthreads: </span>'
                            + source.data.nthreads[value]
                            + '</div>'
                        );
                        return divs.join('\n')
                        r   )r  args)&r  r  r   r   r>  r  r  r   r  r?  r   r*  r  r=  rX  r  r   count_nonzeror   r  varear5   r  r  r   r   r   rj  reversedr   r1  r  rY   r  r   r  r  r  )r   r  max_nthreadsstackersrX   r;  r#  r   rendererline_rendererr'  top_liner  s                r   rQ   zTaskGroupProgress.update  s    ))++ I	L+++GGH'DK t{344Ly $44(4	!%DK/446677H??h???F%.s8V/D/D%E%E < <!>E5 DO+++HUO<<q@@9>.6>C,U3;;9=.6>B,U3;  9??hrrl+hwQw/0; +   *2& $	XgAg./; !/ ! ! /<$U++ {" 1t{': *|<<<	'	 ! )+ ()4    	##DK000{ 3? *@ Hf-- A"F #DK0I% % %	N  $T%9%@%@%B%BCC  D| #' *2
%*2I)>&#vvD*..*KD'''  "" 	Lt{344Ly $44(4	!%  $333NNDK*..*KD'''	L 	Lr   N)r  r  ri  )r   r   r   r   r   r  r  r  r   r]   rQ   r   r   r   r  r  ?  s        ==.- .- .-`S S S S.	
 	
 	
 	
+ + + +Z !NL NL Z ! NL NL NLr   r  c                  >    e Zd ZdZd Zeed                         ZdS )TaskProgresszProgress bars per task typec                t   || _         t          t          i i i i i i                     }t          |          | _        t          d          }t          dd          }t          d:dd||dd	d
d|| _        | j        	                    ddgddgdd           | j        
                    | j        dddddddd	  	         | j        
                    | j        ddddddd           | j        
                    | j        ddddddd           | j        
                    | j        ddddd d!d"           | j        
                    | j        dddd#d$d%d"           | j        
                    | j        ddd#d&d$d'd(d%d)
  
         | j        
                    | j        ddd&d*d+d'd d%d)
  
         | j                            | j        d,ddd-t          d.          /           | j                            | j        d0ddd1dt          d.          2           d3| j        j        _        d| j        j        _        d3| j        j        _        d3| j        j        _        d| j        j        _        d3| j        j        _        t'          d4d56          }t)          d7d89          }| j                            ||           d S );N)allr.  r)  r(  r   r'  r0  r   r  iProgresstask_progressr   r   r   )r   r   r   r  r   r   r   r   r   z#FFFFFFry   )r   r   rt  r  r   r   r   r   z#aaaaaarz   r-  )	r   r   r   r   r   ru  rt  r   r  zreleased-locr   r  )r   r   r   r   r   ru  rt  r   z
memory-locr   z	erred-locr  r   )r   r   r   r   r   ru  r   r  zprocessing-locr*  gffffff?z
queued-loc/r@  )
r   r   r   r   r   ru  hatch_patternhatch_colorr   r  zno-worker-locr{   z	show-namer  10pt)r   r   r   r   x_offsettext_font_sizedone)r   r   r   r   r  
text_alignr  Fr   ay  
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Queued:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@queued</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">No-worker:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@no_worker</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>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Memory:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span>
                </div>
                <div>
                    <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
                </div>
                r   z7https://docs.dask.org/en/stable/dashboard.html#progressz(A description of the progress bars plot.r!  r   )r   rU   rj  r   r   r   r$   r0   r   r  r   r   r   r   r   r   r   r  r   r   r   r   )r   r   r   r   r   r  r   r*  s           r   r   zTaskProgress.__init__W  s   "R"rbQSTTT
 
 'D111A..."a.. 	
 $ 	
 	
 	
 	
	 		#h2q'is 	 	
 	
 	
 		;   	 
	
 
	
 
	
 		;  	 		
 		
 		
 		; 	 		
 		
 		
 		; 	 		
 		
 		
 		;" 	 		
 		
 		
 		;! 	 	
 	
 	
 		;! 	 	
 	
 	
 		; == 	 	
 	
 	
 		; == 	 	
 	
 	
 #(	01	-"'	"'	01	-"'	' 
  
  
B NB
 
 
 		E5)))))r   c                v   i i i i i i i d| j         j                                        D ]}|j        t	          fd                                D                       rd         d         |j        <   d         d         |j        <   d         d         |j        <   d         d         |j        <   d         d         |j        <   d         d         |j        <   d	         d
         |j        <   шfdd         D             d<   d         s!t          | j        j	        d                   sd S t                    }t          | j        |           fddD             }|d         t          d |                                D                       z
  |d<   d|z  | j        j        _        d S )N)r.  r)  r(  r   r&  r'  	no_workerc              3  B   K   | ]}                     |          V  d S r6  )r   )r   sactive_statess     r   r8  z&TaskProgress.update.<locals>.<genexpr>  s1      >>A=$$Q''>>>>>>r   r.  r)  r(  r   r&  r'  z	no-workerr  c                n    i | ]0t          fd                                 D                       1S )c              3  (   K   | ]}|         V  d S r6  r   )r   rZ  rY  s     r   r8  z1TaskProgress.update.<locals>.<dictcomp>.<genexpr>  s'      <<qt<<<<<<r   r   r   r   rY  r  s    @r   r[  z'TaskProgress.update.<locals>.<dictcomp>  sA    VVV3<<<<U\\^^<<<<<VVVr   r  c                `    i | ]*}|t          |                                                   +S r   r  r   s     r   r[  z'TaskProgress.update.<locals>.<dictcomp>  sA     
 
 
 s58??$$%%
 
 
r   )r  r.  r)  r(  r&  r'  r  c              3  ,   K   | ]\  }}|d k    |V  dS )r  Nr   r   rY  rZ  s      r   r8  z&TaskProgress.update.<locals>.<genexpr>&  s3       3
 3
!QAJJAJJJJ3
 3
r   zProgress -- total: %(all)s, waiting: %(waiting)s, queued: %(queued)s, processing: %(processing)s, in-memory: %(memory)s, no-worker: %(no_worker)s, erred: %(erred)s)r   rg  r   r  r  r  r   r   r   r   rU   rQ   r   r\  r   r   r   )r   tpri  totalsr  r  s       @@r   rQ   zTaskProgress.update  s    
 
 ..5577 		I 		IB,M>>>>>>>>> I+8+Bh(*7*@grw'-::-Fj!"'*/<\/Jl#BG,,9),Di )+8+Bh(.;K.Hk"27+VVVVeHoVVVeU| 	C(8(?$@$@ 	F5!!t{A
 
 
 

 
 
  &e}s 3
 3
 ,,..3
 3
 3
 0
 0
  
|
 "(( 		r   N)r   r   r   r   r   r   r]   rQ   r   r   r   r
  r
  T  sS        %%`* `* `*D !7
 7
 Z ! 7
 7
 7
r   r
  c                  H   e Zd ZU dZg dZded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ed9d            Zd:d#Ze	ed$                         Z
d;d%Zd<d&Zd=d(Zd>d)Zd;d*Zd?d.Zd@d2ZdAd5ZdBd6Zd;d7Zd8S )CFinePerformanceMetricszA
    The main overview of the Fine Performance Metrics page.
    )pan
wheel_zoombox_zoomresetrZ   r   r   task_exec_by_prefix_srcr   task_exec_by_prefix_xmaxtask_exec_by_activity_srcget_data_by_activity_srcr  substantial_change	list[str]visible_functionsvisible_activities stacked_chart_visible_activitiesr   function_selectorspan_tag_selectorr&   unit_selectorzfigure | Nonetask_exec_by_activity_charttask_exec_by_prefix_chartget_data_by_activity_chartr   r	   c                Z   || _         t          i           | _        d| _        t          i           | _        t          i           | _        d| _        g | _        g | _        g | _	        d | _
        d | _        d | _        t          ddg g           | _        t          ddg g           | _        t!          d	d
g          | _        d
| j        _        | j                            d| j                   t+          | j        | j        | j        gd          }t-          |d          | _        d S )Nr0  ry   FzFilter by functionzSelect specific functions)r   placeholderr   optionszFilter by span tagzSelect specific span tagszUnit selectionseconds)r   r=  r   stretch_widthchildrenrH  scale_widthrH  )r   r   r,  r-  r.  r/  r0  r2  r3  r4  r8  r9  r:  r   r5  r6  r&   r7  r   	on_change_handle_change_unitr   r   r   )r   r   r   selectors_rows       r   r   zFinePerformanceMetrics.__init__K  s_   "'7R'@'@'@$(+%)9r)B)B)B&(8b(A(A(A%"'!#"$02-+/()-&*.' "-&3	"
 "
 "
 "-&3	"
 "
 "
 $*:YKPPP#, $$Wd.FGGG&&"
 (
 
 
 %
 
 
			r   attrr  oldr  r  Nonec                    d| _         | j        sJ |                                 }|| j        j        d         j        _        d S )NTr   )r0  r9  _bokeh_unit_formatr   r'  r  )r   rG  rH  r  fmts        r   rE  z*FinePerformanceMetrics._handle_change_unitx  sF    "&----%%''CF&,Q/9@@@r   c                X   |                                   |                                  | j        d u }|rd| _        |r[|                                 | _        |                     | j        d          | _        |                     | j        d          | _	        | j
        dz  | j        j        _        | j        rrd| _        |                                  t          | j        | j        | j	        gd          }|r!| j        j                            |           d S || j        j        d	<   d S d S )
NTzTask execution, by activity)r   r   zSend data, by activityg?Fr?  r@  r   )_update_selectors_build_data_sourcesr8  r0  %_build_task_execution_by_prefix_chartr9  _build_pie_chartr.  r/  r:  r-  r   r?  &_update_task_execution_by_prefix_chartr   r   rA  r   )r   needs_figures_rowfigures_rows      r   rQ   zFinePerformanceMetrics.update~  ss    	     """ <D 	+&*D# 	 ::<< * 04/D/D53 0E 0 0D, /3.C.C4 /	 /D / /D+ 6:5RUX5X&.2" 	5&+D#77999243
 ,  K ! 5	"))+66666 *5	"2&&&%	5 	5r   c                   t                      }t                      }| j        j        D ]}t          |t                    s|^}}}}t          |t
                    sJ |                    |           |dk    r0|\  }t          |t
                    sJ |                    |           |                    | j        j	                   |r| j        j	        
                    |           |r|                    d           |                    | j        j	                   |rF| j        j	        
                    |           dt          | j        j	                   d| j        _        | j        j                            d          }	|	r}t          |	j                  }
|
                    | j        j	                   |
rJ| j        j	        
                    |
           dt          | j        j	                   d| j        _        dS dS dS )zUpdate choices available in

        - self.unit_selector
        - self.function_selector
        - self.span_tag_selector
        executezN/AzFilter by function (z):spanszFilter by span tag (N)r  r   cumulative_worker_metricsr  tupler  r  difference_updater7  r=  extendr5  r   r   r  r   spans_search_by_tagr6  )r   units	functionsrY  contextotheractivityunitfunction	spans_exttagss              r   rN  z(FinePerformanceMetrics._update_selectors  s    EE	9 	( 	(Aa'' ./+GeXtdC(((((IIdOOO)###!(C00000h''' 2 :;;; 	5&--e444 	!MM%   ##D$:$BCCC 	"*11)<<<Ns4+A+I'J'JNNN "( 59N4M4Q4Q5
 5
	  	y455D""4#9#ABBB &.55d;;;R3t/E/M+N+NRRR &,,,	 	 r   c                N    | j         j        }|dk    rdS |dk    rdS |dk    rdS dS )Nr>  00:00:00bytesz0.00br  r5  z0.000)r7  r   )r   rb  s     r   rK  z)FinePerformanceMetrics._bokeh_unit_format  s>    !'9:W__7W__37r   valc                    | j         j        }|dk    rt          |          S |dk    rt          t	          |                    S t	          |          x}|k    rt          |          S t          |          S )Nr>  rh  )r7  r   rA   r@   r  r  )r   ri  rb  ivals       r   _formatzFinePerformanceMetrics._format  sp    !'9s###W__C)))#hhd3&&t99s88Or   c                    t          | j                  }	 ddlm} t	           |t
          |                    S # t          $ r d t          |          D             cY S w xY w)Nr   )interp_palettec                R    g | ]$}t           |t          t                     z           %S r   )r/   r   )r   r;  s     r   r   z7FinePerformanceMetrics._get_palette.<locals>.<listcomp>  s(    DDDaIa#i..01DDDr   )r   r3  bokeh.palettesrn  r   r/   ImportErrorr   )r   r^  rn  s      r   _get_palettez#FinePerformanceMetrics._get_palette  s    '((	E555555y!44555 	E 	E 	EDD588DDDDDD	Es   #: #A A c                   t                      }t                      }t          t                    }t          t                    }t          t                    }t          | j        j                  }| j        j                            d          }|r(| j        j        r |j	        | j        j         }|j
        }	nM|r#|j        r|                                }|j
        }	n(d | j        j
                                        D             }	|	                                D ]\  \  }
}}}}|
dk    sJ t          |t                    sJ t          |t                    sJ | j        j        sJ || j        j        k    r_|r||vrft          |          }| j        j        s|dk    rd}|||fxx         |z  cc<   ||xx         |z  cc<   |                    |           |                    |           | j        j        s| j        j        s| j        j
                                        D ]\  }}t          |t$                    r|d         dk    rw|\  }}}t          |t                    sJ t          |t                    sJ | j        j        sJ || j        j        k    r%|                    |           ||xx         |z  cc<   |t          | j                  k    rd| _        t+          |          | _        |t          | j                  k    rt+          |          | _        |                     |          \  | j        _        | _        |                     |          | j        _        |                     |          | j        _        d	S )
ab  Pre-process and filter fine performance metrics; build data tables in
        Bokeh format

        Updates:

        - self.substantial_change
        - self.visible_activities
        - self.visible_functions
        - self.task_exec_by_prefix_src.data
        - self.task_exec_by_activity_src.data
        - self.get_data_by_activity_src.data
        rW  c                \    i | ])\  }}t          |t                    r|d          dk    &||*S )r   rV  )r  rY  r#  s      r   r[  z>FinePerformanceMetrics._build_data_sources.<locals>.<dictcomp>!  sK       Aqa'' -.aDI,=,= 1,=,=,=r   rV  zidle or other spansr   r   zget-dataTN)r  r   r   r5  r   r   r  r   r6  merge_by_tagsrX  rW  	merge_allr\  r  r  r7  r  rY  r2  r0  r  r3  $_build_task_execution_by_prefix_datar,  r   r-  _build_pie_datar.  r/  )r   r2  r3  execute_by_funcrV  r  function_selrd  spanexecute_metricsr_  rc  ra  rb  rZ  rY  _s                    r   rO  z*FinePerformanceMetrics._build_data_sources   s     EE UU?J5?Q?Q+6u+=+=,7,>,>4178848N4M4Q4Q5
 5
	  	/5 	*9*D,B,HID"<OO 
	9? 
	&&((D"<OO  NDJJLL  O 7F6K6K6M6M 	- 	-2/Wh$i''''h,,,,,dC(((((%++++t)///  < < 8}}H )/ "H@U4U4U!Hh.///14///H"!!(+++""8,,,,%+ 		0D4J4P 		0@FFHH 0 01a'' 0AaDJ,>,>()%Ax%h44444%dC00000-3333t1777*..x888 ***a/*** D$: ; ;;;&*D#%+,=%>%>D"T%<!=!===&,-?&@&@D#
 55oFF	
(-).2.B.B7.K.K&+-1-A-A(-K-K%***r   r   defaultdict[str, float]dict[str, list]c           	        	  j                                          fdD             	d t          t          	          d           D             }fd|D             fd|D             	fd|D             	t	          	          }                     |          }|rd|z  nd	|rd
t          j        z  |z  nd		 fd	D             fd	D             |gt          	          z  dS )zvBuild the data source for a pie chart by activity

        See also
        --------
        _build_pie_chart
        c                     g | ]
}|         S r   r   )r   ra  r   s     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>d  s    <<<X$x.<<<r   c                    g | ]	\  }}||
S r   r   )r   r;  rZ  s      r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>h  s"    SSSTQQRSqSSSr   c                    | d          S rX  r   )els    r   rZ  z8FinePerformanceMetrics._build_pie_data.<locals>.<lambda>h  s    r!uf r   r  c                     g | ]
}|         S r   r   )r   r;  
activitiess     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>i  s    111jm111r   c                     g | ]
}|         S r   r   )r   r;  r  s     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>j  s    +++!71:+++r   c                     g | ]
}|         S r   r   )r   r;  r   s     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>k  s    )))&))))r         Y@ry   g       @c                P    g | ]"}                     |          d |z  ddz   #S r  r  z%)rl  )r   rZ  	percent_kr   s     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>t  s;    RRRaT\\!__'AA	M'A'A'A'AARRRr   c                    g | ]}|z  S r   r   )r   rZ  angle_ks     r   r   z:FinePerformanceMetrics._build_pie_data.<locals>.<listcomp>u  s    222aa'k222r   )ra  r   r   angler   
total_text)	r3  rr  r  r=  r   rl  r   rb  r   )
r   r   idxtotal_valuer  r  r  r  r  r   s
   ``   @@@@@r   rx  z&FinePerformanceMetrics._build_pie_dataY  s\    ,
 ##%%<<<<<<< TSVIf$5$5;L;LMMMSSS1111S111
++++s+++))))S)))&kk\\+..
+6?EK''C	1<E#-+--#"RRRRR6RRR22226222%,V4
 
 	
r   r   r   r0   c                    t          dd|ddd          }d|j        _        d|j        _        d|j        _        |                    d	d
dt          dd          t          d          ddd|	  	         |S )z`Create pie chart by activity

        See also
        --------
        _build_pie_data
        r   
scale_bothr   z*@{activity}: @text<br>total: @{total_text}r=  )r   rH  r   r   r   r   NFr   rd   r  r  Tr>  r@  r   ra  rA  )r0   r%  r  r   rO  rP  rN  r2   )r   r   r   piecharts       r   rQ  z'FinePerformanceMetrics._build_pie_chartz  s     $A
 
 
 $(  %(,%wT:::Woo# 	 
	
 
	
 
	
 r   #defaultdict[tuple[str, str], float]tuple[dict[str, list], float]c                     fd j         D             }d |D             } j          fd|D             d}g } j        D ]cfd j         D             }t          |          s&|                               ||<    fdt	          ||          D             |d d<   d| j        k    rd	 _        | j        d
d
<   |t          |d          fS )zBuild the data source for the execute by function stacked chart

        See also
        --------
        _build_task_execution_by_prefix_chart
        _update_task_execution_by_prefix_chart
        c                T    g | ]#t          fd j        D                       $S )c              3  ,   K   | ]}|f         V  d S r6  r   )r   ra  r   rc  s     r   r8  zYFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>.<genexpr>  s-      QQXXx'(QQQQQQr   )r   r3  )r   rc  r   r   s    @r   r   zOFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>  sM     
 
 
 QQQQQ9PQQQQQ
 
 
r   c                     g | ]}|rd |z  ndS )r  ry   r   )r   rZ  s     r   r   zOFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>  s%    ???aq)%!))c???r   c                :    g | ]}                     |          S r   r  )r   rZ  r   s     r   r   zOFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>  s#    DDD1t||ADDDr   )__functions____total_textc                $    g | ]}|f         S r   r   )r   rc  ra  r   s     r   r   zOFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>  s#    VVV8d8X-.VVVr   c                V    g | ]%\  }}                     |          d ||z  ddz   &S r  r  )r   rZ  perc_kir   s      r   r   zOFinePerformanceMetrics._build_task_execution_by_prefix_data.<locals>.<listcomp>  sO     ) ) )Aw Q":q7{":":":"::) ) )r   ___textTNry   r  )r2  r3  r  r   rX  r4  r0  r>  )r   r   func_totalsperc_krN  sc_visible_activitiesr   ra  s   ``     @r   rw  z;FinePerformanceMetrics._build_task_execution_by_prefix_data  sb   
 
 
 
 
 2
 
 
 @?;???1DDDDDDD 
  

 !#/ 		 		HVVVVVt?UVVVFv;; !((222"CM) ) ) )"%ff"5"5) ) )C$X$$$%% !D$III&*D#7LD1!!!4CS11111r   c           	        t          g dddd                    | j                            }d|j        _        t          dd          |_        t          d	
          |j        d         _	        d|j        _
        d|j        _        |S )zCreate empty stacked bar chart for execute by function

        See also
        --------
        _build_task_execution_by_prefix_data
        _update_task_execution_by_prefix_chart
        r   r  zTask execution, by function,)r  r   rH  r   r   Tr   rd   rg  r  r  N)r0   join
BASE_TOOLSr   r   r$   r   r!   r   r'  r)  rO  rP  )r   barcharts     r   rP  z<FinePerformanceMetrics._build_task_execution_by_prefix_chart  s     $/((4?++
 
 
 "& #1a==&:*&M&M&Mq#14.(,%r   c                $     j         }|J t           j         |_         fdt	                                            j                  D             }t          |          t           j                  k    sJ |	                     j        dd j
        | j                  }|j        dt           j                           |_        |D ]<}d|j        d|j         dfd	g}|                    t          ||g
                     =||_        dS )zRebuild X axis and tooltips of execution by prefix stacked chart

        See also
        --------
        _build_task_execution_by_prefix_data
        _build_task_execution_by_prefix_chart
        Nc                ,    g | ]\  }}|j         v |S r   )r4  )r   prw   r   s      r   r   zQFinePerformanceMetrics._update_task_execution_by_prefix_chart.<locals>.<listcomp>  s5     
 
 
1D999 999r   r  r   )r   r   r   r   r  )rc  z@__functionsz@{__z_text})r   z@____total_text)r   r1  )r9  r   r2  r  rX  rr  r3  r   r4  
hbar_stackr,  r   r  r   r   r   r1  )r   r  r  r1  r  r   s   `     r   rR  z=FinePerformanceMetrics._update_task_execution_by_prefix_chart  sO    1###&(>?
 
 
 
D--//1HII
 
 

 7||s4#HIIIIII''1/> ( 
 
	 "(>#do*>*>(>? 	O 	OD,6DI6667,H
 y(tfMMMNNNN&r   N)r   rZ   r   r	   )rG  r  rH  r  r  r  r  rI  )r  rI  rC  )ri  r   r  r  )r  r1  )r   r~  r  r  )r   r   r   r  r  r0   )r   r  r  r  )r  r0   )r   r   r   r   r  r  r]   r   rE  r   rQ   rN  rK  rl  rr  rO  rx  rQ  rw  rP  rR  r   r   r   r'  r'  5  s          <;;J----####////....    !!!!////""""""""....,,,,----*
 *
 *
 Z*
XG G G G !,5 ,5 Z ! ,5\/ / / /b	 	 	 	
 
 
 
E E E EWL WL WL WLr
 
 
 
B   @#2 #2 #2 #2J   0%' %' %' %' %' %'r   r'  c                  ~    e Zd ZdZed             Zeed                         Zed	d            Z	ed	d            Z
dS )

Contentionz?
    Event Loop Health (and GIL Contention, if configured)
    c                   || _         t          g dg dg d          | _        d}| j         j        j        s*d}| j        D ] }| j        |         d d d         | j        |<   !t          | j                  | _        t          d|t          | j        d	          d
ddd|| _	        | j	        
                    d	ddd| j        t          d	ddgddgdd                     d| j	        j        _        d| j	        j        _        d| j	        j        _        d| j	        j        _        t'          ddgd          }| j	                            |           d S ) N))rZ   
Event Loop)rZ   GIL)Workersr  )r  r  r   r   r   r   )0s0%r  r  )r/  r   r   zEvent Loop & GIL Contentionr  re   r0  r/  r   rd   r   r   )r   r   r  r   r   r   r   r@  z#b8e0cez#81aae4r  rd   )r  r  r  r   r?  )r   r   r   rt  r   ru  r  r   TF)Namez@names)Valuez@textr  r   r  r   )r   rj  r   monitormonitor_gil_contentionr   r   r0   r   r   r  r3   r   group_paddingr   r   r   r   r  r   r   )r   r   r   r   r  r   s         r   r   zContention.__init__  s   "    <<)))	
 	
 	
	 . ~%< 	5 Ey 5 5!%3!!4	#&DI666 
7!34$
 
 
 
	 		;"""I.%u-   	 	
 	
 	
 +/	'01	-"&	"'	(*<=G
 
 
 		E"""""r   c                   | j         }|j        j        |j        | j        t          d |j                                        D                       t          |j                  pdz  | j	        gd d rdnd         | j
        d<   fdt          | j
        d                   D             | j
        d<   t          | j        | j
                   d S )Nc              3  0   K   | ]}|j         d          V  dS )event_loop_intervalNre  r   r<  s     r   r8  z$Contention.update.<locals>.<genexpr>D  s*      MMQ	/0MMMMMMr   rd   re   r   c                T    g | ]$\  }}|d z  rr	|dz  ddnt          |          %S )re   r  z.1f%re  )r   r;  r   monitor_gils      r   r   z%Contention.update.<locals>.<listcomp>J  sV     
 
 
1 "#QJ;Jq3wKNN
 
 
r   r   )r   r  r  _tick_interval_observedgil_contention_schedulerr   r   r   r   gil_contention_workersr   r=  rQ   r   )r   r  r  s     @r   rQ   zContention.update;  s     Ni6 %)MM!):J:J:L:LMMMMM19~~"$'
 %
$+$QQ1
$&	(
 
 
 
!$)H"566
 
 
	& 	t{DI&&&&&r   r  r   c                    | j         j        }|r;t          d |                                D                       t	          |          z  S t          d          S )Nc              3  L   K   | ]}|j                             d d          V   dS )gil_contentionr   N)rf  r   r  s     r   r8  z4Contention.gil_contention_workers.<locals>.<genexpr>T  sD        78	.22     r   NaN)r   r   r   r   r   r   )r   r   s     r   r  z!Contention.gil_contention_workersP  sh    .( 	  <CNN<L<L    G  U||r   c                    | j         j                                                            dt	          d                    S )Nr  r  )r   r  recentr   r   r  s    r   r  z#Contention.gil_contention_schedulerY  s0    ~%,,..223CU5\\RRRr   N)r  r   )r   r   r   r   r]   r   r   rQ   propertyr  r  r   r   r   r  r    s          4# 4# Z4#l !' ' Z ! '&    X S S S XS S Sr   r  c                  >    e Zd ZU dZded<   ddd	Zed
             ZdS )ExceptionsTablea  
    Exceptions logged in tasks.

    Since there might be many related exceptions (e.g., all tasks in a given
    task group fail for the same reason), we make a best-effort attempt to
    (1) aggregate to the task group, and (2) deduplicate similar looking tasks.
    rZ   r   r   r   r  r   r	   c                   || _         g d| _        t          d | j        D                       | _        t	          d          }t          dd|d          t          dd|d	          t          d
d
|d	          t          dd|d          t          ddt          d          d          g}d|v rd|d         i}ni }t          d| j        |dd|d dt          || _	        d S )N)Task	Exception	Traceback	Worker(s)Countc                    i | ]}|g S r   r   r  s     r   r[  z,ExceptionsTable.__init__.<locals>.<dictcomp>t      'B'B'B!2'B'B'Br   z.<code title="<%- value %>"><%= value %></code>)templater  r  )fieldr   r'  r   r  i,  r  r     r  z0,0r  r   rH  Tr   columnsreorderablesortabler   index_positionr   )
r   r/  r   r   r   r-   r    r,   rM   r   )r   r   r   r   code_formatterr  rH  s          r   r   zExceptionsTable.__init__i  sr   "
 
 

 ''B'Btz'B'B'BCC.E
 
 
 (	   !!(	   !!(	   !!(	   )777	  3
B F""(&*?@KKK 	
;	
 	
 ,	
 	
 	
			r   c                   d | j         D             }| j        j        }|D ]}|d                             |j                   |d                             |j                   |d                             |j                   |d                             d                    |j                             |d                             t          |j                             t          | j        |           d S )Nc                    i | ]}|g S r   r   r  s     r   r[  z*ExceptionsTable.update.<locals>.<dictcomp>  s    444D"444r   r  r  r  r  z,
r  )r/  r   erred_tasksr   r  exception_texttraceback_textr  erred_onr   rQ   r   )r   r  r  rl  s       r   rQ   zExceptionsTable.update  s    44444n0 	7 	7BV##BF+++[!(():;;;[!(():;;;[!((BK)@)@AAAW$$S%5%56666t{H%%%%%r   Nr   )r   rZ   r   r  r   r	   )r   r   r   r   r  r   r   rQ   r   r   r   r  r  ^  sd           >
 >
 >
 >
 >
@ !& & ! & & &r   r  c                  8    e Zd ZdZh dZddZed             ZdS )WorkerTablezStatus of the current workers

    This is two plots, a text-based table for each host and a thin horizontal
    plot laying out hosts by their current memory use.
    >   rY   ready	executing	in_flightr~  managed_bytesspilled_bytes   c                    | _         g d _         j         j                                        }t	           fd|D              j        z
             _        g d}dddddd	d
dddddt          d  j        D                        _        fd|D             t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          t          d          d}t          d3 j        fd|D             dd|d dt          }|D ]1}||v r+||         |j        |                    |                   _        2ddg j        z   }	fd|	D             t          d3 j        fd|	D             dd|d dt          }
|	D ]1}||v r+||         |
j        |	                    |                   _        2t          d d!"          }t!          d3d#d d$d%d&|d'd(d)|}|                     j        d*d(d+d,-           d.|j        _        d(|j        _        d.|j        _        d.|j        _        |                    |t1                                 t          d d/"          }t!          d3d0d d$d%d&|d'd(d)|}|                     j        d1d(d+d,-           d.|j        _        d(|j        _        d.|j        _        d.|j        _        |                    |t1                                 | _        d2|v rd2|d2         i}ni }|||g} j        r|                    |
           t7          |i | _        d S )4N)r   r   r  r  r.  r-  memory_percentmemory_managedmemory_unmanaged_oldmemory_unmanaged_recentmemory_spillednum_fdsr  r  r  r  cpu_fractionc           	         h | ]N}|j                                         D ]2\  }}|j        vt          |t          t
          t          f          0|3OS r   )rf  r\  r/  r  r  r  r   )r   r   r_  rZ  r   s       r   r1  z'WorkerTable.__init__.<locals>.<setcomp>  so       J,,..  AqDJ&&:a#sE9J+K+K&  '&&&r   )r   r   r  r  r.  r-  r  r  r  r  r  r  r  r  r  r  r  zmemory %r  zunmanaged oldzunmanaged recentr  z# fdsznet readz	net writez	disk readz
disk write)r-  r  r  r  r  r  r  r  r  r  r  c                    i | ]}|g S r   r   r  s     r   r[  z(WorkerTable.__init__.<locals>.<dictcomp>  r  r   c           
     \    i | ](}|t          |                    ||                     )S )r  r   r-   r   r   r   column_title_renamess     r   r[  z(WorkerTable.__init__.<locals>.<dictcomp>  sI     
 
 
 +D0D0H0Ht0T0TUUU
 
 
r   z0 %r  z0.0 %r  z0 br5  )r  r  r.  r-  r  r  r  r  r  r  r  r  r  r  c                     g | ]
}|         S r   r   )r   r^  r  s     r   r   z(WorkerTable.__init__.<locals>.<listcomp>&  s    555AWQZ555r   Tr  r   r   c           
     \    i | ](}|t          |                    ||                     )S r  r  r   s     r   r[  z(WorkerTable.__init__.<locals>.<dictcomp>3  sI     
 
 
 +D0D0H0Ht0T0TUUU
 
 
r   c                     g | ]
}|         S r   r   )r   r^  extra_columnss     r   r   z(WorkerTable.__init__.<locals>.<listcomp>:  s    ;;;!]1%;;;r   r   a  
                <div>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">Worker (@name): </span>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">@memory_percent{0.0 %}</span>
                </div>
                r   zMemory Use (%)r  )grz   r  r   r   )r   r   r   r  r   r   r   min_border_rightr  r   r   )r   r   r   r  r   Fa  
                <div>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">Worker (@name): </span>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">@cpu_fraction{0 %}</span>
                </div>
                zCPU Use (%)r  rH  r   )r   r/  r   r   r  excluded_namesextra_namesr   r   r    r,   rM   r  r  r'  r   r0   r  r   r   r   r   r   r   r   cpu_plotr   r   r   )r   r   r   r   r   table_namesr  tabler   r  extra_tabler   mem_plotr	  rH  
componentsr  r  r  s   `               @@@r   r   zWorkerTable.__init__  s/   "
 
 

& .(//11!   !   !"
 

 
 
& $('$3'9'$.%0%0&2 
  
 ''B'Btz'B'B'BCC
 
 
 
#
 
 
 #%000-W===%W555+7;;;-W===$37$C$C$C'6g'F'F'F-W===$35$A$A$A%4E%B%B%B&c222's333%4E%B%B%B&5U&C&C&C
 

"  
;5555555
 
 ,
 
   	T 	TDz!!CMdCSk//556@y)D,<<
 
 
 
#
 
 

   
;;;;;{;;;
 
 ,
 
   	 	Dz!!ISJ#K$5$5d$;$;<F '
 
 
  

"!

 

 

 

 	;"2abS 	 	
 	
 	
 "'/0,!&!&5-//222'
 
 
  

!

 

 

 

 	;.AB3 	 	
 	
 	
 "'/0,!&!&5-//222 F""(&*?@KKK%0
 	+k***J6+66			r   c           	        d | j         | j        z   D             }t          t          | j        j                                        d                     D ]\  }}|j        }| j         | j        z   D ]}d|v rI|                    d          \  }}}|j	        
                    |i           
                    |d           }	n|j	        
                    |d           }	||                             |	           |j        |j        n||d         d<   |j        |d         d<   |j        r|j	        d         |j        z  |d	         d<   nd
|d	         d<   |j        |d         d<   |j        |d         d<   |j        |d         d<   |j        |d         d<   |j        |d         d<   |j        |d         d<   |j	        d         dz  |d         d<   |j	        d         dz  |j        z  |d         d<   |j        |d         d<   | j         | j        z   D ]}|dk    r4||                             ddt+          ||                    d           =	 t+          | j        j                  dk    rd }
nm|d	k    rrt-          d | j        j                                        D                       }|r8t-          d | j        j                                        D                       |z  nd
}
n|dk    ret-          d | j        j                                        D                       dz  t+          | j        j                                                  z  }
n|dk    rot-          d | j        j                                        D                       dz  t-          d | j        j                                        D                       z  }
nt-          ||                   }
||                             d|
           # t.          $ r  ||                             dd            Y w xY w| j        j                            |           d S )Nc                    i | ]}|g S r   r   r  s     r   r[  z&WorkerTable.update.<locals>.<dictcomp>  s    CCCTbCCCr   c                *    t          | j                  S r6  )r  r   )r   s    r   rZ  z$WorkerTable.update.<locals>.<lambda>  s    3rw<< r   r  r  r   r   r   r.  r  r   r-  r  r  r  r  r  r  r  r  r   zTotal ()c              3  $   K   | ]}|j         V  d S r6  r7  r   s     r   r8  z%WorkerTable.update.<locals>.<genexpr>  s5       $ $,.$ $ $ $ $ $r   c              3  0   K   | ]}|j         d          V  dS )r.  Nre  r   s     r   r8  z%WorkerTable.update.<locals>.<genexpr>  s=          $& !#
8 4           r   c              3  0   K   | ]}|j         d          V  dS r  Nre  r   s     r   r8  z%WorkerTable.update.<locals>.<genexpr>  )      XX"BJu-XXXXXXr   r  c              3  0   K   | ]}|j         d          V  dS r  re  r   s     r   r8  z%WorkerTable.update.<locals>.<genexpr>  r  r   c              3  $   K   | ]}|j         V  d S r6  r  r   s     r   r8  z%WorkerTable.update.<locals>.<genexpr>  s$      TTbbkTTTTTTr   )r/  r  r=  r  r   r   r   r.  	partitionrf  r   r   r   r   r-  r  r  r  r  r  insertr   r   	TypeErrorr   r   rQ   )r   r   r;  r   minfor   n0r}  n1rZ  
total_data	total_mems               r   rQ   zWorkerTable.update  s   CCTZ$2B%BCCC4>)00228O8OPPP
 
 	/ 	/EAr IE
T%55 % %$;; $s 3 3IB2
r2..222t<<AA
tT22AT
!!!$$$$*,'*=rww1DL"$*DOB 0-/Z-ABO-S%&r**-/%&r*')D $).D!"2&/4/BD'(,272HD*+B/272HD*+B/).D!"2& j/%7DKO')z%'85'@2;'ND $#%;DR  J!11 '	+ '	+Dv~~T
!!!%As4:%A%A%ABBB#+t~-..!33!%JJ--- # $ $26.2H2O2O2Q2Q$ $ $ ! !I %     *..*@*G*G*I*I        (	( (   J U]]XX8N8U8U8W8WXXXXXdn4;;==>>? J
 ^++XX8N8U8U8W8WXXXXXTTDN4J4Q4Q4S4STTTTTU J "%T$ZJT
!!!Z0000 + + +T
!!!T*****+ 	%%%%%s   
F*O66&P P N)r  )r   r   r   r   r  r   r   rQ   r   r   r   r  r    si           NB7 B7 B7 B7H !H& H& ! H& H& H&r   r  c                  .    e Zd ZdZd Zed             ZdS )	Shufflingru   c                   t                      5  || _        t          i dg dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg i          | _        t          g dg dd          | _        t          d4dddt          dd          d|| _        | j                            | j        dddd
           t          g ddd id!"          }| j        
                    |           d| j        j        _        d#| j        j        _        t          d$%          | j        j        d         _        t          d4d&ddt          dd          d|| _        d'| j        j        _        | j                            | j        dddd           t          g d(d)d id!"          }| j        
                    |           t          d$%          | j        j        d         _        t          d4d*ddd+|| _        g d}t          d4|d,d dd-|| _        | j                            d.d/d| j        0           d | j        j        _        d| j        j        _        t          d$%          | j        j        d         _        t          d1gd23          }| j        
                    |           t3          | j        | j                  | _        d d d            d S # 1 swxY w Y   d S )5Nr~   r   comm_memorycomm_memory_limitcomm_bucketscomm_avg_durationcomm_avg_size	comm_readcomm_written
comm_colordisk_memorydisk_memory_limitdisk_bucketsdisk_avg_durationdisk_avg_size	disk_readdisk_written
disk_colorzNetwork SendzNetwork Receivez
Disk Writez	Disk Readr  r   r   zComms Bufferr   r   r   r  r  r   )r   r   r   r   r   ))Memory Usedz@comm_memory{0.00 b})Average Writez@comm_avg_size{0.00 b})	# Bucketsz@comm_buckets)Average Duration@comm_avg_durationr;  r   hline)r   r  r  rd   r  r  zDisk BufferF))r7  z@disk_memory{0.00 b})r8  z@disk_avg_size{0.00 b})r9  z@disk_buckets)r:  @disk_avg_durationr=  zTotal movement)r   r   r   Totals)r   r   r   r   r   r   r  )Totalz@values{0.00b}r  r  r   )r]   r   r   r   totals_sourcer0   r$   r%  ry  r   r   r   r   r?  r!   r   r'  r-  r   r   r%  r  r  rP  r  r   r   )r   r   r   r   titless        r   r   zShuffling.__init__  s   \\ z	@ z	@&DN*b "2 (	
 #B ( $R   #B !" "2 ( #B ( $R   !" #B#$ !"%  DK, "2WWW*ll " "D  &  $!(;//	   
    D !!{#" "       1*=	 	 	E &&u----.D$*+,D$(2Fg2V2V2VD"1%/%  #!(;//	   
    D .3D"*!!{#" "       1*=	 	 	E &&u---2Fg2V2V2VD"1%/  &!(  	 DK TSSF  !%	 
  DK K)	     15DK-()DK%-A-Q-Q-QDKa *56  E K!!%(((D,d.>??DIuz	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@ z	@s   J?KK"Kc           	        t                      5  | j        j        d         j        }|s	 d d d            d S t	          |                                          d         }t          t                    }t                      }t          |	                                          D ]P\  }\  }}|d         
                    |           |d         
                    |           dD ]}||         d         pd}|| d         
                    ||         d	                    || d
         
                    ||         d                    || d         
                    |           || d         
                    ||         d                    || d         
                    ||         d                             dd                     || d         
                    ||         d                             dd                     || d         
                    ||         d                    || d         
                    ||         d                    | j        j        |         j        |dz
  k     r || d         
                    d           ||         d         |k    r || d         
                    d           || d         
                    d           R	 g dt          |d                   t          |d                   t          |d                    t          |d!                   gd"}	t          | j        |	           t          | j        t%          |                     t'          |d#         |d$         z             d%z  }
|
| j        j        _        |
| j        j        _        d d d            d S # 1 swxY w Y   d S )&Nshuffler   r   r~   )commr  r-  r   _totalr   _memoryr.  _memory_limit_bucketsbuckets_avg_durationdiagnosticsavg_duration	_avg_sizeavg_size_readr  _writtenwrittenr  _colorr*  r{   r|   r5  r+  r*  r3  r2  r6  r&  r.  g333333?)r]   r   r  
heartbeatsr   r   r   rY   r=  r\  r   r   r   r  r   rQ   r@  r   rj  r>  r%  r   r?  r-  )r   inputr   r  r;  r~   ri  rL  r-  r%  r  s              r   rQ   zShuffling.update\  sq   \\ H	1 H	1N-i8CE H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1
 ((,Et$$D&&C"+EKKMM":": ? ?;FAS	  ###X%%f---. ? ?F#$V9^#<#ALF***+221V9W3EFFFF+++,33AfIh4GHHHF111299,GGGF,,,-44QvYy5IJJJF111299&	-044^QGG   F---.55&	-044ZCC   F)))*11!F)F2CDDDF,,,-44QvYy5IJJJ~-f5?#'II.../66v>>>>68,|;;.../66u====.../66v>>>>'?*2 TSS^,--[)**^,--[)**	 F 4%v...4;T

+++01D9L4MMNNQTTE+0D$(+0D$(QH	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1 H	1s   ONOOON)r   r   r   r   r   r   rQ   r   r   r   r#  r#    sQ        (({@ {@ {@z !I1 I1 ! I1 I1 I1r   r#  z100%1920px1080px12pxz1px solid lightgrayzinset 1px 0 8px 0 lightgrayauto)r   r   z	max-widthz
max-heightpaddingborderz
box-shadowoverflowr  stylestylesc                      e Zd ZddZdS )SchedulerLogsNc                    |                     |d          }|sd}n>t          d                    d |D                                                                 }t	          dd|it
          | _        d S )NT)r   r  zC<p style="font-family: monospace; margin: 0;">No logs to report</p>
c              3  v   K   | ]4\  }}}t          j        |                              d           d|V  5dS )z%H:%M:%S.%fz - N)r   fromtimestampstrftime)r   rY   r  r  s       r   r8  z)SchedulerLogs.__init__.<locals>.<genexpr>  sg         *eT  -d33<<]KKKKTTS     r   r   r   )get_logsr\   r  _repr_html_r.   _BOKEH_STYLES_KWARGSr   )r   r   r   logs	logs_htmls        r   r   zSchedulerLogs.__init__  s    !!$!?? 	U I 		   .2      kmm  ??Y?*>??			r   r6  )r   r   r   r   r   r   r   r_  r_    s.        @ @ @ @ @ @r   r_  c                   t          | d          }d|_        t          ||d           |                    |j                   t
                              d          |_        |j        	                    |           t          |_        d S )NrF  rC  zDask: Scheduler System Monitorr   simple.html)rK   r   rG   add_rootr   envget_templater  template_variablesrQ   BOKEH_THEMEtheme)r   extradocsysmons       r   systemmonitor_docru    sx    9.AAAF0CI#vs+++LL##M22CL!!%(((CIIIr   c                   d|_         t          | dd          }t          | dd          }t          | ddd          }t	          | dd          }t          ||d           t          ||d           t          ||d           t          ||d           |j        j        |j        _        |	                    t          t          |j        |j        |j        |j        |j                  t          t          |j        |j                                                 t                               d	          |_        |j                            |           t*          |_        d S )
NzDask: Shufflingi  r  i@  r  r  )r   r   r  r   rk  )r   r#  rE  r   r  rG   r  r  r  rl  r   r   r   r%  r-  r%  rm  rn  r  ro  rQ   rp  rq  )r   rr  rs  	shufflingrH  
timeseries
event_loops          r   shuffling_docrz    s^   !CI)3s;;;I"9CDDDN!c5  J IS===J#y#...#~s333#z3///#z3///#-?#:J LL#%%   z+Z_==>>		
 		
   ##M22CL!!%(((CIIIr   c           
        t          |           }t          |           }t          |           }|j        j        |j        _        d|_        t          ||d           t          ||d           t          ||d           |                    t          |j        t          |j        |j        d                               t                              d          |_        |j                            |           t          |_        d S )NzDask: Work Stealingr   rF  rC  rk  )rt   r  r  r   r   r   rG   rl  r   r   rm  rn  r  ro  rQ   rp  rq  )r   rr  rs  r}   stealing_tsstealing_eventss         r   stealing_docr~    s    )$$I$Y//K$Y//O#.#3#;O %CI#y#...#{C000#444LLN $*  	
 	
	 	 	 ##M22CL!!%(((CIIIr   c                ^   t          | dd          }|                                 t          ||d           d|_        |                    t          |j        d                     t                              d          |_	        |j
                            |           t          |_        d S )	Nr     )r   r   zDask: Scheduler EventsrB  rC  rk  )r  rQ   rG   r   rl  r   r   rm  rn  r  ro  rp  rq  )r   rr  rs  r  s       r   
events_docr    s    IuS111F
MMOOO#vs+++(CILL???@@@##M22CL!!%(((CIIIr   c                :   t          |           }|                                 t          ||d           d|_        |                    |j                   t                              d          |_        |j	                            |           t          |_        d S )Nr   zDask: Exceptionsrk  )r  rQ   rG   r   rl  r   rm  rn  r  ro  rp  rq  r   rr  rs  r  s       r   exceptions_docr  #  s    I&&E	LLNNN#ud+++"CILL##M22CL!!%(((CIIIr   c                :   t          |           }|                                 t          ||d           d|_        |                    |j                   t                              d          |_        |j	                            |           t          |_        d S )Nr   zDask: Workersrk  )r  rQ   rG   r   rl  r   rm  rn  r  ro  rp  rq  r  s       r   workers_docr  /  s    	""E	LLNNN#uc***CILL##M22CL!!%(((CIIIr   c                :   t          |           }|                                 d|_        |                    |j                   t
                              d          |_        |j                            |           t          |_
        t          ||d           d S )Nz Dask: Cluster Hardware Bandwidthrk  r   )r  rQ   r   rl  r   rm  rn  r  ro  rp  rq  rG   )r   rr  rs  hws       r   hardware_docr  ;  s    	)		BIIKKK2CILL##M22CL!!%(((CI#r3'''''r   c                |   t          | t          j                            d          dd          }|                                 t          ||d           d|_        |                    |j                   t          
                    d          |_        |j                            |           t          |_        d S )Nz8distributed.scheduler.dashboard.tasks.task-stream-length60srF  r  r  rH  r2  zDask: Task Streamrk  )r  r   r?   r   rQ   rG   r   rl  r   rm  rn  r  ro  rp  rq  )r   rr  rs  rl  s       r   	tasks_docr  H  s    	[__F
 
 "
 
 
B IIKKK#r4(((#CILL##M22CL!!%(((CIIIr   c                >   t          | d          }d|_        |                                 t          ||d           |                    |j                   t                              d          |_        |j	                            |           t          |_        d S )NrF  rC  zDask: Task Graphr  rk  )r  r   rQ   rG   rl  r   rm  rn  r  ro  rp  rq  )r   rr  rs  graphs       r   	graph_docr  [  s    i^<<<E"CI	LLNNN#uc***LL##M22CL!!%(((CIIIr   c                >   t          | d          }d|_        |                                 t          ||d           |                    |j                   t                              d          |_        |j	                            |           t          |_        d S )NrF  rC  zDask: Task Groups Graphr  rk  )rk  r   rQ   rG   rl  r   rm  rn  r  ro  rp  rq  )r   rr  rs  tg_graphs       r   tg_graph_docr  h  s    i^DDDH)CIOO#x---LL##M22CL!!%(((CIIIr   c                   t          | d          }|                                 t          ||d           |                    |j                   t          | j                  dk    r*t          | d          }t          | d          }|j	        }n)t          | d          }t          | d          }|j        }t          | d          }t          | d          }t          | d          }	|j        }
|j        }|                                 |	                                 |                                 |                                 |                                 t          ||d           t          ||	d           t          ||d           t          ||d           t          ||d           |                    |j                   t          |d          t          |
d          t          |d          t          |	j        d          g}t!          d	d
          }|D ](}d|j        _        |j                            |           )t)          |dd          }|                    |           t+          | t,          j                            d          dd          }|                                 t          ||d           |                    |j                   t3          | d          }|                                 t          ||d           |                    |j                   d|_        t6          |_        t:                              d          |_        |j                             |           d S )NrF  rC  r  
Processingr;  CPUrt   zData Transferzfhttps://docs.dask.org/en/stable/dashboard.html#task-processing-cpu-utilization-occupancy-data-transferz:A description of Task Processing/CPU Utilization/Occupancyr!  r   processing_tabs)rG  r   rH  z9distributed.scheduler.dashboard.status.task-stream-length5sr  zDask: Statuszstatus.html)!r  rQ   rG   rl  r   r   r   rE  r  r  ra  r   rt   rk  r  rL   r   r<  r   r   r'   r  r   r?   r   r
  r   rp  rq  rm  rn  r  ro  )r   rr  rs  r  rH  r   processing_rootcurrent_loadr}   rs  cpu_rootoccupancy_rootrG  r*  tab	proc_tabsr  r  s                     r   
status_docr  t  s   "9.IIIN#~s333LL$%%%
9$$&ynMMM GGG
$6/	~VVV(OOO
$/ynEEEL)@@@I1)XXX&H^N!!####~s333#5s;;;#z3///#|S111#y#...LL$%%% 	l;;;xu---~[999-2/JJJ	D yP  E  # #%,	"	E""""$%6NSSSILL[__G
 
 "  K #{C000LL!""" GGGM#}c222LL#$$$CICI##M22CL!!%(((((r   r   c                @   t                      5   | |fddi|}|                                 t          |||           |                    t	          ||                     t
          |_        dt          |           z   |_        d d d            d S # 1 swxY w Y   d S )NrH  rF  zDask: )	r]   rQ   rG   rl  r0  rp  rq  rB   r   )clsintervalr   rr  rs  fig_attrr   rM  s           r   individual_docr    s     
 - -c)BBB6BB

c3111WS(++,,,	x}},	- - - - - - - - - - - - - - - - - -s   A7BBBc                    t          | d|          }|                    |j                   |                                 t          |_        d S NrF  rH  rs  )rJ   rl  r   trigger_updaterp  rq  r   rr  rs  profs       r   individual_profile_docr    sG    9.cJJJDLLCIIIr   c                    t          | d|          }|                    |j                   |                                 t          |_        d S r  )rI   rl  r   r  rp  rq  r  s       r   individual_profile_server_docr    sG    CHHHDLLCIIIr   c                   d|_         t          | d|          }|                    |j                   t                              d          |_        |j                            |           t          |_
        |                                 d S )NzDask: ProfilerF  r  rk  )r   rJ   rl  r   rm  rn  r  ro  rQ   rp  rq  r  r  s       r   profile_docr    s|    CI9.cJJJDLL##M22CL!!%(((CIr   c                   d|_         t          | d|          }|                    |j                   t                              d          |_        |j                            |           t          |_
        |                                 d S )NzDask: Profile of Event LooprF  r  rk  )r   rI   rl  r   rm  rn  r  ro  rQ   rp  rq  r  r  s       r   profile_server_docr    s|    -CICHHHDLL##M22CL!!%(((CIr   )r  )r   )
__future__r   loggingr   r  oscollectionsr   r   collections.abcr   r   numbersr   typingr	   r
   rp   r   bokeh.core.propertiesr   r   bokeh.ior   bokeh.layoutsr   r   bokeh.modelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   bokeh.models.widgetsr,   r-   bokeh.models.widgets.markupsr.   rp  r/   bokeh.plottingr0   bokeh.themesr1   bokeh.transformr2   r3   r4   r5   jinja2r6   r7   tlzr8   r9   r:   tlz.curriedr;   r<   r=   tornador>   r   r?   
dask.utilsr@   rA   rB   rC   rD   rE   distributed.corerF    distributed.dashboard.componentsrG   'distributed.dashboard.components.sharedrH   rI   rJ   rK   distributed.dashboard.corerL   distributed.dashboard.utilsrM   rN   rO   rP   rQ   $distributed.diagnostics.graph_layoutrR    distributed.diagnostics.progressrS   'distributed.diagnostics.progress_streamrT   rU   #distributed.diagnostics.task_streamrV   ri  rX   rK  distributed.metricsrY   distributed.schedulerrZ   distributed.spansr[   distributed.utilsr\   r]   r   !distributed.dashboard.export_toolr^   r_   	getLoggerr   loggerpathr  dirname__file__rm  rp  r$  rb  r(  r  rt   r   r   r  rE  ra  rk  r  r  r  r  r   r$  rs  r  r  r  r  r  r  r  r  rk  r  r
  r'  r  r  r  r#  _STYLESr7  rg  r_  ru  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   <module>r     s4   " " " " " "    				 0 0 0 0 0 0 0 0 $ $ $ $ $ $                         D D D D D D D D       % % % % % % % %                                                           < 8 7 7 7 7 7 7 7 , , , , , , $ $ $ $ $ $ ! ! ! ! ! !       C C C C C C C C C C C C 0 0 0 0 0 0 0 0 # # # # # # # # # # , , , , , , , , , ,                             $ # # # # # B B B B B B            0 / / / / /              = < < < < < 8 8 8 8 8 8 L L L L L L L L @ @ @ @ @ @ G G G G G G I I I I I I $ $ $ $ $ $ + + + + + + 5 5 5 5 5 5 - - - - - - - -;??677 <<<<<<<JGCLL		8	$	$k
RW__X..dFKPP    eW\\"'//(33T<HH   )P)P)PQQ
gX\  ()+ 
R( R( R( R( R(" R( R( R(j&Q &Q &Q &Q &Q, &Q &Q &QR. . . . . . . .bH$ H$ H$ H$ H$& H$ H$ H$VV$ V$ V$ V$ V$& V$ V$ V$r/ / / / // / / /dm$ m$ m$ m$ m$- m$ m$ m$`I= I= I= I= I=! I= I= I=X;$ ;$ ;$ ;$ ;$' ;$ ;$ ;$|a$ a$ a$ a$ a$) a$ a$ a$HT$ T$ T$ T$ T$/ T$ T$ T$n}, }, }, }, },) }, }, },@[8 [8 [8 [8 [8& [8 [8 [8|\2 \2 \2 \2 \2( \2 \2 \2~F$ F$ F$ F$ F$$ F$ F$ F$Rw$ w$ w$ w$ w$$ w$ w$ w$t'. '. '. '. '.+ '. '. '.Ta/ a/ a/ a/ a/' a/ a/ a/HR/ R/ R/ R/ R/ R/ R/ R/jP> P> P> P> P># P> P> P>fU U U Up|< |< |< |< |<" |< |< |<~x4 x4 x4 x4 x4' x4 x4 x4vRL RL RL RL RL* RL RL RLj^
 ^
 ^
 ^
 ^
% ^
 ^
 ^
BG' G' G' G' G'/ G' G' G'T\S \S \S \S \S# \S \S \S~W& W& W& W& W&( W& W& W&ta& a& a& a& a&$ a& a& a&H	J1 J1 J1 J1 J1" J1 J1 J1\ #/	 	 #W-$g.@ @ @ @ @ @ @ @(      D   4          	( 	( 	(   $ 	 	 	    M) M) M)` - - - -              r   