#! @BASH@ # Copyright (C) 1999-2016 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Contributed by Ulrich Drepper , 1999. # The GNU C Library is free software; you can redistribute it and/or # 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. # 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 # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with the GNU C Library; if not, see # . setglobal memusageso = ''@SLIBDIR@/libmemusage.so'' setglobal memusagestat = ''@BINDIR@/memusagestat'' setglobal TEXTDOMAIN = 'libc' # Print usage message. proc do_usage { printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage> !2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage exit 1 } # Message for missing argument. proc do_missing_arg { printf >&2 $"%s: option '%s' requires an argument\n" memusage $1> !2 $"%s: option '%s' requires an argument\n" memusage "$1" do_usage } # Print help message proc do_help { echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]... Profile memory usage of PROGRAM. -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 through timer -m,--mmap Also trace mmap & friends -?,--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. " printf $"For bug reporting instructions, please see:\\n%s.\\n" \ "@REPORT_BUGS_TO@" exit 0 } proc do_version { echo 'memusage @PKGVERSION@@VERSION@' printf $"Copyright (C) %s Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " "2016" printf $"Written by %s. " "Ulrich Drepper" exit 0 } # These variables are local setglobal buffer = '' setglobal data = '' setglobal memusagestat_args = '' setglobal notimer = '' setglobal png = '' setglobal progname = '' setglobal tracemmap = '' # Process arguments. But stop as soon as the program name is found. while test $Argc -gt 0 { match $1 { with -V | --v | --ve | --ver | --vers | --versi | --versio | --version do_version with -\? | --h | --he | --hel | --help do_help with --us | --usa | --usag | --usage echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered] [--buffer=SIZE] [--no-timer] [--time-based] [--total] [--title=STRING] [--x-size=SIZE] [--y-size=SIZE] PROGRAM [PROGRAMOPTION]..." exit 0 with -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal progname = $1 with --pr=* | --pro=* | --prog=* | --progn=* | --progna=* | --prognam=* | --progname=* setglobal progname = $(1##*=) with -p | --pn | --png if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal png = $1 with --pn=* | --png=* setglobal png = $(1##*=) with -d | --d | --da | --dat | --data if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal data = $1 with --d=* | --da=* | --dat=* | --data=* setglobal data = $(1##*=) with -u | --un | --unb | --unbu | --unbuf | --unbuff | --unbuffe | --unbuffer | --unbuffere | --unbuffered setglobal buffer = '1' with -b | --b | --bu | --buf | --buff | --buffe | --buffer if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal buffer = $1 with --b=* | --bu=* | --buf=* | --buff=* | --buffe=* | --buffer=* setglobal buffer = $(1##*=) with --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer setglobal notimer = 'yes' with -m | --m | --mm | --mma | --mmap setglobal tracemmap = 'yes' with -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based setglobal memusagestat_args = ""$memusagestat_args -t"" with -T | --to | --tot | --tota | --total setglobal memusagestat_args = ""$memusagestat_args -T"" with --tit | --titl | --title if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal memusagestat_args = ""$memusagestat_args -s $1"" with --tit=* | --titl=* | --title=* setglobal memusagestat_args = ""$memusagestat_args -s $(1##*=)"" with -x | --x | --x- | --x-s | --x-si | --x-siz | --x-size if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal memusagestat_args = ""$memusagestat_args -x $1"" with --x=* | --x-=* | --x-s=* | --x-si=* | --x-siz=* | --x-size=* setglobal memusagestat_args = ""$memusagestat_args -x $(1##*=)"" with -y | --y | --y- | --y-s | --y-si | --y-siz | --y-size if test $Argc -eq 1 { do_missing_arg $1 } shift setglobal memusagestat_args = ""$memusagestat_args -y $1"" with --y=* | --y-=* | --y-s=* | --y-si=* | --y-siz=* | --y-size=* setglobal memusagestat_args = ""$memusagestat_args -y $(1##*=)"" with --p | --p=* | --t | --t=* | --ti | --ti=* | --u echo >&2 $"memusage: option \`$(1##*=)' is ambiguous> !2 $"memusage: option \`${1##*=}' is ambiguous" do_usage with -- # Stop processing arguments. shift break with --* echo >&2 $"memusage: unrecognized option \`$1'> !2 $"memusage: unrecognized option \`$1'" do_usage with * # Unknown option. This means the rest is the program name and parameters. break } shift } # See whether any arguments are left. if test $Argc -eq 0 { echo >&2 $"No program name given> !2 $"No program name given" do_usage } # This will be in the environment. setglobal add_env = ""LD_PRELOAD=$memusageso"" # Generate data file name. setglobal datafile = '' if test -n $data { setglobal datafile = $data } elif test -n $png { setglobal datafile = $[mktemp -t memusage.XXXXXX] || exit trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE } if test -n $datafile { setglobal add_env = ""$add_env MEMUSAGE_OUTPUT=$datafile"" } # Set program name. if test -n $progname { setglobal add_env = ""$add_env MEMUSAGE_PROG_NAME=$progname"" } # Set buffer size. if test -n $buffer { setglobal add_env = ""$add_env MEMUSAGE_BUFFER_SIZE=$buffer"" } # Disable timers. if test -n $notimer { setglobal add_env = ""$add_env MEMUSAGE_NO_TIMER=yes"" } # Trace mmap. if test -n $tracemmap { setglobal add_env = ""$add_env MEMUSAGE_TRACE_MMAP=yes"" } # Execute the program itself. eval $add_env '"$@"' setglobal result = $Status # Generate the PNG data file if wanted and there is something to generate # it from. if test -n $png -a -n $datafile -a -s $datafile { # Append extension .png if it isn't already there. match $png { with *.png with * setglobal png = ""$png.png"" } $memusagestat $memusagestat_args $datafile $png } if test -z $data -a -n $datafile { rm -f $datafile } exit $result # Local Variables: # mode:ksh # End: