Skip to content

Commit 24feaab

Browse files
jeffreytan81jeffreytan81
andauthored
Fix statistics dump to report per-target (#113723)
"statistics dump" currently report the statistics of all targets in debugger instead of current target. This is wrong because there is a "statistics dump --all-targets" option that supposed to include everything. This PR fixes the issue by only report statistics for current target instead of all. It also includes the change to reset statistics debug info/symbol table parsing/indexing time during debugger destroy. This is required so that we report current statistics if we plan to reuse lldb/lldb-dap across debug sessions --------- Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
1 parent d9eda6b commit 24feaab

File tree

20 files changed

+173
-4
lines changed

20 files changed

+173
-4
lines changed

lldb/include/lldb/API/SBDebugger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ class LLDB_API SBDebugger {
426426

427427
SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier);
428428

429+
/// Clear collected statistics for targets belonging to this debugger. This
430+
/// includes clearing symbol table and debug info parsing/index time for all
431+
/// modules, breakpoint resolve time and target statistics.
432+
void ResetStatistics();
433+
429434
#ifndef SWIG
430435
/// Run the command interpreter.
431436
///

lldb/include/lldb/API/SBTarget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ class LLDB_API SBTarget {
101101
/// A SBStructuredData with the statistics collected.
102102
lldb::SBStructuredData GetStatistics(SBStatisticsOptions options);
103103

104+
/// Reset the statistics collected for this target.
105+
/// This includes clearing symbol table and debug info parsing/index time for
106+
/// all modules, breakpoint resolve time and target statistics.
107+
void ResetStatistics();
108+
104109
/// Return the platform object associated with the target.
105110
///
106111
/// After return, the platform object should be checked for

lldb/include/lldb/Breakpoint/Breakpoint.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
588588
/// Get statistics associated with this breakpoint in JSON format.
589589
llvm::json::Value GetStatistics();
590590

591+
void ResetStatistics();
592+
591593
/// Get the time it took to resolve all locations in this breakpoint.
592594
StatsDuration::Duration GetResolveTime() const { return m_resolve_time; }
593595

lldb/include/lldb/Core/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ class Module : public std::enable_shared_from_this<Module>,
881881
/// ElapsedTime RAII object.
882882
StatsDuration &GetSymtabIndexTime() { return m_symtab_index_time; }
883883

884+
void ResetStatistics();
885+
884886
/// \class LookupInfo Module.h "lldb/Core/Module.h"
885887
/// A class that encapsulates name lookup information.
886888
///

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ 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+
/// Reset the statistics for the symbol file.
426+
virtual void ResetStatistics() {}
427+
425428
/// Get the additional modules that this symbol file uses to parse debug info.
426429
///
427430
/// Some debug info is stored in stand alone object files that are represented

lldb/include/lldb/Symbol/SymbolFileOnDemand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile {
182182
lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override;
183183
lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override;
184184

185+
void ResetStatistics() override;
186+
185187
uint32_t GetAbilities() override;
186188

187189
Symtab *GetSymtab() override { return m_sym_file_impl->GetSymtab(); }

lldb/include/lldb/Target/Statistics.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class StatsDuration {
4141
}
4242
operator Duration() const { return get(); }
4343

44+
void reset() { value.store(0, std::memory_order_relaxed); }
45+
4446
StatsDuration &operator+=(Duration dur) {
4547
value.fetch_add(std::chrono::duration_cast<InternalDuration>(dur).count(),
4648
std::memory_order_relaxed);
@@ -201,6 +203,8 @@ class SummaryStatistics {
201203

202204
llvm::json::Value ToJSON() const;
203205

206+
void Reset() { m_total_time.reset(); }
207+
204208
/// Basic RAII class to increment the summary count when the call is complete.
205209
class SummaryInvocation {
206210
public:
@@ -250,6 +254,8 @@ class SummaryStatisticsCache {
250254

251255
llvm::json::Value ToJSON();
252256

257+
void Reset();
258+
253259
private:
254260
llvm::StringMap<SummaryStatisticsSP> m_summary_stats_map;
255261
std::mutex m_map_mutex;
@@ -271,6 +277,7 @@ class TargetStats {
271277
StatsDuration &GetCreateTime() { return m_create_time; }
272278
StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }
273279
StatsSuccessFail &GetFrameVariableStats() { return m_frame_var; }
280+
void Reset(Target &target);
274281

275282
protected:
276283
StatsDuration m_create_time;
@@ -311,6 +318,16 @@ class DebuggerStats {
311318
ReportStatistics(Debugger &debugger, Target *target,
312319
const lldb_private::StatisticsOptions &options);
313320

321+
/// Reset metrics associated with one or all targets in a debugger.
322+
///
323+
/// \param debugger
324+
/// The debugger to reset the target list from if \a target is NULL.
325+
///
326+
/// \param target
327+
/// The target to reset statistics for, or if null, reset statistics
328+
/// for all targets
329+
static void ResetStatistics(Debugger &debugger, Target *target);
330+
314331
protected:
315332
// Collecting stats can be set to true to collect stats that are expensive
316333
// to collect. By default all stats that are cheap to collect are enabled.

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,8 @@ class Target : public std::enable_shared_from_this<Target>,
16351635
llvm::json::Value
16361636
ReportStatistics(const lldb_private::StatisticsOptions &options);
16371637

1638+
void ResetStatistics();
1639+
16381640
TargetStats &GetStatistics() { return m_stats; }
16391641

16401642
protected:

lldb/source/API/SBDebugger.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,12 @@ SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) {
16671667
DataVisualization::GetSyntheticForType(type_name.GetSP()));
16681668
}
16691669

1670+
void SBDebugger::ResetStatistics() {
1671+
LLDB_INSTRUMENT_VA(this);
1672+
if (m_opaque_sp)
1673+
DebuggerStats::ResetStatistics(*m_opaque_sp, nullptr);
1674+
}
1675+
16701676
static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {
16711677
if (categories == nullptr)
16721678
return {};

lldb/source/API/SBTarget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ SBStructuredData SBTarget::GetStatistics(SBStatisticsOptions options) {
220220
return data;
221221
}
222222

223+
void SBTarget::ResetStatistics() {
224+
LLDB_INSTRUMENT_VA(this);
225+
TargetSP target_sp(GetSP());
226+
if (target_sp)
227+
DebuggerStats::ResetStatistics(target_sp->GetDebugger(), target_sp.get());
228+
}
229+
223230
void SBTarget::SetCollectingStats(bool v) {
224231
LLDB_INSTRUMENT_VA(this, v);
225232

0 commit comments

Comments
 (0)