[Lldb-commits] [lldb] r176714 - Added very lightweight, statically-allocated

Sean Callanan scallanan at apple.com
Fri Mar 8 12:04:58 PST 2013


Author: spyffe
Date: Fri Mar  8 14:04:57 2013
New Revision: 176714

URL: http://llvm.org/viewvc/llvm-project?rev=176714&view=rev
Log:
Added very lightweight, statically-allocated
counters for a variety of metrics associated
with expression parsing.  This should give some
idea of how much work the expression parser is
doing on Clang's behalf, and help with hopefully
reducing that load over time.

<rdar://problem/13210748> Audit type search/import for expressions

Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
    lldb/trunk/source/Expression/ClangASTSource.cpp
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Symbol/ClangASTImporter.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=176714&r1=176713&r2=176714&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Fri Mar  8 14:04:57 2013
@@ -20,6 +20,68 @@
 #include "lldb/Symbol/ClangNamespaceDecl.h"
 
 namespace lldb_private {
+    
+class ClangASTMetrics
+{
+public:
+    static void DumpCounters (lldb::LogSP log);
+    static void ClearLocalCounters ()
+    {
+        local_counters = { 0, 0, 0, 0, 0, 0 };
+    }
+    
+    static void RegisterVisibleQuery ()
+    {
+        ++global_counters.m_visible_query_count;
+        ++local_counters.m_visible_query_count;
+    }
+    
+    static void RegisterLexicalQuery ()
+    {
+        ++global_counters.m_lexical_query_count;
+        ++local_counters.m_lexical_query_count;
+    }
+    
+    static void RegisterLLDBImport ()
+    {
+        ++global_counters.m_lldb_import_count;
+        ++local_counters.m_lldb_import_count;
+    }
+    
+    static void RegisterClangImport ()
+    {
+        ++global_counters.m_clang_import_count;
+        ++local_counters.m_clang_import_count;
+    }
+    
+    static void RegisterDeclCompletion ()
+    {
+        ++global_counters.m_decls_completed_count;
+        ++local_counters.m_decls_completed_count;
+    }
+    
+    static void RegisterRecordLayout ()
+    {
+        ++global_counters.m_record_layout_count;
+        ++local_counters.m_record_layout_count;
+    }
+    
+private:
+    struct Counters
+    {
+        uint64_t    m_visible_query_count;
+        uint64_t    m_lexical_query_count;
+        uint64_t    m_lldb_import_count;
+        uint64_t    m_clang_import_count;
+        uint64_t    m_decls_completed_count;
+        uint64_t    m_record_layout_count;
+    };
+    
+    static Counters global_counters;
+    static Counters local_counters;
+    
+    static void DumpCounters (lldb::LogSP log, Counters &counters);
+};
 
 class ClangASTImporter 
 {

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=176714&r1=176713&r2=176714&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Fri Mar  8 14:04:57 2013
@@ -367,7 +367,9 @@ clang::ExternalLoadResult
 ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
                                           bool (*predicate)(Decl::Kind),
                                           llvm::SmallVectorImpl<Decl*> &decls)
-{    
+{
+    ClangASTMetrics::RegisterLexicalQuery();
+
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
     const Decl *context_decl = dyn_cast<Decl>(decl_context);
@@ -485,6 +487,8 @@ ClangASTSource::FindExternalVisibleDecls
 {
     assert (m_ast_context);
     
+    ClangASTMetrics::RegisterVisibleQuery();
+    
     const ConstString name(context.m_decl_name.getAsString().c_str());
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -1435,6 +1439,8 @@ ClangASTSource::layoutRecordType(const R
                                  BaseOffsetMap &base_offsets,
                                  BaseOffsetMap &virtual_base_offsets)
 {
+    ClangASTMetrics::RegisterRecordLayout();
+    
     static unsigned int invocation_id = 0;
     unsigned int current_id = invocation_id++;
     
@@ -1677,7 +1683,9 @@ void *
 ClangASTSource::GuardedCopyType (ASTContext *dest_context, 
                                  ASTContext *source_context,
                                  void *clang_type)
-{    
+{
+    ClangASTMetrics::RegisterLLDBImport();
+    
     SetImportInProgress(true);
     
     QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=176714&r1=176713&r2=176714&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Mar  8 14:04:57 2013
@@ -75,7 +75,9 @@ ClangExpressionDeclMap::~ClangExpression
 
 bool 
 ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx)
-{    
+{
+    ClangASTMetrics::ClearLocalCounters();
+    
     EnableParserVars();
     m_parser_vars->m_exe_ctx = exe_ctx;
     
@@ -111,6 +113,11 @@ ClangExpressionDeclMap::WillParse(Execut
 void 
 ClangExpressionDeclMap::DidParse()
 {
+    lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+
+    if (log)
+        ClangASTMetrics::DumpCounters(log);
+    
     if (m_parser_vars.get())
     {
         for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
@@ -2605,6 +2612,8 @@ ClangExpressionDeclMap::FindExternalVisi
 {
     assert (m_ast_context);
     
+    ClangASTMetrics::RegisterVisibleQuery();
+    
     const ConstString name(context.m_decl_name.getAsString().c_str());
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));

Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=176714&r1=176713&r2=176714&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Fri Mar  8 14:04:57 2013
@@ -21,7 +21,32 @@
 using namespace lldb_private;
 using namespace clang;
 
-clang::QualType 
+ClangASTMetrics::Counters ClangASTMetrics::global_counters = { 0, 0, 0, 0, 0, 0 };
+ClangASTMetrics::Counters ClangASTMetrics::local_counters = { 0, 0, 0, 0, 0, 0 };
+
+void ClangASTMetrics::DumpCounters (lldb::LogSP log, ClangASTMetrics::Counters &counters)
+{
+    log->Printf("  Number of visible Decl queries by name     : %llu", counters.m_visible_query_count);
+    log->Printf("  Number of lexical Decl queries             : %llu", counters.m_lexical_query_count);
+    log->Printf("  Number of imports initiated by LLDB        : %llu", counters.m_lldb_import_count);
+    log->Printf("  Number of imports conducted by Clang       : %llu", counters.m_clang_import_count);
+    log->Printf("  Number of Decls completed                  : %llu", counters.m_decls_completed_count);
+    log->Printf("  Number of records laid out                 : %llu", counters.m_record_layout_count);
+}
+
+void ClangASTMetrics::DumpCounters (lldb::LogSP log)
+{
+    if (!log)
+        return;
+    
+    log->Printf("== ClangASTMetrics output ==");
+    log->Printf("-- Global metrics --");
+    DumpCounters (log, global_counters);
+    log->Printf("-- Local metrics --");
+    DumpCounters (log, local_counters);
+}
+
+clang::QualType
 ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
                             clang::ASTContext *src_ast,
                             clang::QualType type)
@@ -211,7 +236,9 @@ ClangASTImporter::CompleteDecl (clang::D
 
 bool
 ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
-{   
+{
+    ClangASTMetrics::RegisterDeclCompletion();
+    
     DeclOrigin decl_origin = GetDeclOrigin(decl);
     
     if (!decl_origin.Valid())
@@ -231,6 +258,8 @@ ClangASTImporter::CompleteTagDecl (clang
 bool
 ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl)
 {
+    ClangASTMetrics::RegisterDeclCompletion();
+
     clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
         
     if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl))
@@ -253,6 +282,8 @@ ClangASTImporter::CompleteTagDeclWithOri
 bool
 ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
 {
+    ClangASTMetrics::RegisterDeclCompletion();
+
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
     DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
@@ -474,6 +505,8 @@ ClangASTImporter::Minion::ImportDefiniti
 clang::Decl 
 *ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
 {
+    ClangASTMetrics::RegisterClangImport();
+    
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
         
     if (log)





More information about the lldb-commits mailing list