]>
Commit | Line | Data |
---|---|---|
43fc8f18 | 1 | #! @BASH@ |
c0dafcf1 | 2 | # Copyright (C) 1999-2008, 2009, 2010, 2011 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 | |
f50fa10c UD |
21 | memusageso='@SLIBDIR@/libmemusage.so' |
22 | memusagestat='@BINDIR@/memusagestat' | |
8e597a18 | 23 | TEXTDOMAIN=libc |
43fc8f18 UD |
24 | |
25 | # Print usage message. | |
26 | do_usage() { | |
de81b246 | 27 | printf >&2 $"Try \`%s --help' or `%s --usage' for more information.\n" memusage memusage |
43fc8f18 UD |
28 | exit 1 |
29 | } | |
30 | ||
479620b9 UD |
31 | # Message for missing argument. |
32 | do_missing_arg() { | |
de81b246 | 33 | printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1" |
479620b9 UD |
34 | do_usage |
35 | } | |
36 | ||
37 | # Print help message | |
43fc8f18 | 38 | do_help() { |
ba80a015 | 39 | echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]... |
926de5eb UD |
40 | Profile memory usage of PROGRAM. |
41 | ||
479620b9 UD |
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 | |
11bf311e | 47 | --no-timer Don't collect additional information through timer |
94eb5b36 | 48 | -m,--mmap Also trace mmap & friends |
479620b9 UD |
49 | |
50 | -?,--help Print this help and exit | |
51 | --usage Give a short usage message | |
52 | -V,--version Print version information and exit | |
53 | ||
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 | |
60 | ||
61 | Mandatory arguments to long options are also mandatory for any corresponding | |
62 | short options. | |
63 | ||
cbbcaf23 | 64 | " |
f60ddf9b | 65 | echo $"For bug reporting instructions, please see: |
cbbcaf23 UD |
66 | <http://www.gnu.org/software/libc/bugs.html>. |
67 | " | |
43fc8f18 UD |
68 | exit 0 |
69 | } | |
70 | ||
71 | do_version() { | |
ba80a015 | 72 | echo 'memusage (GNU libc) @VERSION@' |
8e597a18 | 73 | printf $"Copyright (C) %s Free Software Foundation, Inc. |
43fc8f18 UD |
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. | |
c0dafcf1 | 76 | " "2011" |
8e597a18 UD |
77 | printf $"Written by %s. |
78 | " "Ulrich Drepper" | |
43fc8f18 UD |
79 | exit 0 |
80 | } | |
81 | ||
07fb5185 UD |
82 | # These variables are local |
83 | buffer= | |
84 | data= | |
85 | memusagestat_args= | |
86 | notimer= | |
87 | png= | |
88 | progname= | |
89 | tracemmap= | |
90 | ||
43fc8f18 UD |
91 | # Process arguments. But stop as soon as the program name is found. |
92 | while test $# -gt 0; do | |
93 | case "$1" in | |
479620b9 | 94 | -V | --v | --ve | --ver | --vers | --versi | --versio | --version) |
43fc8f18 UD |
95 | do_version |
96 | ;; | |
479620b9 | 97 | -\? | --h | --he | --hel | --help) |
43fc8f18 UD |
98 | do_help |
99 | ;; | |
479620b9 | 100 | --us | --usa | --usag | --usage) |
ba80a015 | 101 | echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered] |
561470e0 UD |
102 | [--buffer=SIZE] [--no-timer] [--time-based] [--total] |
103 | [--title=STRING] [--x-size=SIZE] [--y-size=SIZE] | |
104 | PROGRAM [PROGRAMOPTION]..." | |
479620b9 UD |
105 | exit 0 |
106 | ;; | |
107 | -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname) | |
926de5eb | 108 | if test $# -eq 1; then |
479620b9 | 109 | do_missing_arg $1 |
926de5eb UD |
110 | fi |
111 | shift | |
43fc8f18 UD |
112 | progname="$1" |
113 | ;; | |
926de5eb UD |
114 | --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*) |
115 | progname=${1##*=} | |
116 | ;; | |
479620b9 | 117 | -p | --pn | --png) |
926de5eb | 118 | if test $# -eq 1; then |
479620b9 | 119 | do_missing_arg $1 |
926de5eb UD |
120 | fi |
121 | shift | |
43fc8f18 UD |
122 | png="$1" |
123 | ;; | |
926de5eb UD |
124 | --pn=* | --png=*) |
125 | png=${1##*=} | |
126 | ;; | |
479620b9 | 127 | -d | --d | --da | --dat | --data) |
926de5eb | 128 | if test $# -eq 1; then |
479620b9 | 129 | do_missing_arg $1 |
926de5eb UD |
130 | fi |
131 | shift | |
43fc8f18 UD |
132 | data="$1" |
133 | ;; | |
926de5eb UD |
134 | --d=* | --da=* | --dat=* | --data=*) |
135 | data=${1##*=} | |
136 | ;; | |
479620b9 | 137 | -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered) |
926de5eb UD |
138 | buffer=1 |
139 | ;; | |
479620b9 | 140 | -b | --b | --bu | --buf | --buff | --buffe | --buffer) |
926de5eb | 141 | if test $# -eq 1; then |
479620b9 | 142 | do_missing_arg $1 |
926de5eb UD |
143 | fi |
144 | shift | |
145 | buffer="$1" | |
146 | ;; | |
147 | --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*) | |
148 | buffer=${1##*=} | |
149 | ;; | |
150 | --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer) | |
151 | notimer=yes | |
152 | ;; | |
94eb5b36 UD |
153 | -m | --m | --mm | --mma | --mmap) |
154 | tracemmap=yes | |
155 | ;; | |
479620b9 | 156 | -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based) |
ba80a015 | 157 | memusagestat_args="$memusagestat_args -t" |
926de5eb | 158 | ;; |
479620b9 | 159 | -T | --to | --tot | --tota | --total) |
ba80a015 | 160 | memusagestat_args="$memusagestat_args -T" |
926de5eb UD |
161 | ;; |
162 | --tit | --titl | --title) | |
163 | if test $# -eq 1; then | |
479620b9 | 164 | do_missing_arg $1 |
926de5eb UD |
165 | fi |
166 | shift | |
ba80a015 | 167 | memusagestat_args="$memusagestat_args -s $1" |
926de5eb UD |
168 | ;; |
169 | --tit=* | --titl=* | --title=*) | |
ba80a015 | 170 | memusagestat_args="$memusagestat_args -s ${1##*=}" |
926de5eb | 171 | ;; |
479620b9 | 172 | -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size) |
926de5eb | 173 | if test $# -eq 1; then |
479620b9 | 174 | do_missing_arg $1 |
926de5eb UD |
175 | fi |
176 | shift | |
ba80a015 | 177 | memusagestat_args="$memusagestat_args -x $1" |
926de5eb UD |
178 | ;; |
179 | --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*) | |
ba80a015 | 180 | memusagestat_args="$memusagestat_args -x ${1##*=}" |
926de5eb | 181 | ;; |
479620b9 | 182 | -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size) |
926de5eb | 183 | if test $# -eq 1; then |
479620b9 | 184 | do_missing_arg $1 |
926de5eb UD |
185 | fi |
186 | shift | |
ba80a015 | 187 | memusagestat_args="$memusagestat_args -y $1" |
926de5eb UD |
188 | ;; |
189 | --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*) | |
ba80a015 | 190 | memusagestat_args="$memusagestat_args -y ${1##*=}" |
926de5eb | 191 | ;; |
479620b9 | 192 | --p | --p=* | --t | --t=* | --ti | --ti=* | --u) |
ba80a015 | 193 | echo >&2 $"memusage: option \`${1##*=}' is ambiguous" |
479620b9 | 194 | do_usage |
926de5eb | 195 | ;; |
43fc8f18 UD |
196 | --) |
197 | # Stop processing arguments. | |
198 | shift | |
199 | break | |
200 | ;; | |
479620b9 | 201 | --*) |
ba80a015 | 202 | echo >&2 $"memusage: unrecognized option \`$1'" |
479620b9 UD |
203 | do_usage |
204 | ;; | |
43fc8f18 UD |
205 | *) |
206 | # Unknown option. This means the rest is the program name and parameters. | |
207 | break | |
208 | ;; | |
209 | esac | |
210 | shift | |
211 | done | |
212 | ||
213 | # See whether any arguments are left. | |
479620b9 UD |
214 | if test $# -eq 0; then |
215 | echo >&2 $"No program name given" | |
216 | do_usage | |
43fc8f18 UD |
217 | fi |
218 | ||
219 | # This will be in the environment. | |
ba80a015 | 220 | add_env="LD_PRELOAD=$memusageso" |
43fc8f18 UD |
221 | |
222 | # Generate data file name. | |
b5c6276a | 223 | datafile= |
43fc8f18 UD |
224 | if test -n "$data"; then |
225 | datafile="$data" | |
226 | elif test -n "$png"; then | |
07fb5185 UD |
227 | datafile=$(mktemp -t memusage.XXXXXX) || exit |
228 | trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE | |
43fc8f18 UD |
229 | fi |
230 | if test -n "$datafile"; then | |
ba80a015 | 231 | add_env="$add_env MEMUSAGE_OUTPUT=$datafile" |
43fc8f18 UD |
232 | fi |
233 | ||
c788cd70 UD |
234 | # Set program name. |
235 | if test -n "$progname"; then | |
236 | add_env="$add_env MEMUSAGE_PROG_NAME=$progname" | |
237 | fi | |
238 | ||
926de5eb UD |
239 | # Set buffer size. |
240 | if test -n "$buffer"; then | |
ba80a015 | 241 | add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer" |
926de5eb UD |
242 | fi |
243 | ||
244 | # Disable timers. | |
245 | if test -n "$notimer"; then | |
ba80a015 | 246 | add_env="$add_env MEMUSAGE_NO_TIMER=yes" |
926de5eb UD |
247 | fi |
248 | ||
94eb5b36 UD |
249 | # Trace mmap. |
250 | if test -n "$tracemmap"; then | |
251 | add_env="$add_env MEMUSAGE_TRACE_MMAP=yes" | |
252 | fi | |
253 | ||
43fc8f18 | 254 | # Execute the program itself. |
b5c6276a | 255 | eval $add_env '"$@"' |
43fc8f18 UD |
256 | result=$? |
257 | ||
b5c6276a | 258 | # Generate the PNG data file if wanted and there is something to generate |
43fc8f18 | 259 | # it from. |
b5c6276a | 260 | if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then |
926de5eb | 261 | # Append extension .png if it isn't already there. |
b5c6276a UD |
262 | case $png in |
263 | *.png) ;; | |
264 | *) png="$png.png" ;; | |
265 | esac | |
ba80a015 | 266 | $memusagestat $memusagestat_args "$datafile" "$png" |
43fc8f18 UD |
267 | fi |
268 | ||
b5c6276a UD |
269 | if test -z "$data" -a -n "$datafile"; then |
270 | rm -f "$datafile" | |
43fc8f18 UD |
271 | fi |
272 | ||
273 | exit $result | |
274 | # Local Variables: | |
275 | # mode:ksh | |
276 | # End: |