| #!/bin/bash |
| # Copyright 2018 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. |
| |
| ### generate a report with component exposed data |
| |
| ## usage: fx debug-report [f|--format <FORMAT>] |
| ## [-s|--system-objects] |
| ## [--] [<REGEX> [...<REGEX>]] |
| ## |
| ## Runs and generate a debug report from the selected components. |
| ## |
| ## -f|--format <FORMAT> What formatter to be used for the output. |
| ## These will be passed on to the underlying iquery |
| ## tool. Supported values: |
| ## - text: Human readable output. [DEFAULT] |
| ## - json: Simple to parse JSON format. |
| ## -s|--system-objects Whether to include the system generated debug |
| ## information. This is information includes current |
| ## register and stack traces for all threads. |
| ## False by default. |
| ## |
| ## REGEX Basic Regular Expression (as understood by GNU grep) to filter |
| ## out components. Only matching components will be included in the |
| ## report. |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| |
| # Defaults. |
| system_objects=false |
| formatter="" |
| |
| # Flag parsing. |
| while [[ "$1" =~ ^- ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| -f|--format) |
| shift |
| formatter="$1" |
| ;; |
| -s|--system-objects) |
| system_objects=true |
| ;; |
| --) |
| break |
| ;; |
| *) |
| break |
| esac |
| shift |
| done |
| |
| # Post-flag processing. |
| format="--format=${formatter}" |
| host="$(get-fuchsia-device-addr)" |
| regexps="$@" |
| find_target="/hub" |
| |
| # Find all the available services. |
| find="$(fx-command-exec "ssh" "${host}" "iquery --find ${find_target}")" |
| |
| # Check if we want the system objects |
| if [[ "${system_objects}" = "false" ]]; then |
| find="$(echo "${find}" | grep -v "system_objects$")" |
| fi |
| |
| # Join al given regexp into a format grep can consume. |
| if [[ ! -z ${regexps} ]]; then |
| filters="" |
| for regex in ${regexps}; do |
| filters="$(echo "${filters} -e ${regex}")" |
| done |
| find="$(echo "${find}" | grep ${filters})" |
| fi |
| |
| # Flatten to the format iquery expects. |
| flatten="$(echo "${find}" | tr '\n' ' ')" |
| |
| fx-command-exec "ssh" "${host}" "iquery --absolute_paths --cat ${format} --recursive ${flatten}" |