@@ -25,10 +25,12 @@ def __init__(
2525 select_dimensions = [".*" ],
2626 select_events = [".*" ],
2727 x = 1000 ,
28+ show_workers = True ,
2829 ):
2930
3031 self .select_dimensions = select_dimensions
3132 self .select_events = select_events
33+ self .show_workers = show_workers
3234
3335 # placeholder
3436 self .sources = {}
@@ -52,10 +54,16 @@ def __init__(
5254 self .start = 0 # replace with system_metrics_reader.get_first_available_timestamp()/1000000
5355 self .system_metrics = self .preprocess_system_metrics (events , system_metrics = {})
5456
55- if x < self .system_metrics ["CPUUtilization" ]["total" ].shape [0 ]:
57+ min_width = float ("inf" )
58+ for key in self .system_metrics .keys ():
59+ if key .startswith ("CPUUtilization" ):
60+ width = self .system_metrics [key ]["total" ].shape [0 ]
61+ if width <= min_width :
62+ min_width = width
63+ if x < min_width :
5664 self .width = x
5765 else :
58- self .width = self . system_metrics [ "CPUUtilization" ][ "total" ]. shape [ 0 ] - 1
66+ self .width = min_width - 1
5967
6068 # create plot
6169 self .create_plot ()
@@ -64,13 +72,17 @@ def preprocess_system_metrics(self, events, system_metrics):
6472
6573 # read all available system metric events and store them in dict
6674 for event in events :
67- if event .dimension not in system_metrics :
68- system_metrics [event .dimension ] = {}
69- self .available_dimensions .append (event .dimension )
70- if event .name not in system_metrics [event .dimension ]:
71- system_metrics [event .dimension ][event .name ] = []
75+ if self .show_workers is True :
76+ event_unique_id = f"{ event .dimension } -nodeid:{ str (event .node_id )} "
77+ else :
78+ event_unique_id = event .dimension
79+ if event_unique_id not in system_metrics :
80+ system_metrics [event_unique_id ] = {}
81+ self .available_dimensions .append (event_unique_id )
82+ if event .name not in system_metrics [event_unique_id ]:
83+ system_metrics [event_unique_id ][event .name ] = []
7284 self .available_events .append (event .name )
73- system_metrics [event . dimension ][event .name ].append ([event .timestamp , event .value ])
85+ system_metrics [event_unique_id ][event .name ].append ([event .timestamp , event .value ])
7486
7587 for dimension in system_metrics :
7688 for event in system_metrics [dimension ]:
@@ -200,8 +212,15 @@ def create_plot(self):
200212 def find_time_annotations (self , indexes ):
201213
202214 if len (indexes ) > 0 :
203- begin_timestamp = self .system_metrics ["CPUUtilization" ]["total" ][np .min (indexes ), 0 ]
204- end_timestamp = self .system_metrics ["CPUUtilization" ]["total" ][np .max (indexes ), 0 ]
215+ cpu_util = None
216+ for key in self .system_metrics .keys ():
217+ if key .startswith ("CPUUtilization" ):
218+ width = self .system_metrics [key ]["total" ].shape [0 ]
219+ if cpu_util is None or np .min (indexes ) <= width <= np .max (indexes ):
220+ cpu_util = self .system_metrics [key ]
221+
222+ begin_timestamp = cpu_util ["total" ][np .min (indexes ), 0 ]
223+ end_timestamp = cpu_util ["total" ][np .max (indexes ), 0 ]
205224 total_time = end_timestamp - begin_timestamp
206225 print (
207226 f"Selected timerange: { begin_timestamp + self .start } to { end_timestamp + self .start } "
@@ -281,8 +300,15 @@ def plot_dataloaders(self, events, begin_timestamp, end_timestamp):
281300 def plot_detailed_profiler_data (self , indexes ):
282301
283302 if len (indexes ) > 0 :
284- begin_timestamp = self .system_metrics ["CPUUtilization" ]["cpu0" ][np .min (indexes ), 0 ]
285- end_timestamp = self .system_metrics ["CPUUtilization" ]["cpu0" ][np .max (indexes ), 0 ]
303+ cpu_util = None
304+ for key in self .system_metrics .keys ():
305+ if key .startswith ("CPUUtilization" ):
306+ width = self .system_metrics [key ]["cpu0" ].shape [0 ]
307+ if cpu_util is None or np .min (indexes ) <= width <= np .max (indexes ):
308+ cpu_util = self .system_metrics [key ]
309+
310+ begin_timestamp = cpu_util ["cpu0" ][np .min (indexes ), 0 ]
311+ end_timestamp = cpu_util ["cpu0" ][np .max (indexes ), 0 ]
286312 print (
287313 f"Selected timerange: { begin_timestamp + self .start } to { end_timestamp + self .start } "
288314 )
@@ -408,13 +434,22 @@ def update_data(self, current_timestamp):
408434 event
409435 ][self .system_metrics [dimension ][event ][:, 0 ].argsort ()]
410436
411- self .width = self .system_metrics ["CPUUtilization" ]["total" ].shape [0 ] - 1
437+ max_width = 0
438+ cpu_util = None
439+ for key in self .system_metrics .keys ():
440+ if key .startswith ("CPUUtilization" ):
441+ width = self .system_metrics [key ]["total" ].shape [0 ]
442+ if cpu_util is None or width >= max_width :
443+ max_width = width
444+ cpu_util = self .system_metrics [key ]
445+
446+ self .width = max_width - 1
412447
413448 if self .width > 1000 :
414- min_value = self . system_metrics [ "CPUUtilization" ] ["total" ][- 1000 , 0 ]
449+ min_value = cpu_util ["total" ][- 1000 , 0 ]
415450 else :
416- min_value = self . system_metrics [ "CPUUtilization" ] ["total" ][- self .width , 0 ]
417- max_value = self . system_metrics [ "CPUUtilization" ] ["total" ][- 1 , 0 ]
451+ min_value = cpu_util ["total" ][- self .width , 0 ]
452+ max_value = cpu_util ["total" ][- 1 , 0 ]
418453
419454 for figure in self .figures :
420455 figure .x_range .start = int (min_value )
0 commit comments