https://github.com/GeorgeHuyubo updated https://github.com/llvm/llvm-project/pull/134563
>From b4992fb5a841e546ef503f0257164b7d1f8c70ce Mon Sep 17 00:00:00 2001 From: George Hu <georgehuy...@gmail.com> Date: Fri, 4 Apr 2025 13:37:36 -0700 Subject: [PATCH] Add download time for each module in statistics --- lldb/include/lldb/Symbol/SymbolFile.h | 5 +++ lldb/include/lldb/Target/Statistics.h | 1 + lldb/include/lldb/Utility/FileSpec.h | 8 +++++ .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 7 +++++ .../SymbolFile/DWARF/SymbolFileDWARF.h | 3 ++ .../Debuginfod/SymbolLocatorDebuginfod.cpp | 31 ++++++++++++------- lldb/source/Target/Statistics.cpp | 8 +++++ lldb/source/Utility/FileSpec.cpp | 6 ++++ 8 files changed, 58 insertions(+), 11 deletions(-) diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index f35d3ee9f22ae..29fa99ba18323 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -422,6 +422,11 @@ class SymbolFile : public PluginInterface { /// hasn't been indexed yet, or a valid duration if it has. virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; } + /// Return the time it took to download any extra symbol files. + /// + /// \returns 0.0 if no extra symbol files need to be downloaded + virtual double GetSymbolDownloadTime() { return 0.0; } + /// Reset the statistics for the symbol file. virtual void ResetStatistics() {} diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index ee365357fcf31..2d3a7fcceec53 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -122,6 +122,7 @@ struct ModuleStats { double symtab_index_time = 0.0; double debug_parse_time = 0.0; double debug_index_time = 0.0; + double symbol_download_time = 0.0; uint64_t debug_info_size = 0; bool symtab_loaded_from_cache = false; bool symtab_saved_to_cache = false; diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index 3fa89b1dcff28..b59fa299c7f9b 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -75,6 +75,9 @@ class FileSpec { /// \see FileSpec::SetFile (const char *path) explicit FileSpec(llvm::StringRef path, Style style = Style::native); + explicit FileSpec(llvm::StringRef path, const double download_time, + Style style = Style::native); + explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple); bool DirectoryEquals(const FileSpec &other) const; @@ -416,6 +419,9 @@ class FileSpec { /// The lifetime of the StringRefs is tied to the lifetime of the FileSpec. std::vector<llvm::StringRef> GetComponents() const; + /// Get the download time of the file. + double GetDownloadTime() { return m_download_time; } + protected: // Convenience method for setting the file without changing the style. void SetFile(llvm::StringRef path); @@ -430,6 +436,8 @@ class FileSpec { No }; + /// The download time of the file. + double m_download_time = 0.0; /// The unique'd directory path. ConstString m_directory; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index b95159d882bc7..8afb7b9dfb01c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -4349,6 +4349,13 @@ LanguageType SymbolFileDWARF::GetLanguageFamily(DWARFUnit &unit) { return LanguageTypeFromDWARF(lang); } +double SymbolFileDWARF::GetSymbolDownloadTime() { + double time = GetObjectFile()->GetFileSpec().GetDownloadTime(); + if (m_dwp_symfile) + time += m_dwp_symfile->GetObjectFile()->GetFileSpec().GetDownloadTime(); + return time; +} + StatsDuration::Duration SymbolFileDWARF::GetDebugInfoIndexTime() { if (m_index) return m_index->GetIndexTime(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 7309f7a86b659..16f609ee10807 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -309,6 +309,9 @@ class SymbolFileDWARF : public SymbolFileCommon { StatsDuration::Duration GetDebugInfoParseTime() override { return m_parse_time; } + + double GetSymbolDownloadTime() override; + StatsDuration::Duration GetDebugInfoIndexTime() override; StatsDuration &GetDebugInfoParseTimeRef() { return m_parse_time; } diff --git a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp index f9aa6b1a98765..3cfd1598b56b6 100644 --- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp +++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp @@ -188,17 +188,26 @@ GetFileForModule(const ModuleSpec &module_spec, std::string cache_file_name = llvm::toHex(build_id, true); if (!file_name.empty()) cache_file_name += "-" + file_name.str(); - llvm::Expected<std::string> result = llvm::getCachedOrDownloadArtifact( - cache_file_name, url_path, cache_path, debuginfod_urls, timeout); - if (result) - return FileSpec(*result); - - Log *log = GetLog(LLDBLog::Symbols); - auto err_message = llvm::toString(result.takeError()); - LLDB_LOGV(log, - "Debuginfod failed to download symbol artifact {0} with error {1}", - url_path, err_message); - return {}; + StatsDuration duration; + std::string local_path; + { + ElapsedTime elapsed(duration); + llvm::Expected<std::string> result = llvm::getCachedOrDownloadArtifact( + cache_file_name, url_path, cache_path, debuginfod_urls, timeout); + + if (!result) { + Log *log = GetLog(LLDBLog::Symbols); + auto err_message = llvm::toString(result.takeError()); + LLDB_LOGV( + log, + "Debuginfod failed to download symbol artifact {0} with error {1}", + url_path, err_message); + return {}; + } + local_path = *result; + } + + return FileSpec(local_path, duration.get().count()); } std::optional<ModuleSpec> SymbolLocatorDebuginfod::LocateExecutableObjectFile( diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index b5d2e7bda1edf..73e96b6df36ec 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -71,6 +71,7 @@ json::Value ModuleStats::ToJSON() const { module.try_emplace("debugInfoHadIncompleteTypes", debug_info_had_incomplete_types); module.try_emplace("symbolTableStripped", symtab_stripped); + module.try_emplace("symbolDownloadTime", symbol_download_time); if (!symfile_path.empty()) module.try_emplace("symbolFilePath", symfile_path); @@ -288,6 +289,7 @@ llvm::json::Value DebuggerStats::ReportStatistics( json::Array json_targets; json::Array json_modules; + double symbol_download_time = 0.0; double symtab_parse_time = 0.0; double symtab_index_time = 0.0; double debug_parse_time = 0.0; @@ -345,6 +347,10 @@ llvm::json::Value DebuggerStats::ReportStatistics( ++debug_index_saved; module_stat.debug_index_time = sym_file->GetDebugInfoIndexTime().count(); module_stat.debug_parse_time = sym_file->GetDebugInfoParseTime().count(); + module_stat.symbol_download_time += sym_file->GetSymbolDownloadTime(); + if (sym_file->GetObjectFile() != module->GetObjectFile()) + module_stat.symbol_download_time += + module->GetObjectFile()->GetFileSpec().GetDownloadTime(); module_stat.debug_info_size = sym_file->GetDebugInfoSize(load_all_debug_info); module_stat.symtab_stripped = module->GetObjectFile()->IsStripped(); @@ -361,6 +367,7 @@ llvm::json::Value DebuggerStats::ReportStatistics( if (module_stat.debug_info_had_variable_errors) ++num_modules_with_variable_errors; } + symbol_download_time += module_stat.symbol_download_time; symtab_parse_time += module_stat.symtab_parse_time; symtab_index_time += module_stat.symtab_index_time; debug_parse_time += module_stat.debug_parse_time; @@ -391,6 +398,7 @@ llvm::json::Value DebuggerStats::ReportStatistics( } json::Object global_stats{ + {"totalSymbolDownloadTime", symbol_download_time}, {"totalSymbolTableParseTime", symtab_parse_time}, {"totalSymbolTableIndexTime", symtab_index_time}, {"totalSymbolTablesLoadedFromCache", symtabs_loaded}, diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index bb2b8647342b8..89c3eba44c306 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -72,6 +72,12 @@ FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) { SetFile(path, style); } +FileSpec::FileSpec(llvm::StringRef path, const double download_time, + Style style) + : m_download_time(download_time) { + SetFile(path, style); +} + FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple) : FileSpec{path, triple.isOSWindows() ? Style::windows : Style::posix} {} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits