| #!/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" and |
| ## "ninjatrace_critical_path.json" files in the build directories (separately |
| ## for Zircon and Fuchsia build directories). Then use the chrome://tracing view |
| ## to load that file into your browser. |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-config-read |
| |
| TMP_DIR="$(mktemp -d)" |
| readonly TMP_DIR |
| trap 'rm -rf "${TMP_DIR}"' EXIT |
| |
| artifacts_dir="$(mktemp -d -p ${TMP_DIR})" |
| "${PREBUILT_NINJA}" -C "${FUCHSIA_BUILD_DIR}" -t compdb > "${artifacts_dir}/compdb.json" |
| "${PREBUILT_NINJA}" -C "${FUCHSIA_BUILD_DIR}" -t graph > "${artifacts_dir}/graph.dot" |
| |
| "${HOST_OUT_DIR}/ninjatrace" \ |
| -ninjalog "${FUCHSIA_BUILD_DIR}/.ninja_log" \ |
| -compdb "${artifacts_dir}/compdb.json" \ |
| -graph "${artifacts_dir}/graph.dot" \ |
| -trace-json "${FUCHSIA_BUILD_DIR}/ninjatrace.json" \ |
| -critical-path |
| echo "Now visit chrome://tracing and load ${FUCHSIA_BUILD_DIR}/ninjatrace.json" |