diff options
Diffstat (limited to 'afdo_tools')
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis.py | 12 | ||||
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis_e2e_test.py | 6 | ||||
-rwxr-xr-x | afdo_tools/bisection/afdo_prof_analysis_test.py | 32 | ||||
-rwxr-xr-x | afdo_tools/generate_afdo_from_tryjob.py | 6 | ||||
-rwxr-xr-x | afdo_tools/run_afdo_tryjob.py | 4 |
5 files changed, 30 insertions, 30 deletions
diff --git a/afdo_tools/bisection/afdo_prof_analysis.py b/afdo_tools/bisection/afdo_prof_analysis.py index 36531106..94e5366b 100755 --- a/afdo_tools/bisection/afdo_prof_analysis.py +++ b/afdo_tools/bisection/afdo_prof_analysis.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -109,7 +109,7 @@ class DeciderState(object): self.state_file) return - with open(self.state_file) as f: + with open(self.state_file, encoding='utf-8') as f: try: data = json.load(f) except: @@ -127,7 +127,7 @@ class DeciderState(object): def save_state(self): state = {'seed': self.seed, 'accumulated_results': self.accumulated_results} tmp_file = self.state_file + '.new' - with open(tmp_file, 'w') as f: + with open(tmp_file, 'w', encoding='utf-8') as f: json.dump(state, f, indent=2) os.rename(tmp_file, self.state_file) logging.info('Logged state to %s...', self.state_file) @@ -270,7 +270,7 @@ def range_search(decider, good, bad, common_funcs, lo, hi): def find_upper_border(good_copy, funcs, lo, hi, last_bad_val=None): """Finds the upper border of problematic range.""" mid = average(lo, hi) - if mid == lo or mid == hi: + if mid in (lo, hi): return last_bad_val or hi for func in funcs[lo:mid]: @@ -288,7 +288,7 @@ def range_search(decider, good, bad, common_funcs, lo, hi): def find_lower_border(good_copy, funcs, lo, hi, last_bad_val=None): """Finds the lower border of problematic range.""" mid = average(lo, hi) - if mid == lo or mid == hi: + if mid in (lo, hi): return last_bad_val or lo for func in funcs[lo:mid]: @@ -428,7 +428,7 @@ def main(flags): 'good_only_functions': gnb_result, 'bad_only_functions': bng_result } - with open(flags.analysis_output_file, 'wb') as f: + with open(flags.analysis_output_file, 'w', encoding='utf-8') as f: json.dump(results, f, indent=2) if flags.remove_state_on_completion: os.remove(flags.state_file) diff --git a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py index 85c1c175..b293b8aa 100755 --- a/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py +++ b/afdo_tools/bisection/afdo_prof_analysis_e2e_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -15,13 +15,13 @@ import tempfile import unittest from datetime import date -import afdo_prof_analysis as analysis +from afdo_tools.bisection import afdo_prof_analysis as analysis class ObjectWithFields(object): """Turns kwargs given to the constructor into fields on an object. - Example usage: + Examples: x = ObjectWithFields(a=1, b=2) assert x.a == 1 assert x.b == 2 diff --git a/afdo_tools/bisection/afdo_prof_analysis_test.py b/afdo_tools/bisection/afdo_prof_analysis_test.py index 7bd3050c..245edc33 100755 --- a/afdo_tools/bisection/afdo_prof_analysis_test.py +++ b/afdo_tools/bisection/afdo_prof_analysis_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -8,12 +8,12 @@ from __future__ import print_function -import afdo_prof_analysis as analysis - import random -import StringIO +import io import unittest +from afdo_tools.bisection import afdo_prof_analysis as analysis + class AfdoProfAnalysisTest(unittest.TestCase): """Class for testing AFDO Profile Analysis""" @@ -33,17 +33,17 @@ class AfdoProfAnalysisTest(unittest.TestCase): analysis.random.seed(5) # 5 is an arbitrary choice. For consistent testing def test_text_to_json(self): - test_data = StringIO.StringIO('deflate_slow:87460059:3\n' - ' 3: 24\n' - ' 14: 54767\n' - ' 15: 664 fill_window:22\n' - ' 16: 661\n' - ' 19: 637\n' - ' 41: 36692 longest_match:36863\n' - ' 44: 36692\n' - ' 44.2: 5861\n' - ' 46: 13942\n' - ' 46.1: 14003\n') + test_data = io.StringIO('deflate_slow:87460059:3\n' + ' 3: 24\n' + ' 14: 54767\n' + ' 15: 664 fill_window:22\n' + ' 16: 661\n' + ' 19: 637\n' + ' 41: 36692 longest_match:36863\n' + ' 44: 36692\n' + ' 44.2: 5861\n' + ' 46: 13942\n' + ' 46.1: 14003\n') expected = { 'deflate_slow': ':87460059:3\n' ' 3: 24\n' @@ -115,7 +115,7 @@ class AfdoProfAnalysisTest(unittest.TestCase): self.bad_items, common_funcs, 0, len(common_funcs)) - self.assertEquals(['func_a', 'func_b'], problem_range) + self.assertEqual(['func_a', 'func_b'], problem_range) def test_check_good_not_bad(self): func_in_good = 'func_c' diff --git a/afdo_tools/generate_afdo_from_tryjob.py b/afdo_tools/generate_afdo_from_tryjob.py index b8a2d669..3ed578ea 100755 --- a/afdo_tools/generate_afdo_from_tryjob.py +++ b/afdo_tools/generate_afdo_from_tryjob.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -115,7 +115,7 @@ def main(): '--tryjob', required=True, type=_tryjob_arg, - help='Path to our tryjob\'s artifacts. Accepts a gs:// path, pantheon ' + help="Path to our tryjob's artifacts. Accepts a gs:// path, pantheon " 'link, or tryjob ID, e.g. R75-11965.0.0-b3648595. In the last case, ' 'the assumption is that you ran a chell-chrome-pfq-tryjob.') parser.add_argument( @@ -127,7 +127,7 @@ def main(): '-k', '--keep_artifacts_on_failure', action='store_true', - help='Don\'t remove the tempdir on failure') + help="Don't remove the tempdir on failure") args = parser.parse_args() if not distutils.spawn.find_executable(_CREATE_LLVM_PROF): diff --git a/afdo_tools/run_afdo_tryjob.py b/afdo_tools/run_afdo_tryjob.py index de45af0b..e14cd918 100755 --- a/afdo_tools/run_afdo_tryjob.py +++ b/afdo_tools/run_afdo_tryjob.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -94,7 +94,7 @@ def main(): user_patches = args.patch if tag_profiles_with_current_time and use_afdo_generation_stage: - raise ValueError('You can\'t tag profiles with the time + have ' + raise ValueError("You can't tag profiles with the time + have " 'afdo-generate') if not tag_profiles_with_current_time and not use_afdo_generation_stage: |