Skip to content

Commit 4c4a2bf

Browse files
author
George Hu
committed
Add download time for each module in statistics
1 parent d7cb24e commit 4c4a2bf

File tree

11 files changed

+125
-22
lines changed

11 files changed

+125
-22
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,14 @@ class PluginManager {
377377
static SymbolLocatorCreateInstance
378378
GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx);
379379

380-
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
380+
static ModuleSpec
381+
LocateExecutableObjectFile(const ModuleSpec &module_spec,
382+
std::string *locator_name = nullptr);
381383

382384
static FileSpec
383385
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
384-
const FileSpecList &default_search_paths);
386+
const FileSpecList &default_search_paths,
387+
std::string *locator_name = nullptr);
385388

386389
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
387390
Status &error,

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "lldb/Core/PluginInterface.h"
1414
#include "lldb/Symbol/Symtab.h"
1515
#include "lldb/Symbol/UnwindTable.h"
16+
#include "lldb/Target/Statistics.h"
1617
#include "lldb/Utility/AddressableBits.h"
1718
#include "lldb/Utility/DataExtractor.h"
1819
#include "lldb/Utility/Endian.h"
@@ -589,6 +590,8 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
589590
/// this routine to set eTypeDebugInfo when loading debug link files.
590591
virtual void SetType(Type type) { m_type = type; }
591592

593+
virtual StatsDuration &GetDownloadTime() { return m_download_time; }
594+
592595
/// The object file should be able to calculate the strata of the object
593596
/// file.
594597
///
@@ -752,6 +755,7 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
752755

753756
protected:
754757
// Member variables.
758+
StatsDuration m_download_time; ///< Time to download the object file
755759
FileSpec m_file;
756760
Type m_type;
757761
Strata m_strata;

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@ class SymbolFile : public PluginInterface {
422422
/// hasn't been indexed yet, or a valid duration if it has.
423423
virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; }
424424

425+
/// Return the time it took to download any extra symbol files.
426+
///
427+
/// \returns 0.0 if no extra symbol files need to be downloaded
428+
virtual StatsDuration::Duration GetSymbolDownloadTime() { return {}; }
429+
425430
/// Reset the statistics for the symbol file.
426431
virtual void ResetStatistics() {}
427432

lldb/include/lldb/Target/Statistics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct ModuleStats {
122122
double symtab_index_time = 0.0;
123123
double debug_parse_time = 0.0;
124124
double debug_index_time = 0.0;
125+
double symbol_download_time = 0.0;
125126
uint64_t debug_info_size = 0;
126127
bool symtab_loaded_from_cache = false;
127128
bool symtab_saved_to_cache = false;

lldb/source/Core/DynamicLoader.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lldb/Core/Progress.h"
1717
#include "lldb/Core/Section.h"
1818
#include "lldb/Symbol/ObjectFile.h"
19+
#include "lldb/Symbol/SymbolFile.h"
1920
#include "lldb/Target/MemoryRegionInfo.h"
2021
#include "lldb/Target/Platform.h"
2122
#include "lldb/Target/Process.h"
@@ -25,6 +26,8 @@
2526
#include "lldb/Utility/Log.h"
2627
#include "lldb/lldb-private-interfaces.h"
2728

29+
#include "Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.h"
30+
2831
#include "llvm/ADT/StringRef.h"
2932

3033
#include <memory>
@@ -243,15 +246,40 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
243246
// find an executable and symbol file.
244247
if (!module_sp) {
245248
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
246-
module_spec.GetSymbolFileSpec() =
247-
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
248-
ModuleSpec objfile_module_spec =
249-
PluginManager::LocateExecutableObjectFile(module_spec);
249+
StatsDuration symbol_duration;
250+
std::string symbol_locator_name;
251+
StatsDuration object_duration;
252+
std::string object_locator_name;
253+
ModuleSpec objfile_module_spec;
254+
{
255+
ElapsedTime elapsed(symbol_duration);
256+
module_spec.GetSymbolFileSpec() =
257+
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths,
258+
&symbol_locator_name);
259+
}
260+
{
261+
ElapsedTime elapsed(object_duration);
262+
objfile_module_spec = PluginManager::LocateExecutableObjectFile(
263+
module_spec, &object_locator_name);
264+
}
250265
module_spec.GetFileSpec() = objfile_module_spec.GetFileSpec();
251266
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()) &&
252267
FileSystem::Instance().Exists(module_spec.GetSymbolFileSpec())) {
253268
module_sp = std::make_shared<Module>(module_spec);
254269
}
270+
if (module_sp) {
271+
if (object_locator_name ==
272+
SymbolLocatorDebuginfod::GetPluginNameStatic() &&
273+
module_sp->GetObjectFile())
274+
module_sp->GetObjectFile()->GetDownloadTime() += object_duration;
275+
if (symbol_locator_name ==
276+
SymbolLocatorDebuginfod::GetPluginNameStatic()) {
277+
const auto symfile = module_sp->GetSymbolFile();
278+
if (symfile) {
279+
symfile->GetObjectFile()->GetDownloadTime() += symbol_duration;
280+
}
281+
}
282+
}
255283
}
256284

257285
// If we haven't found a binary, or we don't have a SymbolFile, see

lldb/source/Core/ModuleList.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/ModuleList.h"
10+
#include "Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.h"
1011
#include "lldb/Core/Module.h"
1112
#include "lldb/Core/ModuleSpec.h"
1213
#include "lldb/Core/PluginManager.h"
@@ -917,9 +918,14 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
917918

918919
// Fixup the incoming path in case the path points to a valid file, yet the
919920
// arch or UUID (if one was passed in) don't match.
920-
ModuleSpec located_binary_modulespec =
921-
PluginManager::LocateExecutableObjectFile(module_spec);
922-
921+
ModuleSpec located_binary_modulespec;
922+
StatsDuration locate_duration;
923+
std::string locator_name;
924+
{
925+
ElapsedTime elapsed(locate_duration);
926+
located_binary_modulespec =
927+
PluginManager::LocateExecutableObjectFile(module_spec, &locator_name);
928+
}
923929
// Don't look for the file if it appears to be the same one we already
924930
// checked for above...
925931
if (located_binary_modulespec.GetFileSpec() != module_file_spec) {
@@ -992,6 +998,8 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
992998
// By getting the object file we can guarantee that the architecture
993999
// matches
9941000
if (module_sp && module_sp->GetObjectFile()) {
1001+
if (locator_name == SymbolLocatorDebuginfod::GetPluginNameStatic())
1002+
module_sp->GetObjectFile()->GetDownloadTime() += locate_duration;
9951003
if (module_sp->GetObjectFile()->GetType() ==
9961004
ObjectFile::eTypeStubLibrary) {
9971005
module_sp.reset();

lldb/source/Core/PluginManager.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,28 +1217,36 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
12171217
}
12181218

12191219
ModuleSpec
1220-
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
1220+
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec,
1221+
std::string *locator_name) {
12211222
auto instances = GetSymbolLocatorInstances().GetSnapshot();
12221223
for (auto &instance : instances) {
12231224
if (instance.locate_executable_object_file) {
12241225
std::optional<ModuleSpec> result =
12251226
instance.locate_executable_object_file(module_spec);
1226-
if (result)
1227+
if (result) {
1228+
if (locator_name)
1229+
*locator_name = instance.name;
12271230
return *result;
1231+
}
12281232
}
12291233
}
12301234
return {};
12311235
}
12321236

12331237
FileSpec PluginManager::LocateExecutableSymbolFile(
1234-
const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
1238+
const ModuleSpec &module_spec, const FileSpecList &default_search_paths,
1239+
std::string *locator_name) {
12351240
auto instances = GetSymbolLocatorInstances().GetSnapshot();
12361241
for (auto &instance : instances) {
12371242
if (instance.locate_executable_symbol_file) {
12381243
std::optional<FileSpec> result = instance.locate_executable_symbol_file(
12391244
module_spec, default_search_paths);
1240-
if (result)
1245+
if (result) {
1246+
if (locator_name)
1247+
*locator_name = instance.name;
12411248
return *result;
1249+
}
12421250
}
12431251
}
12441252
return {};

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
3434
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
35+
#include "Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.h"
3536

3637
#include "lldb/Host/FileSystem.h"
3738
#include "lldb/Host/Host.h"
@@ -4250,13 +4251,18 @@ const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
42504251
ModuleSpec module_spec;
42514252
module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
42524253
FileSpec dwp_filespec;
4254+
StatsDuration duration;
4255+
std::string locator_name;
42534256
for (const auto &symfile : symfiles.files()) {
42544257
module_spec.GetSymbolFileSpec() =
42554258
FileSpec(symfile.GetPath() + ".dwp", symfile.GetPathStyle());
42564259
LLDB_LOG(log, "Searching for DWP using: \"{0}\"",
42574260
module_spec.GetSymbolFileSpec());
4258-
dwp_filespec =
4259-
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
4261+
{
4262+
ElapsedTime elapsed(duration);
4263+
dwp_filespec = PluginManager::LocateExecutableSymbolFile(
4264+
module_spec, search_paths, &locator_name);
4265+
}
42604266
if (FileSystem::Instance().Exists(dwp_filespec)) {
42614267
break;
42624268
}
@@ -4267,8 +4273,12 @@ const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
42674273
// find the correct DWP file, as the Debuginfod plugin uses *only* this
42684274
// data to correctly match the DWP file with the binary.
42694275
module_spec.GetUUID() = m_objfile_sp->GetUUID();
4270-
dwp_filespec =
4271-
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
4276+
duration.reset();
4277+
{
4278+
ElapsedTime elapsed(duration);
4279+
dwp_filespec = PluginManager::LocateExecutableSymbolFile(
4280+
module_spec, search_paths, &locator_name);
4281+
}
42724282
}
42734283
if (FileSystem::Instance().Exists(dwp_filespec)) {
42744284
LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
@@ -4279,6 +4289,8 @@ const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
42794289
FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
42804290
dwp_file_data_offset);
42814291
if (dwp_obj_file) {
4292+
if (locator_name == SymbolLocatorDebuginfod::GetPluginNameStatic())
4293+
dwp_obj_file->GetDownloadTime() += duration;
42824294
m_dwp_symfile = std::make_shared<SymbolFileDWARFDwo>(
42834295
*this, dwp_obj_file, DIERef::k_file_index_mask);
42844296
}
@@ -4349,6 +4361,14 @@ LanguageType SymbolFileDWARF::GetLanguageFamily(DWARFUnit &unit) {
43494361
return LanguageTypeFromDWARF(lang);
43504362
}
43514363

4364+
StatsDuration::Duration SymbolFileDWARF::GetSymbolDownloadTime() {
4365+
StatsDuration total_time;
4366+
total_time += GetObjectFile()->GetDownloadTime();
4367+
if (m_dwp_symfile)
4368+
total_time += m_dwp_symfile->GetObjectFile()->GetDownloadTime();
4369+
return total_time;
4370+
}
4371+
43524372
StatsDuration::Duration SymbolFileDWARF::GetDebugInfoIndexTime() {
43534373
if (m_index)
43544374
return m_index->GetIndexTime();

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ class SymbolFileDWARF : public SymbolFileCommon {
309309
StatsDuration::Duration GetDebugInfoParseTime() override {
310310
return m_parse_time;
311311
}
312+
313+
StatsDuration::Duration GetSymbolDownloadTime() override;
314+
312315
StatsDuration::Duration GetDebugInfoIndexTime() override;
313316

314317
StatsDuration &GetDebugInfoParseTimeRef() { return m_parse_time; }

lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "lldb/Utility/StreamString.h"
2222
#include "lldb/Utility/Timer.h"
2323

24+
#include "Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.h"
25+
2426
using namespace lldb;
2527
using namespace lldb_private;
2628

@@ -103,14 +105,25 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
103105
module_spec.GetSymbolFileSpec() = fspec;
104106
module_spec.GetUUID() = uuid;
105107
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
106-
FileSpec dsym_fspec =
107-
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
108+
StatsDuration duration;
109+
FileSpec dsym_fspec;
110+
std::string locator_name;
111+
{
112+
ElapsedTime elapsed(duration);
113+
dsym_fspec = PluginManager::LocateExecutableSymbolFile(
114+
module_spec, search_paths, &locator_name);
115+
}
108116
if (!dsym_fspec || IsDwpSymbolFile(module_sp, dsym_fspec)) {
109117
// If we have a stripped binary or if we have a DWP file, SymbolLocator
110118
// plugins may be able to give us an unstripped binary or an
111119
// 'only-keep-debug' stripped file.
112-
ModuleSpec unstripped_spec =
113-
PluginManager::LocateExecutableObjectFile(module_spec);
120+
ModuleSpec unstripped_spec;
121+
duration.reset();
122+
{
123+
ElapsedTime elapsed(duration);
124+
unstripped_spec =
125+
PluginManager::LocateExecutableObjectFile(module_spec, &locator_name);
126+
}
114127
if (!unstripped_spec)
115128
return nullptr;
116129
// The default SymbolLocator plugin returns the original binary if no other
@@ -127,7 +140,8 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
127140
dsym_file_data_sp, dsym_file_data_offset);
128141
if (!dsym_objfile_sp)
129142
return nullptr;
130-
143+
if (locator_name == SymbolLocatorDebuginfod::GetPluginNameStatic())
144+
dsym_objfile_sp->GetDownloadTime() += duration;
131145
// This objfile is for debugging purposes. Sadly, ObjectFileELF won't
132146
// be able to figure this out consistently as the symbol file may not
133147
// have stripped the code sections, etc.

lldb/source/Target/Statistics.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ json::Value ModuleStats::ToJSON() const {
7171
module.try_emplace("debugInfoHadIncompleteTypes",
7272
debug_info_had_incomplete_types);
7373
module.try_emplace("symbolTableStripped", symtab_stripped);
74+
module.try_emplace("symbolDownloadTime", symbol_download_time);
7475
if (!symfile_path.empty())
7576
module.try_emplace("symbolFilePath", symfile_path);
7677

@@ -288,6 +289,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
288289

289290
json::Array json_targets;
290291
json::Array json_modules;
292+
double symbol_download_time = 0.0;
291293
double symtab_parse_time = 0.0;
292294
double symtab_index_time = 0.0;
293295
double debug_parse_time = 0.0;
@@ -345,6 +347,11 @@ llvm::json::Value DebuggerStats::ReportStatistics(
345347
++debug_index_saved;
346348
module_stat.debug_index_time = sym_file->GetDebugInfoIndexTime().count();
347349
module_stat.debug_parse_time = sym_file->GetDebugInfoParseTime().count();
350+
module_stat.symbol_download_time +=
351+
sym_file->GetSymbolDownloadTime().count();
352+
if (sym_file->GetObjectFile() != module->GetObjectFile())
353+
module_stat.symbol_download_time +=
354+
module->GetObjectFile()->GetDownloadTime().get().count();
348355
module_stat.debug_info_size =
349356
sym_file->GetDebugInfoSize(load_all_debug_info);
350357
module_stat.symtab_stripped = module->GetObjectFile()->IsStripped();
@@ -361,6 +368,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
361368
if (module_stat.debug_info_had_variable_errors)
362369
++num_modules_with_variable_errors;
363370
}
371+
symbol_download_time += module_stat.symbol_download_time;
364372
symtab_parse_time += module_stat.symtab_parse_time;
365373
symtab_index_time += module_stat.symtab_index_time;
366374
debug_parse_time += module_stat.debug_parse_time;
@@ -391,6 +399,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
391399
}
392400

393401
json::Object global_stats{
402+
{"totalSymbolDownloadTime", symbol_download_time},
394403
{"totalSymbolTableParseTime", symtab_parse_time},
395404
{"totalSymbolTableIndexTime", symtab_index_time},
396405
{"totalSymbolTablesLoadedFromCache", symtabs_loaded},

0 commit comments

Comments
 (0)