2 # Copyright (C) 1999-2008, 2009 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
21 memusageso='@SLIBDIR@/libmemusage.so'
22 memusagestat='@BINDIR@/memusagestat'
25 # Print usage message.
27 echo >&2 $"Try \`memusage --help' for more information."
31 # Message for missing argument.
33 echo >&2 $"memusage: option \`$1' requires an argument"
39 printf $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
40 Profile memory usage of PROGRAM.
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 through timer
48 -m,--mmap Also trace mmap & friends
50 -?,--help Print this help and exit
51 --usage Give a short usage message
52 -V,--version Print version information and exit
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
61 Mandatory arguments to long options are also mandatory for any corresponding
65 printf $"For bug reporting instructions, please see:
72 echo 'memusage @PKGVERSION@@VERSION@'
73 printf $"Copyright (C) %s Free Software Foundation, Inc.
74 This is free software; see the source for copying conditions. There is NO
75 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
77 printf $"Written by %s.
82 # These variables are local
91 # Process arguments. But stop as soon as the program name is found.
92 while test $# -gt 0; do
94 -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
97 -\? | --h | --he | --hel | --help)
100 --us | --usa | --usag | --usage)
101 echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
102 [--buffer=SIZE] [--no-timer] [--time-based] [--total]
103 [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
104 PROGRAM [PROGRAMOPTION]..."
107 -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
108 if test $# -eq 1; then
114 --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
118 if test $# -eq 1; then
127 -d | --d | --da | --dat | --data)
128 if test $# -eq 1; then
134 --d=* | --da=* | --dat=* | --data=*)
137 -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
140 -b | --b | --bu | --buf | --buff | --buffe | --buffer)
141 if test $# -eq 1; then
147 --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
150 --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
153 -m | --m | --mm | --mma | --mmap)
156 -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
157 memusagestat_args="$memusagestat_args -t"
159 -T | --to | --tot | --tota | --total)
160 memusagestat_args="$memusagestat_args -T"
162 --tit | --titl | --title)
163 if test $# -eq 1; then
167 memusagestat_args="$memusagestat_args -s $1"
169 --tit=* | --titl=* | --title=*)
170 memusagestat_args="$memusagestat_args -s ${1##*=}"
172 -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
173 if test $# -eq 1; then
177 memusagestat_args="$memusagestat_args -x $1"
179 --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
180 memusagestat_args="$memusagestat_args -x ${1##*=}"
182 -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
183 if test $# -eq 1; then
187 memusagestat_args="$memusagestat_args -y $1"
189 --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
190 memusagestat_args="$memusagestat_args -y ${1##*=}"
192 --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
193 echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
197 # Stop processing arguments.
202 echo >&2 $"memusage: unrecognized option \`$1'"
206 # Unknown option. This means the rest is the program name and parameters.
213 # See whether any arguments are left.
214 if test $# -eq 0; then
215 echo >&2 $"No program name given"
219 # This will be in the environment.
220 add_env="LD_PRELOAD=$memusageso"
222 # Generate data file name.
224 if test -n "$data"; then
226 elif test -n "$png"; then
227 datafile=$(mktemp -t memusage.XXXXXX) || exit
228 trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
230 if test -n "$datafile"; then
231 add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
235 if test -n "$progname"; then
236 add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
240 if test -n "$buffer"; then
241 add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
245 if test -n "$notimer"; then
246 add_env="$add_env MEMUSAGE_NO_TIMER=yes"
250 if test -n "$tracemmap"; then
251 add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
254 # Execute the program itself.
258 # Generate the PNG data file if wanted and there is something to generate
260 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
261 # Append extension .png if it isn't already there.
266 $memusagestat $memusagestat_args "$datafile" "$png"
269 if test -z "$data" -a -n "$datafile"; then