Codeception icon indicating copy to clipboard operation
Codeception copied to clipboard

[Feature] Show peak memory usage for each executed test

Open aedart opened this issue 2 years ago • 4 comments

Sometimes, when you have many tests for an application, it can be difficult to know when where a component or parts of the system has a memory leak or just consumes a lot of memory. To make it a bit easier to identify such situations, it would be really nice if the default console output could include peak memory usage, per test.

Possible Solution

Ideally, this feature should be added when running PHP v8.2 and upwards, such that memory_get_peak_usage() and memory_reset_peak_usage.

Thus far, I think that it can be implemented as part of the \Codeception\Subscriber\Console::writelnFinishedTest() method, just after the execution time is shown.

However, I'm not that familiar with Codeception's internals... Maybe \Codeception\Test\Test and \Codeception\Event\TestEvent should be updated to support a memory used value? In any case, this would be a small and yet very useful feature.

References

aedart avatar Jan 27 '23 15:01 aedart

If you want this feature very much you can implement custom extension based on Console subscriber and use it in your tests See https://codeception.com/docs/Reporting#Custom-Reporter and https://codeception.com/extensions

Naktibalda avatar Jan 31 '23 17:01 Naktibalda

Alright, thanks.

aedart avatar Feb 05 '23 17:02 aedart

This is a good feature suggestion, so I will leave it open.

You are welcome to raise a pull request with implementation.

Naktibalda avatar Feb 06 '23 07:02 Naktibalda

I made a custom reporter based on the default one for an internal project which displays the current step before the test name and memory consumption of the current test, the total memory and the memor peak. It looks like: image

It is not production ready as it doesn't consider the config from the command line arguments and is not customizable. Perhaps it helps to get you started with your own reporter.

@Naktibalda If you can guide me here a bit I can create a pr if you think some of the code can be used in the Codeception itself as I'm happy to contribute it.

laoneo avatar Nov 01 '23 08:11 laoneo