[clang] [llvm] [llvm][support] Implement tracing virtual file system (PR #88326)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 12 12:52:26 PDT 2024


================
@@ -1125,6 +1125,54 @@ class YAMLVFSWriter {
   void write(llvm::raw_ostream &OS);
 };
 
+/// File system that tracks the number of calls to the underlying file system.
+/// This is particularly useful when wrapped around \c RealFileSystem to add
+/// lightweight tracking of expensive syscalls.
+class TracingFileSystem
+    : public llvm::RTTIExtends<TracingFileSystem, ProxyFileSystem> {
+public:
+  static const char ID;
+
+  std::size_t NumStatusCalls = 0;
----------------
jansvoboda11 wrote:

I'm contemplating whether to make these atomic. The root `FileSystem` class inherits from `ThreadSafeRefCountedBase`, suggesting that VFSs may be thread-safe.

For example in `clang-scan-deps`, all workers _could_ use single `RealFileSystem`. If we wrapped that in a single thread-safe `TracingFileSystem`, we'd very easily get the complete VFS stats. The current non-thread-safe approach would require having N of these VFS stacks and then manually aggregating the individual VFS stats.

Thoughts?

https://github.com/llvm/llvm-project/pull/88326


More information about the cfe-commits mailing list