Skip to content

Commit b452849

Browse files
Jlalondmahesh-attarde
authored andcommitted
[LLDB] Add load core time to target metrics (llvm#161581)
This patch adds a load core time, right now we don't have much insight into the performance of load core, especially for large coredumps. To start collecting information on this I've added some minor instrumentation code to measure the two call sites of `LoadCore`. I've also added a test to validate the new metric is output in statistics dump
1 parent f8eebe6 commit b452849

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

lldb/include/lldb/Target/Statistics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,14 @@ class TargetStats {
322322
void IncreaseSourceRealpathCompatibleCount(uint32_t count);
323323

324324
StatsDuration &GetCreateTime() { return m_create_time; }
325+
StatsDuration &GetLoadCoreTime() { return m_load_core_time; }
325326
StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }
326327
StatsSuccessFail &GetFrameVariableStats() { return m_frame_var; }
327328
void Reset(Target &target);
328329

329330
protected:
330331
StatsDuration m_create_time;
332+
StatsDuration m_load_core_time;
331333
std::optional<StatsTimepoint> m_launch_or_attach_time;
332334
std::optional<StatsTimepoint> m_first_private_stop_time;
333335
std::optional<StatsTimepoint> m_first_public_stop_time;

lldb/source/API/SBTarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
255255
ProcessSP process_sp(target_sp->CreateProcess(
256256
target_sp->GetDebugger().GetListener(), "", &filespec, false));
257257
if (process_sp) {
258+
ElapsedTime loadCoreTime(target_sp->GetStatistics().GetLoadCoreTime());
258259
error.SetError(process_sp->LoadCore());
259260
if (error.Success())
260261
sb_process.SetSP(process_sp);

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
418418
if (process_sp) {
419419
// Seems weird that we Launch a core file, but that is what we
420420
// do!
421-
error = process_sp->LoadCore();
421+
{
422+
ElapsedTime loadCoreTime(
423+
target_sp->GetStatistics().GetLoadCoreTime());
424+
error = process_sp->LoadCore();
425+
}
422426

423427
if (error.Fail()) {
424428
result.AppendError(error.AsCString("unknown core file format"));

lldb/source/Target/Statistics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ TargetStats::ToJSON(Target &target,
148148
target_metrics_json.try_emplace("targetCreateTime",
149149
m_create_time.get().count());
150150

151+
if (m_load_core_time.get().count() > 0) {
152+
target_metrics_json.try_emplace("loadCoreTime",
153+
m_load_core_time.get().count());
154+
}
155+
151156
json::Array breakpoints_array;
152157
double totalBreakpointResolveTime = 0.0;
153158
// Report both the normal breakpoint list and the internal breakpoint list.

lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Test the SBAPI for GetStatistics()
22

33
import json
4+
45
import lldb
56
from lldbsuite.test.decorators import *
67
from lldbsuite.test.lldbtest import *
@@ -54,6 +55,11 @@ def test_stats_api(self):
5455
stats_json,
5556
'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]',
5657
)
58+
self.assertNotIn(
59+
"loadCoreTime",
60+
stats_json,
61+
"LoadCoreTime should not be present in a live, non-coredump target",
62+
)
5763
expressionEvaluation = stats_json["expressionEvaluation"]
5864
self.assertIn(
5965
"successes",
@@ -157,3 +163,25 @@ def test_command_stats_force(self):
157163
stats_force.GetAsJSON(stream_force)
158164
debug_stats_force = json.loads(stream_force.GetData())
159165
self.assertEqual(debug_stats_force["totalDebugInfoByteSize"], 445)
166+
167+
def test_core_load_time(self):
168+
"""
169+
Test to see if the coredump path is included in statistics dump.
170+
"""
171+
yaml_file = "arm64-minidump-build-ids.yaml"
172+
src_dir = self.getSourceDir()
173+
minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp")
174+
self.yaml2obj(os.path.join(src_dir, yaml_file), minidump_path)
175+
target = self.dbg.CreateTarget(None)
176+
process = target.LoadCore(minidump_path)
177+
self.assertTrue(process.IsValid())
178+
179+
stats_options = lldb.SBStatisticsOptions()
180+
stats = target.GetStatistics(stats_options)
181+
stream = lldb.SBStream()
182+
stats.GetAsJSON(stream)
183+
debug_stats = json.loads(stream.GetData())
184+
self.assertTrue("targets" in debug_stats)
185+
target_info = debug_stats["targets"][0]
186+
self.assertTrue("loadCoreTime" in target_info)
187+
self.assertTrue(float(target_info["loadCoreTime"]) > 0.0)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- !minidump
2+
Streams:
3+
- Type: SystemInfo
4+
Processor Arch: ARM
5+
Platform ID: Linux
6+
CSD Version: '15E216'
7+
CPU:
8+
CPUID: 0x00000000
9+
- Type: ModuleList
10+
Modules:
11+
- Base of Image: 0x0000000000001000
12+
Size of Image: 0x00001000
13+
Module Name: '/tmp/a'
14+
CodeView Record: 4C4570420102030405060708090A0B0C0D0E0F1011121314
15+
- Base of Image: 0x0000000000001000
16+
Size of Image: 0x00001000
17+
Module Name: '/tmp/b'
18+
CodeView Record: 4C4570420A141E28323C46505A646E78828C96A0AAB4BEC8
19+
...

0 commit comments

Comments
 (0)