kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/serving/tools/testdata/debug_serving.sh (about)

     1  #!/bin/bash -e
     2  set -o pipefail
     3  # Copyright 2016 The Kythe Authors. All rights reserved.
     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  # debug_serving.sh splits Kythe LevelDB serving data into separate JSON files
    18  # per table section (e.g. decor, edgeSets, edgePages, etc.).
    19  #
    20  # Usage: debug_serving.sh <path-to-leveldb>
    21  
    22  TABLE="$1"
    23  
    24  if [[ ! -d "$TABLE" ]]; then
    25    echo "ERROR: unable to read serving data at \"$TABLE\"" >&2
    26    exit 1
    27  fi
    28  
    29  scan_leveldb=kythe/go/util/tools/scan_leveldb/scan_leveldb
    30  jq=external/com_github_stedolan_jq/jq
    31  
    32  if [[ ! -x "$scan_leveldb" || -d "$scan_leveldb" ]]; then
    33    scan_leveldb="$(which scan_leveldb)"
    34  fi
    35  if [[ ! -x "$jq" || -d "$jq" ]]; then
    36    jq="$(which jq)"
    37  fi
    38  
    39  scan() {
    40    local out="$TABLE.${1%:}.json"
    41    echo -n "$out: " >&2
    42    "$scan_leveldb" --prefix $1 --proto_value $2 --json "$TABLE" | \
    43      tee >(wc -l >&2) | \
    44      "$jq" -S . > "$out"
    45  }
    46  
    47  scan edgeSets:  kythe.proto.serving.PagedEdgeSet
    48  scan edgePages: kythe.proto.serving.EdgePage
    49  scan xrefs:     kythe.proto.serving.PagedCrossReferences
    50  scan xrefPages: kythe.proto.serving.PagedCrossReferences.Page
    51  scan decor:     kythe.proto.serving.FileDecorations