Files
glibc/malloc/memusage.sh
T

273 lines
7.5 KiB
Bash
Raw Normal View History

1999-10-05 01:55:45 +00:00
#! @BASH@
2004-01-01 20:42:01 +00:00
# Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
1999-10-05 01:55:45 +00:00
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@gnu.org>, 1999.
# The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
1999-10-05 01:55:45 +00:00
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
# Lesser General Public License for more details.
1999-10-05 01:55:45 +00:00
2001-07-06 04:58:11 +00:00
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
1999-10-05 01:55:45 +00:00
2001-04-04 00:01:02 +00:00
memusageso=@SLIBDIR@/libmemusage.so
2000-06-20 04:46:22 +00:00
memusagestat=@BINDIR@/memusagestat
2004-01-01 20:42:01 +00:00
TEXTDOMAIN=libc
1999-10-05 01:55:45 +00:00
# Print usage message.
do_usage() {
2000-06-20 04:46:22 +00:00
echo >&2 $"Try \`memusage --help' for more information."
1999-10-05 01:55:45 +00:00
exit 1
}
1999-10-05 06:32:59 +00:00
# Message for missing argument.
do_missing_arg() {
2000-06-20 04:46:22 +00:00
echo >&2 $"memusage: option \`$1' requires an argument"
1999-10-05 06:32:59 +00:00
do_usage
}
# Print help message
1999-10-05 01:55:45 +00:00
do_help() {
2000-06-20 04:46:22 +00:00
echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
1999-10-05 05:32:24 +00:00
Profile memory usage of PROGRAM.
1999-10-05 06:32:59 +00:00
-n,--progname=NAME Name of the program file to profile
-p,--png=FILE Generate PNG graphic and store it in FILE
-d,--data=FILE Generate binary data file and store it in FILE
-u,--unbuffered Don't buffer output
-b,--buffer=SIZE Collect SIZE entries before writing them out
--no-timer Don't collect additional information though timer
2002-05-01 19:15:46 +00:00
-m,--mmap Also trace mmap & friends
1999-10-05 06:32:59 +00:00
-?,--help Print this help and exit
--usage Give a short usage message
-V,--version Print version information and exit
The following options only apply when generating graphical output:
-t,--time-based Make graph linear in time
-T,--total Also draw graph of total memory use
--title=STRING Use STRING as title of the graph
-x,--x-size=SIZE Make graphic SIZE pixels wide
-y,--y-size=SIZE Make graphic SIZE pixels high
Mandatory arguments to long options are also mandatory for any corresponding
short options.
1999-10-05 05:32:24 +00:00
2004-05-17 18:59:35 +00:00
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>."
1999-10-05 01:55:45 +00:00
exit 0
}
do_version() {
2000-06-20 04:46:22 +00:00
echo 'memusage (GNU libc) @VERSION@'
2004-01-01 20:42:01 +00:00
printf $"Copyright (C) %s Free Software Foundation, Inc.
1999-10-05 01:55:45 +00:00
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2004-01-01 20:42:01 +00:00
" "2004"
printf $"Written by %s.
" "Ulrich Drepper"
1999-10-05 01:55:45 +00:00
exit 0
}
# Process arguments. But stop as soon as the program name is found.
while test $# -gt 0; do
case "$1" in
1999-10-05 06:32:59 +00:00
-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
1999-10-05 01:55:45 +00:00
do_version
;;
1999-10-05 06:32:59 +00:00
-\? | --h | --he | --hel | --help)
1999-10-05 01:55:45 +00:00
do_help
;;
1999-10-05 06:32:59 +00:00
--us | --usa | --usag | --usage)
2000-06-20 04:46:22 +00:00
echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
1999-10-05 06:32:59 +00:00
[--buffer=SIZE] [--no-timer] [--time-based] [--total]
[--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
PROGRAM [PROGRAMOPTION]..."
exit 0
;;
-n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
1999-10-05 01:55:45 +00:00
progname="$1"
;;
1999-10-05 05:32:24 +00:00
--pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=*)
progname=${1##*=}
;;
1999-10-05 06:32:59 +00:00
-p | --pn | --png)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
1999-10-05 01:55:45 +00:00
png="$1"
;;
1999-10-05 05:32:24 +00:00
--pn=* | --png=*)
png=${1##*=}
;;
1999-10-05 06:32:59 +00:00
-d | --d | --da | --dat | --data)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
1999-10-05 01:55:45 +00:00
data="$1"
;;
1999-10-05 05:32:24 +00:00
--d=* | --da=* | --dat=* | --data=*)
data=${1##*=}
;;
1999-10-05 06:32:59 +00:00
-u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered)
1999-10-05 05:32:24 +00:00
buffer=1
;;
1999-10-05 06:32:59 +00:00
-b | --b | --bu | --buf | --buff | --buffe | --buffer)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
buffer="$1"
;;
--b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=*)
buffer=${1##*=}
;;
--n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
notimer=yes
;;
2002-05-01 19:15:46 +00:00
-m | --m | --mm | --mma | --mmap)
tracemmap=yes
;;
1999-10-05 06:32:59 +00:00
-t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -t"
1999-10-05 05:32:24 +00:00
;;
1999-10-05 06:32:59 +00:00
-T | --to | --tot | --tota | --total)
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -T"
1999-10-05 05:32:24 +00:00
;;
--tit | --titl | --title)
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -s $1"
1999-10-05 05:32:24 +00:00
;;
--tit=* | --titl=* | --title=*)
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -s ${1##*=}"
1999-10-05 05:32:24 +00:00
;;
1999-10-05 06:32:59 +00:00
-x | --x | --x- | --x-s | --x-si | --x-siz | --x-size)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -x $1"
1999-10-05 05:32:24 +00:00
;;
--x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=*)
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -x ${1##*=}"
1999-10-05 05:32:24 +00:00
;;
1999-10-05 06:32:59 +00:00
-y | --y | --y- | --y-s | --y-si | --y-siz | --y-size)
1999-10-05 05:32:24 +00:00
if test $# -eq 1; then
1999-10-05 06:32:59 +00:00
do_missing_arg $1
1999-10-05 05:32:24 +00:00
fi
shift
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -y $1"
1999-10-05 05:32:24 +00:00
;;
--y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=*)
2000-06-20 04:46:22 +00:00
memusagestat_args="$memusagestat_args -y ${1##*=}"
1999-10-05 05:32:24 +00:00
;;
1999-10-05 06:32:59 +00:00
--p | --p=* | --t | --t=* | --ti | --ti=* | --u)
2000-06-20 04:46:22 +00:00
echo >&2 $"memusage: option \`${1##*=}' is ambiguous"
1999-10-05 06:32:59 +00:00
do_usage
1999-10-05 05:32:24 +00:00
;;
1999-10-05 01:55:45 +00:00
--)
# Stop processing arguments.
shift
break
;;
1999-10-05 06:32:59 +00:00
--*)
2000-06-20 04:46:22 +00:00
echo >&2 $"memusage: unrecognized option \`$1'"
1999-10-05 06:32:59 +00:00
do_usage
;;
1999-10-05 01:55:45 +00:00
*)
# Unknown option. This means the rest is the program name and parameters.
break
;;
esac
shift
done
# See whether any arguments are left.
1999-10-05 06:32:59 +00:00
if test $# -eq 0; then
echo >&2 $"No program name given"
do_usage
1999-10-05 01:55:45 +00:00
fi
# This will be in the environment.
2000-06-20 04:46:22 +00:00
add_env="LD_PRELOAD=$memusageso"
1999-10-05 01:55:45 +00:00
# Generate data file name.
1999-10-08 17:16:17 +00:00
datafile=
1999-10-05 01:55:45 +00:00
if test -n "$data"; then
datafile="$data"
elif test -n "$png"; then
2000-06-20 04:46:22 +00:00
datafile=$(mktemp ${TMPDIR:-/tmp}/memusage.XXXXXX 2> /dev/null)
1999-10-05 01:55:45 +00:00
if test $? -ne 0; then
# Lame, but if there is no `mktemp' program the user cannot expect more.
1999-10-05 06:32:59 +00:00
if test "$RANDOM" != "$RANDOM"; then
2000-06-20 04:46:22 +00:00
datafile=${TMPDIR:-/tmp}/memusage.$RANDOM
1999-10-05 06:32:59 +00:00
else
2000-06-20 04:46:22 +00:00
datafile=${TMPDIR:-/tmp}/memusage.$$
1999-10-05 06:32:59 +00:00
fi
1999-10-05 01:55:45 +00:00
fi
fi
if test -n "$datafile"; then
2000-06-20 04:46:22 +00:00
add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
1999-10-05 01:55:45 +00:00
fi
2001-09-20 19:06:30 +00:00
# Set program name.
if test -n "$progname"; then
add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
fi
1999-10-05 05:32:24 +00:00
# Set buffer size.
if test -n "$buffer"; then
2000-06-20 04:46:22 +00:00
add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
1999-10-05 05:32:24 +00:00
fi
# Disable timers.
if test -n "$notimer"; then
2000-06-20 04:46:22 +00:00
add_env="$add_env MEMUSAGE_NO_TIMER=yes"
1999-10-05 05:32:24 +00:00
fi
2002-05-01 19:15:46 +00:00
# Trace mmap.
if test -n "$tracemmap"; then
add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
fi
1999-10-05 01:55:45 +00:00
# Execute the program itself.
1999-10-08 17:16:17 +00:00
eval $add_env '"$@"'
1999-10-05 01:55:45 +00:00
result=$?
1999-10-08 17:16:17 +00:00
# Generate the PNG data file if wanted and there is something to generate
1999-10-05 01:55:45 +00:00
# it from.
1999-10-08 17:16:17 +00:00
if test -n "$png" -a -n "$datafile" -a -s "$datafile"; then
1999-10-05 05:32:24 +00:00
# Append extension .png if it isn't already there.
1999-10-08 17:16:17 +00:00
case $png in
*.png) ;;
*) png="$png.png" ;;
esac
2000-06-20 04:46:22 +00:00
$memusagestat $memusagestat_args "$datafile" "$png"
1999-10-05 01:55:45 +00:00
fi
1999-10-08 17:16:17 +00:00
if test -z "$data" -a -n "$datafile"; then
rm -f "$datafile"
1999-10-05 01:55:45 +00:00
fi
exit $result
# Local Variables:
# mode:ksh
# End: