Skip to content

Commit 7fe3586

Browse files
committed
Send statistics in initialized event
Differential Revision: https://reviews.llvm.org/D138077
1 parent fcaf6dd commit 7fe3586

File tree

9 files changed

+65
-17
lines changed

9 files changed

+65
-17
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def __init__(self, recv, send, init_commands, log_file=None):
134134
self.configuration_done_sent = False
135135
self.frame_scopes = {}
136136
self.init_commands = init_commands
137+
self.initialized_event = None
137138

138139
@classmethod
139140
def encode_content(cls, s):
@@ -231,6 +232,8 @@ def handle_recv_packet(self, packet):
231232
self._process_stopped()
232233
tid = body['threadId']
233234
self.thread_stop_reasons[tid] = body
235+
elif event == 'initialized':
236+
self.initialized_event = packet
234237
elif event == 'breakpoint':
235238
# Breakpoint events come in when a breakpoint has locations
236239
# added or removed. Keep track of them so we can look for them

lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py renamed to lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,27 @@
1010
import re
1111
import json
1212

13-
class TestVSCode_terminatedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
13+
class TestVSCode_eventStatistic(lldbvscode_testcase.VSCodeTestCaseBase):
14+
15+
def check_statistic(self, statistics):
16+
self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
17+
self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
18+
self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
19+
20+
self.assertIsNotNone(statistics['memory'])
21+
self.assertNotIn('modules', statistics.keys())
22+
23+
def check_target(self, statistics):
24+
# lldb-vscode debugs one target at a time
25+
target = json.loads(statistics['targets'])[0]
26+
self.assertTrue(target['totalBreakpointResolveTime'] > 0)
27+
28+
breakpoints = target['breakpoints']
29+
self.assertIn('foo',
30+
breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
31+
'foo is a symbol breakpoint')
32+
self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
33+
'target has source line breakpoint in main.cpp')
1434

1535
@skipIfWindows
1636
@skipIfRemote
@@ -45,20 +65,33 @@ def test_terminated_event(self):
4565
self.continue_to_exit()
4666

4767
statistics = self.vscode.wait_for_terminated()['statistics']
48-
self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
49-
self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
50-
self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
68+
self.check_statistic(statistics)
69+
self.check_target(statistics)
5170

52-
self.assertIsNotNone(statistics['memory'])
53-
self.assertNotIn('modules', statistics.keys())
71+
@skipIfWindows
72+
@skipIfRemote
73+
def test_initialized_event(self):
74+
'''
75+
Initialized Event
76+
Now contains the statistics of a debug session:
77+
totalDebugInfoByteSize > 0
78+
totalDebugInfoEnabled > 0
79+
totalModuleCountHasDebugInfo > 0
80+
totalBreakpointResolveTime > 0
81+
...
82+
'''
5483

55-
# lldb-vscode debugs one target at a time
56-
target = json.loads(statistics['targets'])[0]
57-
self.assertTrue(target['totalBreakpointResolveTime'] > 0)
84+
program_basename = "a.out.stripped"
85+
program = self.getBuildArtifact(program_basename)
86+
self.build_and_launch(program)
87+
# Set breakpoints
88+
functions = ['foo']
89+
breakpoint_ids = self.set_function_breakpoints(functions)
90+
self.assertEquals(len(breakpoint_ids), len(functions), 'expect one breakpoint')
91+
main_bp_line = line_number('main.cpp', '// main breakpoint 1')
92+
breakpoint_ids.append(self.set_source_breakpoints('main.cpp', [main_bp_line]))
5893

59-
breakpoints = target['breakpoints']
60-
self.assertIn('foo',
61-
breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
62-
'foo is a symbol breakpoint')
63-
self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
64-
'target has source line breakpoint in main.cpp')
94+
self.continue_to_breakpoints(breakpoint_ids)
95+
statistics = self.vscode.initialized_event['statistics']
96+
self.check_statistic(statistics)
97+
self.continue_to_exit()

lldb/tools/lldb-vscode/JSONUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,12 @@ llvm::json::Object CreateTerminatedEventObject() {
12091209
return event;
12101210
}
12111211

1212+
llvm::json::Object CreateInitializedEventObject() {
1213+
llvm::json::Object event(CreateEventObject("initialized"));
1214+
addStatistic(event);
1215+
return event;
1216+
}
1217+
12121218
std::string JSONToString(const llvm::json::Value &json) {
12131219
std::string data;
12141220
llvm::raw_string_ostream os(data);

lldb/tools/lldb-vscode/JSONUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
491491
/// A body JSON object with debug info and breakpoint info
492492
llvm::json::Object CreateTerminatedEventObject();
493493

494+
/// Create a "Initialized" JSON object that contains statistics
495+
///
496+
/// \return
497+
/// A body JSON object with debug info
498+
llvm::json::Object CreateInitializedEventObject();
499+
494500
/// Convert a given JSON object to a string.
495501
std::string JSONToString(const llvm::json::Value &json);
496502

lldb/tools/lldb-vscode/lldb-vscode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ void request_attach(const llvm::json::Object &request) {
687687
g_vsc.SendJSON(llvm::json::Value(std::move(response)));
688688
if (error.Success()) {
689689
SendProcessEvent(Attach);
690-
g_vsc.SendJSON(CreateEventObject("initialized"));
690+
g_vsc.SendJSON(CreateInitializedEventObject());
691691
}
692692
}
693693

@@ -1754,7 +1754,7 @@ void request_launch(const llvm::json::Object &request) {
17541754
SendProcessEvent(Attach); // this happens when doing runInTerminal
17551755
else
17561756
SendProcessEvent(Launch);
1757-
g_vsc.SendJSON(llvm::json::Value(CreateEventObject("initialized")));
1757+
g_vsc.SendJSON(CreateInitializedEventObject());
17581758
}
17591759

17601760
// "NextRequest": {

0 commit comments

Comments
 (0)