This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch gas]: Make 'as -statistics' print a believable value of "data size"
- From: Simon Baldwin <simonb at google dot com>
- To: binutils at sourceware dot org
- Date: Fri, 19 Oct 2012 13:23:59 +0200
- Subject: [patch gas]: Make 'as -statistics' print a believable value of "data size"
Make 'as -statistics' print a believable value of "data size".
Currently 'as -statistics' prints a "data size" that is the difference
between the final sbrk(0) and &environ. This value is essentially random.
This patch updates as.c to instead use the difference between the final and
the intial sbrk(0). This may still not be accurate (malloc may allocate
with mmap, allocation might exceed the range of long, mallinfo would be
better), but it is a cheap and relatively non-invasive improvement.
Tested for x86_64. Comparative results shown below. OK?
If yes, there is another instance of this in bfd ld that would benefit from
the same treatment.
Test results:
for i in $(seq 1 10); do
build_before/gas/as-new -statistics </dev/null 2>&1 | grep 'data size'
done
build_before/gas/as-new: data size 21727136
build_before/gas/as-new: data size 11524000
build_before/gas/as-new: data size 1677216
build_before/gas/as-new: data size 460704
build_before/gas/as-new: data size 30205856
build_before/gas/as-new: data size 20223904
build_before/gas/as-new: data size 29267872
build_before/gas/as-new: data size 11868064
build_before/gas/as-new: data size 6870944
build_before/gas/as-new: data size 21362592
for i in $(seq 1 10); do
build_after/gas/as-new -statistics </dev/null 2>&1 | grep 'data size'
done
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
build_after/gas/as-new: data size 270336
gas/ChangeLog
2012-10-19 Simon Baldwin <simonb@google.com>
* as.c (dump_statistics): Compute data size as the delta between
current sbrk(0) and start_sbrk.
* (main): Set start_sbrk to sbrk(0) on entry.
Index: gas/as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.102
diff -u -p -r1.102 as.c
--- gas/as.c 7 Jun 2012 12:47:23 -0000 1.102
+++ gas/as.c 19 Oct 2012 11:05:17 -0000
@@ -124,6 +124,9 @@ static struct itbl_file_list *itbl_files
#endif
static long start_time;
+#ifdef HAVE_SBRK
+char *start_sbrk;
+#endif
static int flag_macro_alternate;
@@ -975,7 +978,7 @@ dump_statistics (void)
myname, run_time / 1000000, run_time % 1000000);
#ifdef HAVE_SBRK
fprintf (stderr, _("%s: data size %ld\n"),
- myname, (long) (lim - (char *) &environ));
+ myname, (long) (lim - start_sbrk));
#endif
subsegs_print_statistics (stderr);
@@ -1135,6 +1138,9 @@ main (int argc, char ** argv)
int macro_strip_at;
start_time = get_run_time ();
+#ifdef HAVE_SBRK
+ start_sbrk = (char *) sbrk (0);
+#endif
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
setlocale (LC_MESSAGES, "");
--
Google UK Limited | Registered Office: Belgrave House, 76 Buckingham
Palace Road, London SW1W 9TQ | Registered in England Number: 3977902