[Feature] Show peak memory usage for each executed test
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
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
Alright, thanks.
This is a good feature suggestion, so I will leave it open.
You are welcome to raise a pull request with implementation.
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:
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.