[PATCH 09/19] mspace: add mspace_malloc_stats_return
Alon Levy
alevy at redhat.com
Thu May 31 03:24:43 PDT 2012
---
src/mspace.c | 33 +++++++++++++++++++++++++++------
src/mspace.h | 5 ++++-
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/mspace.c b/src/mspace.c
index 17d976a..822aade 100644
--- a/src/mspace.c
+++ b/src/mspace.c
@@ -1479,7 +1479,8 @@ static struct mallinfo internal_mallinfo(mstate m) {
}
#endif /* !NO_MALLINFO */
-static void internal_malloc_stats(mstate m) {
+static void internal_malloc_stats(mstate m, size_t *ret_maxfp, size_t *ret_fp,
+ size_t *ret_used) {
if (!PREACTION(m)) {
size_t maxfp = 0;
size_t fp = 0;
@@ -1503,9 +1504,21 @@ static void internal_malloc_stats(mstate m) {
}
}
- PRINT((m->user_data, "max system bytes = %10lu\n", (unsigned long)(maxfp)));
- PRINT((m->user_data, "system bytes = %10lu\n", (unsigned long)(fp)));
- PRINT((m->user_data, "in use bytes = %10lu\n", (unsigned long)(used)));
+ if (ret_maxfp || ret_fp || ret_used) {
+ if (ret_maxfp) {
+ *ret_maxfp = maxfp;
+ }
+ if (ret_fp) {
+ *ret_fp = fp;
+ }
+ if (ret_used) {
+ *ret_used = used;
+ }
+ } else {
+ PRINT((m->user_data, "max system bytes = %10lu\n", (unsigned long)(maxfp)));
+ PRINT((m->user_data, "system bytes = %10lu\n", (unsigned long)(fp)));
+ PRINT((m->user_data, "in use bytes = %10lu\n", (unsigned long)(used)));
+ }
POSTACTION(m);
}
@@ -2389,16 +2402,24 @@ void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) {
return internal_memalign(ms, alignment, bytes);
}
-void mspace_malloc_stats(mspace msp) {
+void mspace_malloc_stats_return(mspace msp, size_t *ret_maxfp, size_t *ret_fp,
+ size_t *ret_used)
+{
+
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
- internal_malloc_stats(ms);
+ internal_malloc_stats(ms, ret_maxfp, ret_fp, ret_used);
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
}
+
+void mspace_malloc_stats(mspace msp) {
+ mspace_malloc_stats_return(msp, NULL, NULL, NULL);
+}
+
size_t mspace_footprint(mspace msp) {
size_t result;
mstate ms = (mstate)msp;
diff --git a/src/mspace.h b/src/mspace.h
index 8f5ba83..46a6a56 100644
--- a/src/mspace.h
+++ b/src/mspace.h
@@ -131,9 +131,12 @@ struct mallinfo mspace_mallinfo(mspace msp);
/*
mspace_malloc_stats behaves as malloc_stats, but reports
- properties of the given space.
+ properties of the given space. The return variant returns instead of
+ printing the three quantities, maxfp, fp, and used.
*/
void mspace_malloc_stats(mspace msp);
+void mspace_malloc_stats_return(mspace msp, size_t *ret_maxfp, size_t *ret_fp,
+ size_t *ret_used);
/*
mspace_trim behaves as malloc_trim, but
--
1.7.10.1
More information about the xorg-devel
mailing list