Return 0 for process gpu mem if no entry found
If no entry is found with the process PID in the gpu_mem_total BPF map,
return 0 for the process's GPU memory usage.
Test: libmeminfo_test
Bug: 208594690
Change-Id: If22b754b3f9a570e0fc12741385e4b461f52e0db
diff --git a/sysmeminfo.cpp b/sysmeminfo.cpp
index b1593b8..b7a9c70 100644
--- a/sysmeminfo.cpp
+++ b/sysmeminfo.cpp
@@ -373,6 +373,8 @@
#if defined(__ANDROID__) && !defined(__ANDROID_APEX__) && !defined(__ANDROID_VNDK__)
static constexpr const char kBpfGpuMemTotalMap[] = "/sys/fs/bpf/map_gpu_mem_gpu_mem_total_map";
+ uint64_t gpu_mem;
+
// BPF Key [32-bits GPU ID | 32-bits PID]
uint64_t kBpfKeyGpuUsage = ((uint64_t)gpu_id << 32) | pid;
@@ -384,13 +386,18 @@
}
auto res = map.readValue(kBpfKeyGpuUsage);
- if (!res.ok()) {
+
+ if (res.ok()) {
+ gpu_mem = res.value();
+ } else if (res.error().code() == ENOENT) {
+ gpu_mem = 0;
+ } else {
LOG(ERROR) << "Invalid file format: " << kBpfGpuMemTotalMap;
return false;
}
if (size) {
- *size = res.value() / 1024;
+ *size = gpu_mem / 1024;
}
return true;
#else