sparc: Fix llrint and llround missing exceptions on SPARC V8
[glibc.git] / malloc / memusage.sh
blobd2d9d17ea8948a30b35ff8937d25ace758a4a35d
1 #!/bin/bash
2 # Copyright (C) 1999-2024 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
19 memusageso='@SLIBDIR@/libmemusage.so'
20 memusagestat='@BINDIR@/memusagestat'
21 TEXTDOMAIN=libc
23 # Print usage message.
24 do_usage() {
25 printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
26 exit 1
29 # Message for missing argument.
30 do_missing_arg() {
31 printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1"
32 do_usage
35 # Print help message
36 do_help() {
37 echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
38 Profile memory usage of PROGRAM.
40 -n,--progname=NAME Name of the program file to profile
41 -p,--png=FILE Generate PNG graphic and store it in FILE
42 -d,--data=FILE Generate binary data file and store it in FILE
43 -u,--unbuffered Don't buffer output
44 -b,--buffer=SIZE Collect SIZE entries before writing them out
45 --no-timer Don't collect additional information through timer
46 -m,--mmap Also trace mmap & friends
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.
63 printf $"For bug reporting instructions, please see:\\n%s.\\n" \
64 "@REPORT_BUGS_TO@"
65 exit 0
68 do_version() {
69 echo 'memusage @PKGVERSION@@VERSION@'
70 printf $"Copyright (C) %s Free Software Foundation, Inc.
71 This is free software; see the source for copying conditions. There is NO
72 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
73 " "2024"
74 printf $"Written by %s.
75 " "Ulrich Drepper"
76 exit 0
79 # These variables are local
80 buffer=
81 data=
82 memusagestat_args=
83 notimer=
84 png=
85 progname=
86 tracemmap=
88 # Process arguments. But stop as soon as the program name is found.
89 while test $# -gt 0; do
90 case "$1" in
91 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
92 do_version
94 -\? | --h | --he | --hel | --help)
95 do_help
97 --us | --usa | --usag | --usage)
98 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
99 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
100 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
101 PROGRAM [PROGRAMOPTION]..."
102 exit 0
104 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
105 if test $# -eq 1; then
106 do_missing_arg $1
108 shift
109 progname="$1"
111 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
112 progname=${1##*=}
114 -p | --pn | --png)
115 if test $# -eq 1; then
116 do_missing_arg $1
118 shift
119 png="$1"
121 --pn=* | --png=*)
122 png=${1##*=}
124 -d | --d | --da | --dat | --data)
125 if test $# -eq 1; then
126 do_missing_arg $1
128 shift
129 data="$1"
131 --d=* | --da=* | --dat=* | --data=*)
132 data=${1##*=}
134 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
135 buffer=1
137 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
138 if test $# -eq 1; then
139 do_missing_arg $1
141 shift
142 buffer="$1"
144 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
145 buffer=${1##*=}
147 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
148 notimer=yes
150 -m | --m | --mm | --mma | --mmap)
151 tracemmap=yes
153 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
154 memusagestat_args="$memusagestat_args -t"
156 -T | --to | --tot | --tota | --total)
157 memusagestat_args="$memusagestat_args -T"
159 --tit | --titl | --title)
160 if test $# -eq 1; then
161 do_missing_arg $1
163 shift
164 memusagestat_args="$memusagestat_args -s $1"
166 --tit=* | --titl=* | --title=*)
167 memusagestat_args="$memusagestat_args -s ${1##*=}"
169 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
170 if test $# -eq 1; then
171 do_missing_arg $1
173 shift
174 memusagestat_args="$memusagestat_args -x $1"
176 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
177 memusagestat_args="$memusagestat_args -x ${1##*=}"
179 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
180 if test $# -eq 1; then
181 do_missing_arg $1
183 shift
184 memusagestat_args="$memusagestat_args -y $1"
186 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
187 memusagestat_args="$memusagestat_args -y ${1##*=}"
189 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
190 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
191 do_usage
194 # Stop processing arguments.
195 shift
196 break
198 --*)
199 echo >&2 $"memusage: unrecognized option \`$1'"
200 do_usage
203 # Unknown option. This means the rest is the program name and parameters.
204 break
206 esac
207 shift
208 done
210 # See whether any arguments are left.
211 if test $# -eq 0; then
212 echo >&2 $"No program name given"
213 do_usage
216 # This will be in the environment.
217 add_env="LD_PRELOAD=$memusageso"
219 # Generate data file name.
220 datafile=
221 if test -n "$data"; then
222 datafile="$data"
223 elif test -n "$png"; then
224 datafile=$(mktemp -t memusage.XXXXXX) || exit
225 trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
227 if test -n "$datafile"; then
228 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
231 # Set program name.
232 if test -n "$progname"; then
233 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
236 # Set buffer size.
237 if test -n "$buffer"; then
238 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
241 # Disable timers.
242 if test -n "$notimer"; then
243 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
246 # Trace mmap.
247 if test -n "$tracemmap"; then
248 add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
251 # Execute the program itself.
252 eval $add_env '"$@"'
253 result=$?
255 # Generate the PNG data file if wanted and there is something to generate
256 # it from.
257 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
258 # Append extension .png if it isn't already there.
259 case $png in
260 *.png) ;;
261 *) png="$png.png" ;;
262 esac
263 $memusagestat $memusagestat_args "$datafile" "$png"
266 if test -z "$data" -a -n "$datafile"; then
267 rm -f "$datafile"
270 exit $result
271 # Local Variables:
272 # mode:ksh
273 # End: