diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-03 15:57:36 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-03 15:57:36 +0000 |
commit | 9086b037eb418807f99d5ce5825f285d6b427cc6 (patch) | |
tree | 77dc031614745bb406dbd90cea9a082a1b5cdd54 /afdo_redaction/remove_indirect_calls.py | |
parent | 732a4eb324abf0d0f0c2bf539634a5e45ef5f56f (diff) | |
parent | 40214b48188358a80b7478bfff21d4814dd9177c (diff) | |
download | toolchain-utils-android14-mainline-adbd-release.tar.gz |
Snap for 10428683 from 40214b48188358a80b7478bfff21d4814dd9177c to mainline-adbd-releaseaml_adb_341520010aml_adb_341517070aml_adb_340912530aml_adb_340912350aml_adb_340912200aml_adb_340912000android14-mainline-adbd-release
Change-Id: I578fe57f97e55cbf6f5fc268be1f15035a00433b
Diffstat (limited to 'afdo_redaction/remove_indirect_calls.py')
-rwxr-xr-x | afdo_redaction/remove_indirect_calls.py | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/afdo_redaction/remove_indirect_calls.py b/afdo_redaction/remove_indirect_calls.py index 0dc15077..32dab3f4 100755 --- a/afdo_redaction/remove_indirect_calls.py +++ b/afdo_redaction/remove_indirect_calls.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Copyright 2019 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -17,21 +17,20 @@ objects as Chrome, this can become problematic, and lead to NaCl doubling in size (or worse). See crbug.com/1005023 and crbug.com/916130. """ -from __future__ import division, print_function import argparse import re def _remove_indirect_call_targets(lines): - # Lines with indirect call targets look like: - # 1.1: 1234 foo:111 bar:122 - # - # Where 1.1 is the line info/discriminator, 1234 is the total number of - # samples seen for that line/discriminator, foo:111 is "111 of the calls here - # went to foo," and bar:122 is "122 of the calls here went to bar." - call_target_re = re.compile( - r""" + # Lines with indirect call targets look like: + # 1.1: 1234 foo:111 bar:122 + # + # Where 1.1 is the line info/discriminator, 1234 is the total number of + # samples seen for that line/discriminator, foo:111 is "111 of the calls here + # went to foo," and bar:122 is "122 of the calls here went to bar." + call_target_re = re.compile( + r""" ^\s+ # Top-level lines are function records. \d+(?:\.\d+)?: # Line info/discriminator \s+ @@ -39,42 +38,48 @@ def _remove_indirect_call_targets(lines): \s+ ((?:[^\s:]+:\d+\s*)+) # Indirect call target(s) $ - """, re.VERBOSE) - for line in lines: - line = line.rstrip() + """, + re.VERBOSE, + ) + for line in lines: + line = line.rstrip() - match = call_target_re.match(line) - if not match: - yield line + '\n' - continue + match = call_target_re.match(line) + if not match: + yield line + "\n" + continue - group_start, group_end = match.span(1) - assert group_end == len(line) - yield line[:group_start].rstrip() + '\n' + group_start, group_end = match.span(1) + assert group_end == len(line) + yield line[:group_start].rstrip() + "\n" def run(input_stream, output_stream): - for line in _remove_indirect_call_targets(input_stream): - output_stream.write(line) + for line in _remove_indirect_call_targets(input_stream): + output_stream.write(line) def main(): - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--input', - default='/dev/stdin', - help='File to read from. Defaults to stdin.') - parser.add_argument( - '--output', - default='/dev/stdout', - help='File to write to. Defaults to stdout.') - args = parser.parse_args() - - with open(args.input) as stdin: - with open(args.output, 'w') as stdout: - run(stdin, stdout) - - -if __name__ == '__main__': - main() + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.add_argument( + "--input", + default="/dev/stdin", + help="File to read from. Defaults to stdin.", + ) + parser.add_argument( + "--output", + default="/dev/stdout", + help="File to write to. Defaults to stdout.", + ) + args = parser.parse_args() + + with open(args.input) as stdin: + with open(args.output, "w") as stdout: + run(stdin, stdout) + + +if __name__ == "__main__": + main() |