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 | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 8 | # |
| 9 | # Copyright (C) 2014-2015, Arm Limited, All Rights Reserved |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 10 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 11 | # |
| 12 | # This file is provided under the Apache License 2.0, or the |
| 13 | # GNU General Public License v2.0 or later. |
| 14 | # |
| 15 | # ********** |
| 16 | # Apache License 2.0: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 17 | # |
| 18 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 19 | # not use this file except in compliance with the License. |
| 20 | # You may obtain a copy of the License at |
| 21 | # |
| 22 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 23 | # |
| 24 | # Unless required by applicable law or agreed to in writing, software |
| 25 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 26 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 27 | # See the License for the specific language governing permissions and |
| 28 | # limitations under the License. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 29 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 30 | # ********** |
| 31 | # |
| 32 | # ********** |
| 33 | # GNU General Public License v2.0 or later: |
| 34 | # |
| 35 | # This program is free software; you can redistribute it and/or modify |
| 36 | # it under the terms of the GNU General Public License as published by |
| 37 | # the Free Software Foundation; either version 2 of the License, or |
| 38 | # (at your option) any later version. |
| 39 | # |
| 40 | # This program is distributed in the hope that it will be useful, |
| 41 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 | # GNU General Public License for more details. |
| 44 | # |
| 45 | # You should have received a copy of the GNU General Public License along |
| 46 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 47 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 48 | # |
| 49 | # ********** |
| 50 | # |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 51 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 52 | |
| 53 | set -eu |
| 54 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 55 | CONFIG_H='include/mbedtls/config.h' |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 56 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 57 | CLIENT='mini_client' |
| 58 | |
Manuel Pégourié-Gonnard | 47e0214 | 2015-03-18 16:52:20 +0000 | [diff] [blame] | 59 | 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] | 60 | CFLAGS_MEM=-g3 |
| 61 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 62 | if [ -r $CONFIG_H ]; then :; else |
| 63 | echo "$CONFIG_H not found" >&2 |
| 64 | exit 1 |
| 65 | fi |
| 66 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 67 | if grep -i cmake Makefile >/dev/null; then |
| 68 | echo "Not compatible with CMake" >&2 |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
Manuel Pégourié-Gonnard | 4a7ed71 | 2015-03-11 10:26:50 +0000 | [diff] [blame] | 72 | if [ $( uname ) != Linux ]; then |
| 73 | echo "Only work on Linux" >&2 |
| 74 | exit 1 |
| 75 | fi |
| 76 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 77 | if git status | grep -F $CONFIG_H >/dev/null 2>&1; then |
| 78 | echo "config.h not clean" >&2 |
| 79 | exit 1 |
| 80 | fi |
| 81 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 82 | # make measurements with one configuration |
| 83 | # usage: do_config <name> <unset-list> <server-args> |
| 84 | do_config() |
| 85 | { |
| 86 | NAME=$1 |
| 87 | UNSET_LIST=$2 |
| 88 | SERVER_ARGS=$3 |
| 89 | |
| 90 | echo "" |
| 91 | echo "config-$NAME:" |
| 92 | cp configs/config-$NAME.h $CONFIG_H |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | scripts/config.pl unset MBEDTLS_SSL_SRV_C |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 94 | |
| 95 | for FLAG in $UNSET_LIST; do |
| 96 | scripts/config.pl unset $FLAG |
| 97 | done |
| 98 | |
Manuel Pégourié-Gonnard | a6b95f0 | 2015-09-09 13:47:28 +0200 | [diff] [blame] | 99 | grep -F SSL_MAX_CONTENT_LEN $CONFIG_H || echo 'SSL_MAX_CONTENT_LEN=16384' |
| 100 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 101 | printf " Executable size... " |
| 102 | |
| 103 | make clean |
| 104 | CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os lib >/dev/null 2>&1 |
| 105 | cd programs |
| 106 | CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os ssl/$CLIENT >/dev/null |
| 107 | strip ssl/$CLIENT |
Manuel Pégourié-Gonnard | 4a7ed71 | 2015-03-11 10:26:50 +0000 | [diff] [blame] | 108 | stat -c '%s' ssl/$CLIENT |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 109 | cd .. |
| 110 | |
| 111 | printf " Peak ram usage... " |
| 112 | |
| 113 | make clean |
| 114 | CFLAGS=$CFLAGS_MEM make OFLAGS=-Os lib >/dev/null 2>&1 |
| 115 | cd programs |
| 116 | CFLAGS=$CFLAGS_MEM make OFLAGS=-Os ssl/$CLIENT >/dev/null |
| 117 | cd .. |
| 118 | |
| 119 | ./ssl_server2 $SERVER_ARGS >/dev/null & |
| 120 | SRV_PID=$! |
| 121 | sleep 1; |
| 122 | |
| 123 | if valgrind --tool=massif --stacks=yes programs/ssl/$CLIENT >/dev/null 2>&1 |
| 124 | then |
| 125 | FAILED=0 |
| 126 | else |
| 127 | echo "client failed" >&2 |
| 128 | FAILED=1 |
| 129 | fi |
| 130 | |
| 131 | kill $SRV_PID |
| 132 | wait $SRV_PID |
| 133 | |
| 134 | scripts/massif_max.pl massif.out.* |
| 135 | mv massif.out.* massif-$NAME.$$ |
| 136 | } |
| 137 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 138 | # preparation |
| 139 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 140 | CONFIG_BAK=${CONFIG_H}.bak |
| 141 | cp $CONFIG_H $CONFIG_BAK |
| 142 | |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 143 | rm -f massif.out.* |
| 144 | |
| 145 | printf "building server... " |
| 146 | |
| 147 | make clean |
| 148 | make lib >/dev/null 2>&1 |
| 149 | (cd programs && make ssl/ssl_server2) >/dev/null |
| 150 | cp programs/ssl/ssl_server2 . |
| 151 | |
| 152 | echo "done" |
| 153 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 154 | # actual measurements |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 155 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 156 | do_config "ccm-psk-tls1_2" \ |
| 157 | "" \ |
| 158 | "psk=000102030405060708090A0B0C0D0E0F" |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 159 | |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 160 | do_config "suite-b" \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 161 | "MBEDTLS_BASE64_C MBEDTLS_PEM_PARSE_C MBEDTLS_CERTS_C" \ |
Manuel Pégourié-Gonnard | c5b849b | 2014-12-01 12:15:47 +0100 | [diff] [blame] | 162 | "" |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 163 | |
| 164 | # cleanup |
| 165 | |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 166 | mv $CONFIG_BAK $CONFIG_H |
Manuel Pégourié-Gonnard | f166c54 | 2014-12-01 11:30:56 +0100 | [diff] [blame] | 167 | make clean |
| 168 | rm ssl_server2 |
Manuel Pégourié-Gonnard | 4d5cc11 | 2014-11-25 12:21:48 +0100 | [diff] [blame] | 169 | |
| 170 | exit $FAILED |