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
> :information_source: The `memprof_enabled_flags()` function can be called to
87
+
> check whether profiling is currently enabled in `dump_on_limit` mode.
88
+
89
+
### Step 2: Dumping the profile
90
+
91
+
In this mode, `memprof` will automatically save the profile if the program
92
+
exceeds the memory limit (when PHP triggers an error like `Fatal error: Allowed
93
+
memory size of 15728640 bytes exhausted (tried to allocate 1024 bytes)` error).
94
+
95
+
By default, the profile is saved in a file named `memprof.callgrind.*` in `/tmp`
96
+
or `C:\Windows\Temp`.
97
+
98
+
### Step 3: Visualizing the profile
77
99
78
100
The recommended way to visualize the result is to use Kcachegrind (on Linux) or Qcachegrind (on MacOS, Windows). Google Perftools are also supported. See the documentation of ``memprof_dump_callgrind()`` and variants.
79
101
@@ -97,42 +119,62 @@ Use Homebrew: https://formulae.brew.sh/formula/qcachegrind
97
119
98
120
Download it from https://sourceforge.net/projects/qcachegrindwin/
99
121
100
-
### Usage example
122
+
##Advanced usage
101
123
102
-
```
103
-
<?php // test.php
124
+
### Profile trigger
104
125
105
-
do_some_work();
126
+
Profiling is enabled at request startup when one of these is true:
106
127
107
-
if (function_exists('memprof_enabled') && memprof_enabled()) {
*`dump_on_limit`: Will dump the profile in callgrind format in `/tmp` or
146
+
`C:\Windows\Temp`. The output directory can be changed with the
147
+
`memprof.output_dir` ini setting.
148
+
*`native`: Will profile native `malloc()` allocations, not only PHP's (This is
149
+
not thread safe, see bellow).
150
+
151
+
### Profiling native allocations
152
+
153
+
Memprof doesn't track native allocations by default, but this can be enabled
154
+
by setting `MEMPROF_PROFILE` to `native`.
155
+
156
+
Native allocations are the allocations made outside of PHP's own memory
157
+
allocator. Typically, external libraries such as libxml2 (used in the DOM
158
+
extension) make native allocations. PHP can also make native allocations for
159
+
persistent resources.
160
+
161
+
Enabling native allocation tracking will profile these allocations in addition
162
+
to PHP's own allocations.
163
+
164
+
Note that when native tracking is enabled, the program will crash if a native
165
+
library uses threads, because the underlying hooks are not thread safe.
129
166
130
167
## Functions documentation
131
168
132
169
### memprof_enabled()
133
170
134
171
Returns whether memory profiling is currently enabled (see above).
135
172
173
+
### memprof_enabled_flags()
174
+
175
+
Returns whether memory profiling and which profiling features are enabled (see
176
+
above).
177
+
136
178
### memprof_dump_callgrind(resource $stream)
137
179
138
180
Dumps the current profile in callgrind format. The result can be visualized with tools such as
@@ -194,7 +236,8 @@ The array exposes the following information:
194
236
multiple places, it is possible to see which call path caused it to leak the
195
237
most memory
196
238
197
-
Example output:
239
+
<details>
240
+
<summary>Example output</summary>
198
241
199
242
Array
200
243
(
@@ -262,10 +305,10 @@ Example output:
262
305
)
263
306
)
264
307
)
308
+
</details>
265
309
266
310
## Troubleshooting
267
311
268
-
* If you are experiencing crashes, try disabling malloc hooks by setting HAVE_MALLOC_HOOKS to 0 in config.h after running configure; then run ``make clean && make && make install``. (Using malloc hooks may crash if some other extension uses threads internally.)
269
312
* The extensions may conflict with xdebug, blackfire, or other extensions. If that's the case for you, please report it.
270
313
271
314
## PHP versions
@@ -274,10 +317,6 @@ The current branch supports PHP 7.1 to PHP 8.
0 commit comments