Skip to content

Commit 1140061

Browse files
committed
Revert "Remove useless method"
This reverts commit 09368f9.
1 parent 09368f9 commit 1140061

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ The `examples/` directory at the root of the repository contains more detailed e
191191

192192
php examples/objects_list.php
193193

194+
## Information on structs size
195+
Display size in byte of main data structs size in PHP. Will mainly differ between 32bits et 64bits environments.
196+
197+
```php
198+
meminfo_structs_size(fopen('php://stdout','w'));
199+
```
200+
201+
It can be useful to understand difference in memory usage between two platforms.
202+
203+
Example Output on 64bits environment:
204+
205+
```
206+
Structs size on this platform:
207+
Class (zend_class_entry): 568 bytes.
208+
Object (zend_object): 32 bytes.
209+
Variable (zval): 24 bytes.
210+
Variable value (zvalue_value): 16 bytes.
211+
```
212+
194213
Usage in production
195214
-------------------
196215
PHP Meminfo can be used in production, as it does not have any impact on performances outside of the call to the `meminfo` functions.
@@ -200,7 +219,7 @@ Nevertheless, production environment is not where you debug ;)
200219
Other memory debugging tools for PHP
201220
-------------------------------------
202221
- XDebug (https://xdebug.org/)
203-
With the trace feature and the memory delta option (see XDebug documentation), you can trace function memory usage. You can use the provided script to get an aggregated view (TODO link)
222+
With the trace feature and the memory delta option (tool see XDebug documentation), you can trace function memory usage. You can use the provided script to get an aggregated view (TODO link)
204223

205224
- PHP Memprof (https://github.com/arnaud-lb/php-memory-profiler)
206225
Provides aggregated data about memory usage by functions. Far less resource intensive than a full trace from XDebug.

extension/php5/meminfo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
const zend_function_entry meminfo_functions[] = {
21+
PHP_FE(meminfo_structs_size, NULL)
2122
PHP_FE(meminfo_objects_list, NULL)
2223
PHP_FE(meminfo_objects_summary, NULL)
2324
PHP_FE(meminfo_gc_roots_list, NULL)

extension/php5/php_meminfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define MEMINFO_COPYRIGHT "Copyright (c) 2010-2016 by Benoit Jacquemont"
88
#define MEMINFO_COPYRIGHT_SHORT "Copyright (c) 2011-2016"
99

10+
PHP_FUNCTION(meminfo_structs_size);
1011
PHP_FUNCTION(meminfo_objects_list);
1112
PHP_FUNCTION(meminfo_objects_summary);
1213
PHP_FUNCTION(meminfo_gc_roots_list);

extension/php7/meminfo.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121

2222
const zend_function_entry meminfo_functions[] = {
23+
PHP_FE(meminfo_structs_size, NULL)
2324
PHP_FE(meminfo_objects_list, NULL)
2425
PHP_FE(meminfo_objects_summary, NULL)
2526
PHP_FE(meminfo_info_dump, NULL)
@@ -39,6 +40,28 @@ zend_module_entry meminfo_module_entry = {
3940
STANDARD_MODULE_PROPERTIES
4041
};
4142

43+
PHP_FUNCTION(meminfo_structs_size)
44+
{
45+
zval *zval_stream;
46+
php_stream *stream;
47+
48+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zval_stream) == FAILURE) {
49+
return;
50+
}
51+
52+
php_stream_from_zval(stream, zval_stream);
53+
54+
php_stream_printf(stream, "Simple Zend Type size on this platform\n");
55+
php_stream_printf(stream, " Zend Signed Integer (zend_long): %ld bytes.\n", sizeof(zend_long));
56+
php_stream_printf(stream, " Zend Unsigned Integer (zend_ulong): %ld bytes.\n", sizeof(zend_ulong));
57+
php_stream_printf(stream, " Zend Unsigned Char (zend_uchar): %ld bytes.\n", sizeof(zend_uchar));
58+
59+
php_stream_printf(stream, "Structs size on this platform:\n");
60+
php_stream_printf(stream, " Variable (zval): %ld bytes.\n", sizeof(zval));
61+
php_stream_printf(stream, " Class (zend_class_entry): %ld bytes.\n", sizeof(zend_class_entry));
62+
php_stream_printf(stream, " Object (zend_object): %ld bytes.\n", sizeof(zend_object));
63+
}
64+
4265
PHP_FUNCTION(meminfo_objects_list)
4366
{
4467
zval *zval_stream;

extension/php7/php_meminfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#define MEMINFO_COPYRIGHT "Copyright (c) 2010-2017 by Benoit Jacquemont"
1010
#define MEMINFO_COPYRIGHT_SHORT "Copyright (c) 2011-2017"
1111

12+
PHP_FUNCTION(meminfo_structs_size);
13+
1214
PHP_FUNCTION(meminfo_objects_list);
1315
PHP_FUNCTION(meminfo_objects_summary);
1416

0 commit comments

Comments
 (0)