| #!/bin/bash |
| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| #### CATEGORY=Build |
| ### Collect Ninja trace information for analysis in chrome://tracing |
| |
| ## Usage: fx ninjatrace2json |
| ## |
| ## Use this after a build to write "ninjatrace.json" in the build directory. |
| ## |
| ## See //build/scripts/ninjatrace2json.py for more usage information. |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-config-read |
| |
| # Collect any system profiles from `fx build-profile`. |
| # See implementation in tools/devshell/lib/vars.sh inside fx-run-ninja(). |
| readonly BUILD_LOG_DIR="$(fx-get-last-build-log-dir)" |
| readonly BUILD_PROFILE_DIR="${BUILD_LOG_DIR}/build_profile" |
| |
| command=("${PREBUILT_PYTHON3}" |
| "$FUCHSIA_DIR/build/scripts/ninjatrace2json.py" |
| "--fuchsia-build-dir" "$FUCHSIA_BUILD_DIR" |
| "--ninja-path" "$PREBUILT_NINJA" |
| "--ninjatrace-path" "$PREBUILT_NINJATRACE" |
| "--subbuilds-in-place" ) |
| |
| # If there exists at least one vmstat log, copy it. |
| readonly recent_vmstat_profile="${BUILD_PROFILE_DIR}/vmstat.log" |
| if [[ -f "${recent_vmstat_profile}" ]]; then |
| readonly recent_vmstat_profile_json="${recent_vmstat_profile}.json" |
| if [[ -f "$recent_vmstat_profile_json" ]]; then |
| command+=("--vmstat-profile" "$recent_vmstat_profile_json") |
| fi |
| fi |
| |
| # If there exists at least one ifconfig log, copy it. |
| readonly recent_ifconfig_profile="${BUILD_PROFILE_DIR}/ifconfig.log" |
| if [[ -f "${recent_ifconfig_profile}" ]]; then |
| readonly recent_ifconfig_profile_json="${recent_ifconfig_profile}.json" |
| if [[ -f "$recent_ifconfig_profile_json" ]]; then |
| command+=("--ifconfig-profile" "$recent_ifconfig_profile_json") |
| fi |
| fi |
| |
| exec "${command[@]}" "$@" |