| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Pulls historical swarming task metadata from Findit and prints a report.""" | 5 """Pulls historical swarming task metadata from Findit and prints a report.""" |
| 6 | 6 |
| 7 from collections import defaultdict | 7 from collections import defaultdict |
| 8 from collections import OrderedDict | 8 from collections import OrderedDict |
| 9 import datetime | 9 import datetime |
| 10 import os | 10 import os |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 _REMOTE_API_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) | 13 _REMOTE_API_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) |
| 14 sys.path.insert(1, _REMOTE_API_DIR) | 14 sys.path.insert(1, _REMOTE_API_DIR) |
| 15 | 15 |
| 16 import remote_api | 16 import remote_api |
| 17 | 17 |
| 18 from model import wf_analysis_status | 18 from model import analysis_status |
| 19 from model.wf_swarming_task import WfSwarmingTask | 19 from model.wf_swarming_task import WfSwarmingTask |
| 20 | 20 |
| 21 | 21 |
| 22 NOT_AVAILABLE = 'N/A' | 22 NOT_AVAILABLE = 'N/A' |
| 23 | 23 |
| 24 | 24 |
| 25 # TODO(lijeffrey): Refactor helper methods into module sharable with | 25 # TODO(lijeffrey): Refactor helper methods into module sharable with |
| 26 # try_job_data_query.py. | 26 # try_job_data_query.py. |
| 27 def _GetAverageOfNumbersInList(numbers): | 27 def _GetAverageOfNumbersInList(numbers): |
| 28 """Returns a float average of numbers or NOT_AVAILABLE if numbers is empty.""" | 28 """Returns a float average of numbers or NOT_AVAILABLE if numbers is empty.""" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 ... | 75 ... |
| 76 } | 76 } |
| 77 """ | 77 """ |
| 78 categorized_data = defaultdict( | 78 categorized_data = defaultdict( |
| 79 lambda: defaultdict( | 79 lambda: defaultdict( |
| 80 lambda: defaultdict( | 80 lambda: defaultdict( |
| 81 lambda: defaultdict(list)))) | 81 lambda: defaultdict(list)))) |
| 82 | 82 |
| 83 for swarming_task in swarming_task_list: | 83 for swarming_task in swarming_task_list: |
| 84 if (not swarming_task.parameters or not swarming_task.tests_statuses or | 84 if (not swarming_task.parameters or not swarming_task.tests_statuses or |
| 85 swarming_task.status != wf_analysis_status.ANALYZED): | 85 swarming_task.status != analysis_status.COMPLETED): |
| 86 # Disregard any swarming tasks that are not yet completed or were | 86 # Disregard any swarming tasks that are not yet completed or were |
| 87 # triggered before 'parameters' and 'tests_statuses' were introduced. | 87 # triggered before 'parameters' and 'tests_statuses' were introduced. |
| 88 continue | 88 continue |
| 89 | 89 |
| 90 priority = swarming_task.parameters['priority'] | 90 priority = swarming_task.parameters['priority'] |
| 91 master_name = swarming_task.master_name | 91 master_name = swarming_task.master_name |
| 92 builder_name = swarming_task.builder_name | 92 builder_name = swarming_task.builder_name |
| 93 step_name = swarming_task.key.id() | 93 step_name = swarming_task.key.id() |
| 94 | 94 |
| 95 categorized_data[priority][master_name][builder_name][step_name].append( | 95 categorized_data[priority][master_name][builder_name][step_name].append( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 'iterations_to_rerun') | 161 'iterations_to_rerun') |
| 162 if iterations_to_rerun is not None: | 162 if iterations_to_rerun is not None: |
| 163 iteration_counts.append(iterations_to_rerun) | 163 iteration_counts.append(iterations_to_rerun) |
| 164 | 164 |
| 165 # Number of tests. | 165 # Number of tests. |
| 166 number_of_tests = len(swarming_task.tests_statuses) | 166 number_of_tests = len(swarming_task.tests_statuses) |
| 167 if number_of_tests: | 167 if number_of_tests: |
| 168 tests_counts.append(number_of_tests) | 168 tests_counts.append(number_of_tests) |
| 169 | 169 |
| 170 # Error rate. | 170 # Error rate. |
| 171 if swarming_task.status == wf_analysis_status.ERROR: | 171 if swarming_task.status == analysis_status.ERROR: |
| 172 error_count += 1 | 172 error_count += 1 |
| 173 | 173 |
| 174 average_execution_time = (_GetAverageOfNumbersInList( | 174 average_execution_time = (_GetAverageOfNumbersInList( |
| 175 execution_times_seconds) if execution_times_seconds else NOT_AVAILABLE) | 175 execution_times_seconds) if execution_times_seconds else NOT_AVAILABLE) |
| 176 average_time_in_queue = ( | 176 average_time_in_queue = ( |
| 177 _GetAverageOfNumbersInList(in_queue_times) if in_queue_times else | 177 _GetAverageOfNumbersInList(in_queue_times) if in_queue_times else |
| 178 NOT_AVAILABLE) | 178 NOT_AVAILABLE) |
| 179 longest_execution_time = ( | 179 longest_execution_time = ( |
| 180 str(datetime.timedelta(seconds=max(execution_times_seconds))) | 180 str(datetime.timedelta(seconds=max(execution_times_seconds))) |
| 181 if execution_times_seconds else NOT_AVAILABLE) | 181 if execution_times_seconds else NOT_AVAILABLE) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 if not findit_tmp_dir: | 347 if not findit_tmp_dir: |
| 348 findit_tmp_dir = os.getcwd() | 348 findit_tmp_dir = os.getcwd() |
| 349 | 349 |
| 350 report_path = os.path.join(findit_tmp_dir, | 350 report_path = os.path.join(findit_tmp_dir, |
| 351 'swarming_task_metadata_report.html') | 351 'swarming_task_metadata_report.html') |
| 352 | 352 |
| 353 with open(report_path, 'w') as f: | 353 with open(report_path, 'w') as f: |
| 354 f.write(CreateHtmlPage(final_report, START_DATE, END_DATE)) | 354 f.write(CreateHtmlPage(final_report, START_DATE, END_DATE)) |
| 355 | 355 |
| 356 print 'Swarming task metadata report available at file://%s' % report_path | 356 print 'Swarming task metadata report available at file://%s' % report_path |
| OLD | NEW |