Commit 3006f751 authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[Build] extract_unwind_tables.py: Remove temp file usage.

extract_unwind_tables.py calls dump_syms, and processes ~400 MB of
data from ~105 M lines. Previously these data were written to a temp
file, which is then opened and read line-by-line. This approach creates
churn, and is prone to out-of-disk-space problem.

This CL removes temp file usage by directly piping dump_syms output to
_ParseCfiData(), using subprocess.Popen(bufsize=-1)'s |stdout|. Run time
is unaffected.

Fixed: 1068862
Change-Id: Iaa0d433dcb91a8b15fff4dd6ce0a34fcba8d6376
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141220
Commit-Queue: Samuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757740}
parent 6d6c8e11
......@@ -254,10 +254,8 @@ def _WriteCfiData(cfi_data, out_file):
_Write2Bytes(out_file, data)
def _ParseCfiData(sym_file, output_path):
with open(sym_file, 'r') as f:
cfi_data = _GetAllCfiRows(f)
def _ParseCfiData(sym_stream, output_path):
cfi_data = _GetAllCfiRows(sym_stream)
with open(output_path, 'wb') as out_file:
_WriteCfiData(cfi_data, out_file)
......@@ -275,13 +273,11 @@ def main():
help='The path of the dump_syms binary')
args = parser.parse_args()
cmd = ['./' + args.dump_syms_path, args.input_path]
proc = subprocess.Popen(cmd, bufsize=-1, stdout=subprocess.PIPE)
_ParseCfiData(proc.stdout, args.output_path)
assert proc.wait() == 0
with tempfile.NamedTemporaryFile() as sym_file:
out = subprocess.call(
['./' +args.dump_syms_path, args.input_path], stdout=sym_file)
assert not out
sym_file.flush()
_ParseCfiData(sym_file.name, args.output_path)
return 0
if __name__ == '__main__':
......
......@@ -24,9 +24,8 @@ from util import build_utils
class TestExtractUnwindTables(unittest.TestCase):
def testExtractCfi(self):
with tempfile.NamedTemporaryFile() as input_file, \
tempfile.NamedTemporaryFile() as output_file:
input_file.write("""
with tempfile.NamedTemporaryFile() as output_file:
test_data_lines = """
MODULE Linux arm CDE12FE1DF2B37A9C6560B4CBEE056420 lib_chrome.so
INFO CODE_ID E12FE1CD2BDFA937C6560B4CBEE05642
FILE 0 ../../base/allocator/allocator_check.cc
......@@ -63,9 +62,8 @@ STACK CFI INIT 3b92114 6c .cfa: sp 0 + .ra: lr
STACK CFI 3b92118 .cfa: r7 16 + .ra: .cfa -20 + ^
STACK CFI INIT 3b93214 fffff .cfa: sp 0 + .ra: lr
STACK CFI 3b93218 .cfa: r7 16 + .ra: .cfa -4 + ^
""")
input_file.flush()
extract_unwind_tables._ParseCfiData(input_file.name, output_file.name)
""".splitlines()
extract_unwind_tables._ParseCfiData(test_data_lines, output_file.name)
expected_cfi_data = {
0xe1a1e4 : [0x2, 0x11, 0x4, 0x50],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment