This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4bacc3c9b33: [Modules] Add stats to measure performance of 
building and loading modules. (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86895/new/

https://reviews.llvm.org/D86895

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  llvm/lib/Support/MemoryBuffer.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc

Index: llvm/lib/Support/Windows/Path.inc
===================================================================
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -710,6 +710,7 @@
 }
 
 std::error_code status(const Twine &path, file_status &result, bool Follow) {
+  ++NumStatusCalls;
   SmallString<128> path_storage;
   SmallVector<wchar_t, 128> path_utf16;
 
@@ -742,11 +743,13 @@
 }
 
 std::error_code status(int FD, file_status &Result) {
+  ++NumStatusCalls;
   HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
   return getStatus(FileHandle, Result);
 }
 
 std::error_code status(file_t FileHandle, file_status &Result) {
+  ++NumStatusCalls;
   return getStatus(FileHandle, Result);
 }
 
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -736,6 +736,7 @@
 }
 
 std::error_code status(const Twine &Path, file_status &Result, bool Follow) {
+  ++NumStatusCalls;
   SmallString<128> PathStorage;
   StringRef P = Path.toNullTerminatedStringRef(PathStorage);
 
@@ -745,6 +746,7 @@
 }
 
 std::error_code status(int FD, file_status &Result) {
+  ++NumStatusCalls;
   struct stat Status;
   int StatRet = ::fstat(FD, &Status);
   return fillStatus(StatRet, Status, Result);
Index: llvm/lib/Support/Path.cpp
===================================================================
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/Path.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Errc.h"
@@ -31,6 +32,10 @@
 using namespace llvm;
 using namespace llvm::support::endian;
 
+#define DEBUG_TYPE "file-system"
+
+ALWAYS_ENABLED_STATISTIC(NumStatusCalls, "Number of `status` calls.");
+
 namespace {
   using llvm::StringRef;
   using llvm::sys::path::is_separator;
Index: llvm/lib/Support/MemoryBuffer.cpp
===================================================================
--- llvm/lib/Support/MemoryBuffer.cpp
+++ llvm/lib/Support/MemoryBuffer.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Errno.h"
@@ -34,6 +35,12 @@
 #endif
 using namespace llvm;
 
+#define DEBUG_TYPE "memory-buffer"
+
+ALWAYS_ENABLED_STATISTIC(NumMmapFile, "Number of mmap-ed files.");
+ALWAYS_ENABLED_STATISTIC(NumAllocFile,
+                         "Number of files read into allocated memory buffer.");
+
 //===----------------------------------------------------------------------===//
 // MemoryBuffer implementation itself.
 //===----------------------------------------------------------------------===//
@@ -449,8 +456,10 @@
       // buffer by copying off the stream.
       sys::fs::file_type Type = Status.type();
       if (Type != sys::fs::file_type::regular_file &&
-          Type != sys::fs::file_type::block_file)
+          Type != sys::fs::file_type::block_file) {
+        ++NumAllocFile;
         return getMemoryBufferForStream(FD, Filename);
+      }
 
       FileSize = Status.getSize();
     }
@@ -463,8 +472,10 @@
     std::unique_ptr<MB> Result(
         new (NamedBufferAlloc(Filename)) MemoryBufferMMapFile<MB>(
             RequiresNullTerminator, FD, MapSize, Offset, EC));
-    if (!EC)
+    if (!EC) {
+      ++NumMmapFile;
       return std::move(Result);
+    }
   }
 
   auto Buf = WritableMemoryBuffer::getNewUninitMemBuffer(MapSize, Filename);
@@ -475,6 +486,7 @@
   }
 
   // Read until EOF, zero-initialize the rest.
+  ++NumAllocFile;
   MutableArrayRef<char> ToRead = Buf->getBuffer();
   while (!ToRead.empty()) {
     Expected<size_t> ReadBytes =
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -100,6 +100,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -142,6 +143,15 @@
 using llvm::BitstreamCursor;
 using llvm::RoundingMode;
 
+#define DEBUG_TYPE "modules"
+
+ALWAYS_ENABLED_STATISTIC(NumTryLoadModule, "Number of times tried to load a "
+                                           "module. Includes failed attempts "
+                                           "and using cached results.");
+ALWAYS_ENABLED_STATISTIC(NumReadASTCore,
+                         "Number of ReadASTCore() invocations. Includes only "
+                         "actual AST core parsing and ignores cached results.");
+
 //===----------------------------------------------------------------------===//
 // ChainedASTReaderListener implementation
 //===----------------------------------------------------------------------===//
@@ -4203,6 +4213,7 @@
                                             SourceLocation ImportLoc,
                                             unsigned ClientLoadCapabilities,
                                             SmallVectorImpl<ImportedSubmodule> *Imported) {
+  ++NumTryLoadModule;
   llvm::SaveAndRestore<SourceLocation>
     SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
 
@@ -4552,6 +4563,7 @@
     return Failure;
   }
 
+  ++NumReadASTCore;
   // This is used for compatibility with older PCH formats.
   bool HaveReadControlBlock = false;
   while (true) {
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -55,6 +55,10 @@
 
 using namespace clang;
 
+#define DEBUG_TYPE "modules"
+
+ALWAYS_ENABLED_STATISTIC(NumCompiledModules, "Number of compiled modules.");
+
 CompilerInstance::CompilerInstance(
     std::shared_ptr<PCHContainerOperations> PCHContainerOps,
     InMemoryModuleCache *SharedModuleCache)
@@ -1063,6 +1067,7 @@
                   llvm::function_ref<void(CompilerInstance &)> PostBuildStep =
                       [](CompilerInstance &) {}) {
   llvm::TimeTraceScope TimeScope("Module Compile", ModuleName);
+  ++NumCompiledModules;
 
   // Construct a compiler invocation for creating this module.
   auto Invocation =
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to