|
2 | 2 | import sys
|
3 | 3 | import yaml
|
4 | 4 | import shutil
|
| 5 | +import time |
5 | 6 |
|
6 | 7 | from lib import Options
|
7 | 8 | from lib.colorer import color_stdout
|
|
15 | 16 | from lib.utils import safe_makedirs
|
16 | 17 | from lib.utils import print_tail_n
|
17 | 18 | from lib.utils import print_unidiff
|
| 19 | +from lib.utils import get_proc_stat_rss |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class BaseWatcher(object):
|
@@ -51,6 +53,7 @@ def process_result(self, obj):
|
51 | 53 | obj.show_reproduce_content))
|
52 | 54 |
|
53 | 55 | def print_statistics(self):
|
| 56 | + print("ALX ####################\n") |
54 | 57 | """Returns are there failed tasks."""
|
55 | 58 | if self.stats:
|
56 | 59 | color_stdout('Statistics:\n', schema='test_var')
|
@@ -178,6 +181,70 @@ def __del__(self):
|
178 | 181 | pass
|
179 | 182 |
|
180 | 183 |
|
| 184 | +class RSSMonitor(BaseWatcher): |
| 185 | + def __init__(self, get_not_done_worker_ids, worker_id_to_pid): |
| 186 | + self.get_not_done_worker_ids = get_not_done_worker_ids |
| 187 | + self.worker_id_to_pid = worker_id_to_pid |
| 188 | + self.activity = 0.0 |
| 189 | + self.worker_current_task = dict() |
| 190 | + self.failed_tasks = dict() |
| 191 | + self.rss_results = dict() |
| 192 | + |
| 193 | + def process_result(self, obj): |
| 194 | + if isinstance(obj, WorkerCurrentTask): |
| 195 | + self.worker_current_task[obj.worker_id] = obj |
| 196 | + print("ALX process_result ================ {} {}\n" . format(obj.task_name, self.worker_id_to_pid[obj.worker_id])) |
| 197 | + self.rss_results[obj.task_name] = get_proc_stat_rss(self.worker_id_to_pid[obj.worker_id]) |
| 198 | + |
| 199 | + if isinstance(obj, WorkerTaskResult): |
| 200 | + if obj.short_status == 'fail': |
| 201 | + print("ALX FAILED process_result ================ {}\n" . format(obj.task_name)) |
| 202 | + self.failed_tasks[obj.task_name] = 1 |
| 203 | + |
| 204 | + def process_timeout(self, delta_seconds): |
| 205 | + rss = None |
| 206 | + rss_new_array = [] |
| 207 | + self.activity += delta_seconds |
| 208 | + worker_ids = self.get_not_done_worker_ids() |
| 209 | + |
| 210 | + running_tasks = [task for worker_id, task |
| 211 | + in self.worker_current_task.items() |
| 212 | + if worker_id in worker_ids] |
| 213 | + for task in running_tasks: |
| 214 | + if task.task_name in self.rss_results: |
| 215 | + rss = get_proc_stat_rss(self.worker_id_to_pid[task.worker_id]) |
| 216 | + if rss > self.rss_results[task.task_name]: |
| 217 | + self.rss_results[task.task_name] = rss |
| 218 | + print("ALX process_timeout ============ {} sec, pid={} '{}' {}\n" . format(round(self.activity, 1), self.worker_id_to_pid[task.worker_id], task.task_name, rss)) |
| 219 | + |
| 220 | + def print_statistics(self): |
| 221 | + print("ALX ####################\n") |
| 222 | + """Returns are there failed tasks.""" |
| 223 | + if self.rss_results: |
| 224 | + color_stdout('RSS Statistics:\n', schema='test_var') |
| 225 | + for task_name in self.rss_results: |
| 226 | + color_stdout('* %s: %d\n' % (task_name, self.rss_results[task_name]), schema='test_var') |
| 227 | + |
| 228 | + if not self.failed_tasks: |
| 229 | + return False |
| 230 | + |
| 231 | + color_stdout('Failed tasks:\n', schema='test_var') |
| 232 | + for task_id, worker_name, result_checksum, show_reproduce_content in self.failed_tasks: |
| 233 | + logfile = self.get_logfile(worker_name) |
| 234 | + task_id_str = yaml.safe_dump(task_id, default_flow_style=True) |
| 235 | + color_stdout('- %s' % task_id_str, schema='test_var') |
| 236 | + color_stdout('# results file checksum: %s\n' % result_checksum) |
| 237 | + color_stdout('# logfile: %s\n' % logfile) |
| 238 | + reproduce_file_path = get_reproduce_file(worker_name) |
| 239 | + color_stdout('# reproduce file: %s\n' % reproduce_file_path) |
| 240 | + if show_reproduce_content: |
| 241 | + color_stdout("---\n", schema='separator') |
| 242 | + print_tail_n(reproduce_file_path) |
| 243 | + color_stdout("...\n", schema='separator') |
| 244 | + |
| 245 | + return True |
| 246 | + |
| 247 | + |
181 | 248 | class OutputWatcher(BaseWatcher):
|
182 | 249 | def __init__(self):
|
183 | 250 | self.buffer = dict()
|
|
0 commit comments