Add "()" when casting to uint64_t for 64-bit store
[glibc.git] / malloc / memusage.sh
blob7ed68c0773dc5e79654e2e2b588af3864cd78332
1 #! @BASH@
2 # Copyright (C) 1999-2011, 2012 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 echo $"For bug reporting instructions, please see:
65 <http://www.gnu.org/software/libc/bugs.html>.
67 exit 0
70 do_version() {
71 echo 'memusage (GNU libc) @VERSION@'
72 printf $"Copyright (C) %s Free Software Foundation, Inc.
73 This is free software; see the source for copying conditions. There is NO
74 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75 " "2012"
76 printf $"Written by %s.
77 " "Ulrich Drepper"
78 exit 0
81 # These variables are local
82 buffer=
83 data=
84 memusagestat_args=
85 notimer=
86 png=
87 progname=
88 tracemmap=
90 # Process arguments. But stop as soon as the program name is found.
91 while test $# -gt 0; do
92 case "$1" in
93 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
94 do_version
96 -\? | --h | --he | --hel | --help)
97 do_help
99 --us | --usa | --usag | --usage)
100 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
101 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
102 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
103 PROGRAM [PROGRAMOPTION]..."
104 exit 0
106 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
107 if test $# -eq 1; then
108 do_missing_arg $1
110 shift
111 progname="$1"
113 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
114 progname=${1##*=}
116 -p | --pn | --png)
117 if test $# -eq 1; then
118 do_missing_arg $1
120 shift
121 png="$1"
123 --pn=* | --png=*)
124 png=${1##*=}
126 -d | --d | --da | --dat | --data)
127 if test $# -eq 1; then
128 do_missing_arg $1
130 shift
131 data="$1"
133 --d=* | --da=* | --dat=* | --data=*)
134 data=${1##*=}
136 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
137 buffer=1
139 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
140 if test $# -eq 1; then
141 do_missing_arg $1
143 shift
144 buffer="$1"
146 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
147 buffer=${1##*=}
149 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
150 notimer=yes
152 -m | --m | --mm | --mma | --mmap)
153 tracemmap=yes
155 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
156 memusagestat_args="$memusagestat_args -t"
158 -T | --to | --tot | --tota | --total)
159 memusagestat_args="$memusagestat_args -T"
161 --tit | --titl | --title)
162 if test $# -eq 1; then
163 do_missing_arg $1
165 shift
166 memusagestat_args="$memusagestat_args -s $1"
168 --tit=* | --titl=* | --title=*)
169 memusagestat_args="$memusagestat_args -s ${1##*=}"
171 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
172 if test $# -eq 1; then
173 do_missing_arg $1
175 shift
176 memusagestat_args="$memusagestat_args -x $1"
178 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
179 memusagestat_args="$memusagestat_args -x ${1##*=}"
181 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
182 if test $# -eq 1; then
183 do_missing_arg $1
185 shift
186 memusagestat_args="$memusagestat_args -y $1"
188 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
189 memusagestat_args="$memusagestat_args -y ${1##*=}"
191 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
192 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
193 do_usage
196 # Stop processing arguments.
197 shift
198 break
200 --*)
201 echo >&2 $"memusage: unrecognized option \`$1'"
202 do_usage
205 # Unknown option. This means the rest is the program name and parameters.
206 break
208 esac
209 shift
210 done
212 # See whether any arguments are left.
213 if test $# -eq 0; then
214 echo >&2 $"No program name given"
215 do_usage
218 # This will be in the environment.
219 add_env="LD_PRELOAD=$memusageso"
221 # Generate data file name.
222 datafile=
223 if test -n "$data"; then
224 datafile="$data"
225 elif test -n "$png"; then
226 datafile=$(mktemp -t memusage.XXXXXX) || exit
227 trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
229 if test -n "$datafile"; then
230 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
233 # Set program name.
234 if test -n "$progname"; then
235 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
238 # Set buffer size.
239 if test -n "$buffer"; then
240 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
243 # Disable timers.
244 if test -n "$notimer"; then
245 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
248 # Trace mmap.
249 if test -n "$tracemmap"; then
250 add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
253 # Execute the program itself.
254 eval $add_env '"$@"'
255 result=$?
257 # Generate the PNG data file if wanted and there is something to generate
258 # it from.
259 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
260 # Append extension .png if it isn't already there.
261 case $png in
262 *.png) ;;
263 *) png="$png.png" ;;
264 esac
265 $memusagestat $memusagestat_args "$datafile" "$png"
268 if test -z "$data" -a -n "$datafile"; then
269 rm -f "$datafile"
272 exit $result
273 # Local Variables:
274 # mode:ksh
275 # End: