]>
Commit | Line | Data |
---|---|---|
43fc8f18 | 1 | #! @BASH@ |
0308a475 | 2 | # Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
43fc8f18 UD |
3 | # This file is part of the GNU C Library. |
4 | # Contributed by Ulrich Drepper <drepper@gnu.org>, 1999. | |
5 | ||
6 | # The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
43fc8f18 UD |
10 | |
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 | |
41bdb6e2 | 14 | # Lesser General Public License for more details. |
43fc8f18 | 15 | |
41bdb6e2 AJ |
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 | |
19 | # 02111-1307 USA. | |
43fc8f18 | 20 | |
c891b2df | 21 | memusageso=@SLIBDIR@/libmemusage.so |
ba80a015 | 22 | memusagestat=@BINDIR@/memusagestat |
43fc8f18 UD |
23 | |
24 | # Print usage message. | |
25 | do_usage() { | |
ba80a015 | 26 | echo >&2 $"Try \`memusage --help' for more information." |
43fc8f18 UD |
27 | exit 1 |
28 | } | |
29 | ||
479620b9 UD |
30 | # Message for missing argument. |
31 | do_missing_arg() { | |
ba80a015 | 32 | echo >&2 $"memusage: option \`$1' requires an argument" |
479620b9 UD |
33 | do_usage |
34 | } | |
35 | ||
36 | # Print help message | |
43fc8f18 | 37 | do_help() { |
ba80a015 | 38 | echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]... |
926de5eb UD |
39 | Profile memory usage of PROGRAM. |
40 | ||
479620b9 UD |
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 though timer | |
47 | ||
48 | -?,--help Print this help and exit | |
49 | --usage Give a short usage message | |
50 | -V,--version Print version information and exit | |
51 | ||
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 | |
58 | ||
59 | Mandatory arguments to long options are also mandatory for any corresponding | |
60 | short options. | |
61 | ||
43fc8f18 UD |
62 | Report bugs using the \`glibcbug' script to <bugs@gnu.org>." |
63 | exit 0 | |
64 | } | |
65 | ||
66 | do_version() { | |
ba80a015 | 67 | echo 'memusage (GNU libc) @VERSION@' |
0308a475 | 68 | echo $"Copyright (C) 2002 Free Software Foundation, Inc. |
43fc8f18 UD |
69 | This is free software; see the source for copying conditions. There is NO |
70 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
71 | Written by Ulrich Drepper." | |
72 | exit 0 | |
73 | } | |
74 | ||
75 | # Process arguments. But stop as soon as the program name is found. | |
76 | while test $# -gt 0; do | |
77 | case "$1" in | |
479620b9 | 78 | -V | --v | --ve | --ver | --vers | --versi | --versio | --version) |
43fc8f18 UD |
79 | do_version |
80 | ;; | |
479620b9 | 81 | -\? | --h | --he | --hel | --help) |
43fc8f18 UD |
82 | do_help |
83 | ;; | |
479620b9 | 84 | --us | --usa | --usag | --usage) |
ba80a015 | 85 | echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered] |
479620b9 UD |
86 | [--buffer=SIZE] [--no-timer] [--time-based] [--total] |
87 | [--title=STRING] [--x-size=SIZE] [--y-size=SIZE] | |
88 | PROGRAM [PROGRAMOPTION]..." | |
89 | exit 0 | |
90 | ;; | |
91 | -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname) | |
926de5eb | 92 | if test $# -eq 1; then |
479620b9 | 93 | do_missing_arg $1 |
926de5eb UD |
94 | fi |
95 | shift | |
43fc8f18 UD |
96 | progname="$1" |
97 | ;; | |
926de5eb UD |
98 | --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*) |
99 | progname=${1##*=} | |
100 | ;; | |
479620b9 | 101 | -p | --pn | --png) |
926de5eb | 102 | if test $# -eq 1; then |
479620b9 | 103 | do_missing_arg $1 |
926de5eb UD |
104 | fi |
105 | shift | |
43fc8f18 UD |
106 | png="$1" |
107 | ;; | |
926de5eb UD |
108 | --pn=* | --png=*) |
109 | png=${1##*=} | |
110 | ;; | |
479620b9 | 111 | -d | --d | --da | --dat | --data) |
926de5eb | 112 | if test $# -eq 1; then |
479620b9 | 113 | do_missing_arg $1 |
926de5eb UD |
114 | fi |
115 | shift | |
43fc8f18 UD |
116 | data="$1" |
117 | ;; | |
926de5eb UD |
118 | --d=* | --da=* | --dat=* | --data=*) |
119 | data=${1##*=} | |
120 | ;; | |
479620b9 | 121 | -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered) |
926de5eb UD |
122 | buffer=1 |
123 | ;; | |
479620b9 | 124 | -b | --b | --bu | --buf | --buff | --buffe | --buffer) |
926de5eb | 125 | if test $# -eq 1; then |
479620b9 | 126 | do_missing_arg $1 |
926de5eb UD |
127 | fi |
128 | shift | |
129 | buffer="$1" | |
130 | ;; | |
131 | --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*) | |
132 | buffer=${1##*=} | |
133 | ;; | |
134 | --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer) | |
135 | notimer=yes | |
136 | ;; | |
479620b9 | 137 | -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based) |
ba80a015 | 138 | memusagestat_args="$memusagestat_args -t" |
926de5eb | 139 | ;; |
479620b9 | 140 | -T | --to | --tot | --tota | --total) |
ba80a015 | 141 | memusagestat_args="$memusagestat_args -T" |
926de5eb UD |
142 | ;; |
143 | --tit | --titl | --title) | |
144 | if test $# -eq 1; then | |
479620b9 | 145 | do_missing_arg $1 |
926de5eb UD |
146 | fi |
147 | shift | |
ba80a015 | 148 | memusagestat_args="$memusagestat_args -s $1" |
926de5eb UD |
149 | ;; |
150 | --tit=* | --titl=* | --title=*) | |
ba80a015 | 151 | memusagestat_args="$memusagestat_args -s ${1##*=}" |
926de5eb | 152 | ;; |
479620b9 | 153 | -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size) |
926de5eb | 154 | if test $# -eq 1; then |
479620b9 | 155 | do_missing_arg $1 |
926de5eb UD |
156 | fi |
157 | shift | |
ba80a015 | 158 | memusagestat_args="$memusagestat_args -x $1" |
926de5eb UD |
159 | ;; |
160 | --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*) | |
ba80a015 | 161 | memusagestat_args="$memusagestat_args -x ${1##*=}" |
926de5eb | 162 | ;; |
479620b9 | 163 | -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size) |
926de5eb | 164 | if test $# -eq 1; then |
479620b9 | 165 | do_missing_arg $1 |
926de5eb UD |
166 | fi |
167 | shift | |
ba80a015 | 168 | memusagestat_args="$memusagestat_args -y $1" |
926de5eb UD |
169 | ;; |
170 | --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*) | |
ba80a015 | 171 | memusagestat_args="$memusagestat_args -y ${1##*=}" |
926de5eb | 172 | ;; |
479620b9 | 173 | --p | --p=* | --t | --t=* | --ti | --ti=* | --u) |
ba80a015 | 174 | echo >&2 $"memusage: option \`${1##*=}' is ambiguous" |
479620b9 | 175 | do_usage |
926de5eb | 176 | ;; |
43fc8f18 UD |
177 | --) |
178 | # Stop processing arguments. | |
179 | shift | |
180 | break | |
181 | ;; | |
479620b9 | 182 | --*) |
ba80a015 | 183 | echo >&2 $"memusage: unrecognized option \`$1'" |
479620b9 UD |
184 | do_usage |
185 | ;; | |
43fc8f18 UD |
186 | *) |
187 | # Unknown option. This means the rest is the program name and parameters. | |
188 | break | |
189 | ;; | |
190 | esac | |
191 | shift | |
192 | done | |
193 | ||
194 | # See whether any arguments are left. | |
479620b9 UD |
195 | if test $# -eq 0; then |
196 | echo >&2 $"No program name given" | |
197 | do_usage | |
43fc8f18 UD |
198 | fi |
199 | ||
200 | # This will be in the environment. | |
ba80a015 | 201 | add_env="LD_PRELOAD=$memusageso" |
43fc8f18 UD |
202 | |
203 | # Generate data file name. | |
b5c6276a | 204 | datafile= |
43fc8f18 UD |
205 | if test -n "$data"; then |
206 | datafile="$data" | |
207 | elif test -n "$png"; then | |
ba80a015 | 208 | datafile=$(mktemp ${TMPDIR:-/tmp}/memusage.XXXXXX 2> /dev/null) |
43fc8f18 UD |
209 | if test $? -ne 0; then |
210 | # Lame, but if there is no `mktemp' program the user cannot expect more. | |
479620b9 | 211 | if test "$RANDOM" != "$RANDOM"; then |
ba80a015 | 212 | datafile=${TMPDIR:-/tmp}/memusage.$RANDOM |
479620b9 | 213 | else |
ba80a015 | 214 | datafile=${TMPDIR:-/tmp}/memusage.$$ |
479620b9 | 215 | fi |
43fc8f18 UD |
216 | fi |
217 | fi | |
218 | if test -n "$datafile"; then | |
ba80a015 | 219 | add_env="$add_env MEMUSAGE_OUTPUT=$datafile" |
43fc8f18 UD |
220 | fi |
221 | ||
c788cd70 UD |
222 | # Set program name. |
223 | if test -n "$progname"; then | |
224 | add_env="$add_env MEMUSAGE_PROG_NAME=$progname" | |
225 | fi | |
226 | ||
926de5eb UD |
227 | # Set buffer size. |
228 | if test -n "$buffer"; then | |
ba80a015 | 229 | add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer" |
926de5eb UD |
230 | fi |
231 | ||
232 | # Disable timers. | |
233 | if test -n "$notimer"; then | |
ba80a015 | 234 | add_env="$add_env MEMUSAGE_NO_TIMER=yes" |
926de5eb UD |
235 | fi |
236 | ||
43fc8f18 | 237 | # Execute the program itself. |
b5c6276a | 238 | eval $add_env '"$@"' |
43fc8f18 UD |
239 | result=$? |
240 | ||
b5c6276a | 241 | # Generate the PNG data file if wanted and there is something to generate |
43fc8f18 | 242 | # it from. |
b5c6276a | 243 | if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then |
926de5eb | 244 | # Append extension .png if it isn't already there. |
b5c6276a UD |
245 | case $png in |
246 | *.png) ;; | |
247 | *) png="$png.png" ;; | |
248 | esac | |
ba80a015 | 249 | $memusagestat $memusagestat_args "$datafile" "$png" |
43fc8f18 UD |
250 | fi |
251 | ||
b5c6276a UD |
252 | if test -z "$data" -a -n "$datafile"; then |
253 | rm -f "$datafile" | |
43fc8f18 UD |
254 | fi |
255 | ||
256 | exit $result | |
257 | # Local Variables: | |
258 | # mode:ksh | |
259 | # End: |