dmitry          Tue Jul 25 13:40:05 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /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/php-src/NEWS?r1=1.2027.2.547.2.144&r2=1.2027.2.547.2.145&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.144 php-src/NEWS:1.2027.2.547.2.145
--- php-src/NEWS:1.2027.2.547.2.144     Tue Jul 25 13:24:53 2006
+++ php-src/NEWS        Tue Jul 25 13:40:04 2006
@@ -1,6 +1,10 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Aug 2006, PHP 5.2.0RC2
+- 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. (Dmitry)
+
 - Moved extensions to PECL:
   . ext/filepro (Derick, Tony)
   . ext/hwapi (Derick, Tony)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.144.2.3.2.3&r2=1.144.2.3.2.4&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.144.2.3.2.3 
ZendEngine2/zend_alloc.c:1.144.2.3.2.4
--- ZendEngine2/zend_alloc.c:1.144.2.3.2.3      Mon Jul 24 08:15:26 2006
+++ ZendEngine2/zend_alloc.c    Tue Jul 25 13:40:05 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.144.2.3.2.3 2006/07/24 08:15:26 dmitry Exp $ */
+/* $Id: zend_alloc.c,v 1.144.2.3.2.4 2006/07/25 13:40:05 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;
@@ -1736,15 +1763,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.63.2.2.2.1&r2=1.63.2.2.2.2&diff_format=u
Index: ZendEngine2/zend_alloc.h
diff -u ZendEngine2/zend_alloc.h:1.63.2.2.2.1 
ZendEngine2/zend_alloc.h:1.63.2.2.2.2
--- ZendEngine2/zend_alloc.h:1.63.2.2.2.1       Tue Jul 18 09:06:32 2006
+++ ZendEngine2/zend_alloc.h    Tue Jul 25 13:40:05 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.h,v 1.63.2.2.2.1 2006/07/18 09:06:32 dmitry Exp $ */
+/* $Id: zend_alloc.h,v 1.63.2.2.2.2 2006/07/25 13:40:05 dmitry Exp $ */
 
 #ifndef ZEND_ALLOC_H
 #define ZEND_ALLOC_H
@@ -108,8 +108,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.203.2.7.2.5&r2=1.203.2.7.2.6&diff_format=u
Index: php-src/ext/standard/var.c
diff -u php-src/ext/standard/var.c:1.203.2.7.2.5 
php-src/ext/standard/var.c:1.203.2.7.2.6
--- php-src/ext/standard/var.c:1.203.2.7.2.5    Mon Jul 24 23:40:57 2006
+++ php-src/ext/standard/var.c  Tue Jul 25 13:40:05 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: var.c,v 1.203.2.7.2.5 2006/07/24 23:40:57 helly Exp $ */
+/* $Id: var.c,v 1.203.2.7.2.6 2006/07/25 13:40:05 dmitry Exp $ */
 
 
 
@@ -912,14 +912,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.19.2.7.2.3&r2=1.19.2.7.2.4&diff_format=u
Index: php-src/sapi/apache/mod_php5.c
diff -u php-src/sapi/apache/mod_php5.c:1.19.2.7.2.3 
php-src/sapi/apache/mod_php5.c:1.19.2.7.2.4
--- php-src/sapi/apache/mod_php5.c:1.19.2.7.2.3 Tue Jul 18 09:06:33 2006
+++ php-src/sapi/apache/mod_php5.c      Tue Jul 25 13:40:05 2006
@@ -17,7 +17,7 @@
    | PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]>                      |
    +----------------------------------------------------------------------+
  */
-/* $Id: mod_php5.c,v 1.19.2.7.2.3 2006/07/18 09:06:33 dmitry Exp $ */
+/* $Id: mod_php5.c,v 1.19.2.7.2.4 2006/07/25 13:40:05 dmitry Exp $ */
 
 #include "php_apache_http.h"
 #include "http_conf_globals.h"
@@ -684,7 +684,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.136.2.2.2.2&r2=1.136.2.2.2.3&diff_format=u
Index: php-src/sapi/apache2filter/sapi_apache2.c
diff -u php-src/sapi/apache2filter/sapi_apache2.c:1.136.2.2.2.2 
php-src/sapi/apache2filter/sapi_apache2.c:1.136.2.2.2.3
--- php-src/sapi/apache2filter/sapi_apache2.c:1.136.2.2.2.2     Tue Jul 18 
09:06:33 2006
+++ php-src/sapi/apache2filter/sapi_apache2.c   Tue Jul 25 13:40:05 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sapi_apache2.c,v 1.136.2.2.2.2 2006/07/18 09:06:33 dmitry Exp $ */
+/* $Id: sapi_apache2.c,v 1.136.2.2.2.3 2006/07/25 13:40:05 dmitry Exp $ */
 
 #include <fcntl.h>
 
@@ -526,7 +526,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.57.2.10.2.2&r2=1.57.2.10.2.3&diff_format=u
Index: php-src/sapi/apache2handler/sapi_apache2.c
diff -u php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.2 
php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.3
--- php-src/sapi/apache2handler/sapi_apache2.c:1.57.2.10.2.2    Tue Jul 18 
09:06:33 2006
+++ php-src/sapi/apache2handler/sapi_apache2.c  Tue Jul 25 13:40:05 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sapi_apache2.c,v 1.57.2.10.2.2 2006/07/18 09:06:33 dmitry Exp $ */
+/* $Id: sapi_apache2.c,v 1.57.2.10.2.3 2006/07/25 13:40:05 dmitry Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -598,7 +598,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.11.2.1.2.1&r2=1.11.2.1.2.2&diff_format=u
Index: php-src/sapi/apache_hooks/mod_php5.c
diff -u php-src/sapi/apache_hooks/mod_php5.c:1.11.2.1.2.1 
php-src/sapi/apache_hooks/mod_php5.c:1.11.2.1.2.2
--- php-src/sapi/apache_hooks/mod_php5.c:1.11.2.1.2.1   Tue Jul 18 09:06:33 2006
+++ php-src/sapi/apache_hooks/mod_php5.c        Tue Jul 25 13:40:05 2006
@@ -17,7 +17,7 @@
    | PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]>                       
                  |
    +----------------------------------------------------------------------+
  */
-/* $Id: mod_php5.c,v 1.11.2.1.2.1 2006/07/18 09:06:33 dmitry Exp $ */
+/* $Id: mod_php5.c,v 1.11.2.1.2.2 2006/07/25 13:40:05 dmitry Exp $ */
 
 #include "php_apache_http.h"
 
@@ -742,7 +742,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