]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - malloc/memusage.sh
Use relaxed atomics for malloc have_fastchunks
[thirdparty/glibc.git] / malloc / memusage.sh
index 1268f8879a589dcae159da588153cad41b998117..93ece87a31979b54607f8e874a0d60e44477052d 100755 (executable)
@@ -1,35 +1,35 @@
 #! @BASH@
-# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
 # 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
-# modify it under the terms of the GNU Library General Public License as
-# published by the Free Software Foundation; either version 2 of the
-# License, or (at your option) any later version.
+# 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
-# Library General Public License for more details.
+# Lesser General Public License for more details.
 
-# You should have received a copy of the GNU Library General Public
-# License along with the GNU C Library; see the file COPYING.LIB.  If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
 
-memusageso=@SLIBDIR@/libmemusage.so
-memusagestat=@BINDIR@/memusagestat
+memusageso='@SLIBDIR@/libmemusage.so'
+memusagestat='@BINDIR@/memusagestat'
+TEXTDOMAIN=libc
 
 # Print usage message.
 do_usage() {
-  echo >&2 $"Try \`memusage --help' for more information."
+  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
   exit 1
 }
 
 # Message for missing argument.
 do_missing_arg() {
-  echo >&2 $"memusage: option \`$1' requires an argument"
+  printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1"
   do_usage
 }
 
@@ -43,7 +43,8 @@ Profile memory usage of PROGRAM.
    -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
+      --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
@@ -59,19 +60,32 @@ Profile memory usage of PROGRAM.
 Mandatory arguments to long options are also mandatory for any corresponding
 short options.
 
-Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
+"
+  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+    "@REPORT_BUGS_TO@"
   exit 0
 }
 
 do_version() {
-  echo 'memusage (GNU libc) @VERSION@'
-  echo $"Copyright (C) 2001 Free Software Foundation, Inc.
+  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.
-Written by Ulrich Drepper."
+" "2017"
+  printf $"Written by %s.
+" "Ulrich Drepper"
   exit 0
 }
 
+# These variables are local
+buffer=
+data=
+memusagestat_args=
+notimer=
+png=
+progname=
+tracemmap=
+
 # Process arguments.  But stop as soon as the program name is found.
 while test $# -gt 0; do
   case "$1" in
@@ -83,9 +97,9 @@ while test $# -gt 0; do
     ;;
   --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]..."
+           [--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)
@@ -134,6 +148,9 @@ while test $# -gt 0; do
   --n | --no | --no- | --no-t | --no-ti | --no-tim | --no-time | --no-timer)
     notimer=yes
     ;;
+  -m | --m | --mm | --mma | --mmap)
+    tracemmap=yes
+    ;;
   -t | --tim | --time | --time- | --time-b | --time-ba | --time-bas | --time-base | --time-based)
     memusagestat_args="$memusagestat_args -t"
     ;;
@@ -205,20 +222,18 @@ datafile=
 if test -n "$data"; then
   datafile="$data"
 elif test -n "$png"; then
-  datafile=$(mktemp ${TMPDIR:-/tmp}/memusage.XXXXXX 2> /dev/null)
-  if test $? -ne 0; then
-    # Lame, but if there is no `mktemp' program the user cannot expect more.
-    if test "$RANDOM" != "$RANDOM"; then
-      datafile=${TMPDIR:-/tmp}/memusage.$RANDOM
-    else
-      datafile=${TMPDIR:-/tmp}/memusage.$$
-    fi
-  fi
+  datafile=$(mktemp -t memusage.XXXXXX) || exit
+  trap 'rm -f "$datafile"; exit 1' HUP INT QUIT TERM PIPE
 fi
 if test -n "$datafile"; then
   add_env="$add_env MEMUSAGE_OUTPUT=$datafile"
 fi
 
+# Set program name.
+if test -n "$progname"; then
+  add_env="$add_env MEMUSAGE_PROG_NAME=$progname"
+fi
+
 # Set buffer size.
 if test -n "$buffer"; then
   add_env="$add_env MEMUSAGE_BUFFER_SIZE=$buffer"
@@ -229,6 +244,11 @@ if test -n "$notimer"; then
   add_env="$add_env MEMUSAGE_NO_TIMER=yes"
 fi
 
+# Trace mmap.
+if test -n "$tracemmap"; then
+  add_env="$add_env MEMUSAGE_TRACE_MMAP=yes"
+fi
+
 # Execute the program itself.
 eval $add_env '"$@"'
 result=$?