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(
diff --git a/src/traced/probes/filesystem/inode_file_data_source.h b/src/traced/probes/filesystem/inode_file_data_source.h
index db6d887..af881d4 100644
--- a/src/traced/probes/filesystem/inode_file_data_source.h
+++ b/src/traced/probes/filesystem/inode_file_data_source.h
@@ -23,6 +23,7 @@
 #include <memory>
 #include <set>
 #include <string>
+#include <unordered_map>
 
 #include "perfetto/base/weak_ptr.h"
 #include "perfetto/traced/data_source_types.h"
@@ -48,7 +49,8 @@
 // Creates block_device_map for /system partition
 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);
 
 void FillInodeEntry(InodeFileMap* destination,
                     Inode inode_number,
@@ -58,7 +60,8 @@
  public:
   InodeFileDataSource(
       TracingSessionID,
-      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);
 
@@ -89,7 +92,8 @@
 
  private:
   const TracingSessionID session_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::multimap<BlockDeviceID, std::string> mount_points_;
   std::unique_ptr<TraceWriter> writer_;
diff --git a/src/traced/probes/probes_producer.h b/src/traced/probes/probes_producer.h
index b5b8d5e..bd550c7 100644
--- a/src/traced/probes/probes_producer.h
+++ b/src/traced/probes/probes_producer.h
@@ -146,7 +146,8 @@
   std::map<DataSourceInstanceID, std::unique_ptr<InodeFileDataSource>>
       file_map_sources_;
   LRUInodeCache cache_{kLRUInodeCacheSize};
-  std::map<BlockDeviceID, std::map<Inode, InodeMapValue>> system_inodes_;
+  std::map<BlockDeviceID, std::unordered_map<Inode, InodeMapValue>>
+      system_inodes_;
 };
 
 }  // namespace perfetto