Skip to content

Commit e51ed29

Browse files
committed
Add new target metric to track time
1 parent fe9fba8 commit e51ed29

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-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: 23 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 *
@@ -157,3 +158,25 @@ def test_command_stats_force(self):
157158
stats_force.GetAsJSON(stream_force)
158159
debug_stats_force = json.loads(stream_force.GetData())
159160
self.assertEqual(debug_stats_force["totalDebugInfoByteSize"], 445)
161+
162+
def test_core_load_time(self):
163+
"""
164+
Test to see if the coredump path is included in statistics dump.
165+
"""
166+
yaml_file = "arm64-minidump-build-ids.yaml"
167+
src_dir = self.getSourceDir()
168+
minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp")
169+
self.yaml2obj(os.path.join(src_dir, yaml_file), minidump_path)
170+
target = self.dbg.CreateTarget(None)
171+
process = target.LoadCore(minidump_path)
172+
self.assertTrue(process.IsValid())
173+
174+
stats_options = lldb.SBStatisticsOptions()
175+
stats = target.GetStatistics(stats_options)
176+
stream = lldb.SBStream()
177+
stats.GetAsJSON(stream)
178+
debug_stats = json.loads(stream.GetData())
179+
self.assertTrue("targets" in debug_stats)
180+
target_info = debug_stats["targets"][0]
181+
self.assertTrue("loadCoreTime" in target_info)
182+
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)