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_test.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'libmeminfo/libdmabufinfo/dmabufinfo_test.cpp') diff --git a/libmeminfo/libdmabufinfo/dmabufinfo_test.cpp b/libmeminfo/libdmabufinfo/dmabufinfo_test.cpp index aa5f16c22..95aa2c799 100644 --- a/libmeminfo/libdmabufinfo/dmabufinfo_test.cpp +++ b/libmeminfo/libdmabufinfo/dmabufinfo_test.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -61,18 +62,16 @@ struct ion_heap_data { #define EXPECT_PID_IN_FDREFS(_bufptr, _pid, _expect) \ do { \ - const std::vector& _fdrefs = _bufptr->fdrefs(); \ - auto _ref = std::find_if(_fdrefs.begin(), _fdrefs.end(), \ - [&](const pid_t& p) { return p == _pid; }); \ - EXPECT_EQ((_ref == _fdrefs.end()), _expect); \ + const std::unordered_map& _fdrefs = _bufptr->fdrefs(); \ + auto _ref = _fdrefs.find(_pid); \ + EXPECT_EQ((_ref != _fdrefs.end()), _expect); \ } while (0) #define EXPECT_PID_IN_MAPREFS(_bufptr, _pid, _expect) \ do { \ - const std::vector& _maprefs = _bufptr->maprefs(); \ - auto _ref = std::find_if(_maprefs.begin(), _maprefs.end(), \ - [&](const pid_t& p) { return p == _pid; }); \ - EXPECT_EQ((_ref == _maprefs.end()), _expect); \ + const std::unordered_map& _maprefs = _bufptr->maprefs(); \ + auto _ref = _maprefs.find(_pid); \ + EXPECT_EQ((_ref != _maprefs.end()), _expect); \ } while (0) TEST(DmaBufInfoParser, TestReadDmaBufInfo) { -- cgit v1.2.3