You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-26Lines changed: 57 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ MEMINFO
2
2
=======
3
3
PHP Meminfo is a PHP extension that gives you insights on the PHP memory content.
4
4
5
-
Its main goal is to help you understand memory leaks, but by looking at data present in memory, you can better understand your application behaviour.
5
+
Its main goal is to help you understand memory leaks: by looking at data present in memory, you can better understand your application behaviour.
6
6
7
7
One of the main source of inspiration for this tool is the Java jmap tool with the -histo option (see `man jmap`).
8
8
@@ -13,6 +13,7 @@ Compiled and tested on:
13
13
- PHP 5.4.4 (Debian 7)
14
14
- PHP 5.5.8 (Ubuntu 12.04 LTS)
15
15
- PHP 5.5.20 (CentOS 7)
16
+
- PHP 5.6.17 (Debian 8)
16
17
17
18
Compilation instructions
18
19
------------------------
@@ -24,7 +25,7 @@ $ apt-get install php5-dev
24
25
Once you have this command, follow this steps:
25
26
26
27
## Compilation
27
-
From the root of the extension directory:
28
+
From the root of the `extension/` directory:
28
29
29
30
```bash
30
31
$ phpize
@@ -40,31 +41,18 @@ Add the following line to your `php.ini`:
40
41
extension=meminfo.so
41
42
```
42
43
43
-
Usage
44
-
-----
45
-
All meminfo functions take a stream handle as a parameter. It allows you to specify a file, as well as to use standard output with the `php://stdout` stream.
46
-
47
-
## Exploring Memory usage
48
-
The provided user interface allows you to explore the content of your memory. It will show you the items instanciated, the dependencies between items and the size of each of them.
49
-
50
-
### Summary Screen
51
-
The main screen lists the top memory consumers, ordered by their total size.
52
-

53
-
54
-
### Item details Screen
55
-
Clicking on an item brings you to the Item Details Screen.
56
-

57
-
58
-
On this screen, you will see 5 parts:
59
-
- title
60
-
Item type (object, array, string, boolean, etc...) and its pointer address in memory at the time of the data extraction.
61
-
This memory address is used as the unique identifier of the item
44
+
Installing analyzers
45
+
--------------------
46
+
Analyzers allow to analyze a memory dump (see below).
62
47
63
-
- Information
64
-
Small summary on the item itself, like the class name in case of object and memory size information.
48
+
```bash
49
+
$ cd analyzers
50
+
$ composer update
51
+
```
65
52
66
-
### How memory size is computed
67
-
See [the dedicated documentation](/doc/memory_calculation.md).
53
+
Usage
54
+
-----
55
+
All meminfo functions take a stream handle as a parameter. It allows you to specify a file (ex `fopen('/tmp/file.txt', 'w')`, as well as to use standard output with the `php://stdout` stream.
68
56
69
57
## Object instances count per class
70
58
Display the number of instances per class, ordered descending. Very useful to identify the content of a memory leak.
@@ -73,7 +61,7 @@ Display the number of instances per class, ordered descending. Very useful to id
The result will provide something similar to the following example (generated at the end of the Symfony2 console launch)
64
+
The result will provide something similar to the following example generated at the end of a Symfony2 console launch:
77
65
78
66
```
79
67
Instances count by class:
@@ -98,6 +86,49 @@ The `examples/` directory at the root of the repository contains more detailed e
98
86
$ php examples/objects_summary.php
99
87
```
100
88
89
+
## Memory state dump
90
+
This feature allow to dump the list of items present in memory at the time of the function execution. Each memory items (string, boolean, objects, array, etc...) are dumped in a JSON format, with the following information:
91
+
- in memory address
92
+
- type (object, array, int, string, ...)
93
+
- class (only for objects)
94
+
- object handle (only for objects.
95
+
- self size (without the size of the linked objects)
96
+
- is_root (tells if the item is directly linked to a variable)
97
+
- symbol name (variable name, if linked to a variable)
98
+
- execution frame (name of the method where the variable has been declared)
99
+
- children: list of linked items with the key value if array or property name if object and the item address in memory
100
+
101
+
### Analyzing a memory dump
102
+
The analyzer is available from the `analyzer/` directory. It will be invoked with:
103
+
```bash
104
+
$ bin/analyzer
105
+
```
106
+
107
+
#### Querying a memory dump
108
+
The `query` command on the analyzer allows you to filter out some items from a memory dump. The `-f` option can be used several times, effectively *anding* the filters. The supported operators are exact match `=` and regexp match `~`.
109
+
110
+
The `-v`option display all the information of the items found.
111
+
112
+
##### Examples
113
+
- finding array that are not directly linked to a variable
#### Finding out why an object has not been removed from memory
123
+
When you are tracking down a memory leak, it's very interesting to understand why an object is still in memory.
124
+
125
+
The analyzer provides the `ref-path` command that load the memory dump as a graph in memory and findout all paths linking an item to a root (a variable define in an execution frame).
126
+
127
+
Without the `-v` option, the output will contains only item memory adress and key/property name. Adding the `-v` option will display all the information of the linked items.
0 commit comments