summaryrefslogtreecommitdiffstats
path: root/libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
diff options
context:
space:
mode:
Diffstat (limited to 'libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h')
-rw-r--r--libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h37
1 files changed, 31 insertions, 6 deletions
diff --git a/libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h b/libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
index 29ce4d0bd..74eff3cca 100644
--- a/libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
+++ b/libmeminfo/libdmabufinfo/include/dmabufinfo/dmabufinfo.h
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
+#include <unordered_map>
namespace android {
namespace dmabufinfo {
@@ -33,20 +34,27 @@ struct DmaBuffer {
~DmaBuffer() = default;
// Adds one file descriptor reference for the given pid
- void AddFdRef(pid_t pid) { fdrefs_.emplace_back(pid); }
+ void AddFdRef(pid_t pid) {
+ AddRefToPidMap(pid, &fdrefs_);
+ }
// Adds one map reference for the given pid
- void AddMapRef(pid_t pid) { maprefs_.emplace_back(pid); }
+ void AddMapRef(pid_t pid) {
+ AddRefToPidMap(pid, &maprefs_);
+ }
// Getters for each property
uint64_t size() { return size_; }
- const std::vector<pid_t>& fdrefs() const { return fdrefs_; }
- const std::vector<pid_t>& maprefs() const { return maprefs_; }
+ const std::unordered_map<pid_t, int>& fdrefs() const { return fdrefs_; }
+ const std::unordered_map<pid_t, int>& maprefs() const { return maprefs_; }
ino_t inode() const { return inode_; }
uint64_t total_refs() const { return fdrefs_.size() + maprefs_.size(); }
uint64_t count() const { return count_; };
const std::string& name() const { return name_; }
const std::string& exporter() const { return exporter_; }
+ void SetName(const std::string& name) { name_ = name; }
+ void SetExporter(const std::string& exporter) { exporter_ = exporter; }
+ void SetCount(uint64_t count) { count_ = count; }
private:
ino_t inode_;
@@ -54,20 +62,37 @@ struct DmaBuffer {
uint64_t count_;
std::string exporter_;
std::string name_;
- std::vector<pid_t> fdrefs_;
- std::vector<pid_t> maprefs_;
+ std::unordered_map<pid_t, int> fdrefs_;
+ std::unordered_map<pid_t, int> maprefs_;
+ void AddRefToPidMap(pid_t pid, std::unordered_map<pid_t, int>* map) {
+ // The first time we find a ref, we set the ref count to 1
+ // otherwise, increment the existing ref count
+ auto [it, inserted] = map->insert(std::make_pair(pid, 1));
+ if (!inserted)
+ it->second++;
+ }
};
// Read and return current dma buf objects from
// DEBUGFS/dma_buf/bufinfo. The references to each dma buffer are not
// populated here and will return an empty vector.
+//
// Returns false if something went wrong with the function, true otherwise.
bool ReadDmaBufInfo(std::vector<DmaBuffer>* dmabufs,
const std::string& path = "/sys/kernel/debug/dma_buf/bufinfo");
+
// Read and return dmabuf objects for a given process without the help
// of DEBUGFS
+//
+// Returns false if something went wrong with the function, true otherwise.
bool ReadDmaBufInfo(pid_t pid, std::vector<DmaBuffer>* dmabufs);
+// Append dmabuf objects for a given process without the help
+// of DEBUGFS to an existing vector
+//
+// Returns false if something went wrong with the function, true otherwise.
+bool AppendDmaBufInfo(pid_t pid, std::vector<DmaBuffer>* dmabufs);
+
} // namespace dmabufinfo
} // namespace android