Implement auto dump on out-of-memory - #123
Conversation
Two new INI settings have been added called `meminfo.dump_on_limit` and `meminfo.dump_dir`. When dump_on_limit is enabled, meminfo will attempt to create a heap dump when an OOM error is detected in the `dump_dir` directory. OOM errors are detected by registering an error handler, then checking for a prefix of "Allowed memory size of" on the error message.
tortis
commented
Mar 27, 2022
@BitOne When I did my original implementation, I did some testing with a real world scenario, but I haven't done that yet with this implementation. I did test some trivial examples (and added a test for it). My main concern is if we'll get a secondary OOM error when we try to dump a very large "real world" heap. Hopefully changing the memory limit before we try the dump will handle this though. 🤞 |
BitOne
left a comment
There was a problem hiding this comment.
Can you check the indentation to make it homogeneous with the rest of the code?
Otherwise, pretty cool, stuff thank you!
Uh oh!
There was an error while loading. Please reload this page.
| return s3; | ||
| } | ||
| #define MEMORY_LIMIT_ERROR_PREFIX "Allowed memory size of" |
There was a problem hiding this comment.
Is there no other way to check for memory exhaustion error?
There was a problem hiding this comment.
I found this technique in memprof when I was researching how to do it. Unfortunately I didn't find any other options.
| PHP_INI_BEGIN() | ||
| STD_PHP_INI_ENTRY("meminfo.dump_on_limit", "Off", PHP_INI_ALL, OnUpdateBool, dump_on_limit, zend_meminfo_globals, meminfo_globals) | ||
| PHP_INI_ENTRY("meminfo.dump_dir", "/tmp", PHP_INI_ALL, NULL) |
There was a problem hiding this comment.
@BitOne Do you think we can just let this default to "/tmp" for now? It might not be the best for Windows, but I think most users will probably set the dump_dir if they are going to use this anyway right?
Two new INI settings have been added called
meminfo.dump_on_limitandmeminfo.dump_dir. When dump_on_limit is enabled, meminfo will attemptto create a heap dump when an OOM error is detected in the
dump_dirdirectory.
OOM errors are detected by registering an error handler, then checking
for a prefix of "Allowed memory size of" on the error message.
dump_diron windows?resolves#122