Don't use multi-line string literals.
[glibc.git] / malloc / memusage.sh
blob0c383268c624a37cd4f78b797b039ec367fdd239
1 #! @BASH@
2 # Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Ulrich Drepper <drepper@gnu.org>, 1999.
6 # The GNU C Library is free software; you can redistribute it and/or
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.
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
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, write to the Free
18 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # 02111-1307 USA.
21 memusageso=@SLIBDIR@/libmemusage.so
22 memusagestat=@BINDIR@/memusagestat
24 # Print usage message.
25 do_usage() {
26 echo >&2 $"Try \`memusage --help' for more information."
27 exit 1
30 # Message for missing argument.
31 do_missing_arg() {
32 echo >&2 $"memusage: option \`$1' requires an argument"
33 do_usage
36 # Print help message
37 do_help() {
38 echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
39 Profile memory usage of PROGRAM.
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
46 --no-timer Don't collect additional information though timer
48 -?,--help Print this help and exit
49 --usage Give a short usage message
50 -V,--version Print version information and exit
52 The following options only apply when generating graphical output:
53 -t,--time-based Make graph linear in time
54 -T,--total Also draw graph of total memory use
55 --title=STRING Use STRING as title of the graph
56 -x,--x-size=SIZE Make graphic SIZE pixels wide
57 -y,--y-size=SIZE Make graphic SIZE pixels high
59 Mandatory arguments to long options are also mandatory for any corresponding
60 short options.
62 Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
63 exit 0
66 do_version() {
67 echo 'memusage (GNU libc) @VERSION@'
68 echo $"Copyright (C) 2002 Free Software Foundation, Inc.
69 This is free software; see the source for copying conditions. There is NO
70 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
71 Written by Ulrich Drepper."
72 exit 0
75 # Process arguments. But stop as soon as the program name is found.
76 while test $# -gt 0; do
77 case "$1" in
78 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
79 do_version
81 -\? | --h | --he | --hel | --help)
82 do_help
84 --us | --usa | --usag | --usage)
85 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
86 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
87 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
88 PROGRAM [PROGRAMOPTION]..."
89 exit 0
91 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
92 if test $# -eq 1; then
93 do_missing_arg $1
95 shift
96 progname="$1"
98 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
99 progname=${1##*=}
101 -p | --pn | --png)
102 if test $# -eq 1; then
103 do_missing_arg $1
105 shift
106 png="$1"
108 --pn=* | --png=*)
109 png=${1##*=}
111 -d | --d | --da | --dat | --data)
112 if test $# -eq 1; then
113 do_missing_arg $1
115 shift
116 data="$1"
118 --d=* | --da=* | --dat=* | --data=*)
119 data=${1##*=}
121 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
122 buffer=1
124 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
125 if test $# -eq 1; then
126 do_missing_arg $1
128 shift
129 buffer="$1"
131 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
132 buffer=${1##*=}
134 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
135 notimer=yes
137 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
138 memusagestat_args="$memusagestat_args -t"
140 -T | --to | --tot | --tota | --total)
141 memusagestat_args="$memusagestat_args -T"
143 --tit | --titl | --title)
144 if test $# -eq 1; then
145 do_missing_arg $1
147 shift
148 memusagestat_args="$memusagestat_args -s $1"
150 --tit=* | --titl=* | --title=*)
151 memusagestat_args="$memusagestat_args -s ${1##*=}"
153 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
154 if test $# -eq 1; then
155 do_missing_arg $1
157 shift
158 memusagestat_args="$memusagestat_args -x $1"
160 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
161 memusagestat_args="$memusagestat_args -x ${1##*=}"
163 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
164 if test $# -eq 1; then
165 do_missing_arg $1
167 shift
168 memusagestat_args="$memusagestat_args -y $1"
170 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
171 memusagestat_args="$memusagestat_args -y ${1##*=}"
173 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
174 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
175 do_usage
178 # Stop processing arguments.
179 shift
180 break
182 --*)
183 echo >&2 $"memusage: unrecognized option \`$1'"
184 do_usage
187 # Unknown option. This means the rest is the program name and parameters.
188 break
190 esac
191 shift
192 done
194 # See whether any arguments are left.
195 if test $# -eq 0; then
196 echo >&2 $"No program name given"
197 do_usage
200 # This will be in the environment.
201 add_env="LD_PRELOAD=$memusageso"
203 # Generate data file name.
204 datafile=
205 if test -n "$data"; then
206 datafile="$data"
207 elif test -n "$png"; then
208 datafile=$(mktemp ${TMPDIR:-/tmp}/memusage.XXXXXX 2> /dev/null)
209 if test $? -ne 0; then
210 # Lame, but if there is no `mktemp' program the user cannot expect more.
211 if test "$RANDOM" != "$RANDOM"; then
212 datafile=${TMPDIR:-/tmp}/memusage.$RANDOM
213 else
214 datafile=${TMPDIR:-/tmp}/memusage.$$
218 if test -n "$datafile"; then
219 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
222 # Set program name.
223 if test -n "$progname"; then
224 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
227 # Set buffer size.
228 if test -n "$buffer"; then
229 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
232 # Disable timers.
233 if test -n "$notimer"; then
234 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
237 # Execute the program itself.
238 eval $add_env '"$@"'
239 result=$?
241 # Generate the PNG data file if wanted and there is something to generate
242 # it from.
243 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
244 # Append extension .png if it isn't already there.
245 case $png in
246 *.png) ;;
247 *) png="$png.png" ;;
248 esac
249 $memusagestat $memusagestat_args "$datafile" "$png"
252 if test -z "$data" -a -n "$datafile"; then
253 rm -f "$datafile"
256 exit $result
257 # Local Variables:
258 # mode:ksh
259 # End: