php-memory-profiler icon indicating copy to clipboard operation
php-memory-profiler copied to clipboard

Pause and resume profiling?

Open rask opened this issue 5 years ago • 2 comments

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?

rask avatar Aug 13 '19 11:08 rask

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.

arnaud-lb avatar Aug 22 '19 11:08 arnaud-lb

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 ?

rask avatar Aug 22 '19 14:08 rask