Skip to content

Commit 00b2f83

Browse files
committed
Merge branch 'feature/memory_leak_testing' into firmware_version_upgrade
2 parents 7c31897 + 88e26bd commit 00b2f83

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

bindings/python/src/DeviceBindings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack) {
607607
return d.getLeonMssCpuUsage();
608608
},
609609
DOC(dai, DeviceBase, getLeonMssCpuUsage))
610+
.def(
611+
"getProcessMemoryUsage",
612+
[](DeviceBase& d) {
613+
py::gil_scoped_release release;
614+
return d.getProcessMemoryUsage();
615+
},
616+
DOC(dai, DeviceBase, getProcessMemoryUsage))
610617
.def(
611618
"addLogCallback",
612619
[](DeviceBase& d, std::function<void(LogMessage)> callback) {

include/depthai/device/DeviceBase.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ class DeviceBase {
592592
*/
593593
CpuUsage getLeonMssCpuUsage();
594594

595+
/**
596+
* Retrieves current Rss memory usage of the device process
597+
*
598+
* @returns Current Rss memory used
599+
*/
600+
int64_t getProcessMemoryUsage();
601+
595602
/**
596603
* Check if EEPROM is available
597604
* @returns True if EEPROM is present on board, false otherwise

src/device/DeviceBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,10 @@ CpuUsage DeviceBase::getLeonMssCpuUsage() {
12411241
return pimpl->rpcClient->call("getLeonMssCpuUsage").as<CpuUsage>();
12421242
}
12431243

1244+
int64_t DeviceBase::getProcessMemoryUsage() {
1245+
return pimpl->rpcClient->call("getProcessMemoryUsage").as<int64_t>();
1246+
}
1247+
12441248
UsbSpeed DeviceBase::getUsbSpeed() {
12451249
return pimpl->rpcClient->call("getUsbSpeed").as<UsbSpeed>();
12461250
}

tests/stability/stability_test_depthai.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import time
44
from typing import List, Dict
55
import datetime
6+
import sys
7+
8+
MEMORY_LEAK_DETECTION_THRESHOLD = 1.05
69

710
def stability_test(fps):
811
# Creates the pipeline and a default device implicitly
@@ -66,6 +69,11 @@ def stability_test(fps):
6669
print("Starting the stability test...")
6770
tStart = time.time()
6871
p.start()
72+
73+
# Delay so the device process finishes starting up
74+
time.sleep(10)
75+
initialProcessMemoryUsage = p.getDefaultDevice().getProcessMemoryUsage()
76+
print(f"Initial depthai-device process memory usage is: {initialProcessMemoryUsage} kB")
6977
while True:
7078
for name, queue in benchmarkReportQueues.items():
7179
report = queue.get(timeout=datetime.timedelta(minutes=1)) # 1 minute timeout
@@ -77,6 +85,12 @@ def stability_test(fps):
7785
else:
7886
raise RuntimeError(f"Timeout reached for {name} benchmark report")
7987
queue.tryGetAll() # Clear the queue
88+
89+
# Detect memory leaks
90+
processMemoryUsage = p.getDefaultDevice().getProcessMemoryUsage()
91+
if processMemoryUsage > MEMORY_LEAK_DETECTION_THRESHOLD * initialProcessMemoryUsage:
92+
raise RuntimeError("Memory used by depthai-device process increased above the given threshold - potential memory leak detected")
93+
print(f"Memory used by depthai-device process: {processMemoryUsage} kB. Current time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}")
8094
print(f"Running for {datetime.timedelta(seconds=time.time() - tStart)}", flush=True)
8195

8296
if __name__ == "__main__":

0 commit comments

Comments
 (0)