bulbazord created this revision. bulbazord added reviewers: clayborg, JDevlieghere, aprantl. Herald added a project: All. bulbazord requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Context: I plan on using this change primarily downstream in the apple fork of llvm to track swift module loading time. The idea is that TypeSystems from modules can self-report statistics when performing the statistics dump of a module. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137191 Files: lldb/include/lldb/Core/Module.h lldb/include/lldb/Symbol/TypeSystem.h lldb/source/Core/Module.cpp lldb/source/Symbol/TypeSystem.cpp lldb/source/Target/Statistics.cpp Index: lldb/source/Target/Statistics.cpp =================================================================== --- lldb/source/Target/Statistics.cpp +++ lldb/source/Target/Statistics.cpp @@ -256,7 +256,20 @@ debug_parse_time += module_stat.debug_parse_time; debug_index_time += module_stat.debug_index_time; debug_info_size += module_stat.debug_info_size; - json_modules.emplace_back(module_stat.ToJSON()); + json::Value module_stat_json = module_stat.ToJSON(); + module->ForEachTypeSystem([&](TypeSystem *ts) { + if (ts) { + json::Object *module_stat_obj = module_stat_json.getAsObject(); + if (!module_stat_obj) + return false; + auto stats = ts->ReportStatistics(); + if (stats.hasValue()) { + module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue()); + } + } + return true; + }); + json_modules.emplace_back(module_stat_json); } ConstStringStats const_string_stats; Index: lldb/source/Symbol/TypeSystem.cpp =================================================================== --- lldb/source/Symbol/TypeSystem.cpp +++ lldb/source/Symbol/TypeSystem.cpp @@ -178,6 +178,10 @@ return {}; } +llvm::Optional<llvm::json::Value> TypeSystem::ReportStatistics() { + return llvm::None; +} + #pragma mark TypeSystemMap TypeSystemMap::TypeSystemMap() : m_mutex(), m_map() {} Index: lldb/source/Core/Module.cpp =================================================================== --- lldb/source/Core/Module.cpp +++ lldb/source/Core/Module.cpp @@ -369,6 +369,11 @@ return m_type_system_map.GetTypeSystemForLanguage(language, this, true); } +void Module::ForEachTypeSystem( + std::function<bool(TypeSystem *)> const &callback) { + m_type_system_map.ForEach(callback); +} + void Module::ParseAllDebugSymbols() { std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t num_comp_units = GetNumCompileUnits(); Index: lldb/include/lldb/Symbol/TypeSystem.h =================================================================== --- lldb/include/lldb/Symbol/TypeSystem.h +++ lldb/include/lldb/Symbol/TypeSystem.h @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallBitVector.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" +#include "llvm/Support/JSON.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Expression/Expression.h" @@ -510,6 +511,8 @@ // meaningless type itself, instead preferring to use the dynamic type virtual bool IsMeaninglessWithoutDynamicResolution(void *type); + virtual llvm::Optional<llvm::json::Value> ReportStatistics(); + protected: SymbolFile *m_sym_file = nullptr; }; Index: lldb/include/lldb/Core/Module.h =================================================================== --- lldb/include/lldb/Core/Module.h +++ lldb/include/lldb/Core/Module.h @@ -814,6 +814,8 @@ llvm::Expected<TypeSystem &> GetTypeSystemForLanguage(lldb::LanguageType language); + void ForEachTypeSystem(std::function<bool(TypeSystem *)> const &callback); + // Special error functions that can do printf style formatting that will // prepend the message with something appropriate for this module (like the // architecture, path and object name (if any)). This centralizes code so
Index: lldb/source/Target/Statistics.cpp =================================================================== --- lldb/source/Target/Statistics.cpp +++ lldb/source/Target/Statistics.cpp @@ -256,7 +256,20 @@ debug_parse_time += module_stat.debug_parse_time; debug_index_time += module_stat.debug_index_time; debug_info_size += module_stat.debug_info_size; - json_modules.emplace_back(module_stat.ToJSON()); + json::Value module_stat_json = module_stat.ToJSON(); + module->ForEachTypeSystem([&](TypeSystem *ts) { + if (ts) { + json::Object *module_stat_obj = module_stat_json.getAsObject(); + if (!module_stat_obj) + return false; + auto stats = ts->ReportStatistics(); + if (stats.hasValue()) { + module_stat_obj->try_emplace("TypeSystemInfo", stats.getValue()); + } + } + return true; + }); + json_modules.emplace_back(module_stat_json); } ConstStringStats const_string_stats; Index: lldb/source/Symbol/TypeSystem.cpp =================================================================== --- lldb/source/Symbol/TypeSystem.cpp +++ lldb/source/Symbol/TypeSystem.cpp @@ -178,6 +178,10 @@ return {}; } +llvm::Optional<llvm::json::Value> TypeSystem::ReportStatistics() { + return llvm::None; +} + #pragma mark TypeSystemMap TypeSystemMap::TypeSystemMap() : m_mutex(), m_map() {} Index: lldb/source/Core/Module.cpp =================================================================== --- lldb/source/Core/Module.cpp +++ lldb/source/Core/Module.cpp @@ -369,6 +369,11 @@ return m_type_system_map.GetTypeSystemForLanguage(language, this, true); } +void Module::ForEachTypeSystem( + std::function<bool(TypeSystem *)> const &callback) { + m_type_system_map.ForEach(callback); +} + void Module::ParseAllDebugSymbols() { std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t num_comp_units = GetNumCompileUnits(); Index: lldb/include/lldb/Symbol/TypeSystem.h =================================================================== --- lldb/include/lldb/Symbol/TypeSystem.h +++ lldb/include/lldb/Symbol/TypeSystem.h @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallBitVector.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" +#include "llvm/Support/JSON.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Expression/Expression.h" @@ -510,6 +511,8 @@ // meaningless type itself, instead preferring to use the dynamic type virtual bool IsMeaninglessWithoutDynamicResolution(void *type); + virtual llvm::Optional<llvm::json::Value> ReportStatistics(); + protected: SymbolFile *m_sym_file = nullptr; }; Index: lldb/include/lldb/Core/Module.h =================================================================== --- lldb/include/lldb/Core/Module.h +++ lldb/include/lldb/Core/Module.h @@ -814,6 +814,8 @@ llvm::Expected<TypeSystem &> GetTypeSystemForLanguage(lldb::LanguageType language); + void ForEachTypeSystem(std::function<bool(TypeSystem *)> const &callback); + // Special error functions that can do printf style formatting that will // prepend the message with something appropriate for this module (like the // architecture, path and object name (if any)). This centralizes code so
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits