|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +# Copyright 2018- The Pixie Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# SPDX-License-Identifier: Apache-2.0 |
| 18 | + |
| 19 | +usage() { |
| 20 | + echo "This script downloads all of the files listed in the mappings section of a heap profile." |
| 21 | + echo "" |
| 22 | + echo "Usage: $0 <heap_profile_dir> <vizier_cluster_id> [<gcloud ssh opts>...]" |
| 23 | + echo "<heap_profile_dir> : the directory where the heap profile and memory mapped files will be stored. It will be created if it does not exist." |
| 24 | + echo "<vizier_cluster_id> : the ID of the Vizier cluster to connect to." |
| 25 | + echo "Common gcloud ssh options include --project." |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +heap_profile_dir="$1" |
| 30 | +cluster_id="$2" |
| 31 | +script_dir=$(dirname "$(realpath "$0")") |
| 32 | +repo_root=$(git rev-parse --show-toplevel) |
| 33 | + |
| 34 | +if [ -z "$heap_profile_dir" ] || [ -z "$cluster_id" ]; then |
| 35 | + usage |
| 36 | +fi |
| 37 | + |
| 38 | +mkdir -p "$heap_profile_dir" |
| 39 | + |
| 40 | +pxl_heap_output_file="${heap_profile_dir}/raw_output_from_hot_table_test.json" |
| 41 | + |
| 42 | +px run -o json -c "$cluster_id" -f "${repo_root}/src/pxl_scripts/px/collect_heap_dumps.pxl" > "$pxl_heap_output_file" |
| 43 | + |
| 44 | +while IFS= read -r line; do |
| 45 | + hostname=$(echo "$line" | jq -r '.hostname') |
| 46 | + heap_content=$(echo "$line" | jq -r '.heap') |
| 47 | + echo "$heap_content" > "${heap_profile_dir}/${hostname}.txt" |
| 48 | + echo "Wrote ${heap_profile_dir}/${hostname}.txt" |
| 49 | +done < "$pxl_heap_output_file" |
| 50 | + |
| 51 | +nodes=() |
| 52 | +for file in "${heap_profile_dir}"/*.txt; do |
| 53 | + hostname=$(basename "${file%.*}") |
| 54 | + nodes+=("$hostname") |
| 55 | + hostname_dir="${heap_profile_dir}/${hostname}" |
| 56 | + mkdir -p "$hostname_dir" |
| 57 | +done |
| 58 | + |
| 59 | +for node in "${nodes[@]}"; do |
| 60 | + "${script_dir}/download_heap_prof_mapped_files.sh" "${heap_profile_dir}/${node}.txt" "$node" "${@:3}" |
| 61 | +done |
0 commit comments