summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/Zend.m417
-rw-r--r--Zend/zend_alloc.c23
-rw-r--r--Zend/zend_globals.h4
3 files changed, 44 insertions, 0 deletions
diff --git a/Zend/Zend.m4 b/Zend/Zend.m4
index 4e7b7f2d87..360c50d009 100644
--- a/Zend/Zend.m4
+++ b/Zend/Zend.m4
@@ -123,6 +123,13 @@ AC_ARG_ENABLE(memory-limit,
ZEND_MEMORY_LIMIT=no
])
+AC_ARG_ENABLE(memory-usage-info,
+[ --enable-memory-usage-info Compile with support for memory usage info. ], [
+ ZEND_MEMORY_USAGE_INFO=$enableval
+],[
+ ZEND_MEMORY_USAGE_INFO=no
+])
+
AC_MSG_CHECKING(whether to enable experimental ZTS)
AC_MSG_RESULT($ZEND_EXPERIMENTAL_ZTS)
@@ -132,6 +139,9 @@ AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION)
AC_MSG_CHECKING(whether to enable a memory limit)
AC_MSG_RESULT($ZEND_MEMORY_LIMIT)
+AC_MSG_CHECKING(whether to enable a memory usage)
+AC_MSG_RESULT($ZEND_MEMORY_USAGE_INFO)
+
AC_MSG_CHECKING(whether to enable Zend debugging)
AC_MSG_RESULT($ZEND_DEBUG)
@@ -167,6 +177,13 @@ else
AC_DEFINE(MEMORY_LIMIT, 0, [Memory limit])
fi
+if test "$ZEND_MEMORY_USAGE_INFO" = "yes"; then
+ AC_DEFINE(MEMORY_USAGE_INFO, 1, [Memory usage])
+else
+ AC_DEFINE(MEMORY_USAGE_INFO, 0, [Memory usage])
+fi
+
+
changequote({,})
if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then
INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//`
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index ade2d03c31..7a70333ea9 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -185,6 +185,12 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
#if MEMORY_LIMIT
CHECK_MEMORY_LIMIT(size, SIZE);
#endif
+#if MEMORY_USAGE_INFO
+ AG(cur_allocated_memory) += SIZE;
+ if (AG(cur_allocated_memory) > AG(max_allocated_memory))
+ AG(max_allocated_memory) = AG(cur_allocated_memory);
+#endif
+
HANDLE_UNBLOCK_INTERRUPTIONS();
return (void *)((char *)p + sizeof(zend_mem_header) + MEM_HEADER_PADDING);
}
@@ -228,6 +234,9 @@ ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
#if MEMORY_LIMIT
AG(allocated_memory) -= SIZE;
#endif
+#if MEMORY_USAGE_INFO
+ AG(cur_allocated_memory) -= SIZE;
+#endif
free(p);
HANDLE_UNBLOCK_INTERRUPTIONS();
@@ -305,6 +314,12 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN
#if MEMORY_LIMIT
CHECK_MEMORY_LIMIT(size - p->size, SIZE - REAL_SIZE(p->size));
#endif
+#if MEMORY_USAGE_INFO
+ AG(cur_allocated_memory) += SIZE - REAL_SIZE(p->size);
+ if (AG(cur_allocated_memory) > AG(max_allocated_memory))
+ AG(max_allocated_memory) = AG(cur_allocated_memory);
+#endif
+
p->size = size;
HANDLE_UNBLOCK_INTERRUPTIONS();
@@ -390,6 +405,10 @@ ZEND_API void start_memory_manager(ALS_D)
AG(allocated_memory) = 0;
AG(memory_exhausted) = 0;
#endif
+#if MEMORY_USAGE_INFO
+ AG(cur_allocated_memory) = 0;
+ AG(max_allocated_memory) = 0;
+#endif
memset(AG(fast_cache_list_head), 0, sizeof(AG(fast_cache_list_head)));
memset(AG(cache_count), 0, sizeof(AG(cache_count)));
@@ -488,6 +507,10 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
#if MEMORY_LIMIT
AG(memory_exhausted)=0;
#endif
+#if MEMORY_USAGE_INFO
+ AG(cur_allocated_memory) = 0;
+ AG(max_allocated_memory) = 0;
+#endif
#if (ZEND_DEBUG)
do {
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 867fee8316..b853800c56 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -217,6 +217,10 @@ struct _zend_alloc_globals {
unsigned int allocated_memory;
unsigned char memory_exhausted;
#endif
+#if MEMORY_USAGE_INFO
+ unsigned int cur_allocated_memory;
+ unsigned int max_allocated_memory;
+#endif
};
#endif /* ZEND_GLOBALS_H */