phpunit-vw icon indicating copy to clipboard operation
phpunit-vw copied to clipboard

Feature request: Report 1/2 memory

Open hopeseekr opened this issue 9 years ago • 5 comments

Please have PHPUnit report half the amount of actual memory used in the CI environment ;-)

hopeseekr avatar Oct 06 '15 18:10 hopeseekr

Any idea how to spoof memory_get_peak_usage() ? ^^

hugues-m avatar Oct 07 '15 08:10 hugues-m

You could use runkit extension. Remember to set appropriate flag (internal_override) inside php configuration file i.e. /etc/php/5.5/conf.d/ext-runkit.ini:

[runkit]
extension="/usr/local/opt/php55-runkit/runkit.so"
runkit.internal_override = On

Result:

php > var_dump(memory_get_peak_usage());
int(236288)
php > runkit_function_copy('memory_get_peak_usage', 'memory_get_peak_usage_old');
php > runkit_function_redefine('memory_get_peak_usage', '', 'return (memory_get_peak_usage_old() / 2);');
php > var_dump(memory_get_peak_usage());
int(122432)

Ref:

  • http://php.net/manual/en/function.runkit-function-redefine.php
  • http://php.net/manual/en/runkit.configuration.php

radekk avatar Oct 07 '15 09:10 radekk

+1 my job depends on this

evillemez avatar Oct 07 '15 15:10 evillemez

The moment you install the runkit extension you loose the battle !
It would be easy to even rewrite PhpUnit methods to display unicorns instead of test results. But I don't see any dev in his right mind installing this php extension, and I think part of the fun of this component is its ease of installation and usage ^^

hugues-m avatar Oct 08 '15 08:10 hugues-m

We will not say how I know this, but you can manipulate the literal text of PHPUnit using ob_get_clean() and judicious use of preg_replace() followed with an echo. Try doing this in your endTestSuite() of the listener.

hopeseekr avatar Oct 08 '15 20:10 hopeseekr