[clang] 4000c9e - Reland "[Modules] Add stats to measure performance of building and loading modules."

Volodymyr Sapsai via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 15:44:25 PDT 2020


Author: Volodymyr Sapsai
Date: 2020-10-19T15:44:11-07:00
New Revision: 4000c9ee18ecebe3ff0f197af8c1fb434ad986e5

URL: https://github.com/llvm/llvm-project/commit/4000c9ee18ecebe3ff0f197af8c1fb434ad986e5
DIFF: https://github.com/llvm/llvm-project/commit/4000c9ee18ecebe3ff0f197af8c1fb434ad986e5.diff

LOG: Reland "[Modules] Add stats to measure performance of building and loading modules."

Measure amount of high-level or fixed-cost operations performed during
building/loading modules and during header search. High-level operations
like building a module or processing a .pcm file are motivated by
previous issues where clang was re-building modules or re-reading .pcm
files unnecessarily. Fixed-cost operations like `stat` calls are tracked
because clang cannot change how long each operation takes but it can
perform fewer of such operations to improve the compile time.

Also tracking such stats over time can help us detect compile-time
regressions. Added stats are more stable than the actual measured
compilation time, so expect the detected regressions to be less noisy.

On relanding drop stats in MemoryBuffer.cpp as their value is pretty low
but affects a lot of clients and many of those aren't interested in
modules and header search.

rdar://problem/55715134

Reviewed By: aprantl, bruno

Differential Revision: https://reviews.llvm.org/D86895

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 4613ed8d7f61..445049324780 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/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 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
                   llvm::function_ref<void(CompilerInstance &)> PostBuildStep =
                       [](CompilerInstance &) {}) {
   llvm::TimeTraceScope TimeScope("Module Compile", ModuleName);
+  ++NumCompiledModules;
 
   // Construct a compiler invocation for creating this module.
   auto Invocation =

diff  --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index b2780db85166..e71d73310d52 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/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 namespace clang::serialization::reader;
 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 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
                                             SourceLocation ImportLoc,
                                             unsigned ClientLoadCapabilities,
                                             SmallVectorImpl<ImportedSubmodule> *Imported) {
+  ++NumTryLoadModule;
   llvm::SaveAndRestore<SourceLocation>
     SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
 
@@ -4552,6 +4563,7 @@ ASTReader::ReadASTCore(StringRef FileName,
     return Failure;
   }
 
+  ++NumReadASTCore;
   // This is used for compatibility with older PCH formats.
   bool HaveReadControlBlock = false;
   while (true) {

diff  --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index bbc02a246a50..7f4b7cbdc31e 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/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;

diff  --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 01903ea10e81..622d4fc5b4b1 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -736,6 +736,7 @@ static std::error_code fillStatus(int StatRet, const struct stat &Status,
 }
 
 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(const Twine &Path, file_status &Result, bool Follow) {
 }
 
 std::error_code status(int FD, file_status &Result) {
+  ++NumStatusCalls;
   struct stat Status;
   int StatRet = ::fstat(FD, &Status);
   return fillStatus(StatRet, Status, Result);

diff  --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 399b054d36bd..cb7bf0beba1f 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -710,6 +710,7 @@ handle_status_error:
 }
 
 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(const Twine &path, file_status &result, bool Follow) {
 }
 
 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);
 }
 


        


More information about the cfe-commits mailing list