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