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'
24 # Print usage message.
26 printf >&2 $
"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
30 # Message for missing argument.
32 printf >&2 $
"%s: option '%s' requires an argument\n" memusage
"$1"
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
64 echo $
"For bug reporting instructions, please see:
65 <http://www.gnu.org/software/libc/bugs.html>.
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.
76 printf $
"Written by %s.
81 # These variables are local
90 # Process arguments. But stop as soon as the program name is found.
91 while test $# -gt 0; do
93 -V |
--v |
--ve |
--ver |
--vers |
--versi |
--versio |
--version)
96 -\? |
--h |
--he |
--hel |
--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]..."
106 -n |
--pr |
--pro |
--prog |
--progn |
--progna |
--prognam |
--progname)
107 if test $# -eq 1; then
113 --pr=* |
--pro=* |
--prog=* |
--progn=* |
--progna=* |
--prognam=* |
--progname=*)
117 if test $# -eq 1; then
126 -d |
--d |
--da |
--dat |
--data)
127 if test $# -eq 1; then
133 --d=* |
--da=* |
--dat=* |
--data=*)
136 -u |
--un |
--unb |
--unbu |
--unbuf |
--unbuff |
--unbuffe |
--unbuffer |
--unbuffere |
--unbuffered)
139 -b |
--b |
--bu |
--buf |
--buff |
--buffe |
--buffer)
140 if test $# -eq 1; then
146 --b=* |
--bu=* |
--buf=* |
--buff=* |
--buffe=* |
--buffer=*)
149 --n |
--no |
--no- |
--no-t |
--no-ti |
--no-tim |
--no-time |
--no-timer)
152 -m |
--m |
--mm |
--mma |
--mmap)
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
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
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
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"
196 # Stop processing arguments.
201 echo >&2 $
"memusage: unrecognized option \`$1'"
205 # Unknown option. This means the rest is the program name and parameters.
212 # See whether any arguments are left.
213 if test $# -eq 0; then
214 echo >&2 $
"No program name given"
218 # This will be in the environment.
219 add_env
="LD_PRELOAD=$memusageso"
221 # Generate data file name.
223 if test -n "$data"; then
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"
234 if test -n "$progname"; then
235 add_env
="$add_env MEMUSAGE_PROG_NAME=$progname"
239 if test -n "$buffer"; then
240 add_env
="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
244 if test -n "$notimer"; then
245 add_env
="$add_env MEMUSAGE_NO_TIMER=yes"
249 if test -n "$tracemmap"; then
250 add_env
="$add_env MEMUSAGE_TRACE_MMAP=yes"
253 # Execute the program itself.
257 # Generate the PNG data file if wanted and there is something to generate
259 if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
260 # Append extension .png if it isn't already there.
265 $memusagestat $memusagestat_args "$datafile" "$png"
268 if test -z "$data" -a -n "$datafile"; then