Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / tools / telemetry / catapult_base / support_binaries.py
blob8f73f99411418135eca6bf0f03f57c6c0de23f0b
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import os
6 import stat
8 from catapult_base import cloud_storage
9 from telemetry import decorators
10 from telemetry.internal.util import path
13 def _GetBinPath(binary_name, arch_name, platform_name):
14 return os.path.join(
15 path.GetTelemetryDir(), 'bin', platform_name, arch_name, binary_name)
18 def _IsInCloudStorage(binary_name, arch_name, platform_name):
19 return os.path.exists(
20 _GetBinPath(binary_name, arch_name, platform_name) + '.sha1')
23 @decorators.Cache
24 def FindLocallyBuiltPath(binary_name):
25 """Finds the most recently built |binary_name|."""
26 command = None
27 command_mtime = 0
28 chrome_root = path.GetChromiumSrcDir()
29 required_mode = os.X_OK
30 if binary_name.endswith('.apk'):
31 required_mode = os.R_OK
32 for build_dir, build_type in path.GetBuildDirectories():
33 candidate = os.path.join(chrome_root, build_dir, build_type, binary_name)
34 if os.path.isfile(candidate) and os.access(candidate, required_mode):
35 candidate_mtime = os.stat(candidate).st_mtime
36 if candidate_mtime > command_mtime:
37 command = candidate
38 command_mtime = candidate_mtime
39 return command
42 @decorators.Cache
43 def FindPath(binary_name, arch_name, platform_name):
44 """Returns the path to the given binary name, pulling from the cloud if
45 necessary."""
46 if platform_name == 'win':
47 binary_name += '.exe'
48 command = FindLocallyBuiltPath(binary_name)
49 if not command and _IsInCloudStorage(binary_name, arch_name, platform_name):
50 cloud_storage.GetIfChanged(
51 _GetBinPath(binary_name, arch_name, platform_name),
52 cloud_storage.PUBLIC_BUCKET)
53 command = _GetBinPath(binary_name, arch_name, platform_name)
55 # Ensure the downloaded file is actually executable.
56 if command and os.path.exists(command):
57 os.chmod(command,
58 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP)
60 # Return an absolute path consistently.
61 if command:
62 command = os.path.abspath(command)
63 return command