Snap for 7929046 from 91c67215e53b8a6ce9dcf4575df253c4070b07da to mainline-adbd-release
Change-Id: I21f4a4289e7baec8ea1680286f55b782e51ec596
diff --git a/libdmabufinfo/dmabuf_sysfs_stats.cpp b/libdmabufinfo/dmabuf_sysfs_stats.cpp
index c9254fc..e5a6486 100644
--- a/libdmabufinfo/dmabuf_sysfs_stats.cpp
+++ b/libdmabufinfo/dmabuf_sysfs_stats.cpp
@@ -45,42 +45,6 @@
return true;
}
-static bool GetDmabufAttachmentStats(const std::string& attachment_dir_path,
- std::vector<DmabufAttachmentInfo>& info) {
- std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(attachment_dir_path.c_str()), closedir);
-
- if (!dir) {
- PLOG(ERROR) << "Unable to access: " << attachment_dir_path;
- return false;
- }
-
- struct dirent* dent;
- while ((dent = readdir(dir.get()))) {
- if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue;
- std::string attachment_entry_path =
- ::android::base::StringPrintf("%s/%s", attachment_dir_path.c_str(), dent->d_name);
-
- std::string dev_path;
- if (!android::base::Readlink(attachment_entry_path + "/device", &dev_path)) return false;
-
- DmabufAttachmentInfo attachInfo = {};
- attachInfo.device = android::base::Basename(dev_path);
- if (!ReadUintFromFile(attachment_entry_path + "/map_counter", &attachInfo.map_count))
- return false;
-
- info.emplace_back(attachInfo);
- }
-
- return true;
-}
-
-bool ReadBufferTotalMmapCount(unsigned int inode, unsigned int* mmap_count,
- const std::string& dmabuf_sysfs_path) {
- std::string mmap_count_path =
- ::android::base::StringPrintf("%s/%u/mmap_count", dmabuf_sysfs_path.c_str(), inode);
- return ReadUintFromFile(mmap_count_path, mmap_count);
-}
-
bool ReadBufferExporter(unsigned int inode, std::string* exporter,
const std::string& dmabuf_sysfs_path) {
std::string exporter_path =
@@ -99,8 +63,7 @@
// clear stats
*stats = {};
- // Iterate over all the buffer directories to save exporter name, size, mmap
- // count and attachment information.
+ // Iterate over all the buffer directories to save exporter name, and size.
struct dirent* dent;
while ((dent = readdir(dir.get()))) {
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue;
@@ -134,10 +97,6 @@
stats->total_.size += info.size;
stats->total_.buffer_count++;
- // Read attachments on this buffer.
- std::string attachment_dir = buf_entry_path + "/attachments";
- if (!GetDmabufAttachmentStats(attachment_dir, info.attachments)) return false;
-
stats->buffer_stats_.emplace_back(info);
// update exporter_info_ map.
@@ -149,18 +108,6 @@
struct DmabufTotal total = {.size = info.size, .buffer_count = 1};
stats->exporter_info_[info.exp_name] = total;
}
-
- // update importer_info_ map.
- for (auto& attachment : info.attachments) {
- auto imp_stats = stats->importer_info_.find(attachment.device);
- if (imp_stats != stats->importer_info_.end()) {
- imp_stats->second.size += info.size;
- imp_stats->second.buffer_count++;
- } else {
- struct DmabufTotal total = {.size = info.size, .buffer_count = 1};
- stats->importer_info_[attachment.device] = total;
- }
- }
}
return true;
diff --git a/libdmabufinfo/dmabufinfo.cpp b/libdmabufinfo/dmabufinfo.cpp
index a0fc9da..422fc6e 100644
--- a/libdmabufinfo/dmabufinfo.cpp
+++ b/libdmabufinfo/dmabufinfo.cpp
@@ -302,38 +302,5 @@
return true;
}
-bool ReadDmaBufPss(int pid, uint64_t* pss, const std::string& procfs_path,
- const std::string& dmabuf_sysfs_path) {
- std::vector<DmaBuffer> dmabufs;
-
- if (!ReadDmaBufMapRefs(pid, &dmabufs, procfs_path, dmabuf_sysfs_path)) {
- LOG(ERROR) << "Failed to read mapped DMA buffers for pid " << pid;
- return false;
- }
-
- *pss = 0;
- for (const auto& buf : dmabufs) {
- const auto& maprefs = buf.maprefs();
- auto maprefs_it = maprefs.find(pid);
- if (maprefs_it == maprefs.end()) {
- LOG(ERROR) << "Failed to retrieve DMA buffer mmap count for pid " << pid;
- return false;
- }
- int process_mmap_count = maprefs_it->second;
-
- unsigned int total_mmap_count;
- if (!ReadBufferTotalMmapCount(buf.inode(), &total_mmap_count, dmabuf_sysfs_path)) {
- LOG(ERROR) << "Failed to read size DMA buffer total_mmap_count from sysfs";
- return false;
- }
-
- if (total_mmap_count > 0) {
- *pss += process_mmap_count / total_mmap_count * buf.size();
- }
- }
-
- return true;
-}
-
} // namespace dmabufinfo
} // namespace android
diff --git a/libdmabufinfo/dmabufinfo_test.cpp b/libdmabufinfo/dmabufinfo_test.cpp
index 362eca7..c7f6581 100644
--- a/libdmabufinfo/dmabufinfo_test.cpp
+++ b/libdmabufinfo/dmabufinfo_test.cpp
@@ -244,13 +244,10 @@
TEST_F(DmaBufSysfsStatsParser, TestReadDmaBufSysfsStats) {
using android::base::StringPrintf;
- const std::string device_name = "my_device";
for (unsigned int inode_number = 74831; inode_number < 74841; inode_number++) {
- auto attach_dir_path = StringPrintf("buffers/%u/attachments/2", inode_number);
- ASSERT_TRUE(fs::create_directories(attach_dir_path));
-
auto buffer_path = buffer_stats_path / StringPrintf("%u", inode_number);
+ ASSERT_TRUE(fs::create_directories(buffer_path));
auto buffer_size_path = buffer_path / "size";
const std::string buffer_size = "4096";
@@ -259,15 +256,6 @@
auto exp_name_path = buffer_path / "exporter_name";
const std::string exp_name = "system";
ASSERT_TRUE(android::base::WriteStringToFile(exp_name, exp_name_path));
-
- auto attachment_dir = buffer_path / "attachments/2";
-
- auto device_path = attachment_dir / "device";
- fs::create_symlink(device_name, device_path);
-
- auto map_count_path = attachment_dir / "map_counter";
- const std::string map_count = "1";
- ASSERT_TRUE(android::base::WriteStringToFile(map_count, map_count_path));
}
DmabufSysfsStats stats;
@@ -281,13 +269,6 @@
EXPECT_EQ(buf_info.exp_name, "system");
EXPECT_EQ(buf_info.size, 4096UL);
- auto attach_stats = buf_info.attachments;
- ASSERT_EQ(attach_stats.size(), 1UL);
- auto attach_info = attach_stats[0];
- EXPECT_EQ(attach_info.map_count, 1UL);
-
- EXPECT_EQ(attach_info.device, device_name);
-
auto exporter_stats = stats.exporter_info();
ASSERT_EQ(exporter_stats.size(), 1UL);
auto exp_info = exporter_stats.find("system");
@@ -295,14 +276,6 @@
EXPECT_EQ(exp_info->second.size, 40960UL);
EXPECT_EQ(exp_info->second.buffer_count, 10UL);
- auto importer_stats = stats.importer_info();
- ASSERT_EQ(importer_stats.size(), 1UL);
- auto imp_info = importer_stats.find(device_name);
- ASSERT_TRUE(imp_info != importer_stats.end());
-
- EXPECT_EQ(imp_info->second.size, 40960UL);
- EXPECT_EQ(imp_info->second.buffer_count, 10UL);
-
auto total_size = stats.total_size();
EXPECT_EQ(total_size, 40960UL);
@@ -416,25 +389,6 @@
ASSERT_EQ(dmabuf2->exporter(), exporter);
}
-TEST_F(DmaBufProcessStatsTest, TestReadDmaBufPss) {
- AddFdInfo(1, 1024, false);
- AddFdInfo(2, 2048, true); // Dmabuf 1
-
- std::vector<std::string> map_entries;
- map_entries.emplace_back(CreateMapEntry(3, 1024, false));
- map_entries.emplace_back(CreateMapEntry(4, 1024, true)); // Dmabuf 2
- map_entries.emplace_back(CreateMapEntry(4, 1024, true)); // Dmabuf 2
- AddMapEntries(map_entries);
-
- AddSysfsDmaBufStats(2, 2048, 1); // Dmabuf 1
- AddSysfsDmaBufStats(4, 1024, 5); // Dmabuf 2
-
- uint64_t expected_pss = 2 / 5 * 1024;
- uint64_t pss = 0;
- ASSERT_TRUE(ReadDmaBufPss(pid, &pss, procfs_path, dmabuf_sysfs_path));
- ASSERT_EQ(pss, expected_pss);
-}
-
TEST_F(DmaBufProcessStatsTest, TestReadDmaBufFdRefs) {
AddFdInfo(1, 1024, false);
AddFdInfo(2, 2048, true); // Dmabuf 1
diff --git a/libdmabufinfo/include/dmabufinfo/dmabuf_sysfs_stats.h b/libdmabufinfo/include/dmabufinfo/dmabuf_sysfs_stats.h
index c7729ea..a7c0841 100644
--- a/libdmabufinfo/include/dmabufinfo/dmabuf_sysfs_stats.h
+++ b/libdmabufinfo/include/dmabufinfo/dmabuf_sysfs_stats.h
@@ -23,29 +23,16 @@
namespace dmabufinfo {
/*
- * struct DmabufAttachmentInfo: Information about an attachment on the DMA-BUF.
- *
- * @device: Name of the attaching device.
- * @map_count: The number of distinct mappings of the attachment.
- */
-struct DmabufAttachmentInfo {
- std::string device;
- unsigned int map_count;
-};
-
-/*
* struct DmabufInfo: Represents information about a DMA-BUF.
*
* @inode: The unique inode number for the buffer.
* @exp_name: Name of the exporter of the buffer.
* @size: Size of the buffer.
- * @attachments: represents all attachments on the DMA-BUF.
*/
struct DmabufInfo {
unsigned int inode;
std::string exp_name;
unsigned int size;
- std::vector<DmabufAttachmentInfo> attachments;
};
struct DmabufTotal {
@@ -59,9 +46,6 @@
inline const std::unordered_map<std::string, struct DmabufTotal>& exporter_info() const {
return exporter_info_;
}
- inline const std::unordered_map<std::string, struct DmabufTotal>& importer_info() const {
- return importer_info_;
- }
inline uint64_t total_size() const { return total_.size; }
inline unsigned int total_count() const { return total_.buffer_count; }
@@ -70,13 +54,12 @@
private:
std::vector<DmabufInfo> buffer_stats_;
std::unordered_map<std::string, struct DmabufTotal> exporter_info_;
- std::unordered_map<std::string, struct DmabufTotal> importer_info_;
struct DmabufTotal total_;
};
/*
- * Reads and parses DMA-BUF statistics from sysfs to create per-buffer,
- * per-exporter and per-importer stats.
+ * Reads and parses DMA-BUF statistics from sysfs to create per-buffer
+ * and per-exporter stats.
*
* @stats: output argument that will be populated with information from DMA-BUF sysfs stats.
* @path: Not for use by clients, to be used only for unit testing.
@@ -97,10 +80,6 @@
bool GetDmabufTotalExportedKb(uint64_t* total_exported,
const std::string& path = "/sys/kernel/dmabuf/buffers");
-/* Reads the total mmap count of the DMA buffer with @inode */
-bool ReadBufferTotalMmapCount(unsigned int inode, unsigned int* mmap_count,
- const std::string& dmabuf_sysfs_path = "/sys/kernel/dmabuf/buffers");
-
/* Reads the exporter name of the DMA buffer with @inode */
bool ReadBufferExporter(unsigned int inode, std::string* exporter,
const std::string& dmabuf_sysfs_path = "/sys/kernel/dmabuf/buffers");
diff --git a/libdmabufinfo/tools/dmabuf_dump.cpp b/libdmabufinfo/tools/dmabuf_dump.cpp
index 2466e78..57204f6 100644
--- a/libdmabufinfo/tools/dmabuf_dump.cpp
+++ b/libdmabufinfo/tools/dmabuf_dump.cpp
@@ -228,7 +228,6 @@
auto buffer_stats = stats.buffer_stats();
auto exporter_stats = stats.exporter_info();
- auto importer_stats = stats.importer_info();
printf("\n\n----------------------- DMA-BUF per-buffer stats -----------------------\n");
printf(" Dmabuf Inode | Size(bytes) | Exporter Name |\n");
@@ -236,21 +235,6 @@
printf("%16u |%16u | %16s \n", buf.inode, buf.size, buf.exp_name.c_str());
}
- printf("\n\n----------------------- DMA-BUF attachment stats -----------------------\n");
- printf(" Dmabuf Inode | Attachment(Map Count)\n");
- for (const auto& buf : buffer_stats) {
- printf("%16u", buf.inode);
-
- if (buf.attachments.empty()) {
- printf(" None\n");
- continue;
- }
-
- for (const auto& attachment : buf.attachments)
- printf("%20s(%u) ", attachment.device.c_str(), attachment.map_count);
- printf("\n");
- }
-
printf("\n\n----------------------- DMA-BUF exporter stats -----------------------\n");
printf(" Exporter Name | Total Count | Total Size(bytes) |\n");
for (const auto& it : exporter_stats) {
@@ -258,15 +242,6 @@
it.second.size);
}
- if (!importer_stats.empty()) {
- printf("\n\n---------------------- DMA-BUF per-device stats ----------------------\n");
- printf(" Device | Total Count | Total Size(bytes) |\n");
- for (const auto& it : importer_stats) {
- printf("%32s | %12u| %" PRIu64 "\n", it.first.c_str(), it.second.buffer_count,
- it.second.size);
- }
- }
-
printf("\n\n----------------------- DMA-BUF total stats --------------------------\n");
printf("Total DMA-BUF count: %u, Total DMA-BUF size(bytes): %" PRIu64 "\n", stats.total_count(),
stats.total_size());
diff --git a/libmeminfo_test.cpp b/libmeminfo_test.cpp
index 2ae9dc0..c41e4ff 100644
--- a/libmeminfo_test.cpp
+++ b/libmeminfo_test.cpp
@@ -1009,10 +1009,8 @@
ASSERT_TRUE(android::base::WriteStringToFile("test", system_heap_path));
for (unsigned int inode_number = 74831; inode_number < 74841; inode_number++) {
- auto attach_dir_path = StringPrintf("buffers/%u/attachments", inode_number);
- ASSERT_TRUE(fs::create_directories(attach_dir_path));
-
auto buffer_path = buffer_stats_path / StringPrintf("%u", inode_number);
+ ASSERT_TRUE(fs::create_directories(buffer_path));
auto buffer_size_path = buffer_path / "size";
const std::string buffer_size = "4096";