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

Pause and resume profiling? #32

Open
rask opened this issue Aug 13, 2019 · 2 comments
Open

Pause and resume profiling? #32

rask opened this issue Aug 13, 2019 · 2 comments

Comments

@rask
Copy link

rask commented Aug 13, 2019

I want to profile our PHPUnit tests. I would like to limit profiling to test methods themselves, which would mean no data would be collected during bootstrapping and finding test cases to run. Simple example:

class MyTest extends TestCase
{
    public function setUp() : void
    {
        parent::setUp();

        memprof_enable();
    }

    public function tearDown() : void
    {
        memprof_disable();

        parent::tearDown();
    }

    ... test methods here ...
}

Then in a PHPUnit extension or similar, I would call memprof_dump_callgrind(...) to generate the dump file.

Problem is, when I call memprof_disable(), all collected data is lost, and the resulting dump is empty.

Is there any way to "pause and resume" memprof data collection, or am I stuck with polluting the dumps with "unrelated" code paths that are of no interest to me?

Can I build a new aggregate dump if I somehow combine dump data via memprof_dump_array(...), or will that result in strange values and invalid call paths?

@arnaud-lb
Copy link
Owner

There is no way to pause and resume currently, however the current code would allow to implement that easily (we could add a memprof_disable() option that cause it to not free the current profile). This would properly account for memory allocated between enable() and disable(), while also taking into account the memory releases happening after disable().

Aggregating the data from memprof_dump_array() would work as well, except that if some memory has been released after disable() (thus not really leaked), this will not be visible.

@rask
Copy link
Author

rask commented Aug 22, 2019

I see, I will check the array dump format some more and see if there is a straight forward way to parse that into the wanted format, even at the risk of introducing some drift in the values.

I presume the memprof_disable() option would affect code near this area: https://github.com/arnaud-lb/php-memory-profiler/blob/master/memprof.c#L757 ?

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

No branches or pull requests

2 participants