| #!/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=Run, inspect and debug | |
| ### generate a report with component exposed data | |
| ## usage: fx iquery [f|--format <FORMAT>] | |
| ## [-s|--system-objects] | |
| ## [--] [<REGEX> [...<REGEX>]] | |
| ## | |
| ## Runs and generate a 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. | |
| ## -d|--display Whether to trigger display mode. | |
| ## When display mode is set for text output, node | |
| ## names only include the full path for the root | |
| ## of the hierarchy. | |
| ## | |
| ## 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="" | |
| display=0 | |
| # 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 | |
| ;; | |
| -d|--display) | |
| display=1 | |
| ;; | |
| --) | |
| break | |
| ;; | |
| *) | |
| break | |
| esac | |
| shift | |
| done | |
| # Post-flag processing. | |
| if [ -z "${formatter}" ]; then | |
| formatter="text" | |
| fi | |
| 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 all 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 | |
| paths="--absolute_paths" | |
| if [[ ${display} -ne 0 ]]; then | |
| paths="--display_paths" | |
| fi | |
| # Flatten to the format iquery expects. | |
| flatten="$(echo "${find}" | tr '\n' ' ')" | |
| fx-command-exec "ssh" "${host}" "iquery ${paths} --cat ${format} --recursive ${flatten}" |