From 302a259fa9755537f3bbcb2e848fade9e711ff5c Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Mon, 28 Jan 2019 19:53:30 -0800 Subject: meminfo: handle multiple buffer references in dmabufinfo Change the dmabufinfo library to handle multiple references to the same buffer across PIDs by doing these changes: - Add function AppendDmaBufInfo: appends the information for a specific PID to an existing DmaBuffer vector - Change the way fd/map references to a buffer belonging to a PID are stored in DmaBuffer from vector to unorderedmap - When parsing proc/%pid/{maps|fds}, look up the buffer by inode and update the data if found Test: builds Bug: 63860998 Change-Id: If22feea772f182086ae3446b46d626a750674b1f Signed-off-by: Erick Reyes --- libmeminfo/libdmabufinfo/dmabufinfo.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'libmeminfo/libdmabufinfo/dmabufinfo.cpp') diff --git a/libmeminfo/libdmabufinfo/dmabufinfo.cpp b/libmeminfo/libdmabufinfo/dmabufinfo.cpp index 41ecc5195..b4ad6678a 100644 --- a/libmeminfo/libdmabufinfo/dmabufinfo.cpp +++ b/libmeminfo/libdmabufinfo/dmabufinfo.cpp @@ -119,9 +119,23 @@ static bool ReadDmaBufFdRefs(pid_t pid, std::vector* dmabufs) { return false; } - DmaBuffer& buf = + uint64_t inode = sb.st_ino; + auto buf = std::find_if(dmabufs->begin(), dmabufs->end(), + [&inode](const DmaBuffer& dbuf) { return dbuf.inode() == inode; }); + if (buf != dmabufs->end()) { + if (buf->name() == "" || buf->name() == "") + buf->SetName(name); + if (buf->exporter() == "" || buf->exporter() == "") + buf->SetExporter(exporter); + if (buf->count() == 0) + buf->SetCount(count); + buf->AddFdRef(pid); + return true; + } + + DmaBuffer& db = dmabufs->emplace_back(sb.st_ino, sb.st_blocks * 512, count, exporter, name); - buf.AddFdRef(pid); + db.AddFdRef(pid); } return true; @@ -225,6 +239,10 @@ bool ReadDmaBufInfo(std::vector* dmabufs, const std::string& path) { bool ReadDmaBufInfo(pid_t pid, std::vector* dmabufs) { dmabufs->clear(); + return AppendDmaBufInfo(pid, dmabufs); +} + +bool AppendDmaBufInfo(pid_t pid, std::vector* dmabufs) { if (!ReadDmaBufFdRefs(pid, dmabufs)) { LOG(ERROR) << "Failed to read dmabuf fd references"; return false; -- cgit v1.2.3