We have an app using libgphoto2 and libmagickwand on Raspberry Pi. The app captures a preview from a camera with gphoto2 and uses magickwand to draw a circle at the center of the preview. The app starts up fine. But over time, calls to magickwand often take longer and longer to complete.
The code in question look like the following (irrelevant lines removed):
Below is the timing in milliseconds at the beginning (measured using boost::chrono::high_resolution_clock): (1), (2), ... corresponding to // (1), // (2), ... in the code.
The timing will be like this for about 10-15 seconds. Then some functions start to takes a very long time to complete. For example:
This does not happen every cycle, but regularly enough to make the code unusable. The delay is limited to some magickwand functions (read blob, scale, sample, ...). None of the gphoto2 functions show any changes in the processing time. We use "top" to monitor CPU usage, and during these delays the usage jumps from 30+% to 90+%.
Any guess on what cause this delay and how to fix it? By the way, the problem happens only on a Raspberry Pi (limited resources), and not on a regular desktop running Linux.
The code in question look like the following (irrelevant lines removed):
CODE:
while(1){ retval = gp_camera_capture_preview(m_camera, m_pCamFile, m_context); // (1) gphoto2 call to get a preview image from a camera. gp_file_get_data_and_size(m_pCamFile, &pData, (unsigned long *) &dataSize); // (2) gphoto2 call to copy the image (jpeg file) to a buffer. MagickReadImageBlob(m_magickWand, pData, dataSize); // (3) magickwand call to load the in-memory file to a buffer. MagickDrawImage(m_magickWand, m_drawWand); // (4) m_drawWand hold a simple shape such as a circle. pModData = MagickGetImageBlob(m_magickWand, &dataSize); // (5) magickwand call to get the preview+circle to a buffer // memcpy pModData to a shared memory. MagickRelinquishMemory(pModData); // (6)}
CODE:
Duration Capture: 84. (1) Duration Getdata: 0. (2) Duration ReadImageBlob: 73. (3) Duration Draw: 16. (4)(forgot to print (5)) Duration copy and cleanup: 0. (6)
CODE:
Duration Capture: 42. Duration Getdata: 0. Duration ReadImageBlob: 2562. <===== Duration Draw: 65. Duration copy and cleanup: 0.
Any guess on what cause this delay and how to fix it? By the way, the problem happens only on a Raspberry Pi (limited resources), and not on a regular desktop running Linux.
Statistics: Posted by chu_bun — 2020-03-03T16:49:53-07:00