1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: memusageso='@SLIBDIR@/libmemusage.so'
22: memusagestat='@BINDIR@/memusagestat'
23: TEXTDOMAIN=libc
24:
25:
26: do_usage() {
27: echo >&2 $"Try \`memusage --help' for more information."
28: exit 1
29: }
30:
31:
32: do_missing_arg() {
33: echo >&2 $"memusage: option \`$1' requires an argument"
34: do_usage
35: }
36:
37:
38: do_help() {
39: echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
40: Profile memory usage of PROGRAM.
41:
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
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:
64: For bug reporting instructions, please see:
65: <http://www.gnu.org/software/libc/bugs.html>."
66: exit 0
67: }
68:
69: do_version() {
70: echo 'memusage (GNU libc) @VERSION@'
71: printf $"Copyright (C) %s Free Software Foundation, Inc.
72: This is free software; see the source for copying conditions. There is NO
73: warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74: " "2007"
75: printf $"Written by %s.
76: " "Ulrich Drepper"
77: exit 0
78: }
79:
80:
81: buffer=
82: data=
83: memusagestat_args=
84: notimer=
85: png=
86: progname=
87: tracemmap=
88:
89:
90: while test $# -gt 0; do
91: case "$1" in
92: -V | --v | --ve | --ver | --vers | --versi | --versio | --version)
93: do_version
94: ;;
95: -\? | --h | --he | --hel | --help)
96: do_help
97: ;;
98: --us | --usa | --usag | --usage)
99: echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
100: [--buffer=SIZE] [--no-timer] [--time-based] [--total]
101: [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
102: PROGRAM [PROGRAMOPTION]..."
103: exit 0
104: ;;
105: -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
106: if test $# -eq 1; then
107: do_missing_arg $1
108: fi
109: shift
110: progname="$1"
111: ;;
112: --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
113: progname=${1##*=}
114: ;;
115: -p | --pn | --png)
116: if test $# -eq 1; then
117: do_missing_arg $1
118: fi
119: shift
120: png="$1"
121: ;;
122: --pn=* | --png=*)
123: png=${1##*=}
124: ;;
125: -d | --d | --da | --dat | --data)
126: if test $# -eq 1; then
127: do_missing_arg $1
128: fi
129: shift
130: data="$1"
131: ;;
132: --d=* | --da=* | --dat=* | --data=*)
133: data=${1##*=}
134: ;;
135: -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
136: buffer=1
137: ;;
138: -b | --b | --bu | --buf | --buff | --buffe | --buffer)
139: if test $# -eq 1; then
140: do_missing_arg $1
141: fi
142: shift
143: buffer="$1"
144: ;;
145: --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
146: buffer=${1##*=}
147: ;;
148: --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
149: notimer=yes
150: ;;
151: -m | --m | --mm | --mma | --mmap)
152: tracemmap=yes
153: ;;
154: -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
155: memusagestat_args="$memusagestat_args -t"
156: ;;
157: -T | --to | --tot | --tota | --total)
158: memusagestat_args="$memusagestat_args -T"
159: ;;
160: --tit | --titl | --title)
161: if test $# -eq 1; then
162: do_missing_arg $1
163: fi
164: shift
165: memusagestat_args="$memusagestat_args -s $1"
166: ;;
167: --tit=* | --titl=* | --title=*)
168: memusagestat_args="$memusagestat_args -s ${1##*=}"
169: ;;
170: -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
171: if test $# -eq 1; then
172: do_missing_arg $1
173: fi
174: shift
175: memusagestat_args="$memusagestat_args -x $1"
176: ;;
177: --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
178: memusagestat_args="$memusagestat_args -x ${1##*=}"
179: ;;
180: -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
181: if test $# -eq 1; then
182: do_missing_arg $1
183: fi
184: shift
185: memusagestat_args="$memusagestat_args -y $1"
186: ;;
187: --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
188: memusagestat_args="$memusagestat_args -y ${1##*=}"
189: ;;
190: --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
191: echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
192: do_usage
193: ;;
194: --)
195:
196: shift
197: break
198: ;;
199: --*)
200: echo >&2 $"memusage: unrecognized option \`$1'"
201: do_usage
202: ;;
203: *)
204:
205: break
206: ;;
207: esac
208: shift
209: done
210:
211:
212: if test $# -eq 0; then
213: echo >&2 $"No program name given"
214: do_usage
215: fi
216:
217:
218: add_env="LD_PRELOAD=$memusageso"
219:
220:
221: datafile=
222: if test -n "$data"; then
223: datafile="$data"
224: elif test -n "$png"; then
225: datafile=$(mktemp -t memusage.XXXXXX) || exit
226: trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
227: fi
228: if test -n "$datafile"; then
229: add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
230: fi
231:
232:
233: if test -n "$progname"; then
234: add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
235: fi
236:
237:
238: if test -n "$buffer"; then
239: add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
240: fi
241:
242:
243: if test -n "$notimer"; then
244: add_env="$add_env MEMUSAGE_NO_TIMER=yes"
245: fi
246:
247:
248: if test -n "$tracemmap"; then
249: add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
250: fi
251:
252:
253: eval $add_env '"$@"'
254: result=$?
255:
256:
257:
258: if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
259:
260: case $png in
261: *.png) ;;
262: *) png="$png.png" ;;
263: esac
264: $memusagestat $memusagestat_args "$datafile" "$png"
265: fi
266:
267: if test -z "$data" -a -n "$datafile"; then
268: rm -f "$datafile"
269: fi
270:
271: exit $result
272:
273:
274: