[Lldb-commits] [lldb] 7fe3586 - Send statistics in initialized event
George Hu via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 15 19:09:25 PST 2022
Author: George Hu
Date: 2022-11-15T19:09:05-08:00
New Revision: 7fe3586cda5b683766ec6b6d5ca2d98c2baaf162
URL: https://github.com/llvm/llvm-project/commit/7fe3586cda5b683766ec6b6d5ca2d98c2baaf162
DIFF: https://github.com/llvm/llvm-project/commit/7fe3586cda5b683766ec6b6d5ca2d98c2baaf162.diff
LOG: Send statistics in initialized event
Differential Revision: https://reviews.llvm.org/D138077
Added:
lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile
lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp
lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h
lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp
Modified:
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
lldb/tools/lldb-vscode/JSONUtils.cpp
lldb/tools/lldb-vscode/JSONUtils.h
lldb/tools/lldb-vscode/lldb-vscode.cpp
Removed:
lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
index c2de4ad5c7d9a..49f268ae28793 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -134,6 +134,7 @@ def __init__(self, recv, send, init_commands, log_file=None):
self.configuration_done_sent = False
self.frame_scopes = {}
self.init_commands = init_commands
+ self.initialized_event = None
@classmethod
def encode_content(cls, s):
@@ -231,6 +232,8 @@ def handle_recv_packet(self, packet):
self._process_stopped()
tid = body['threadId']
self.thread_stop_reasons[tid] = body
+ elif event == 'initialized':
+ self.initialized_event = packet
elif event == 'breakpoint':
# Breakpoint events come in when a breakpoint has locations
# added or removed. Keep track of them so we can look for them
diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/Makefile b/lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile
similarity index 100%
rename from lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
rename to lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile
diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py b/lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
similarity index 64%
rename from lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
rename to lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
index ae364a5fe1f0d..b70e21ef7d9da 100644
--- a/lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
+++ b/lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
@@ -10,7 +10,27 @@
import re
import json
-class TestVSCode_terminatedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+class TestVSCode_eventStatistic(lldbvscode_testcase.VSCodeTestCaseBase):
+
+ def check_statistic(self, statistics):
+ self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
+ self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
+ self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
+
+ self.assertIsNotNone(statistics['memory'])
+ self.assertNotIn('modules', statistics.keys())
+
+ def check_target(self, statistics):
+ # lldb-vscode debugs one target at a time
+ target = json.loads(statistics['targets'])[0]
+ self.assertTrue(target['totalBreakpointResolveTime'] > 0)
+
+ breakpoints = target['breakpoints']
+ self.assertIn('foo',
+ breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
+ 'foo is a symbol breakpoint')
+ self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
+ 'target has source line breakpoint in main.cpp')
@skipIfWindows
@skipIfRemote
@@ -45,20 +65,33 @@ def test_terminated_event(self):
self.continue_to_exit()
statistics = self.vscode.wait_for_terminated()['statistics']
- self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
- self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
- self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
+ self.check_statistic(statistics)
+ self.check_target(statistics)
- self.assertIsNotNone(statistics['memory'])
- self.assertNotIn('modules', statistics.keys())
+ @skipIfWindows
+ @skipIfRemote
+ def test_initialized_event(self):
+ '''
+ Initialized Event
+ Now contains the statistics of a debug session:
+ totalDebugInfoByteSize > 0
+ totalDebugInfoEnabled > 0
+ totalModuleCountHasDebugInfo > 0
+ totalBreakpointResolveTime > 0
+ ...
+ '''
- # lldb-vscode debugs one target at a time
- target = json.loads(statistics['targets'])[0]
- self.assertTrue(target['totalBreakpointResolveTime'] > 0)
+ program_basename = "a.out.stripped"
+ program = self.getBuildArtifact(program_basename)
+ self.build_and_launch(program)
+ # Set breakpoints
+ functions = ['foo']
+ breakpoint_ids = self.set_function_breakpoints(functions)
+ self.assertEquals(len(breakpoint_ids), len(functions), 'expect one breakpoint')
+ main_bp_line = line_number('main.cpp', '// main breakpoint 1')
+ breakpoint_ids.append(self.set_source_breakpoints('main.cpp', [main_bp_line]))
- breakpoints = target['breakpoints']
- self.assertIn('foo',
- breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
- 'foo is a symbol breakpoint')
- self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
- 'target has source line breakpoint in main.cpp')
+ self.continue_to_breakpoints(breakpoint_ids)
+ statistics = self.vscode.initialized_event['statistics']
+ self.check_statistic(statistics)
+ self.continue_to_exit()
diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp b/lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp
similarity index 100%
rename from lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
rename to lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp
diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/foo.h b/lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h
similarity index 100%
rename from lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
rename to lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h
diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp b/lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp
similarity index 100%
rename from lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
rename to lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp
diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 53f1d509d08bd..f57fae727114c 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -1209,6 +1209,12 @@ llvm::json::Object CreateTerminatedEventObject() {
return event;
}
+llvm::json::Object CreateInitializedEventObject() {
+ llvm::json::Object event(CreateEventObject("initialized"));
+ addStatistic(event);
+ return event;
+}
+
std::string JSONToString(const llvm::json::Value &json) {
std::string data;
llvm::raw_string_ostream os(data);
diff --git a/lldb/tools/lldb-vscode/JSONUtils.h b/lldb/tools/lldb-vscode/JSONUtils.h
index c812ec87beab0..2400cbc0aca4a 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.h
+++ b/lldb/tools/lldb-vscode/JSONUtils.h
@@ -491,6 +491,12 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
/// A body JSON object with debug info and breakpoint info
llvm::json::Object CreateTerminatedEventObject();
+/// Create a "Initialized" JSON object that contains statistics
+///
+/// \return
+/// A body JSON object with debug info
+llvm::json::Object CreateInitializedEventObject();
+
/// Convert a given JSON object to a string.
std::string JSONToString(const llvm::json::Value &json);
diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 21d2bc2229043..269ff4c6552b8 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -687,7 +687,7 @@ void request_attach(const llvm::json::Object &request) {
g_vsc.SendJSON(llvm::json::Value(std::move(response)));
if (error.Success()) {
SendProcessEvent(Attach);
- g_vsc.SendJSON(CreateEventObject("initialized"));
+ g_vsc.SendJSON(CreateInitializedEventObject());
}
}
@@ -1754,7 +1754,7 @@ void request_launch(const llvm::json::Object &request) {
SendProcessEvent(Attach); // this happens when doing runInTerminal
else
SendProcessEvent(Launch);
- g_vsc.SendJSON(llvm::json::Value(CreateEventObject("initialized")));
+ g_vsc.SendJSON(CreateInitializedEventObject());
}
// "NextRequest": {
More information about the lldb-commits
mailing list