]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/memusage.sh
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / malloc / memusage.sh
CommitLineData
43fc8f18 1#! @BASH@
688903eb 2# Copyright (C) 1999-2018 Free Software Foundation, Inc.
43fc8f18
UD
3# This file is part of the GNU C Library.
4# Contributed by Ulrich Drepper <drepper@gnu.org>, 1999.
5
6# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
43fc8f18
UD
10
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14# Lesser General Public License for more details.
43fc8f18 15
41bdb6e2 16# You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17# License along with the GNU C Library; if not, see
18# <http://www.gnu.org/licenses/>.
43fc8f18 19
f50fa10c
UD
20memusageso='@SLIBDIR@/libmemusage.so'
21memusagestat='@BINDIR@/memusagestat'
8e597a18 22TEXTDOMAIN=libc
43fc8f18
UD
23
24# Print usage message.
25do_usage() {
5c0b8d90 26 printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
43fc8f18
UD
27 exit 1
28}
29
479620b9
UD
30# Message for missing argument.
31do_missing_arg() {
de81b246 32 printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1"
479620b9
UD
33 do_usage
34}
35
36# Print help message
43fc8f18 37do_help() {
ba80a015 38 echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
926de5eb
UD
39Profile memory usage of PROGRAM.
40
479620b9
UD
41 -n,--progname=NAME Name of the program file to profile
42 -p,--png=FILE Generate PNG graphic and store it in FILE
43 -d,--data=FILE Generate binary data file and store it in FILE
44 -u,--unbuffered Don't buffer output
45 -b,--buffer=SIZE Collect SIZE entries before writing them out
11bf311e 46 --no-timer Don't collect additional information through timer
94eb5b36 47 -m,--mmap Also trace mmap & friends
479620b9
UD
48
49 -?,--help Print this help and exit
50 --usage Give a short usage message
51 -V,--version Print version information and exit
52
53 The following options only apply when generating graphical output:
54 -t,--time-based Make graph linear in time
55 -T,--total Also draw graph of total memory use
56 --title=STRING Use STRING as title of the graph
57 -x,--x-size=SIZE Make graphic SIZE pixels wide
58 -y,--y-size=SIZE Make graphic SIZE pixels high
59
60Mandatory arguments to long options are also mandatory for any corresponding
61short options.
62
cbbcaf23 63"
8b748aed
JM
64 printf $"For bug reporting instructions, please see:\\n%s.\\n" \
65 "@REPORT_BUGS_TO@"
43fc8f18
UD
66 exit 0
67}
68
69do_version() {
8b748aed 70 echo 'memusage @PKGVERSION@@VERSION@'
8e597a18 71 printf $"Copyright (C) %s Free Software Foundation, Inc.
43fc8f18
UD
72This is free software; see the source for copying conditions. There is NO
73warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
58b587c1 74" "2017"
8e597a18
UD
75 printf $"Written by %s.
76" "Ulrich Drepper"
43fc8f18
UD
77 exit 0
78}
79
07fb5185
UD
80# These variables are local
81buffer=
82data=
83memusagestat_args=
84notimer=
85png=
86progname=
87tracemmap=
88
43fc8f18
UD
89# Process arguments. But stop as soon as the program name is found.
90while test $# -gt 0; do
91 case "$1" in
479620b9 92 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
43fc8f18
UD
93 do_version
94 ;;
479620b9 95 -\? | --h | --he | --hel | --help)
43fc8f18
UD
96 do_help
97 ;;
479620b9 98 --us | --usa | --usag | --usage)
ba80a015 99 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
561470e0
UD
100 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
101 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
102 PROGRAM [PROGRAMOPTION]..."
479620b9
UD
103 exit 0
104 ;;
105 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
926de5eb 106 if test $# -eq 1; then
479620b9 107 do_missing_arg $1
926de5eb
UD
108 fi
109 shift
43fc8f18
UD
110 progname="$1"
111 ;;
926de5eb
UD
112 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
113 progname=${1##*=}
114 ;;
479620b9 115 -p | --pn | --png)
926de5eb 116 if test $# -eq 1; then
479620b9 117 do_missing_arg $1
926de5eb
UD
118 fi
119 shift
43fc8f18
UD
120 png="$1"
121 ;;
926de5eb
UD
122 --pn=* | --png=*)
123 png=${1##*=}
124 ;;
479620b9 125 -d | --d | --da | --dat | --data)
926de5eb 126 if test $# -eq 1; then
479620b9 127 do_missing_arg $1
926de5eb
UD
128 fi
129 shift
43fc8f18
UD
130 data="$1"
131 ;;
926de5eb
UD
132 --d=* | --da=* | --dat=* | --data=*)
133 data=${1##*=}
134 ;;
479620b9 135 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
926de5eb
UD
136 buffer=1
137 ;;
479620b9 138 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
926de5eb 139 if test $# -eq 1; then
479620b9 140 do_missing_arg $1
926de5eb
UD
141 fi
142 shift
143 buffer="$1"
144 ;;
145 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
146 buffer=${1##*=}
147 ;;
148 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
149 notimer=yes
150 ;;
94eb5b36
UD
151 -m | --m | --mm | --mma | --mmap)
152 tracemmap=yes
153 ;;
479620b9 154 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
ba80a015 155 memusagestat_args="$memusagestat_args -t"
926de5eb 156 ;;
479620b9 157 -T | --to | --tot | --tota | --total)
ba80a015 158 memusagestat_args="$memusagestat_args -T"
926de5eb
UD
159 ;;
160 --tit | --titl | --title)
161 if test $# -eq 1; then
479620b9 162 do_missing_arg $1
926de5eb
UD
163 fi
164 shift
ba80a015 165 memusagestat_args="$memusagestat_args -s $1"
926de5eb
UD
166 ;;
167 --tit=* | --titl=* | --title=*)
ba80a015 168 memusagestat_args="$memusagestat_args -s ${1##*=}"
926de5eb 169 ;;
479620b9 170 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
926de5eb 171 if test $# -eq 1; then
479620b9 172 do_missing_arg $1
926de5eb
UD
173 fi
174 shift
ba80a015 175 memusagestat_args="$memusagestat_args -x $1"
926de5eb
UD
176 ;;
177 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
ba80a015 178 memusagestat_args="$memusagestat_args -x ${1##*=}"
926de5eb 179 ;;
479620b9 180 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
926de5eb 181 if test $# -eq 1; then
479620b9 182 do_missing_arg $1
926de5eb
UD
183 fi
184 shift
ba80a015 185 memusagestat_args="$memusagestat_args -y $1"
926de5eb
UD
186 ;;
187 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
ba80a015 188 memusagestat_args="$memusagestat_args -y ${1##*=}"
926de5eb 189 ;;
479620b9 190 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
ba80a015 191 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
479620b9 192 do_usage
926de5eb 193 ;;
43fc8f18
UD
194 --)
195 # Stop processing arguments.
196 shift
197 break
198 ;;
479620b9 199 --*)
ba80a015 200 echo >&2 $"memusage: unrecognized option \`$1'"
479620b9
UD
201 do_usage
202 ;;
43fc8f18
UD
203 *)
204 # Unknown option. This means the rest is the program name and parameters.
205 break
206 ;;
207 esac
208 shift
209done
210
211# See whether any arguments are left.
479620b9
UD
212if test $# -eq 0; then
213 echo >&2 $"No program name given"
214 do_usage
43fc8f18
UD
215fi
216
217# This will be in the environment.
ba80a015 218add_env="LD_PRELOAD=$memusageso"
43fc8f18
UD
219
220# Generate data file name.
b5c6276a 221datafile=
43fc8f18
UD
222if test -n "$data"; then
223 datafile="$data"
224elif test -n "$png"; then
07fb5185
UD
225 datafile=$(mktemp -t memusage.XXXXXX) || exit
226 trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
43fc8f18
UD
227fi
228if test -n "$datafile"; then
ba80a015 229 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
43fc8f18
UD
230fi
231
c788cd70
UD
232# Set program name.
233if test -n "$progname"; then
234 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
235fi
236
926de5eb
UD
237# Set buffer size.
238if test -n "$buffer"; then
ba80a015 239 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
926de5eb
UD
240fi
241
242# Disable timers.
243if test -n "$notimer"; then
ba80a015 244 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
926de5eb
UD
245fi
246
94eb5b36
UD
247# Trace mmap.
248if test -n "$tracemmap"; then
249 add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
250fi
251
43fc8f18 252# Execute the program itself.
b5c6276a 253eval $add_env '"$@"'
43fc8f18
UD
254result=$?
255
b5c6276a 256# Generate the PNG data file if wanted and there is something to generate
43fc8f18 257# it from.
b5c6276a 258if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
926de5eb 259 # Append extension .png if it isn't already there.
b5c6276a
UD
260 case $png in
261 *.png) ;;
262 *) png="$png.png" ;;
263 esac
ba80a015 264 $memusagestat $memusagestat_args "$datafile" "$png"
43fc8f18
UD
265fi
266
b5c6276a
UD
267if test -z "$data" -a -n "$datafile"; then
268 rm -f "$datafile"
43fc8f18
UD
269fi
270
271exit $result
272# Local Variables:
273# mode:ksh
274# End: