Sam Leffler | 19347f4 | 2022-09-13 00:42:47 +0000 | [diff] [blame^] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # Copyright 2022 Google LLC |
| 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 | # https://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 | # CAmkES system image memory analyzer. |
| 18 | |
| 19 | # Analyze the CAmkES-generated capDL spec for memory use. |
| 20 | # By default the memory foottprint of each component is displayed. |
| 21 | # The -d option will give a breakdown by memory type: |
| 22 | # elf .text + .data |
| 23 | # bss .bss |
| 24 | # ipc_buffer CAmkES per-thread ipc_buffer's |
| 25 | # stack CAmkES per-thread stack |
| 26 | # bootinfo Bootinfo page passed by the rooteserver |
| 27 | # mmio MMIO region (backed by devivce memory) |
| 28 | # copyregion VSpace region (w/o backing memory) |
| 29 | # |
| 30 | # Note mmio + copyregion sections do not count against memory usage as |
| 31 | # they are allocated from dedicated memory that does not have physical |
| 32 | # memory backing. |
| 33 | # |
| 34 | # TODO: account for system resources |
| 35 | # |
| 36 | # ROOTDIR must be set to the top of the shodan development tree |
| 37 | # (as done by build/setup.sh). |
| 38 | |
| 39 | # Usage: kmem [-d] |
| 40 | |
| 41 | if [[ -z "${ROOTDIR}" ]]; then |
| 42 | echo "Source build/setup.sh first" |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | TARGET=${TARGET:-riscv32-unknown-elf} |
| 47 | |
| 48 | # Default is a summary of release build. |
| 49 | DETAILS="0" |
| 50 | BUILD="release" |
| 51 | |
| 52 | function parseargv { |
| 53 | local usage="Usage: kmem.sh [-h|--help] [-d|--details] [-D|--debug] [-R|--release] [-s|--summary]" |
| 54 | local args=$(getopt -o dDRs --long details,debug,release,summary,help -n kmem.sh -- "$@") |
| 55 | |
| 56 | set -- $args |
| 57 | |
| 58 | for i; do |
| 59 | case "$1" in |
| 60 | -d|--details) |
| 61 | DETAILS="1" |
| 62 | shift |
| 63 | ;; |
| 64 | |
| 65 | -s|--summary) |
| 66 | DETAILS="0" |
| 67 | shift |
| 68 | ;; |
| 69 | |
| 70 | -D|--debug) |
| 71 | BUILD="wdebug" |
| 72 | shift |
| 73 | ;; |
| 74 | |
| 75 | -R|--release) |
| 76 | BUILD="release" |
| 77 | shift |
| 78 | ;; |
| 79 | |
| 80 | --) |
| 81 | shift |
| 82 | break |
| 83 | ;; |
| 84 | |
| 85 | -h|--help|*) |
| 86 | echo "$usage" >/dev/stderr |
| 87 | exit 1 |
| 88 | ;; |
| 89 | esac |
| 90 | done |
| 91 | } |
| 92 | |
| 93 | parseargv "$@" |
| 94 | |
| 95 | KATA_OUT="${ROOTDIR}/out/kata/${TARGET}/${BUILD}" |
| 96 | exec awk -f "${ROOTDIR}/scripts/mem.awk" "${KATA_OUT}/system.cdl" DETAILS="${DETAILS}" |