libdmabufinfo: fix PSS calculation

Only map references should be taken into account when calculating PSS. Fd
references if the file is not mapped should not affect PSS.

Bug: 138148041
Test: dmabuf_dump -a
Change-Id: Ibbcb9c3a6c57d753ea1cd016c4345dd1438ddc19
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
diff --git a/libdmabufinfo/include/dmabufinfo/dmabufinfo.h b/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
index a6e7f69..29357c7 100644
--- a/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
+++ b/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
@@ -62,7 +62,7 @@
     void SetName(const std::string& name) { name_ = name; }
     void SetExporter(const std::string& exporter) { exporter_ = exporter; }
     void SetCount(uint64_t count) { count_ = count; }
-    uint64_t Pss() const { return size_ / pids_.size(); }
+    uint64_t Pss(pid_t pid) const { return maprefs_.count(pid) > 0 ? size_ / maprefs_.size() : 0; }
 
     bool operator==(const DmaBuffer& rhs) {
         return (inode_ == rhs.inode()) && (size_ == rhs.size()) && (name_ == rhs.name()) &&
diff --git a/libdmabufinfo/tools/dmabuf_dump.cpp b/libdmabufinfo/tools/dmabuf_dump.cpp
index fb009dd..fe58178 100644
--- a/libdmabufinfo/tools/dmabuf_dump.cpp
+++ b/libdmabufinfo/tools/dmabuf_dump.cpp
@@ -158,11 +158,12 @@
         printf("%22s %16s %16s %16s %16s\n", "Name", "Rss", "Pss", "nr_procs", "Inode");
         for (auto& inode : inodes) {
             DmaBuffer& buf = inode_to_dmabuf[inode];
+            uint64_t proc_pss = buf.Pss(pid);
             printf("%22s %13" PRIu64 " kB %13" PRIu64 " kB %16zu %16" PRIuMAX "\n",
                    buf.name().empty() ? "<unknown>" : buf.name().c_str(), buf.size() / 1024,
-                   buf.Pss() / 1024, buf.pids().size(), static_cast<uintmax_t>(buf.inode()));
+                   proc_pss / 1024, buf.pids().size(), static_cast<uintmax_t>(buf.inode()));
             rss += buf.size();
-            pss += buf.Pss();
+            pss += proc_pss;
         }
         printf("%22s %13" PRIu64 " kB %13" PRIu64 " kB %16s\n", "PROCESS TOTAL", rss / 1024,
                pss / 1024, "");