]> granicus.if.org Git - clang/commitdiff
Add PCH statistics for the number/percent of lexical/visible declcontexts read
authorDouglas Gregor <dgregor@apple.com>
Wed, 22 Apr 2009 22:34:57 +0000 (22:34 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 22 Apr 2009 22:34:57 +0000 (22:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69835 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHReader.h
include/clang/Frontend/PCHWriter.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp

index 72ca6ad569a1075d32e345ba5c5ec68e9dde3e6b..107779aa1da400decac61e5fe8192922cbd7b694 100644 (file)
@@ -185,9 +185,16 @@ private:
 
   /// \brief The number of macros de-serialized from the PCH file.
   unsigned NumMacrosRead;
+
   /// \brief The total number of macros stored in the PCH file.
   unsigned TotalNumMacros;
 
+  /// Number of lexical decl contexts read/total.
+  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
+
+  /// Number of visible decl contexts read/total.
+  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
+
   /// \brief FIXME: document!
   llvm::SmallVector<uint64_t, 4> SpecialTypes;
 
@@ -211,7 +218,8 @@ public:
 
   explicit PCHReader(Preprocessor &PP, ASTContext &Context) 
     : SemaObj(0), PP(PP), Context(Context), Consumer(0),
-      IdentifierTableData(0), NumStatementsRead(0) { }
+      IdentifierTableData(0), NumStatementsRead(0), NumMacrosRead(0),
+      NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0) { }
 
   ~PCHReader() {}
 
index d721f1077f326ac24f8c84193c25ad11ff63f024..e3d0603e0846aba38e0c40cd69456c873a0ebc28 100644 (file)
@@ -136,6 +136,14 @@ private:
   /// \brief The number of macros written to the PCH file.
   unsigned NumMacros;
 
+  /// \brief The number of lexical declcontexts written to the PCH
+  /// file.
+  unsigned NumLexicalDeclContexts;
+
+  /// \brief The number of visible declcontexts written to the PCH
+  /// file.
+  unsigned NumVisibleDeclContexts;
+
   void WriteTargetTriple(const TargetInfo &Target);
   void WriteLanguageOptions(const LangOptions &LangOpts);
   void WriteSourceManagerBlock(SourceManager &SourceMgr);
index 66a849d5761cb0a0f62dad82771c8f1232ee3917..3ade493b4ec0919b742bfb1aa5866e4c9599695d 100644 (file)
@@ -1711,6 +1711,8 @@ PCHReader::ReadPCHBlock(uint64_t &PreprocessorBlockOffset) {
     case pch::STATISTICS:
       TotalNumStatements = Record[0];
       TotalNumMacros = Record[1];
+      TotalLexicalDeclContexts = Record[2];
+      TotalVisibleDeclContexts = Record[3];
       break;
 
     case pch::TENTATIVE_DEFINITIONS:
@@ -2439,6 +2441,7 @@ bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC,
   // Load all of the declaration IDs
   Decls.clear();
   Decls.insert(Decls.end(), Record.begin(), Record.end());
+  ++NumLexicalDeclContextsRead;
   return false;
 }
 
@@ -2479,6 +2482,7 @@ bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC,
       LoadedDecls.push_back(Record[Idx++]);
   }
 
+  ++NumVisibleDeclContextsRead;
   return false;
 }
 
@@ -2525,6 +2529,14 @@ void PCHReader::PrintStats() {
   std::fprintf(stderr, "  %u/%u macros read (%f%%)\n",
                NumMacrosRead, TotalNumMacros,
                ((float)NumMacrosRead/TotalNumMacros * 100));
+  std::fprintf(stderr, "  %u/%u lexical declcontexts read (%f%%)\n",
+               NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
+               ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
+                * 100));
+  std::fprintf(stderr, "  %u/%u visible declcontexts read (%f%%)\n",
+               NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
+               ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
+                * 100));
   std::fprintf(stderr, "\n");
 }
 
index 0aada62599453c4c526c4a824b7f747d3060da92..6557ca5c4272c76a58bdc7bffeca07c95872392f 100644 (file)
@@ -1616,6 +1616,7 @@ uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
        D != DEnd; ++D)
     AddDeclRef(*D, Record);
 
+  ++NumLexicalDeclContexts;
   Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record);
   return Offset;
 }
@@ -1664,6 +1665,7 @@ uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
     return 0;
 
   Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record);
+  ++NumVisibleDeclContexts;
   return Offset;
 }
 
@@ -1997,7 +1999,8 @@ void PCHWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) {
 
 PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream) 
   : Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS), 
-    NumStatements(0), NumMacros(0) { }
+    NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
+    NumVisibleDeclContexts(0) { }
 
 void PCHWriter::WritePCH(Sema &SemaRef) {
   ASTContext &Context = SemaRef.Context;
@@ -2078,6 +2081,8 @@ void PCHWriter::WritePCH(Sema &SemaRef) {
   Record.clear();
   Record.push_back(NumStatements);
   Record.push_back(NumMacros);
+  Record.push_back(NumLexicalDeclContexts);
+  Record.push_back(NumVisibleDeclContexts);
   Stream.EmitRecord(pch::STATISTICS, Record);
   Stream.ExitBlock();
 }