Fix SH4 FP_ILOGB0 (bug 20859).
[glibc.git] / malloc / memusage.sh
blob7430f8881d23c11f7f36179fb3283aa3669caa66
1 #! @BASH@
2 # Copyright (C) 1999-2016 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, see
18 # <http://www.gnu.org/licenses/>.
20 memusageso='@SLIBDIR@/libmemusage.so'
21 memusagestat='@BINDIR@/memusagestat'
22 TEXTDOMAIN=libc
24 # Print usage message.
25 do_usage() {
26 printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
27 exit 1
30 # Message for missing argument.
31 do_missing_arg() {
32 printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1"
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 through timer
47 -m,--mmap Also trace mmap & friends
49 -?,--help Print this help and exit
50 --usage Give a short usage message
51 -V,--version Print version information and exit
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
60 Mandatory arguments to long options are also mandatory for any corresponding
61 short options.
64 printf $"For bug reporting instructions, please see:\\n%s.\\n" \
65 "@REPORT_BUGS_TO@"
66 exit 0
69 do_version() {
70 echo 'memusage @PKGVERSION@@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 " "2016"
75 printf $"Written by %s.
76 " "Ulrich Drepper"
77 exit 0
80 # These variables are local
81 buffer=
82 data=
83 memusagestat_args=
84 notimer=
85 png=
86 progname=
87 tracemmap=
89 # Process arguments. But stop as soon as the program name is found.
90 while test $# -gt 0; do
91 case "$1" in
92 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
93 do_version
95 -\? | --h | --he | --hel | --help)
96 do_help
98 --us | --usa | --usag | --usage)
99 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
100 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
101 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
102 PROGRAM [PROGRAMOPTION]..."
103 exit 0
105 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
106 if test $# -eq 1; then
107 do_missing_arg $1
109 shift
110 progname="$1"
112 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
113 progname=${1##*=}
115 -p | --pn | --png)
116 if test $# -eq 1; then
117 do_missing_arg $1
119 shift
120 png="$1"
122 --pn=* | --png=*)
123 png=${1##*=}
125 -d | --d | --da | --dat | --data)
126 if test $# -eq 1; then
127 do_missing_arg $1
129 shift
130 data="$1"
132 --d=* | --da=* | --dat=* | --data=*)
133 data=${1##*=}
135 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
136 buffer=1
138 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
139 if test $# -eq 1; then
140 do_missing_arg $1
142 shift
143 buffer="$1"
145 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
146 buffer=${1##*=}
148 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
149 notimer=yes
151 -m | --m | --mm | --mma | --mmap)
152 tracemmap=yes
154 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
155 memusagestat_args="$memusagestat_args -t"
157 -T | --to | --tot | --tota | --total)
158 memusagestat_args="$memusagestat_args -T"
160 --tit | --titl | --title)
161 if test $# -eq 1; then
162 do_missing_arg $1
164 shift
165 memusagestat_args="$memusagestat_args -s $1"
167 --tit=* | --titl=* | --title=*)
168 memusagestat_args="$memusagestat_args -s ${1##*=}"
170 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
171 if test $# -eq 1; then
172 do_missing_arg $1
174 shift
175 memusagestat_args="$memusagestat_args -x $1"
177 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
178 memusagestat_args="$memusagestat_args -x ${1##*=}"
180 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
181 if test $# -eq 1; then
182 do_missing_arg $1
184 shift
185 memusagestat_args="$memusagestat_args -y $1"
187 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
188 memusagestat_args="$memusagestat_args -y ${1##*=}"
190 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
191 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
192 do_usage
195 # Stop processing arguments.
196 shift
197 break
199 --*)
200 echo >&2 $"memusage: unrecognized option \`$1'"
201 do_usage
204 # Unknown option. This means the rest is the program name and parameters.
205 break
207 esac
208 shift
209 done
211 # See whether any arguments are left.
212 if test $# -eq 0; then
213 echo >&2 $"No program name given"
214 do_usage
217 # This will be in the environment.
218 add_env="LD_PRELOAD=$memusageso"
220 # Generate data file name.
221 datafile=
222 if test -n "$data"; then
223 datafile="$data"
224 elif test -n "$png"; then
225 datafile=$(mktemp -t memusage.XXXXXX) || exit
226 trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
228 if test -n "$datafile"; then
229 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
232 # Set program name.
233 if test -n "$progname"; then
234 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
237 # Set buffer size.
238 if test -n "$buffer"; then
239 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
242 # Disable timers.
243 if test -n "$notimer"; then
244 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
247 # Trace mmap.
248 if test -n "$tracemmap"; then
249 add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
252 # Execute the program itself.
253 eval $add_env '"$@"'
254 result=$?
256 # Generate the PNG data file if wanted and there is something to generate
257 # it from.
258 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
259 # Append extension .png if it isn't already there.
260 case $png in
261 *.png) ;;
262 *) png="$png.png" ;;
263 esac
264 $memusagestat $memusagestat_args "$datafile" "$png"
267 if test -z "$data" -a -n "$datafile"; then
268 rm -f "$datafile"
271 exit $result
272 # Local Variables:
273 # mode:ksh
274 # End: