hi,
i've written a small patch which logs php's peak memory usage
to the apache log-file.
after applying this patch (against latest CVS) you should
configure php using "--enable-memory-usage". after compile
and installing you have a new apache (and _only_ apache)
log-directive called mod_php_memory_usage which contains the
peak-memory usage for your page. by adding it to your apache
LogFormat you will now get this valuable information in your
log and you can easily spot pages that need lots of memory!
hoto say "%{mod_php_memory_usage}n" in you LogFormat:
LogFormat "%h %l %u %t \"%r\" %>s %b PHP:%{mod_php_memory_usage}n \"%{Referer}i\"
\"%{User-Agent}i\"" combined
patch is attached (should cause _very near_ to no performance
hit)
zeev (& others;-), using AG() after send_parsed_php *is* safe
as the various shutdown functions are first called from the
apache shutdown handler - which is calling up *way* after this.
re,
tc
Index: sapi/apache/mod_php4.c
===================================================================
RCS file: /repository/php4/sapi/apache/mod_php4.c,v
retrieving revision 1.94
diff -u -r1.94 mod_php4.c
--- sapi/apache/mod_php4.c 2001/05/07 22:02:44 1.94
+++ sapi/apache/mod_php4.c 2001/05/10 11:54:17
@@ -540,7 +540,19 @@
static int send_parsed_php(request_rec * r)
{
- return send_php(r, 0, NULL);
+ int result = send_php(r, 0, NULL);
+
+#if MEMORY_USAGE
+ {
+ char mem_usage[ 32 ];
+ ALS_FETCH()
+
+ sprintf(mem_usage,"%u", (int) AG(max_allocated_memory));
+ ap_table_setn(r->notes, "mod_php_memory_usage",
+ap_pstrdup(r->pool,mem_usage));
+ }
+#endif
+
+ return result;
}
Index: Zend/Zend.m4
===================================================================
RCS file: /repository/Zend/Zend.m4,v
retrieving revision 1.22
diff -u -r1.22 Zend.m4
--- Zend/Zend.m4 2001/03/11 19:35:25 1.22
+++ Zend/Zend.m4 2001/05/10 11:56:23
@@ -123,6 +123,13 @@
ZEND_MEMORY_LIMIT=no
])
+AC_ARG_ENABLE(memory-usage,
+[ --enable-memory-usage Compile with memory usage support. ], [
+ ZEND_MEMORY_USAGE=$enableval
+],[
+ ZEND_MEMORY_USAGE=no
+])
+
AC_MSG_CHECKING(whether to enable experimental ZTS)
AC_MSG_RESULT($ZEND_EXPERIMENTAL_ZTS)
@@ -132,6 +139,9 @@
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)
+
AC_MSG_CHECKING(whether to enable Zend debugging)
AC_MSG_RESULT($ZEND_DEBUG)
@@ -166,6 +176,13 @@
else
AC_DEFINE(MEMORY_LIMIT, 0, [Memory limit])
fi
+
+if test "$ZEND_MEMORY_USAGE" = "yes"; then
+ AC_DEFINE(MEMORY_USAGE, 1, [Memory usage])
+else
+ AC_DEFINE(MEMORY_USAGE, 0, [Memory usage])
+fi
+
changequote({,})
if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then
Index: Zend/zend_alloc.c
===================================================================
RCS file: /repository/Zend/zend_alloc.c,v
retrieving revision 1.76
diff -u -r1.76 zend_alloc.c
--- Zend/zend_alloc.c 2001/04/30 05:39:37 1.76
+++ Zend/zend_alloc.c 2001/05/10 11:56:24
@@ -185,6 +185,12 @@
#if MEMORY_LIMIT
CHECK_MEMORY_LIMIT(size, SIZE);
#endif
+#if MEMORY_USAGE
+ 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 @@
#if MEMORY_LIMIT
AG(allocated_memory) -= SIZE;
#endif
+#if MEMORY_USAGE
+ AG(cur_allocated_memory) -= SIZE;
+#endif
free(p);
HANDLE_UNBLOCK_INTERRUPTIONS();
@@ -305,6 +314,12 @@
#if MEMORY_LIMIT
CHECK_MEMORY_LIMIT(size - p->size, SIZE - REAL_SIZE(p->size));
#endif
+#if MEMORY_USAGE
+ 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 @@
AG(allocated_memory) = 0;
AG(memory_exhausted) = 0;
#endif
+#if MEMORY_USAGE
+ 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)));
@@ -487,6 +506,10 @@
}
#if MEMORY_LIMIT
AG(memory_exhausted)=0;
+#endif
+#if MEMORY_USAGE
+ AG(cur_allocated_memory) = 0;
+ AG(max_allocated_memory) = 0;
#endif
#if (ZEND_DEBUG)
Index: Zend/zend_globals.h
===================================================================
RCS file: /repository/Zend/zend_globals.h,v
retrieving revision 1.61
diff -u -r1.61 zend_globals.h
--- Zend/zend_globals.h 2001/02/26 05:43:26 1.61
+++ Zend/zend_globals.h 2001/05/10 11:56:24
@@ -217,6 +217,10 @@
unsigned int allocated_memory;
unsigned char memory_exhausted;
#endif
+#if MEMORY_USAGE
+ unsigned int cur_allocated_memory;
+ unsigned int max_allocated_memory;
+#endif
};
#endif /* ZEND_GLOBALS_H */
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]