blob: 511a1640f2666c295df844898f0adf74fc8bc691 [file] [log] [blame]
Primiano Tucci34bc5592021-02-19 17:53:36 +01001#!/usr/bin/env python3
Primiano Tucci11d94e12022-08-02 17:44:33 +01002# Copyright (C) 2021 The Android Open Source Project
Lalit Maganti31479092019-05-30 20:29:24 +01003#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Primiano Tucci11d94e12022-08-02 17:44:33 +010016# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17# DO NOT EDIT. Auto-generated by tools/gen_amalgamated_python_tools
18# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19
Lalit Maganti31479092019-05-30 20:29:24 +010020# This file should do the same thing when being invoked in any of these ways:
21# ./trace_processor
22# python trace_processor
23# bash trace_processor
24# cat ./trace_processor | bash
25# cat ./trace_processor | python -
26
Primiano Tucci11d94e12022-08-02 17:44:33 +010027BASH_FALLBACK=""" "
Florian Mayer0367ce42021-04-19 15:01:32 +010028exec python3 - "$@" <<'#'EOF
Primiano Tucci11d94e12022-08-02 17:44:33 +010029#""" # yapf: disable
Lalit Maganti31479092019-05-30 20:29:24 +010030
Lalit Maganti31479092019-05-30 20:29:24 +010031
Primiano Tucci11d94e12022-08-02 17:44:33 +010032# ----- Amalgamator: begin of python/perfetto/prebuilts/manifests/trace_processor_shell.py
Lalit Magantibd8a9972022-09-22 14:06:42 +010033# This file has been generated by: /usr/local/google/home/lalitm/perfetto/tools/roll-prebuilts 768b3f226580167fd3ca2d07774033648ebacd2e
Primiano Tucci11d94e12022-08-02 17:44:33 +010034TRACE_PROCESSOR_SHELL_MANIFEST = [{
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010035 'arch':
36 'mac-amd64',
37 'file_name':
38 'trace_processor_shell',
39 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +010040 8385216,
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010041 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +010042 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/mac-amd64/trace_processor_shell',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010043 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +010044 '47d64e6b1f0213d28e06905cde2da24cef4a86563f1a126ddfb1e863ad0e5a31',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010045 'platform':
46 'darwin',
47 'machine': ['x86_64']
48}, {
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010049 'arch':
Primiano Tucci33040842022-04-04 22:18:08 +010050 'mac-arm64',
51 'file_name':
52 'trace_processor_shell',
53 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +010054 7137720,
Primiano Tucci33040842022-04-04 22:18:08 +010055 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +010056 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/mac-arm64/trace_processor_shell',
Primiano Tucci33040842022-04-04 22:18:08 +010057 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +010058 '1ebf66c3c51c00a566c4ac44fac084a29a4ff08c212ea34626eac22367df10f8',
Primiano Tucci33040842022-04-04 22:18:08 +010059 'platform':
60 'darwin',
61 'machine': ['arm64']
62}, {
Primiano Tucci33040842022-04-04 22:18:08 +010063 'arch':
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010064 'linux-amd64',
65 'file_name':
66 'trace_processor_shell',
67 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +010068 9319568,
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010069 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +010070 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/linux-amd64/trace_processor_shell',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010071 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +010072 '0182f6433d98226772a4896d23772256e83466297766dce1c9fb4652b987133e',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010073 'platform':
74 'linux',
75 'machine': ['x86_64']
76}, {
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010077 'arch':
78 'linux-arm',
79 'file_name':
80 'trace_processor_shell',
81 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +010082 7061684,
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010083 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +010084 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/linux-arm/trace_processor_shell',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010085 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +010086 '662989c2bf11f326303050503c0270d27496d9decbbff812d7142a2832bcbc5f',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010087 'platform':
88 'linux',
89 'machine': ['armv6l', 'armv7l', 'armv8l']
90}, {
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010091 'arch':
92 'linux-arm64',
93 'file_name':
94 'trace_processor_shell',
95 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +010096 8436528,
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010097 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +010098 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/linux-arm64/trace_processor_shell',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +010099 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100100 'b2456a97be2e3be8034ccac02fefddf878ca46ee932d5233a021986bcd120d5e',
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100101 'platform':
102 'linux',
103 'machine': ['aarch64']
Lalit Maganti9d035022022-06-13 17:40:31 +0100104}, {
Lalit Maganti9d035022022-06-13 17:40:31 +0100105 'arch':
106 'android-arm',
107 'file_name':
108 'trace_processor_shell',
109 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100110 5705408,
Lalit Maganti9d035022022-06-13 17:40:31 +0100111 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100112 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/android-arm/trace_processor_shell',
Lalit Maganti9d035022022-06-13 17:40:31 +0100113 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100114 'bea2b130ba80889e38763bddaa10c940f66475abeb70ca5f3070d8e1f4f2e080'
Lalit Maganti9d035022022-06-13 17:40:31 +0100115}, {
Lalit Maganti9d035022022-06-13 17:40:31 +0100116 'arch':
117 'android-arm64',
118 'file_name':
119 'trace_processor_shell',
120 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100121 7332576,
Lalit Maganti9d035022022-06-13 17:40:31 +0100122 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100123 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/android-arm64/trace_processor_shell',
Lalit Maganti9d035022022-06-13 17:40:31 +0100124 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100125 '16c05bed6cb5947904987388c6a7f263ee1142bd232cbf32d751f1225a4ed449'
Lalit Maganti9d035022022-06-13 17:40:31 +0100126}, {
Lalit Maganti9d035022022-06-13 17:40:31 +0100127 'arch':
128 'android-x86',
129 'file_name':
130 'trace_processor_shell',
131 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100132 8248980,
Lalit Maganti9d035022022-06-13 17:40:31 +0100133 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100134 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/android-x86/trace_processor_shell',
Lalit Maganti9d035022022-06-13 17:40:31 +0100135 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100136 '4f71094fc24f683b2b3c77cf07bf69a37d407edf4e1fc4c1b9adc9fdb49add44'
Lalit Maganti9d035022022-06-13 17:40:31 +0100137}, {
Lalit Maganti9d035022022-06-13 17:40:31 +0100138 'arch':
139 'android-x64',
140 'file_name':
141 'trace_processor_shell',
142 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100143 8594208,
Lalit Maganti9d035022022-06-13 17:40:31 +0100144 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100145 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/android-x64/trace_processor_shell',
Lalit Maganti9d035022022-06-13 17:40:31 +0100146 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100147 '627e6c8f97230397626ac2387e8162a20473315a181886d7ed0ab514582edd66'
Lalit Maganti9d035022022-06-13 17:40:31 +0100148}, {
Lalit Maganti9d035022022-06-13 17:40:31 +0100149 'arch':
150 'windows-amd64',
151 'file_name':
152 'trace_processor_shell.exe',
153 'file_size':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100154 8925184,
Lalit Maganti9d035022022-06-13 17:40:31 +0100155 'url':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100156 'https://commondatastorage.googleapis.com/perfetto-luci-artifacts/768b3f226580167fd3ca2d07774033648ebacd2e/windows-amd64/trace_processor_shell.exe',
Lalit Maganti9d035022022-06-13 17:40:31 +0100157 'sha256':
Lalit Magantibd8a9972022-09-22 14:06:42 +0100158 '52eb5db1e9d8784639c01d97d6078ba87f0af94030588a15e8685744d17b30cf',
Lalit Maganti9d035022022-06-13 17:40:31 +0100159 'platform':
160 'win32',
161 'machine': ['amd64']
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100162}]
Matthew Clarkson63028d62019-10-10 15:48:23 +0100163
Primiano Tucci11d94e12022-08-02 17:44:33 +0100164# ----- Amalgamator: end of python/perfetto/prebuilts/manifests/trace_processor_shell.py
Lalit Maganti31479092019-05-30 20:29:24 +0100165
Primiano Tucci11d94e12022-08-02 17:44:33 +0100166# ----- Amalgamator: begin of python/perfetto/prebuilts/perfetto_prebuilts.py
167# Copyright (C) 2021 The Android Open Source Project
168#
169# Licensed under the Apache License, Version 2.0 (the "License");
170# you may not use this file except in compliance with the License.
171# You may obtain a copy of the License at
172#
173# http://www.apache.org/licenses/LICENSE-2.0
174#
175# Unless required by applicable law or agreed to in writing, software
176# distributed under the License is distributed on an "AS IS" BASIS,
177# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178# See the License for the specific language governing permissions and
179# limitations under the License.
180"""
181Functions to fetch pre-pinned Perfetto prebuilts.
182
183This function is used in different places:
184- Into the //tools/{trace_processor, traceconv} scripts, which are just plain
185 wrappers around executables.
186- Into the //tools/{heap_profiler, record_android_trace} scripts, which contain
187 some other hand-written python code.
188
189The manifest argument looks as follows:
190TRACECONV_MANIFEST = [
191 {
192 'arch': 'mac-amd64',
193 'file_name': 'traceconv',
194 'file_size': 7087080,
195 'url': https://commondatastorage.googleapis.com/.../trace_to_text',
196 'sha256': 7d957c005b0dc130f5bd855d6cec27e060d38841b320d04840afc569f9087490',
197 'platform': 'darwin',
198 'machine': 'x86_64'
199 },
200 ...
201]
202
203The intended usage is:
204
205 from perfetto.prebuilts.manifests.traceconv import TRACECONV_MANIFEST
206 bin_path = get_perfetto_prebuilt(TRACECONV_MANIFEST)
207 subprocess.call(bin_path, ...)
208"""
209
210import hashlib
211import os
212import platform
213import subprocess
214import sys
215
216
217def download_or_get_cached(file_name, url, sha256):
218 """ Downloads a prebuilt or returns a cached version
219
220 The first time this is invoked, it downloads the |url| and caches it into
221 ~/.perfetto/prebuilts/$tool_name. On subsequent invocations it just runs the
222 cached version.
223 """
224 dir = os.path.join(
225 os.path.expanduser('~'), '.local', 'share', 'perfetto', 'prebuilts')
226 os.makedirs(dir, exist_ok=True)
227 bin_path = os.path.join(dir, file_name)
228 sha256_path = os.path.join(dir, file_name + '.sha256')
229 needs_download = True
230
231 # Avoid recomputing the SHA-256 on each invocation. The SHA-256 of the last
232 # download is cached into file_name.sha256, just check if that matches.
233 if os.path.exists(bin_path) and os.path.exists(sha256_path):
234 with open(sha256_path, 'rb') as f:
235 digest = f.read().decode()
236 if digest == sha256:
237 needs_download = False
238
239 if needs_download:
240 # Either the filed doesn't exist or the SHA256 doesn't match.
241 tmp_path = bin_path + '.tmp'
242 print('Downloading ' + url)
243 subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
244 with open(tmp_path, 'rb') as fd:
245 actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
246 if actual_sha256 != sha256:
247 raise Exception('Checksum mismatch for %s (actual: %s, expected: %s)' %
248 (url, actual_sha256, sha256))
249 os.chmod(tmp_path, 0o755)
250 os.rename(tmp_path, bin_path)
251 with open(sha256_path, 'w') as f:
252 f.write(sha256)
253 return bin_path
254
255
256def get_perfetto_prebuilt(manifest, soft_fail=False, arch=None):
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100257 """ Downloads the prebuilt, if necessary, and returns its path on disk. """
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100258 plat = sys.platform.lower()
259 machine = platform.machine().lower()
260 manifest_entry = None
Primiano Tucci11d94e12022-08-02 17:44:33 +0100261 for entry in manifest:
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100262 # If the caller overrides the arch, just match that (for Android prebuilts).
Lalit Maganti31423632022-06-30 17:21:22 +0100263 if arch:
264 if entry.get('arch') == arch:
265 manifest_entry = entry
266 break
267 continue
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100268 # Otherwise guess the local machine arch.
Primiano Tucci11d94e12022-08-02 17:44:33 +0100269 if entry.get('platform') == plat and machine in entry.get('machine', []):
Primiano Tuccid3e40bd2021-08-03 10:52:39 +0100270 manifest_entry = entry
271 break
272 if manifest_entry is None:
273 if soft_fail:
274 return None
275 raise Exception(
276 ('No prebuilts available for %s-%s\n' % (plat, machine)) +
277 'See https://perfetto.dev/docs/contributing/build-instructions')
278
279 return download_or_get_cached(
280 file_name=manifest_entry['file_name'],
281 url=manifest_entry['url'],
282 sha256=manifest_entry['sha256'])
Lalit Maganti27832482020-05-18 12:10:50 +0100283
284
Primiano Tucci11d94e12022-08-02 17:44:33 +0100285def run_perfetto_prebuilt(manifest):
286 bin_path = get_perfetto_prebuilt(manifest)
287 if sys.platform.lower() == 'win32':
288 sys.exit(subprocess.check_call([bin_path, *sys.argv[1:]]))
289 os.execv(bin_path, [bin_path] + sys.argv[1:])
290
291# ----- Amalgamator: end of python/perfetto/prebuilts/perfetto_prebuilts.py
Matthew Clarkson63028d62019-10-10 15:48:23 +0100292
Lalit Maganti31479092019-05-30 20:29:24 +0100293if __name__ == '__main__':
Primiano Tucci11d94e12022-08-02 17:44:33 +0100294 run_perfetto_prebuilt(TRACE_PROCESSOR_SHELL_MANIFEST)
Lalit Maganti31479092019-05-30 20:29:24 +0100295
Lalit Maganti31479092019-05-30 20:29:24 +0100296#EOF