about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--malloc/memusage.c4
-rw-r--r--malloc/memusagestat.c184
3 files changed, 59 insertions, 133 deletions
diff --git a/ChangeLog b/ChangeLog
index bfae5f6ae9..0f4bcc6ff5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-08-09  Ulrich Drepper  <drepper@redhat.com>
 
+	* malloc/memusage.c (me): Use creat64, not creat.
+	* malloc/memusagestat.c: Fix handling of very large sizes.  [BZ #285]
+	Patch by Guy Maor <guymaor@yahoo.com>.
+
 	* elf/ldconfig.c (options): Mark parameter option names as
 	translatable.  [BZ #253]  Patch by Jakub Bogusz <qboosh@pld-linux.org>.
 
diff --git a/malloc/memusage.c b/malloc/memusage.c
index d5b73f5921..b552ec37b0 100644
--- a/malloc/memusage.c
+++ b/malloc/memusage.c
@@ -1,5 +1,5 @@
 /* Profile heap and stack memory usage of running program.
-   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
@@ -233,7 +233,7 @@ me (void)
       if (outname != NULL && outname[0] != '\0'
 	  && (access (outname, R_OK | W_OK) == 0 || errno == ENOENT))
 	{
-	  fd = creat (outname, 0666);
+	  fd = creat64 (outname, 0666);
 
 	  if (fd == -1)
 	    /* Don't do anything in future calls if we cannot write to
diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c
index fa2d219c36..b1cad9b251 100644
--- a/malloc/memusagestat.c
+++ b/malloc/memusagestat.c
@@ -18,6 +18,8 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#define _FILE_OFFSET_BITS 64
+
 #include <argp.h>
 #include <assert.h>
 #include <errno.h>
@@ -128,6 +130,8 @@ main (int argc, char *argv[])
   uint64_t start_time;
   uint64_t end_time;
   uint64_t total_time;
+  const char *heap_format, *stack_format;
+  int heap_scale, stack_scale, line;
 
   outname = NULL;
   xsize = XSIZE;
@@ -241,13 +245,46 @@ main (int argc, char *argv[])
 
   gdImageRectangle (im_out, 40, 20, xsize - 40, ysize - 20, blue);
 
+  if (maxsize_heap < 1024)
+    {
+      heap_format = "%Zu";
+      heap_scale = 1;
+    }
+  else if (maxsize_heap < 1024 * 1024 * 100)
+    {
+      heap_format = "%Zuk";
+      heap_scale = 1024;
+    }
+  else
+    {
+      heap_format = "%ZuM";
+      heap_scale = 1024 * 1024;
+    }
+
+  if (maxsize_stack < 1024)
+    {
+      stack_format = "%Zu";
+      stack_scale = 1;
+    }
+  else if (maxsize_stack < 1024 * 1024 * 100)
+    {
+      stack_format = "%Zuk";
+      stack_scale = 1024;
+    }
+  else
+    {
+      stack_format = "%ZuM";
+      stack_scale = 1024 * 1024;
+    }
+
   gdImageString (im_out, gdFontSmall, 38, ysize - 14, (unsigned char *) "0",
 		 blue);
+  snprintf(buf, sizeof (buf), heap_format, 0);
   gdImageString (im_out, gdFontSmall, maxsize_heap < 1024 ? 32 : 26,
-		 ysize - 26,
-		 (unsigned char *) (maxsize_heap < 1024 ? "0" : "0k"), red);
+		 ysize - 26, buf, red);
+  snprintf(buf, sizeof (buf), stack_format, 0);
   gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26,
-		 (unsigned char *) (maxsize_stack < 1024 ? "0" : "0k"), green);
+		 buf, green);
 
   if (string != NULL)
     gdImageString (im_out, gdFontLarge, (xsize - strlen (string) * 8) / 2,
@@ -263,148 +300,33 @@ main (int argc, char *argv[])
   gdImageStringUp (im_out, gdFontSmall, xsize - 27, ysize / 2 - 10,
 		   (unsigned char *) "stack", green);
 
-  if (maxsize_heap < 1024)
-    {
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_heap);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, 14, buf, red);
-    }
-  else
-    {
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_heap / 1024);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, 14, buf, red);
-    }
-  if (maxsize_stack < 1024)
-    {
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_stack);
-      gdImageString (im_out, gdFontSmall, xsize - 37, 14, buf, green);
-    }
-  else
-    {
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_stack / 1024);
-      gdImageString (im_out, gdFontSmall, xsize - 37, 14, buf, green);
-    }
+  snprintf (buf, sizeof (buf), heap_format, maxsize_heap / heap_scale);
+  gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, 14, buf, red);
+  snprintf (buf, sizeof (buf), stack_format, maxsize_stack / stack_scale);
+  gdImageString (im_out, gdFontSmall, xsize - 37, 14, buf, green);
 
-
-  if (maxsize_heap < 1024)
-    {
-      cnt = ((ysize - 40) * (maxsize_heap / 4)) / maxsize_heap;
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_heap / 4);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, buf, red);
-    }
-  else
+  for (line = 1; line <= 3; ++line)
     {
-      cnt = ((ysize - 40) * (maxsize_heap / 4096)) / (maxsize_heap / 1024);
+      cnt = ((ysize - 40) * (maxsize_heap / 4 * line / heap_scale)) /
+	(maxsize_heap / heap_scale);
       gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
 			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_heap / 4096);
+      snprintf (buf, sizeof (buf), heap_format, maxsize_heap / 4 * line / 
+		heap_scale);
       gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
 		     ysize - 26 - cnt, buf, red);
-    }
-  if (maxsize_stack < 1024)
-    {
-      cnt2 = ((ysize - 40) * (maxsize_stack / 4)) / maxsize_stack;
-      if (cnt != cnt2)
-	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
-			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_stack / 4);
-      gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
-		     buf, green);
-    }
-  else
-    {
-      cnt2 = ((ysize - 40) * (maxsize_stack / 4096)) / (maxsize_stack / 1024);
-      if (cnt != cnt2)
-	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
-			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_stack / 4096);
-      gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
-		     buf, green);
-    }
 
-  if (maxsize_heap < 1024)
-    {
-      cnt = ((ysize - 40) * (maxsize_heap / 2)) / maxsize_heap;
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_heap / 2);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, buf, red);
-    }
-  else
-    {
-      cnt = ((ysize - 40) * (maxsize_heap / 2048)) / (maxsize_heap / 1024);
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_heap / 2048);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, buf, red);
-    }
-  if (maxsize_stack < 1024)
-    {
-      cnt2 = ((ysize - 40) * (maxsize_stack / 2)) / maxsize_stack;
-      if (cnt != cnt2)
-	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
-			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zu", maxsize_stack / 2);
-      gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
-		     buf, green);
-    }
-  else
-    {
-      cnt2 = ((ysize - 40) * (maxsize_stack / 2048)) / (maxsize_stack / 1024);
-      if (cnt != cnt2)
-	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
-			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zuk", maxsize_stack / 2048);
-      gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
-		     buf, green);
-    }
-
-  if (maxsize_heap < 1024)
-    {
-      cnt = ((ysize - 40) * ((3 * maxsize_heap) / 4)) / maxsize_heap;
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zu", (3 * maxsize_heap) / 4);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, buf, red);
-    }
-  else
-    {
-      cnt = ((ysize - 40) * ((3 * maxsize_heap) / 4096)) / (maxsize_heap
-							    / 1024);
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), "%Zuk", (3 * maxsize_heap) / 4096);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, buf, red);
-    }
-  if (maxsize_stack < 1024)
-    {
-      cnt2 = ((ysize - 40) * ((3 * maxsize_stack) / 4)) / maxsize_stack;
-      if (cnt != cnt2)
-	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
-			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zu", (3 * maxsize_stack) / 4);
-      gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
-		     buf, green);
-    }
-  else
-    {
-      cnt2 = (((ysize - 40) * ((3 * maxsize_stack) / 4096))
-	      / (maxsize_stack / 1024));
+      cnt2 = ((ysize - 40) * (maxsize_stack / 4 * line / stack_scale)) /
+	(maxsize_stack / stack_scale);
       if (cnt != cnt2)
 	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
 			   ysize - 20 - cnt2, green);
-      snprintf (buf, sizeof (buf), "%Zuk", (3 * maxsize_stack) / 4096);
+      snprintf (buf, sizeof (buf), stack_format, maxsize_stack / 4 * line /
+		stack_scale);
       gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2,
 		     buf, green);
     }
 
-
   snprintf (buf, sizeof (buf), "%llu", (unsigned long long) total);
   gdImageString (im_out, gdFontSmall, xsize - 50, ysize - 14, buf, blue);