blob: 2fb8a21ca962627712ad72a5a18146e761ef55e3 [file] [log] [blame]
Sam Leffler19347f42022-09-13 00:42:47 +00001#! /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)
Sam Leffler19347f42022-09-13 00:42:47 +000028#
Sam Leffler315cedb2023-05-22 10:35:58 -070029# Note mmio sections do not count against memory usage as they are
30# allocated from dedicated memory that does not have physical
Sam Leffler19347f42022-09-13 00:42:47 +000031# memory backing.
32#
Sam Leffler19347f42022-09-13 00:42:47 +000033# ROOTDIR must be set to the top of the shodan development tree
34# (as done by build/setup.sh).
35
36# Usage: kmem [-d]
37
38if [[ -z "${ROOTDIR}" ]]; then
39 echo "Source build/setup.sh first"
40 exit 1
41fi
42
Sam Lefflere6be9322023-07-28 16:37:25 -070043# NB: should always be set but default anyway
44PLATFORM=${PLATFORM:-shodan}
Sam Leffler19347f42022-09-13 00:42:47 +000045
46# Default is a summary of release build.
Julian Mullings-Black68cf2ae2023-01-11 21:36:26 +000047DETAILS=""
Sam Leffler19347f42022-09-13 00:42:47 +000048BUILD="release"
Sam Leffler315cedb2023-05-22 10:35:58 -070049KERNEL="--kernel"
50VERBOSE=""
Sam Leffler19347f42022-09-13 00:42:47 +000051
52function parseargv {
Sam Leffler315cedb2023-05-22 10:35:58 -070053 local usage="Usage: kmem.sh [-h|--help] [-d|--details] [-D|--debug] [-R|--release] [-s|--summary] [-u|--user] [-v|--verbose]"
54 local args=$(getopt -o dDRsuv --long details,debug,release,summary,user,verbose,help -n kmem.sh -- "$@")
Sam Leffler19347f42022-09-13 00:42:47 +000055
56 set -- $args
57
58 for i; do
59 case "$1" in
60 -d|--details)
Julian Mullings-Black68cf2ae2023-01-11 21:36:26 +000061 DETAILS="--details"
Sam Leffler19347f42022-09-13 00:42:47 +000062 shift
63 ;;
64
65 -s|--summary)
Julian Mullings-Black68cf2ae2023-01-11 21:36:26 +000066 DETAILS=""
Sam Leffler19347f42022-09-13 00:42:47 +000067 shift
68 ;;
69
70 -D|--debug)
Sam Leffler56293372022-12-16 12:49:18 -080071 BUILD="debug"
Sam Leffler19347f42022-09-13 00:42:47 +000072 shift
73 ;;
74
75 -R|--release)
76 BUILD="release"
77 shift
78 ;;
79
Sam Leffler315cedb2023-05-22 10:35:58 -070080 -u|--user)
81 KERNEL=""
82 shift
83 ;;
84
85 -v|--verbose)
86 VERBOSE="--verbose"
87 shift
88 ;;
89
Sam Leffler19347f42022-09-13 00:42:47 +000090 --)
91 shift
92 break
93 ;;
94
95 -h|--help|*)
96 echo "$usage" >/dev/stderr
97 exit 1
98 ;;
99 esac
100 done
101}
102
103parseargv "$@"
104
Sam Lefflere6be9322023-07-28 16:37:25 -0700105CANTRIP_OUT="${ROOTDIR}/out/cantrip/${PLATFORM}/${BUILD}"
Sam Leffler996c8dc2023-11-22 14:28:12 -0800106PYTHONPATH=${PYTHON_SHODAN_ENV}/lib/python3.11/site-packages/:${PYTHONPATH}
Julian Mullings-Black68cf2ae2023-01-11 21:36:26 +0000107PYTHONPATH="${PYTHONPATH}:${ROOTDIR}/cantrip/projects/capdl/python-capdl-tool"
Sam Leffler315cedb2023-05-22 10:35:58 -0700108exec python3 "${ROOTDIR}/cantrip/tools/seL4/kmem-tool/kmem.py" --object-state "${CANTRIP_OUT}/object-final.pickle" ${DETAILS} ${KERNEL} ${VERBOSE}