Commit eaa20263 authored by Egor Pasko's avatar Egor Pasko Committed by Chromium LUCI CQ

[tools/perf]: Atomically move results of trace2html, and fix a bug

If pinpoint_traces.py is interrupted while html2trace is busy, the next
extraction would take partial results. To make the process robust in
presence of interruptions, create a temporary directory for html2trace,
then atomically rename it to the directory that will be searched on
extraction.

The operation may seem not equivalent to creating a '.tmp.json' and
renaming it, because this is indeed not equivalent. This change fixes
the bug that I missed in previous testing when I forgot to delete the
json_cache, hence this code was not executing. This time json_cache was
deleted before testing.

Bug: 1119406
Change-Id: I7cfb19572a9ffa26827dd113bb92b2253b0a2b2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637838Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Egor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844817}
parent 3c0cb920
...@@ -13,6 +13,7 @@ import multiprocessing ...@@ -13,6 +13,7 @@ import multiprocessing
import os import os
import platform import platform
import re import re
import shutil
import subprocess import subprocess
import sys import sys
import traceback import traceback
...@@ -239,7 +240,8 @@ def ExtractFromOneTraceThrowing(args): ...@@ -239,7 +240,8 @@ def ExtractFromOneTraceThrowing(args):
│   │   └── json.1 │   │   └── json.1
│   ├── trace2 │   ├── trace2
│   │   ├── json │   │   ├── json
│   │   └── json.1 │   │   ├── json.1
│   │   └── json.2
├── chromium@5707819 ├── chromium@5707819
│ │ │ │
│ ... │ ...
...@@ -267,11 +269,17 @@ def ExtractFromOneTraceThrowing(args): ...@@ -267,11 +269,17 @@ def ExtractFromOneTraceThrowing(args):
(label, trace_index, html_trace, json_dir, compiled_regex) = args (label, trace_index, html_trace, json_dir, compiled_regex) = args
if not os.path.exists(json_dir): if not os.path.exists(json_dir):
print 'Converting trace to json: {}'.format(json_dir) print 'Converting trace to json: {}'.format(json_dir)
EnsureDirectoryExists(json_dir) tmp_json_dir = json_dir + '.tmp'
temp_json = os.path.join(json_dir, '.tmp.json') if os.path.exists(tmp_json_dir) and os.path.isdir(tmp_json_dir):
output = subprocess.check_output([HTML2TRACE, html_trace, temp_json]) shutil.rmtree(tmp_json_dir)
for json_file in output.splitlines(): EnsureDirectoryExists(tmp_json_dir)
os.rename(json_file, os.path.join(json_dir, LastAfterSlash(json_file))) json_file = os.path.join(tmp_json_dir, 'json')
output = subprocess.check_output([HTML2TRACE, html_trace, json_file])
for line in output.splitlines():
assert LastAfterSlash(line).startswith('json')
# Rename atomically to make sure that the JSON cache is not consumed
# partially.
os.rename(tmp_json_dir, json_dir)
# Since several json files are produced from the same trace, an event could # Since several json files are produced from the same trace, an event could
# begin and end in different jsons. # begin and end in different jsons.
...@@ -280,6 +288,7 @@ def ExtractFromOneTraceThrowing(args): ...@@ -280,6 +288,7 @@ def ExtractFromOneTraceThrowing(args):
print 'Taking trace: {}'.format(html_trace) print 'Taking trace: {}'.format(html_trace)
for json_file in os.listdir(json_dir): for json_file in os.listdir(json_dir):
if not json_file.startswith('json'): if not json_file.startswith('json'):
print '{} not starting with json'.format(json_file)
continue continue
full_json_file = os.path.join(json_dir, json_file) full_json_file = os.path.join(json_dir, json_file)
tids = LoadJsonFile(full_json_file, compiled_regex) tids = LoadJsonFile(full_json_file, compiled_regex)
......
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