Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Measure memory usage of a minimal client using a small configuration |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 4 | # Currently hardwired to ccm-psk and suite-b, may be expanded later |
| 5 | # |
| 6 | # Use different build options for measuring executable size and memory usage, |
| 7 | # since for memory we want debug information. |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 8 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 9 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 10 | # SPDX-License-Identifier: Apache-2.0 |
| 11 | # |
| 12 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | # not use this file except in compliance with the License. |
| 14 | # You may obtain a copy of the License at |
| 15 | # |
| 16 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | # |
| 18 | # Unless required by applicable law or agreed to in writing, software |
| 19 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | # See the License for the specific language governing permissions and |
| 22 | # limitations under the License. |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 23 | |
| 24 | set -eu |
| 25 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 26 | CONFIG_H='include/mbedtls/config.h' |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 27 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 28 | CLIENT='mini_client' |
| 29 | |
Manuel Pégourié-Gonnard | 47e0214 | 2015-03-18 16:52:20 +0000 | [diff] [blame] | 30 | CFLAGS_EXEC='-fno-asynchronous-unwind-tables -Wl,--gc-section -ffunction-sections -fdata-sections' |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 31 | CFLAGS_MEM=-g3 |
| 32 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 33 | if [ -r $CONFIG_H ]; then :; else |
| 34 | echo "$CONFIG_H not found" >&2 |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 38 | if grep -i cmake Makefile >/dev/null; then |
| 39 | echo "Not compatible with CMake" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
Manuel Pégourié-Gonnard | 4a7ed71 | 2015-03-11 10:26:50 +0000 | [diff] [blame] | 43 | if [ $( uname ) != Linux ]; then |
| 44 | echo "Only work on Linux" >&2 |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 48 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then |
| 49 | echo "config.h not clean" >&2 |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 53 | # make measurements with one configuration |
| 54 | # usage: do_config <name> <unset-list> <server-args> |
| 55 | do_config() |
| 56 | { |
| 57 | NAME=$1 |
| 58 | UNSET_LIST=$2 |
| 59 | SERVER_ARGS=$3 |
| 60 | |
| 61 | echo "" |
| 62 | echo "config-$NAME:" |
| 63 | cp configs/config-$NAME.h $CONFIG_H |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 64 | scripts/config.py unset MBEDTLS_SSL_SRV_C |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 65 | |
| 66 | for FLAG in $UNSET_LIST; do |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 67 | scripts/config.py unset $FLAG |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 68 | done |
| 69 | |
Manuel Pégourié-Gonnard | a6b95f0 | 2015-09-09 13:47:28 +0200 | [diff] [blame] | 70 | grep -F SSL_MAX_CONTENT_LEN $CONFIG_H || echo 'SSL_MAX_CONTENT_LEN=16384' |
| 71 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 72 | printf " Executable size... " |
| 73 | |
| 74 | make clean |
| 75 | CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os lib >/dev/null 2>&1 |
| 76 | cd programs |
| 77 | CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os ssl/$CLIENT >/dev/null |
| 78 | strip ssl/$CLIENT |
Manuel Pégourié-Gonnard | 4a7ed71 | 2015-03-11 10:26:50 +0000 | [diff] [blame] | 79 | stat -c '%s' ssl/$CLIENT |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 80 | cd .. |
| 81 | |
| 82 | printf " Peak ram usage... " |
| 83 | |
| 84 | make clean |
| 85 | CFLAGS=$CFLAGS_MEM make OFLAGS=-Os lib >/dev/null 2>&1 |
| 86 | cd programs |
| 87 | CFLAGS=$CFLAGS_MEM make OFLAGS=-Os ssl/$CLIENT >/dev/null |
| 88 | cd .. |
| 89 | |
| 90 | ./ssl_server2 $SERVER_ARGS >/dev/null & |
| 91 | SRV_PID=$! |
| 92 | sleep 1; |
| 93 | |
| 94 | if valgrind --tool=massif --stacks=yes programs/ssl/$CLIENT >/dev/null 2>&1 |
| 95 | then |
| 96 | FAILED=0 |
| 97 | else |
| 98 | echo "client failed" >&2 |
| 99 | FAILED=1 |
| 100 | fi |
| 101 | |
| 102 | kill $SRV_PID |
| 103 | wait $SRV_PID |
| 104 | |
| 105 | scripts/massif_max.pl massif.out.* |
| 106 | mv massif.out.* massif-$NAME.$$ |
| 107 | } |
| 108 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 109 | # preparation |
| 110 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 111 | CONFIG_BAK=${CONFIG_H}.bak |
| 112 | cp $CONFIG_H $CONFIG_BAK |
| 113 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 114 | rm -f massif.out.* |
| 115 | |
| 116 | printf "building server... " |
| 117 | |
| 118 | make clean |
| 119 | make lib >/dev/null 2>&1 |
| 120 | (cd programs && make ssl/ssl_server2) >/dev/null |
| 121 | cp programs/ssl/ssl_server2 . |
| 122 | |
| 123 | echo "done" |
| 124 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 125 | # actual measurements |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 126 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 127 | do_config "ccm-psk-tls1_2" \ |
| 128 | "" \ |
| 129 | "psk=000102030405060708090A0B0C0D0E0F" |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 130 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 131 | do_config "suite-b" \ |
Mateusz Starzyk | 1aec646 | 2021-02-08 15:34:42 +0100 | [diff] [blame] | 132 | "MBEDTLS_BASE64_C MBEDTLS_PEM_PARSE_C" \ |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 133 | "" |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 134 | |
| 135 | # cleanup |
| 136 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 137 | mv $CONFIG_BAK $CONFIG_H |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 138 | make clean |
| 139 | rm ssl_server2 |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 140 | |
| 141 | exit $FAILED |