Question: any way to get memory usage?
I'm trying to debug some memory usages but couldn't find anything in vips to get the real memory usage. I'm searching for a equivalent to imagicks $imagick->getResource(\Imagick::RESOURCETYPE_MEMORY);
Hello @alexander-schranz,
libvips has calls to do this, but they are not exposed by php-vips-ext, unfortunately. If you are OK compiling stuff yourself, you could add a few lines to vips.c, perhaps here:
https://github.com/libvips/php-vips-ext/blob/master/vips.c#L2073
Something like:
vips_snprintf(digits, 256, "%zd", vips_tracked_get_mem_highwater());
php_info_print_table_row(2, "Memory high water", digits);
Will add a line to php-info giving the memory high water in bytes.
That's the high water mark for memory directly allocated by libvips for image data (pixel buffers). It won't include things like libvips internal hash tables etc. etc.
I added some stuff for this. It would probably be better to have some API.
If you're seeing high memory usage, I would check that you are using sequential where you can, and that references are not being held accidentally. You could try disabling the libvips operation cache, though I wouldn't myself.
https://libvips.github.io/php-vips/docs/classes/Jcupitt.Vips.Config.html#method_cacheSetMax
I'd be happy to look at your code if you can make a small example which shows high usage.
We added lately support for the imagine vips adapter and I just wanted to compare memory usage vips vs imagick in the case how we convert images in sulu.
Sadly I'm not familiar about compiling vips myself it would be create if the library could provide functions to access the memory usage of it.
You don't need to compile libvips, just the binary extension for PHP. There are notes on the process here:
https://github.com/libvips/php-vips-ext#development-regenerate-build-system
It's just:
phpize
./configure
make
sudo make install
But if you are using imagine, you should be OK. You could watch RES for the php process to track memory usage under load.
@jcupitt Ok I'm getting the infos know in the phpinfo() but calling vips_tracked_get_mem_highwater() or vips_tracked_get_mem() itself doesnt work or what is the name of the function?
But think the values are not comparable or I'm just not sure how vips or imagick calculate them. Imagick returns me 8,25mb using the above function and Vips returns me 69mb (mem) 1,28GB (mem_highwater)
We'd need to make some kind of reproducible benchmark to track down high memory usage.
If you can make a standalone script that does what you need, I'd be happy to investigate.