blob: afd8863ac3b606e30b5056bebe32e621a6f44adb [file] [log] [blame]
#!/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
"${PREBUILT_NINJA}" -C "${FUCHSIA_BUILD_DIR}" -t compdb > "${TMP_DIR}/compdb.json"
"${PREBUILT_NINJA}" -C "${FUCHSIA_BUILD_DIR}" -t graph > "${TMP_DIR}/graph.dot"
"${HOST_OUT_DIR}/ninjatrace" \
-ninjalog "${FUCHSIA_BUILD_DIR}/.ninja_log" \
-compdb "${TMP_DIR}/compdb.json" \
-graph "${TMP_DIR}/graph.dot" \
-trace-json "${FUCHSIA_BUILD_DIR}/ninjatrace.json" \
-critical-path
echo "Now visit chrome://tracing and load ${FUCHSIA_BUILD_DIR}/ninjatrace.json"