Clean up headers dependency on inode file scanner
The inode file scanner code has a lot of unnecessary
complexity in headers and dependencies to handle an
integer type. Simplify the code and just directly typedef
the InodeFileMap_Entry_Type to an integer, removing deps
on the protozero type.
This is needed because internal bazel builds require headers
to be self-contained (they are compiled as standalone TUs)
and this make that easier to achieve.
Bug: 140126865
Change-Id: I1444d956a7c3608d31c84b54cf2c7ff22eb575eb
diff --git a/include/perfetto/ext/traced/data_source_types.h b/include/perfetto/ext/traced/data_source_types.h
index b7732ca..103fd41 100644
--- a/include/perfetto/ext/traced/data_source_types.h
+++ b/include/perfetto/ext/traced/data_source_types.h
@@ -23,8 +23,6 @@
#include <set>
#include <string>
-#include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
-
namespace perfetto {
// On ARM, st_ino is not ino_t but unsigned long long.
@@ -33,19 +31,19 @@
// On ARM, st_dev is not dev_t but unsigned long long.
using BlockDeviceID = decltype(stat::st_dev);
+// From inode_file_map.pbzero.h
+using InodeFileMap_Entry_Type = int32_t;
+
class InodeMapValue {
public:
- InodeMapValue(protos::pbzero::InodeFileMap_Entry_Type entry_type,
- std::set<std::string> paths)
+ InodeMapValue(InodeFileMap_Entry_Type entry_type, std::set<std::string> paths)
: entry_type_(entry_type), paths_(std::move(paths)) {}
InodeMapValue() {}
- protos::pbzero::InodeFileMap_Entry_Type type() const { return entry_type_; }
+ InodeFileMap_Entry_Type type() const { return entry_type_; }
const std::set<std::string>& paths() const { return paths_; }
- void SetType(protos::pbzero::InodeFileMap_Entry_Type entry_type) {
- entry_type_ = entry_type;
- }
+ void SetType(InodeFileMap_Entry_Type entry_type) { entry_type_ = entry_type; }
void SetPaths(std::set<std::string> paths) { paths_ = std::move(paths); }
void AddPath(std::string path) { paths_.emplace(std::move(path)); }
@@ -54,7 +52,7 @@
}
private:
- protos::pbzero::InodeFileMap_Entry_Type entry_type_;
+ InodeFileMap_Entry_Type entry_type_;
std::set<std::string> paths_;
};
diff --git a/src/traced/probes/filesystem/file_scanner.cc b/src/traced/probes/filesystem/file_scanner.cc
index c71bbdf..17dd253 100644
--- a/src/traced/probes/filesystem/file_scanner.cc
+++ b/src/traced/probes/filesystem/file_scanner.cc
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
#include "src/traced/probes/filesystem/inode_file_data_source.h"
namespace perfetto {
diff --git a/src/traced/probes/filesystem/file_scanner.h b/src/traced/probes/filesystem/file_scanner.h
index 5fac41d..aee07db 100644
--- a/src/traced/probes/filesystem/file_scanner.h
+++ b/src/traced/probes/filesystem/file_scanner.h
@@ -34,7 +34,7 @@
virtual bool OnInodeFound(BlockDeviceID,
Inode,
const std::string&,
- protos::pbzero::InodeFileMap_Entry_Type) = 0;
+ InodeFileMap_Entry_Type) = 0;
virtual void OnInodeScanDone() = 0;
virtual ~Delegate();
};
diff --git a/src/traced/probes/filesystem/file_scanner_unittest.cc b/src/traced/probes/filesystem/file_scanner_unittest.cc
index a035c56..59b2d95 100644
--- a/src/traced/probes/filesystem/file_scanner_unittest.cc
+++ b/src/traced/probes/filesystem/file_scanner_unittest.cc
@@ -21,6 +21,7 @@
#include <string>
#include "perfetto/base/logging.h"
+#include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
#include "src/base/test/test_task_runner.h"
#include "test/gtest_and_gmock.h"
@@ -33,28 +34,25 @@
class TestDelegate : public FileScanner::Delegate {
public:
- TestDelegate(
- std::function<bool(BlockDeviceID,
- Inode,
- const std::string&,
- protos::pbzero::InodeFileMap_Entry_Type)> callback,
- std::function<void()> done_callback)
+ TestDelegate(std::function<bool(BlockDeviceID,
+ Inode,
+ const std::string&,
+ InodeFileMap_Entry_Type)> callback,
+ std::function<void()> done_callback)
: callback_(std::move(callback)),
done_callback_(std::move(done_callback)) {}
bool OnInodeFound(BlockDeviceID block_device_id,
Inode inode,
const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) override {
+ InodeFileMap_Entry_Type type) override {
return callback_(block_device_id, inode, path, type);
}
void OnInodeScanDone() { return done_callback_(); }
private:
- std::function<bool(BlockDeviceID,
- Inode,
- const std::string&,
- protos::pbzero::InodeFileMap_Entry_Type)>
+ std::function<
+ bool(BlockDeviceID, Inode, const std::string&, InodeFileMap_Entry_Type)>
callback_;
std::function<void()> done_callback_;
};
@@ -63,7 +61,7 @@
FileEntry(BlockDeviceID block_device_id,
Inode inode,
std::string path,
- protos::pbzero::InodeFileMap_Entry_Type type)
+ InodeFileMap_Entry_Type type)
: block_device_id_(block_device_id),
inode_(inode),
path_(std::move(path)),
@@ -78,7 +76,7 @@
BlockDeviceID block_device_id_;
Inode inode_;
std::string path_;
- protos::pbzero::InodeFileMap_Entry_Type type_;
+ InodeFileMap_Entry_Type type_;
};
struct stat CheckStat(const std::string& path) {
@@ -87,8 +85,7 @@
return buf;
}
-FileEntry StatFileEntry(const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) {
+FileEntry StatFileEntry(const std::string& path, InodeFileMap_Entry_Type type) {
struct stat buf = CheckStat(path);
return FileEntry(buf.st_dev, buf.st_ino, path, type);
}
@@ -98,7 +95,7 @@
bool done = false;
TestDelegate delegate(
[&seen](BlockDeviceID, Inode, const std::string&,
- protos::pbzero::InodeFileMap_Entry_Type) {
+ InodeFileMap_Entry_Type) {
++seen;
return false;
},
@@ -116,7 +113,7 @@
base::TestTaskRunner task_runner;
TestDelegate delegate(
[&seen](BlockDeviceID, Inode, const std::string&,
- protos::pbzero::InodeFileMap_Entry_Type) {
+ InodeFileMap_Entry_Type) {
++seen;
return false;
},
@@ -134,8 +131,7 @@
std::vector<FileEntry> file_entries;
TestDelegate delegate(
[&file_entries](BlockDeviceID block_device_id, Inode inode,
- const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) {
+ const std::string& path, InodeFileMap_Entry_Type type) {
file_entries.emplace_back(block_device_id, inode, path, type);
return true;
},
@@ -161,8 +157,7 @@
std::vector<FileEntry> file_entries;
TestDelegate delegate(
[&file_entries](BlockDeviceID block_device_id, Inode inode,
- const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) {
+ const std::string& path, InodeFileMap_Entry_Type type) {
file_entries.emplace_back(block_device_id, inode, path, type);
return true;
},
diff --git a/src/traced/probes/filesystem/inode_file_data_source.cc b/src/traced/probes/filesystem/inode_file_data_source.cc
index 9446c8c..d4643cb 100644
--- a/src/traced/probes/filesystem/inode_file_data_source.cc
+++ b/src/traced/probes/filesystem/inode_file_data_source.cc
@@ -29,6 +29,7 @@
#include "perfetto/ext/tracing/core/trace_writer.h"
#include "protos/perfetto/config/inode_file/inode_file_config.pbzero.h"
+#include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
#include "protos/perfetto/trace/trace_packet.pbzero.h"
#include "src/traced/probes/filesystem/file_scanner.h"
@@ -65,7 +66,7 @@
bool OnInodeFound(BlockDeviceID block_device_id,
Inode inode_number,
const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) {
+ InodeFileMap_Entry_Type type) {
std::unordered_map<Inode, InodeMapValue>& inode_map =
(*map_)[block_device_id];
inode_map[inode_number].SetType(type);
@@ -95,7 +96,8 @@
const InodeMapValue& inode_map_value) {
auto* entry = destination->add_entries();
entry->set_inode_number(inode_number);
- entry->set_type(inode_map_value.type());
+ entry->set_type(static_cast<protos::pbzero::InodeFileMap_Entry_Type>(
+ inode_map_value.type()));
for (const auto& path : inode_map_value.paths())
entry->add_paths(path.c_str());
}
@@ -293,11 +295,10 @@
it->second.erase(inode_number);
}
-bool InodeFileDataSource::OnInodeFound(
- BlockDeviceID block_device_id,
- Inode inode_number,
- const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) {
+bool InodeFileDataSource::OnInodeFound(BlockDeviceID block_device_id,
+ Inode inode_number,
+ const std::string& path,
+ InodeFileMap_Entry_Type type) {
auto it = missing_inodes_.find(block_device_id);
if (it == missing_inodes_.end())
return true;
diff --git a/src/traced/probes/filesystem/inode_file_data_source.h b/src/traced/probes/filesystem/inode_file_data_source.h
index 4b7d3fe..529fe2c 100644
--- a/src/traced/probes/filesystem/inode_file_data_source.h
+++ b/src/traced/probes/filesystem/inode_file_data_source.h
@@ -99,7 +99,7 @@
bool OnInodeFound(BlockDeviceID block_device_id,
Inode inode_number,
const std::string& path,
- protos::pbzero::InodeFileMap_Entry_Type type) override;
+ InodeFileMap_Entry_Type type) override;
void OnInodeScanDone() override;
void AddRootsForBlockDevice(BlockDeviceID block_device_id,
diff --git a/src/traced/probes/filesystem/lru_inode_cache_unittest.cc b/src/traced/probes/filesystem/lru_inode_cache_unittest.cc
index a71a584..86aed74 100644
--- a/src/traced/probes/filesystem/lru_inode_cache_unittest.cc
+++ b/src/traced/probes/filesystem/lru_inode_cache_unittest.cc
@@ -19,6 +19,7 @@
#include <string>
#include <tuple>
+#include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
#include "test/gtest_and_gmock.h"
namespace perfetto {