[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patches] Add MEMUSAGE option group



Joseph S. Myers wrote:
On Tue, 18 Aug 2009, Maxim Kuvyrkov wrote:

Hello Joseph,

The attached patch adds new option group OPTION_EGLIBC_MEMUSAGE, which
controls build and installation of libmemusage library.  This library is  of
no use for certain systems, hence the option.

I believe the same option group should also control the memusage and memusagestat executables (i.e., if the library is disabled then those executables should be disabled as well).

Sorry for delay, I've got side-tracked by the other projects.

Here is a fixed patch that also disables build of memusage and memusagestat utilities when OPTION_EGLIBC_MEMUSAGE is not selected. Tested both natively (i686) and by cross-compiling.

OK to check in?

Thank you,

--
Maxim Kuvyrkov
CodeSourcery
maxim@xxxxxxxxxxxxxxxx
(650) 331-3385 x724
2009-08-18  Maxim Kuvyrkov  <maxim@xxxxxxxxxxxxxxxx>

	Add OPTION_EGLIBC_MEMUSAGE option group and
	OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE option.

	* option-groups.def (OPTION_EGLIBC_MEMUSAGE): Define new option group.
	(OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE): Document option.
	* option-groups.defaults (OPTION_EGLIBC_MEMUSAGE): Add.
	* malloc/Makefile (libmemusage): Build if option group is selected.
	(memusage): Update CPPFLAGS.
	(memusagestat): Don't build without OPTION_EGLIBC_MEMUSAGE.
	* malloc/memusage.c (DEFAULT_BUFFER_SIZE): Allow overriding the default.

 malloc/Makefile        |   10 +++++++++-
 malloc/memusage.c      |    8 +++++++-
 option-groups.def      |   19 +++++++++++++++++++
 option-groups.defaults |    1 +
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/malloc/Makefile b/malloc/Makefile
index c033875..1ba3972 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -20,6 +20,8 @@
 #
 #	Makefile for malloc routines
 #
+include ../option-groups.mak
+
 subdir	:= malloc
 
 all:
@@ -43,9 +45,15 @@ install-lib := libmcheck.a
 non-lib.a := libmcheck.a
 
 # Additional library.
+ifeq ($(OPTION_EGLIBC_MEMUSAGE),y)
 extra-libs = libmemusage
 extra-libs-others = $(extra-libs)
 
+ifdef OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE
+CPPFLAGS-memusage += -D__OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE=$(OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE)
+endif
+endif
+
 libmemusage-routines = memusage
 libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
 
@@ -76,7 +84,7 @@ endif
 # Unless we get a test for the availability of libgd which also works
 # for cross-compiling we disable the memusagestat generation in this
 # situation.
-ifneq ($(cross-compiling),yes)
+ifeq ($(cross-compiling)$(OPTION_EGLIBC_MEMUSAGE),noy)
 # If the gd library is available we build the `memusagestat' program.
 ifneq ($(LIBGD),no)
 others: $(objpfx)memusage
diff --git a/malloc/memusage.c b/malloc/memusage.c
index 382261c..68f9a3d 100644
--- a/malloc/memusage.c
+++ b/malloc/memusage.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/time.h>
+#include <gnu/option-groups.h>
 
 #include <memusage.h>
 
@@ -93,7 +94,12 @@ static __thread uintptr_t start_sp;
 #define peak_stack	peak_use[1]
 #define peak_total	peak_use[2]
 
-#define DEFAULT_BUFFER_SIZE	32768
+#ifndef __OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE
+# define DEFAULT_BUFFER_SIZE	32768
+#else
+# define DEFAULT_BUFFER_SIZE	__OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE
+#endif
+
 static size_t buffer_size;
 
 static int fd = -1;
diff --git a/option-groups.def b/option-groups.def
index 26ef4bb..1c2ee37 100644
--- a/option-groups.def
+++ b/option-groups.def
@@ -465,6 +465,25 @@ config OPTION_EGLIBC_LOCALE_CODE
        group; if you disable OPTION_EGLIBC_LOCALE_CODE, you must also
        disable OPTION_EGLIBC_CATGETS.
 
+config OPTION_EGLIBC_MEMUSAGE
+   bool "Memory profiling library"
+   help
+       This option group includes the `libmemusage' library and
+       the `memusage' and `memusagestat' utilities.
+       These components provide memory profiling functions.
+
+     OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE
+
+       Libmemusage library buffers the profiling data in memory
+       before writing it out to disk.  By default, the library
+       allocates 1.5M buffer, which can be substantial for some
+       systems.  OPTION_EGLIBC_MEMUSAGE_DEFAULT_BUFFER_SIZE option
+       allows to change the default buffer size.  It specifies
+       the number of entries the buffer should have.
+       On most architectures one buffer entry amounts to 48 bytes,
+       so setting this option to the value of 512 will reduce the size of
+       the memory buffer to 24K.
+
 config OPTION_EGLIBC_NIS
    bool "Support for NIS, NIS+, and the special 'compat' services."
    depends OPTION_EGLIBC_INET
diff --git a/option-groups.defaults b/option-groups.defaults
index 4653e64..5f37439 100644
--- a/option-groups.defaults
+++ b/option-groups.defaults
@@ -26,6 +26,7 @@ OPTION_EGLIBC_INET = y
 OPTION_EGLIBC_LIBM = y
 OPTION_EGLIBC_LOCALES = y
 OPTION_EGLIBC_LOCALE_CODE = y
+OPTION_EGLIBC_MEMUSAGE = y
 OPTION_EGLIBC_NIS = y
 OPTION_EGLIBC_NSSWITCH = y
 OPTION_EGLIBC_RCMD = y