|
35 | 35 | MetadataASTransfer, GPUStreamID, GPUStageID |
36 | 36 |
|
37 | 37 | LABEL_HEURISTICS = True |
38 | | -LABEL_MAX_LEN = 60 |
| 38 | +LABEL_MAX_LEN = 42 |
| 39 | +# Where to add ellipsis if label is too long |
| 40 | +# - left = ...X |
| 41 | +# - center = X...X |
| 42 | +# - right = X... |
| 43 | +LABEL_SPLIT = 'left' |
39 | 44 |
|
40 | 45 |
|
41 | 46 | class GPUWorkload: |
@@ -78,30 +83,30 @@ def __init__( |
78 | 83 | self.submit = None |
79 | 84 | self.label_stack = None |
80 | 85 | self.parsed_label_name: Optional[str] = None |
| 86 | + self.parsed_label_name_full: Optional[str] = None |
81 | 87 |
|
82 | 88 | if metadata: |
83 | 89 | self.submit = metadata.submit |
84 | 90 | self.label_stack = metadata.label_stack |
85 | 91 |
|
86 | | - def get_label_name(self) -> Optional[str]: |
| 92 | + def get_label_name_full(self) -> Optional[str]: |
87 | 93 | ''' |
88 | | - Get a cleaned up label name for a workload. |
89 | | -
|
90 | | - Warning: The heuristics here are not robust. |
| 94 | + Get a cleaned up label name for a workload with no shortening. |
91 | 95 |
|
92 | 96 | Returns: |
93 | | - A modified label for use in the UI. |
| 97 | + A label for use in the UI. |
94 | 98 | ''' |
| 99 | + # Cached label already parsed |
| 100 | + if self.parsed_label_name_full is not None: |
| 101 | + return self.parsed_label_name_full |
| 102 | + |
95 | 103 | # No label to parse |
96 | 104 | if not self.label_stack: |
97 | 105 | return None |
98 | 106 |
|
99 | | - # Cached label already parsed |
100 | | - if self.parsed_label_name is not None: |
101 | | - return self.parsed_label_name |
102 | | - |
103 | 107 | if not LABEL_HEURISTICS: |
104 | | - return self.label_stack[-1] |
| 108 | + self.parsed_label_name_full = self.label_stack[-1] |
| 109 | + return self.parsed_label_name_full |
105 | 110 |
|
106 | 111 | # Create a copy we can edit ... |
107 | 112 | labels = list(self.label_stack) |
@@ -141,7 +146,36 @@ def get_label_name(self) -> Optional[str]: |
141 | 146 | else: |
142 | 147 | label = '.'.join(labels) |
143 | 148 |
|
144 | | - if len(label) > LABEL_MAX_LEN: |
| 149 | + self.parsed_label_name_full = label |
| 150 | + return self.parsed_label_name_full |
| 151 | + |
| 152 | + def get_label_name(self) -> Optional[str]: |
| 153 | + ''' |
| 154 | + Get a cleaned up label name for a workload. |
| 155 | +
|
| 156 | + Warning: The heuristics here are not robust. |
| 157 | +
|
| 158 | + Returns: |
| 159 | + A modified label for use in the UI. |
| 160 | + ''' |
| 161 | + # Cached label already parsed |
| 162 | + if self.parsed_label_name is not None: |
| 163 | + return self.parsed_label_name |
| 164 | + |
| 165 | + label = self.get_label_name_full() |
| 166 | + |
| 167 | + # No label to parse |
| 168 | + if not label: |
| 169 | + return None |
| 170 | + |
| 171 | + # Apply ellipsis shortening |
| 172 | + if LABEL_SPLIT == 'left' and len(label) > LABEL_MAX_LEN: |
| 173 | + label = f'...{label[-LABEL_MAX_LEN:]}' |
| 174 | + |
| 175 | + elif LABEL_SPLIT == 'right' and len(label) > LABEL_MAX_LEN: |
| 176 | + label = f'{label[0:LABEL_MAX_LEN]}...' |
| 177 | + |
| 178 | + elif LABEL_SPLIT == 'center' and len(label) > LABEL_MAX_LEN: |
145 | 179 | half_max = LABEL_MAX_LEN // 2 |
146 | 180 | prefix = label[0:half_max] |
147 | 181 | postfix = label[-half_max:] |
@@ -176,6 +210,26 @@ def get_workload_name(self) -> str: |
176 | 210 |
|
177 | 211 | return label |
178 | 212 |
|
| 213 | + def get_workload_name_full(self) -> str: |
| 214 | + ''' |
| 215 | + Get a name for the workload. |
| 216 | +
|
| 217 | + This is based on the application debug label if there is one, but |
| 218 | + with some heuristics to try and clean is up ... |
| 219 | +
|
| 220 | + Returns: |
| 221 | + Returns the label for use in the UI. |
| 222 | + ''' |
| 223 | + label = None |
| 224 | + if self.label_stack: |
| 225 | + label = self.get_label_name_full() |
| 226 | + |
| 227 | + # Default label if no label or get_label_name heuristics stripped it |
| 228 | + if not label: |
| 229 | + return self.get_workload_type_name() |
| 230 | + |
| 231 | + return label |
| 232 | + |
179 | 233 | def get_long_label(self) -> str: |
180 | 234 | ''' |
181 | 235 | Get the long form label for this workload. |
|
0 commit comments