diff options
author | Chris Craik <ccraik@google.com> | 2021-08-02 17:34:46 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2021-08-02 17:34:46 -0700 |
commit | 30083b4a9bbd64fe816781c37d098a923977da29 (patch) | |
tree | f7bdba1367b9c52c29c71364e62cbacb05263b0c | |
parent | 7aa9645603bc7d0d011c6d143c3e3c2832d5bbea (diff) | |
download | traceprocessor-30083b4a9bbd64fe816781c37d098a923977da29.tar.gz |
Add script for updating perfetto binaries
Bug: 195355748
Test: ./gradlew benchmark:benchmark-macro:cC
Change-Id: I6ee09d5126d26e595bff48068bf090173439fc7f
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 37 | ||||
-rwxr-xr-x | generate_perfetto_binaries.py | 100 |
3 files changed, 120 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bcdbea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +perfetto_repo
\ No newline at end of file @@ -1,25 +1,26 @@ -# Trace Processor Shell +# Perfetto Binaries -The source code for `trace_processor_shell` lives in `external/perfetto` in the AOSP source tree. +The source code for several perfetto binaries lives in the `external/perfetto` +project in the AOSP source tree. These binaries enable unbundled perfetto +tracing, and on-device trace processing. -## Building stripped binaries - -Check out the detailed build instructions [here](https://perfetto.dev/docs/contributing/build-instructions). +To set up the perfetto repository for the first time: ```bash -tools/gn args out/<out_folder> - -# Use the following config -target_os = "android" -target_cpu = "arm" / "arm64" / "x64" # Depending on the platform -is_debug = false -monolithic_binaries = true +git clone https://android.googlesource.com/platform/external/perfetto/ perfetto_repo +perfetto_repo/tools/install-build-deps --android +``` -# Finally build the binaries -tools/ninja -C out/<out_folder> +To build stripped binaries from the local repository: -# Strip Binaries -# You should have downloaded the NDK -# ndk_versio = 22.1.7171670 -/path/to/sdk/ndk/<ndk_version>/toolchains/llvm/prebuilt/<platform/paths>/bin/strip <binary_name> +```bash +./generate_perfetto_binaries.py ``` + +This script automates some of the build instructions documented +[here](https://perfetto.dev/docs/contributing/build-instructions). + +Some important things handled are: + - binary stripping (drastically reduces binary size) + - sets `monolithic_binaries = true` (important for unbundled usage) + - handles all architectures supported by macrobenchmark diff --git a/generate_perfetto_binaries.py b/generate_perfetto_binaries.py new file mode 100755 index 0000000..85c853b --- /dev/null +++ b/generate_perfetto_binaries.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import os +import platform +import subprocess +import sys + +from shlex import quote +from shutil import copyfile + +# NOTE - this script is adapted from perfetto/tools/build_all_binaries.py +# If this stops working, check there (e.g. for arg renames) + +ANDROID_ARGS = ('target_os="android"', 'monolithic_binaries=true', 'is_debug=false') + +ANDROID_BUILD_TARGETS = ('traced', 'traced_probes', 'perfetto', 'trace_processor_shell') + +# List of each arch, with a tuple of: +# - perfetto-name (arg in perfetto build) +# - android-tag (used in final output path, used for binary disambig at apk build time) +# - associated ndk subdir for stripping (This includes a %s for host OS) +ARCH_LIST = ( + ('arm', 'arm', 'arm-%s-androideabi'), + ('arm64', 'aarch64', 'aarch64-%s-android'), + ('x64', 'x86_64', 'x86_64-%s-android'), +) + +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--perfetto_checkout_path', help='Path to perfetto checkout', default = 'perfetto_repo') + args = parser.parse_args() + + perfetto_dir = os.path.abspath(args.perfetto_checkout_path) + + out_base_dir = os.path.join(perfetto_dir, 'out') + if not os.path.isdir(out_base_dir): + os.mkdir(out_base_dir) + + gn = os.path.join(perfetto_dir, 'tools', 'gn') + + for arch, arch_tag, ndk_dir_pattern in ARCH_LIST: #ARCH_TABLE.items(): + config_name ='android_%s' % (arch) + gn_args = ANDROID_ARGS + ('target_cpu="%s"' % arch,) + + print('\n\033[32mConfiguring %-20s[%s]\033[0m' % (config_name, ','.join(gn_args))) + out_dir = os.path.join(perfetto_dir, 'out', config_name) + if not os.path.isdir(out_dir): + os.mkdir(out_dir) + gn_cmd = (gn, 'gen', out_dir, '--args=%s' % (' '.join(gn_args)), '--check') + print(' '.join(quote(c) for c in gn_cmd)) + subprocess.check_call(gn_cmd, cwd=perfetto_dir) + + print('\n\033[32mBuilding %-20s[%s]\033[0m' % (config_name, ','.join(ANDROID_BUILD_TARGETS))) + ninja = os.path.join(perfetto_dir, 'tools', 'ninja') + ninja_cmd = (ninja, '-C', '.') + ANDROID_BUILD_TARGETS + subprocess.check_call(ninja_cmd, cwd=out_dir) + + print('\n\033[32mCopying + Stripping %s binaries\033[0m' % (config_name)) + for target in ANDROID_BUILD_TARGETS: + out_file = os.path.join(ROOT_DIR, target, target + "_" + arch_tag) + + # copy out of perfetto out dir + copyfile(os.path.join(out_dir, target), out_file) + + # strip it using ndk from perfetto checkout + strip_path = os.path.join( + perfetto_dir, + "buildtools", + "ndk", + "toolchains", + "llvm", + "prebuilt", + "linux-x86_64", + ndk_dir_pattern % ("linux"), # TODO: support macos + "bin", + "strip") + subprocess.check_call((strip_path, out_file)) + +if __name__ == '__main__': + sys.exit(main()) |