Memory leak ?
Memory leak ?
I am in streaming mode, doing what's suggested;
- ps5000aSetSimpleTrigger(no trigger)
- ps5000aSetDataBuffer()
- ps5000aRunStreaming()
- looping around ps5000aGetStreamingLatestValues()
All is working nicely, but the memory footprint is going up to the gigabytes steadily...
I do NOT allocate memory during the loop, even if I take out all my code, the used memory is increasing. Looks like a a memory leak, maybe in the driver? I know supposedly the driver stores the data, but how can I tell it to release the data as I already processed it? Or should I just use ps5000aGetValuesAsync() ?
But the manual suggest to use ps5000aGetStreamingLatestValues()... Any insights?
Thanks,
Attila
Driver Version: 2.1.82.3072
USB Version: 3.0
Hardware Version: 1
Variant Info: 5244D
Serial: JZ244/0124
Cal Date: 21Jul22
Kernel Version: 1.0
Digital HW Version: 1
Analogue HW Version: 1
Firmware 1: 1.7.15.0
Firmware 2: 1.2.34.0
Re: Memory leak ?
I have had a PS4000 series scope running for months in streaming mode without a problem in C++.
Benno
Re: Memory leak ?
Re: Memory leak ?
Now, the data is indeed present in the buffer and I can use it, but for some reason the memory footprint is just growing... I suspect the driver still stores the data and does not release it?
If I try calling the GetValues() function from the callback, I get an error saying I'm already collecting.
Insight is appreciated.
Code: Select all
uint8_t g_running = 1;
void PREF4 callBackStreaming(int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void* pParameter)
{
// Can not call ps5000aGetValuesAsync() here as it gives PICO_DRIVER_FUNCTION error (A driver function has already been called and not yet finished. Only one call to the driver can be made at any one time.)
// ps5000aGetValues() is for block mode only
// pParameter points to the collection buffer and startindex is at first sample there with noOfSamples -> Data is there.
if (autoStop) g_running = 0;
}
int8_t collectStreamingImmediate(UNIT* unit)
{
int16_t* driverBuffer[1];
PICO_STATUS status;
uint32_t sampleInterval;
if (PICO_OK != ps5000aSetSimpleTrigger(unit->handle, 0, PS5000A_CHANNEL_A, 0, PS5000A_RISING, 0, 0)) return 1;
if (NULL == (driverBuffer[0] = (int16_t*)calloc(DATA_BUFFER_SIZE, sizeof(int16_t)))) return 2;
// if (PICO_OK != ps5000aSetDataBuffers(unit->handle, (PS5000A_CHANNEL)0, NULL, NULL, 0, 0, PS5000A_RATIO_MODE_NONE)) return 3;
if (PICO_OK != ps5000aSetDataBuffer(unit->handle, (PS5000A_CHANNEL)0, driverBuffer[0], DATA_BUFFER_SIZE, 0, PS5000A_RATIO_MODE_NONE)) return 4;
sampleInterval = 256; // Sample at 256ns (8 ns per sample is max resolution) -> needs to be 2^
if (PICO_OK != ps5000aRunStreaming(unit->handle, &sampleInterval, PS5000A_NS, 0, 39062500, 1, 1, PS5000A_RATIO_MODE_NONE, DATA_BUFFER_SIZE)) return 4; // 10 seconds -> at every 256 ns
g_running = 1;
while (g_running)
{
status = ps5000aGetStreamingLatestValues(unit->handle, callBackStreaming, &driverBuffer);
}
ps5000aStop(unit->handle);
if (PICO_OK != ps5000aSetDataBuffer(unit->handle, (PS5000A_CHANNEL)0, NULL, 0, 0, PS5000A_RATIO_MODE_NONE)) return 5;
return 0;
}
Re: Memory leak ?
Code: Select all
ps5000aGetStreamingLatestValues(unit->handle, callBackStreaming, &driverBuffer);
Technical Support Manager
Re: Memory leak ?
https://community.intel.com/t5/Intel-on ... %20America
https://github.com/mono/mono/pull/8090
The leak happens both with the simulated device and the actual one (2000 Series).
By the way, PicoScope, as downloaded from your site, was crashing right after start. I have managed to let it run by downloading your SDK and substituting libpicoipp.1.dylib in the PicoScope package Resources by the one contained in the SDK.
The only other available version for PicoScope (last 6) does not even start. I have tried to install mono from their website and with Homebrew.
Would be nice to have a working software - I'm even considering returning this scope.
Re: Memory leak ?
>>ps5000aGetStreamingLatestValues(unit->handle, callBackStreaming, &driverBuffer);
>You shouldn't pass &driverBuffer into the call back, this parameter is used for passing
>a parameter to the callback function to write values to, it is not related to the actual data.
>In most cases this can be a null pointer.
I thought I have to provide the user allocated buffer (driverBuffer) to ps5000aSetDataBuffer() for the driver to put the data into, no?
If I do that, I have to know into which buffer was the data read by the driver, thus I'm passing that info over to the callback, as I'm not using a global variable.
What am I missing?
What I really do not understand is that the memory footprint of the application grows, even when my user program is not allocating extra memory. Looks like the PicoTech driver keeps allocating more and more memory as it reads from the scope. Thus, my question, how should I tell the driver NOT to keep allocating buffers, but re-use the same one. What is the right usage (sample code?) for streaming data from the scope?
Re: Memory leak ?
Also there is a streaming example in it.
https://github.com/picotech/picosdk-c-examples
Benno
Re: Memory leak ?
For some reason, I thought that the maxPostTriggerSamples value has to be the same as the number of samples collected. Now I understand it has nothing to do with that.
I now set both maxPreTriggerSamples and maxPostTriggerSamples to 0, and simply stream the data from the scope to my ring buffer from which an other thread writes it to file.
Thanks, case closed.