filesystem: Switch to unordered_map
For faster lookups
Bug: 73625480
Change-Id: I6fec4aa68b1039f2ea17c501fe81334a3d626845
diff --git a/src/traced/probes/filesystem/inode_file_data_source.cc b/src/traced/probes/filesystem/inode_file_data_source.cc
index 77e85db..2f5c590 100644
--- a/src/traced/probes/filesystem/inode_file_data_source.cc
+++ b/src/traced/probes/filesystem/inode_file_data_source.cc
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <queue>
+#include <unordered_map>
#include "perfetto/base/logging.h"
#include "perfetto/base/scoped_file.h"
@@ -84,12 +85,13 @@
void CreateStaticDeviceToInodeMap(
const std::string& root_directory,
- std::map<BlockDeviceID, std::map<Inode, InodeMapValue>>* static_file_map) {
+ std::map<BlockDeviceID, std::unordered_map<Inode, InodeMapValue>>*
+ static_file_map) {
ScanFilesDFS(root_directory,
[static_file_map](BlockDeviceID block_device_id,
Inode inode_number, const std::string& path,
protos::pbzero::InodeFileMap_Entry_Type type) {
- std::map<Inode, InodeMapValue>& inode_map =
+ std::unordered_map<Inode, InodeMapValue>& inode_map =
(*static_file_map)[block_device_id];
inode_map[inode_number].SetType(type);
inode_map[inode_number].AddPath(path);
@@ -109,7 +111,8 @@
InodeFileDataSource::InodeFileDataSource(
TracingSessionID id,
- std::map<BlockDeviceID, std::map<Inode, InodeMapValue>>* static_file_map,
+ std::map<BlockDeviceID, std::unordered_map<Inode, InodeMapValue>>*
+ static_file_map,
LRUInodeCache* cache,
std::unique_ptr<TraceWriter> writer)
: session_id_(id),
@@ -153,7 +156,8 @@
});
// Could not be found, just add the inode number
- PERFETTO_DLOG("%zu inodes not found", inode_numbers->size());
+ if (inode_numbers->size() != 0)
+ PERFETTO_DLOG("%zu inodes not found", inode_numbers->size());
for (const auto& unresolved_inode : *inode_numbers) {
auto* entry = destination->add_entries();
entry->set_inode_number(unresolved_inode);
@@ -200,7 +204,8 @@
it = inode_numbers->erase(it);
FillInodeEntry(destination, inode_number, *value);
}
- PERFETTO_DLOG("%" PRIu64 " inodes found in cache", cache_found_count);
+ if (cache_found_count > 0)
+ PERFETTO_DLOG("%" PRIu64 " inodes found in cache", cache_found_count);
}
void InodeFileDataSource::OnInodes(