Commit 07052dac authored by Mikhail Khokhlov's avatar Mikhail Khokhlov Committed by Commit Bot

[tools/perf] Adapt roll_trace_processor interface for autoroller use

Implements 3 commands that will be used by an autoroller to:
- Query the latest dependency version
- Query the current dependency version
- Make the changes to roll the newer version

Bug: b/150129933, skia:10109
Change-Id: I953b728a5555f03a80701e546796534cc74b6147
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142272
Commit-Queue: Mikhail Khokhlov <khokhlov@google.com>
Reviewed-by: default avatarEric Boren <borenet@google.com>
Cr-Commit-Position: refs/heads/master@{#757833}
parent 1cc16822
...@@ -27,16 +27,6 @@ def _GetHostPlatform(): ...@@ -27,16 +27,6 @@ def _GetHostPlatform():
return os_name return os_name
def _GetLatestPath(binary_name, platform):
with tempfile_ext.NamedTemporaryFile() as latest_file:
latest_file.close()
remote_path = posixpath.join(CS_FOLDER, binary_name, platform,
LATEST_FILENAME)
cloud_storage.Get(CS_BUCKET, remote_path, latest_file.name)
with open(latest_file.name) as latest:
return latest.read()
def _CalculateHash(remote_path): def _CalculateHash(remote_path):
with tempfile_ext.NamedTemporaryFile() as f: with tempfile_ext.NamedTemporaryFile() as f:
f.close() f.close()
...@@ -72,7 +62,23 @@ def UploadHostBinary(binary_name, binary_path, version): ...@@ -72,7 +62,23 @@ def UploadHostBinary(binary_name, binary_path, version):
_SetLatestPathForBinary(binary_name, platform, remote_path) _SetLatestPathForBinary(binary_name, platform, remote_path)
def SwitchBinaryToLatestVersion(binary_name): def GetLatestPath(binary_name, platform):
with tempfile_ext.NamedTemporaryFile() as latest_file:
latest_file.close()
remote_path = posixpath.join(CS_FOLDER, binary_name, platform,
LATEST_FILENAME)
cloud_storage.Get(CS_BUCKET, remote_path, latest_file.name)
with open(latest_file.name) as latest:
return latest.read()
def GetCurrentPath(binary_name, platform):
with open(CONFIG_PATH) as f:
config = json.load(f)
return config[binary_name][platform]['remote_path']
def SwitchBinaryToNewPath(binary_name, platform, new_path):
"""Switch the binary version in use to the latest one. """Switch the binary version in use to the latest one.
This function updates the config file to contain the path to the latest This function updates the config file to contain the path to the latest
...@@ -81,10 +87,8 @@ def SwitchBinaryToLatestVersion(binary_name): ...@@ -81,10 +87,8 @@ def SwitchBinaryToLatestVersion(binary_name):
""" """
with open(CONFIG_PATH) as f: with open(CONFIG_PATH) as f:
config = json.load(f) config = json.load(f)
for platform in config[binary_name]: config[binary_name][platform]['remote_path'] = new_path
new_path = _GetLatestPath(binary_name, platform) config[binary_name][platform]['hash'] = _CalculateHash(new_path)
config[binary_name][platform]['remote_path'] = new_path
config[binary_name][platform]['hash'] = _CalculateHash(new_path)
with open(CONFIG_PATH, 'w') as f: with open(CONFIG_PATH, 'w') as f:
json.dump(config, f, indent=4, separators=(',', ': ')) json.dump(config, f, indent=4, separators=(',', ': '))
......
...@@ -68,7 +68,7 @@ class BinaryDepsManagerTests(unittest.TestCase): ...@@ -68,7 +68,7 @@ class BinaryDepsManagerTests(unittest.TestCase):
publicly_readable=True, publicly_readable=True,
) )
def testSwitchBinaryVersion(self): def testSwitchBinaryToNewPath(self):
self.writeConfig({'dep': {'testos': {'remote_path': 'old/path/to/bin'}}}) self.writeConfig({'dep': {'testos': {'remote_path': 'old/path/to/bin'}}})
latest_path = 'new/path/to/bin' latest_path = 'new/path/to/bin'
...@@ -81,7 +81,7 @@ class BinaryDepsManagerTests(unittest.TestCase): ...@@ -81,7 +81,7 @@ class BinaryDepsManagerTests(unittest.TestCase):
with mock.patch('py_utils.cloud_storage.CalculateHash') as hash_patch: with mock.patch('py_utils.cloud_storage.CalculateHash') as hash_patch:
get_patch.side_effect = write_latest_path get_patch.side_effect = write_latest_path
hash_patch.return_value = '123' hash_patch.return_value = '123'
binary_deps_manager.SwitchBinaryToLatestVersion('dep') binary_deps_manager.SwitchBinaryToNewPath('dep', 'testos', latest_path)
self.assertEqual( self.assertEqual(
self.readConfig(), self.readConfig(),
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import argparse
import os import os
import sys import sys
...@@ -18,5 +19,31 @@ from core.tbmv3 import trace_processor ...@@ -18,5 +19,31 @@ from core.tbmv3 import trace_processor
if __name__ == '__main__': if __name__ == '__main__':
binary_deps_manager.SwitchBinaryToLatestVersion( parser = argparse.ArgumentParser()
trace_processor.TP_BINARY_NAME) parser.add_argument(
'--platform', help='linux/mac/win', required=True)
parser.add_argument(
'--path', metavar='PATH', help='Switch to using a trace processor version'
' stored by this cloud path.')
parser.add_argument(
'--print-latest', action='store_true',
help='Print a cloud path to the latest available version.')
parser.add_argument(
'--print-current', action='store_true',
help='Print a cloud path to the currently used version.')
args = parser.parse_args()
if (bool(args.path) + args.print_latest + args.print_current != 1):
raise RuntimeError('Please supply exactly one of --path, '
'--print-latest or --print-current.')
if args.print_latest:
print binary_deps_manager.GetLatestPath(
trace_processor.TP_BINARY_NAME, args.platform)
elif args.print_current:
print binary_deps_manager.GetCurrentPath(
trace_processor.TP_BINARY_NAME, args.platform)
else:
binary_deps_manager.SwitchBinaryToNewPath(
trace_processor.TP_BINARY_NAME, args.platform, args.path)
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