Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Allow to automatically create a dump on memory limit #122

Open
jdecool opened this issue Feb 12, 2022 · 4 comments · May be fixed by #123
Open

[Feature request] Allow to automatically create a dump on memory limit #122

jdecool opened this issue Feb 12, 2022 · 4 comments · May be fixed by #123

Comments

@jdecool
Copy link
Contributor

jdecool commented Feb 12, 2022

I sometimes use the php-memory-profiler with your library to debug memory usage of my projects.

This extension has a nice feature that allows to automatically dump a memory profile when the process crash because of a memory limit.

It could be cool to have this feature for this extension.

@tortis
Copy link

tortis commented Mar 19, 2022

I made an attempt at implementing this feature a while back, with some success. However, I was playing around with learning c and PHP extensions and I went a bit off the rails, so my fork is probably not a suitable contribution to this project.

https://github.com/tortis/php-meminfo#enable-dump-on-limit

@jdecool
Copy link
Contributor Author

jdecool commented Mar 19, 2022

Good work @tortis

I think you can try to add this feature in the official project.
I think @BitOne will help you to improve your code if needed :)

@tortis
Copy link

tortis commented Mar 19, 2022

I think the changes required to add this feature alone wouldn't be too bad. One problem that I ran into when testing it, was that it was very easy to trigger a secondary OOM error while performing the memory dump triggered by the original OOM error.

I attempted to mitigate this problem by converting the "visited items" hash set to not use a PHP (zend) hash which was causing more PHP allocations that can trigger the PHP runtime to OOM again. This might have not been necessary at all, since I think you could just turn off (or increase) the zend memory limit when the first OOM happens. I don't know for sure if that works.

For the same reason, I also converted the recursive traversal to iterative with a stack.

Most of the other changes on my fork were just random stuff where I was playing with the code and doing light refactoring while trying to understand how it works.

@BitOne Is this a feature you'd be interested in adding? I could try an implementation of it with out all the other changes. Or if you'd rather handle it yourself feel free to use any of the work on my branch.

@BitOne
Copy link
Owner

BitOne commented Mar 25, 2022

Hello!

That would be a wonderful feature! I remember I discussed it some years ago with Julien Pauli who at that time was release manager of PHP.

It's something that exists on the Java Virtual Machine, and it is indeed extremely useful.

If that's okay for you @tortis , can you do a PR here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants