dmitry          Tue Jul 25 13:41:08 2006 UTC

  Modified files:              
    /ZendEngine2        zend_alloc.c zend_alloc.h 
    /php-src/ext/standard       var.c 
    /php-src/sapi/apache        mod_php5.c 
    /php-src/sapi/apache2filter sapi_apache2.c 
    /php-src/sapi/apache2handler        sapi_apache2.c 
    /php-src/sapi/apache_hooks  mod_php5.c 
  Log:
  Changed memory_get_usage() and memory_get_peak_usage(). Optional boolean 
argument allows get memory size allocated by emalloc() (by default) or real 
size of memory allocated from system.
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.154&r2=1.155&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.154 ZendEngine2/zend_alloc.c:1.155
--- ZendEngine2/zend_alloc.c:1.154      Mon Jul 24 08:15:42 2006
+++ ZendEngine2/zend_alloc.c    Tue Jul 25 13:41:08 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.154 2006/07/24 08:15:42 dmitry Exp $ */
+/* $Id: zend_alloc.c,v 1.155 2006/07/25 13:41:08 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_alloc.h"
@@ -312,10 +312,12 @@
        size_t              block_size;
        zend_mm_segment    *segments_list;
        zend_mm_storage    *storage;
-       size_t                          size;
+       size_t                          real_size;
 #if MEMORY_LIMIT
-       size_t              peak;
+       size_t              real_peak;
        size_t                          limit;
+       size_t              size;
+       size_t              peak;
 #endif
 #if ZEND_USE_MALLOC_MM
        int                                     use_zend_alloc;
@@ -514,7 +516,7 @@
                        p = p->next_segment;
                }
        }
-       heap->size -= segment->size;
+       heap->real_size -= segment->size;
        ZEND_MM_STORAGE_FREE(segment);
 }
 
@@ -595,10 +597,12 @@
        heap->use_zend_alloc = 1;
 #endif
 
-       heap->size = 0;
+       heap->real_size = 0;
 #if MEMORY_LIMIT
-       heap->peak = 0;
+       heap->real_peak = 0;
        heap->limit = 1<<30;
+       heap->size = 0;
+       heap->peak = 0;
 #endif
 
        heap->overflow = 0;
@@ -996,8 +1000,10 @@
        } else {
                heap->segments_list = NULL;
                zend_mm_init(heap);
-               heap->size = 0;
+               heap->real_size = 0;
 #if MEMORY_LIMIT
+               heap->real_peak = 0;
+               heap->size = 0;
                heap->peak = 0;
 #endif
                heap->overflow = 0;
@@ -1175,7 +1181,7 @@
 
 
 #if MEMORY_LIMIT
-               if (heap->size + segment_size > heap->limit) {
+               if (heap->real_size + segment_size > heap->limit) {
                        /* Memory limit overflow */
 #if ZEND_DEBUG
                        zend_mm_safe_error(heap, "Allowed memory size of %d 
bytes exhausted at %s:%d (tried to allocate %d bytes)", heap->limit, 
__zend_filename, __zend_lineno, size);
@@ -1196,17 +1202,17 @@
 #endif
                        HANDLE_UNBLOCK_INTERRUPTIONS();
 #if ZEND_DEBUG
-                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
at %s:%d (tried to allocate %d bytes)", heap->size, __zend_filename, 
__zend_lineno, size);
+                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
at %s:%d (tried to allocate %d bytes)", heap->real_size, __zend_filename, 
__zend_lineno, size);
 #else
-                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
(tried to allocate %d bytes)", heap->size, size);
+                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
(tried to allocate %d bytes)", heap->real_size, size);
 #endif
                        return NULL;
                }
 
-               heap->size += segment_size;
+               heap->real_size += segment_size;
 #if MEMORY_LIMIT
-               if (heap->size > heap->peak) {
-                       heap->peak = heap->size;
+               if (heap->real_size > heap->real_peak) {
+                       heap->real_peak = heap->real_size;
                }
 #endif
 
@@ -1242,6 +1248,14 @@
 # endif
        ZEND_MM_SET_END_MAGIC(best_fit);
 #endif
+
+#if MEMORY_LIMIT
+       heap->size += true_size;
+       if (heap->peak < heap->size) {
+               heap->peak = heap->size;
+       }
+#endif
+
        HANDLE_UNBLOCK_INTERRUPTIONS();
 
        return ZEND_MM_DATA_OF(best_fit);
@@ -1278,6 +1292,11 @@
 #endif
 
        HANDLE_BLOCK_INTERRUPTIONS();
+
+#if MEMORY_LIMIT
+       heap->size -= size;
+#endif
+
        if (ZEND_MM_PREV_BLOCK_IS_FREE(mm_block)) {
                next_block = ZEND_MM_NEXT_BLOCK(mm_block);
                if (ZEND_MM_IS_FREE_BLOCK(next_block)) {
@@ -1349,6 +1368,14 @@
        }
        mm_block = ZEND_MM_HEADER_OF(p);
        true_size = ZEND_MM_TRUE_SIZE(size);
+
+#if MEMORY_LIMIT
+       heap->size = heap->size + true_size - ZEND_MM_BLOCK_SIZE(mm_block);
+       if (heap->peak < heap->size) {
+               heap->peak = heap->size;
+       }
+#endif
+       
        if (true_size <= ZEND_MM_BLOCK_SIZE(mm_block)) {
                size_t remaining_size = ZEND_MM_BLOCK_SIZE(mm_block) - 
true_size;
 
@@ -1439,7 +1466,7 @@
 
                segment_copy = (zend_mm_segment *) ((char *)mm_block - 
ZEND_MM_ALIGNED_SEGMENT_SIZE);
 #if MEMORY_LIMIT
-               if (heap->size + segment_size - segment_copy->size > 
heap->limit) {
+               if (heap->real_size + segment_size - segment_copy->size > 
heap->limit) {
                        HANDLE_UNBLOCK_INTERRUPTIONS();
 #if ZEND_DEBUG
                        zend_mm_safe_error(heap, "Allowed memory size of %d 
bytes exhausted at %s:%d (tried to allocate %d bytes)", heap->limit, 
__zend_filename, __zend_lineno, size);
@@ -1453,16 +1480,16 @@
                if (!segment) {
                        HANDLE_UNBLOCK_INTERRUPTIONS();
 #if ZEND_DEBUG
-                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
at %s:%d (tried to allocate %d bytes)", heap->size, __zend_filename, 
__zend_lineno, size);
+                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
at %s:%d (tried to allocate %d bytes)", heap->real_size, __zend_filename, 
__zend_lineno, size);
 #else
-                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
(tried to allocate %d bytes)", heap->size, size);
+                       zend_mm_safe_error(heap, "Out of memory (allocated %d) 
(tried to allocate %d bytes)", heap->real_size, size);
 #endif
                        return NULL;
                }
-               heap->size += segment_size - segment->size;
+               heap->real_size += segment_size - segment->size;
 #if MEMORY_LIMIT
-               if (heap->size > heap->peak) {
-                       heap->peak = heap->size;
+               if (heap->real_size > heap->real_peak) {
+                       heap->real_peak = heap->real_size;
                }
 #endif
                segment->size = segment_size;
@@ -1778,15 +1805,27 @@
 #endif
 }
 
-ZEND_API size_t zend_memory_usage(TSRMLS_D)
+ZEND_API size_t zend_memory_usage(int real_usage TSRMLS_DC)
 {
-       return AG(mm_heap)->size;
+       if (real_usage) {
+               return AG(mm_heap)->real_size;
+       } else {
+#if MEMORY_LIMIT
+               return AG(mm_heap)->size;
+#else
+               return AG(mm_heap)->real_size;
+#endif
+       }
 }
 
 #if MEMORY_LIMIT
-ZEND_API size_t zend_memory_peak_usage(TSRMLS_D)
+ZEND_API size_t zend_memory_peak_usage(int real_usage TSRMLS_DC)
 {
-       return AG(mm_heap)->peak;
+       if (real_usage) {
+               return AG(mm_heap)->real_peak;
+       } else {
+               return AG(mm_heap)->peak;
+       }
 }
 #endif
 
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.h?r1=1.72&r2=1.73&diff_format=u
Index: ZendEngine2/zend_alloc.h
diff -u ZendEngine2/zend_alloc.h:1.72 ZendEngine2/zend_alloc.h:1.73
--- ZendEngine2/zend_alloc.h:1.72       Tue Jul 18 09:08:05 2006
+++ ZendEngine2/zend_alloc.h    Tue Jul 25 13:41:08 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.h,v 1.72 2006/07/18 09:08:05 dmitry Exp $ */
+/* $Id: zend_alloc.h,v 1.73 2006/07/25 13:41:08 dmitry Exp $ */
 
 #ifndef ZEND_ALLOC_H
 #define ZEND_ALLOC_H
@@ -119,8 +119,8 @@
 #endif
 
 #if MEMORY_LIMIT
-ZEND_API size_t zend_memory_usage(TSRMLS_D);
-ZEND_API size_t zend_memory_peak_usage(TSRMLS_D);
+ZEND_API size_t zend_memory_usage(int real_usage TSRMLS_DC);
+ZEND_API size_t zend_memory_peak_usage(int real_usage TSRMLS_DC);
 #endif
 
 END_EXTERN_C()
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/var.c?r1=1.241&r2=1.242&diff_format=u
Index: php-src/ext/standard/var.c
diff -u php-src/ext/standard/var.c:1.241 php-src/ext/standard/var.c:1.242
--- php-src/ext/standard/var.c:1.241    Mon Jul 24 23:28:00 2006
+++ php-src/ext/standard/var.c  Tue Jul 25 13:41:08 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: var.c,v 1.241 2006/07/24 23:28:00 helly Exp $ */
+/* $Id: var.c,v 1.242 2006/07/25 13:41:08 dmitry Exp $ */
 
 
 
@@ -1152,14 +1152,25 @@
 /* {{{ proto int memory_get_usage()
     Returns the allocated by PHP memory */
 PHP_FUNCTION(memory_get_usage) {
+       zend_bool real_usage = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) 
== FAILURE) {
+               RETURN_FALSE;
+       }
        
-       RETURN_LONG(zend_memory_usage(TSRMLS_C));
+       RETURN_LONG(zend_memory_usage(real_usage TSRMLS_CC));
 }
 /* }}} */
 /* {{{ proto int memory_get_peak_usage()
     Returns the peak allocated by PHP memory */
 PHP_FUNCTION(memory_get_peak_usage) {
-       RETURN_LONG(zend_memory_peak_usage(TSRMLS_C));
+       zend_bool real_usage = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) 
== FAILURE) {
+               RETURN_FALSE;
+       }
+
+       RETURN_LONG(zend_memory_peak_usage(real_usage TSRMLS_CC));
 }
 /* }}} */
 #endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache/mod_php5.c?r1=1.36&r2=1.37&diff_format=u
Index: php-src/sapi/apache/mod_php5.c
diff -u php-src/sapi/apache/mod_php5.c:1.36 php-src/sapi/apache/mod_php5.c:1.37
--- php-src/sapi/apache/mod_php5.c:1.36 Tue Jul 18 09:08:06 2006
+++ php-src/sapi/apache/mod_php5.c      Tue Jul 25 13:41:08 2006
@@ -17,7 +17,7 @@
    | PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]>                      |
    +----------------------------------------------------------------------+
  */
-/* $Id: mod_php5.c,v 1.36 2006/07/18 09:08:06 dmitry Exp $ */
+/* $Id: mod_php5.c,v 1.37 2006/07/25 13:41:08 dmitry Exp $ */
 
 #include "php_apache_http.h"
 #include "http_conf_globals.h"
@@ -669,7 +669,7 @@
                char *mem_usage;
                TSRMLS_FETCH();
  
-               mem_usage = ap_psprintf(r->pool, "%u", 
zend_memory_peak_usage(TSRMLS_C));
+               mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 
TSRMLS_CC));
                ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
        }
 #endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache2filter/sapi_apache2.c?r1=1.140&r2=1.141&diff_format=u
Index: php-src/sapi/apache2filter/sapi_apache2.c
diff -u php-src/sapi/apache2filter/sapi_apache2.c:1.140 
php-src/sapi/apache2filter/sapi_apache2.c:1.141
--- php-src/sapi/apache2filter/sapi_apache2.c:1.140     Tue Jul 18 09:08:06 2006
+++ php-src/sapi/apache2filter/sapi_apache2.c   Tue Jul 25 13:41:08 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sapi_apache2.c,v 1.140 2006/07/18 09:08:06 dmitry Exp $ */
+/* $Id: sapi_apache2.c,v 1.141 2006/07/25 13:41:08 dmitry Exp $ */
 
 #include <fcntl.h>
 
@@ -521,7 +521,7 @@
                                {
                                        char *mem_usage;
  
-                                       mem_usage = apr_psprintf(ctx->r->pool, 
"%u", zend_memory_peak_usage(TSRMLS_C));
+                                       mem_usage = apr_psprintf(ctx->r->pool, 
"%u", zend_memory_peak_usage(1 TSRMLS_CC));
                                        apr_table_set(ctx->r->notes, 
"mod_php_memory_usage", mem_usage);
                                }
 #endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache2handler/sapi_apache2.c?r1=1.70&r2=1.71&diff_format=u
Index: php-src/sapi/apache2handler/sapi_apache2.c
diff -u php-src/sapi/apache2handler/sapi_apache2.c:1.70 
php-src/sapi/apache2handler/sapi_apache2.c:1.71
--- php-src/sapi/apache2handler/sapi_apache2.c:1.70     Tue Jul 18 09:08:06 2006
+++ php-src/sapi/apache2handler/sapi_apache2.c  Tue Jul 25 13:41:08 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sapi_apache2.c,v 1.70 2006/07/18 09:08:06 dmitry Exp $ */
+/* $Id: sapi_apache2.c,v 1.71 2006/07/25 13:41:08 dmitry Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -593,7 +593,7 @@
                {
                        char *mem_usage;
 
-                       mem_usage = apr_psprintf(ctx->r->pool, "%u", 
zend_memory_peak_usage(TSRMLS_C));
+                       mem_usage = apr_psprintf(ctx->r->pool, "%u", 
zend_memory_peak_usage(1 TSRMLS_CC));
                        apr_table_set(r->notes, "mod_php_memory_usage", 
mem_usage);
                }
 #endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache_hooks/mod_php5.c?r1=1.19&r2=1.20&diff_format=u
Index: php-src/sapi/apache_hooks/mod_php5.c
diff -u php-src/sapi/apache_hooks/mod_php5.c:1.19 
php-src/sapi/apache_hooks/mod_php5.c:1.20
--- php-src/sapi/apache_hooks/mod_php5.c:1.19   Tue Jul 18 09:08:06 2006
+++ php-src/sapi/apache_hooks/mod_php5.c        Tue Jul 25 13:41:08 2006
@@ -17,7 +17,7 @@
    | PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]>                       
                  |
    +----------------------------------------------------------------------+
  */
-/* $Id: mod_php5.c,v 1.19 2006/07/18 09:08:06 dmitry Exp $ */
+/* $Id: mod_php5.c,v 1.20 2006/07/25 13:41:08 dmitry Exp $ */
 
 #include "php_apache_http.h"
 
@@ -727,7 +727,7 @@
                char *mem_usage;
                TSRMLS_FETCH();
  
-               mem_usage = ap_psprintf(r->pool, "%u", 
zend_memory_peak_usage(TSRMLS_C));
+               mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 
TSRMLS_CC));
                ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
        }
 #endif

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to