Skip to content

Commit 5c310d1

Browse files
authored
Default transcript dumping in "statistics dump" to false (#145436)
### Summary Currently, if the setting `interpreter.save-transcript` is enabled, whenever we call "statistics dump", it'll default to reporting a huge list of transcripts which can be a bit noisy. This is because the current check `GetIncludeTranscript` returns `!GetSummaryOnly()` by default if no specific transcript-setting option is given in the statistics dump command (ie. `statistics dump --transcripts=false` or `statistics dump --transcripts=true`). Then when `interpreter.save-transcript` is enabled, this saves a list of transcripts, and the transcript list ends up getting logged by default. These changes default the option to log transcripts in the `statistics dump` command to "false". This can still be enabled via the `--transcripts` option if users want to see a transcript. Since `interpreter.save-transcript` is false by default, the main delta is that if `interpreter.save-transcript` is true and summary mode is false, we now disable saving the transcript. This also adds a warning to 'statistics dump --transcript=true' when interpreter.save-transcript is disabled, which should help users understand why transcript data is empty. ### Testing #### Manual testing Tested with `settings set interpreter.save-transcript true` enabled at startup on a toy hello-world program: ``` (lldb) settings set interpreter.save-transcript true (lldb) target create "/home/qxy11/hello-world/a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) statistics dump { /* no transcript */ } (lldb) statistics dump --transcript=true { "transcript": [ { "command": "statistics dump", "commandArguments": "", "commandName": "statistics dump", "durationInSeconds": 0.0019650000000000002, "error": "", "output": "{... }, { "command": "statistics dump --transcript=true", "commandArguments": "--transcript=true", "commandName": "statistics dump", "timestampInEpochSeconds": 1750720021 } ] } ``` Without `settings set interpreter.save-transcript true`: ``` (lldb) target create "/home/qxy11/hello-world/a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) statistics dump { /* no transcript */ } (lldb) statistics dump --transcript=true { /* no transcript */ } warning: transcript requested but none was saved. Enable with 'settings set interpreter.save-transcript true' ``` #### Unit tests Changed unit tests to account for new expected default behavior to `false`, and added a couple new tests around expected behavior with `--transcript=true`. ``` lldb-dotest -p TestStats ~/llvm-sand/external/llvm-project/lldb/test/API/commands/statistics/basic/ ```
1 parent 066a14d commit 5c310d1

File tree

5 files changed

+83
-17
lines changed

5 files changed

+83
-17
lines changed

lldb/include/lldb/API/SBStatisticsOptions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class LLDB_API SBStatisticsOptions {
5757
/// a JSON array with all commands the user and/or scripts executed during a
5858
/// debug session.
5959
///
60-
/// Defaults to true, unless the `SummaryOnly` mode is enabled, in which case
61-
/// this is turned off unless specified.
60+
/// Defaults to false.
6261
void SetIncludeTranscript(bool b);
6362
bool GetIncludeTranscript() const;
6463

lldb/include/lldb/Target/Statistics.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,7 @@ struct StatisticsOptions {
191191

192192
void SetIncludeTranscript(bool value) { m_include_transcript = value; }
193193
bool GetIncludeTranscript() const {
194-
if (m_include_transcript.has_value())
195-
return m_include_transcript.value();
196-
// `m_include_transcript` has no value set, so return a value based on
197-
// `m_summary_only`.
198-
return !GetSummaryOnly();
194+
return m_include_transcript.value_or(false);
199195
}
200196

201197
void SetIncludePlugins(bool value) { m_include_plugins = value; }

lldb/source/Commands/CommandObjectStats.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommandObjectStats.h"
1010
#include "lldb/Core/Debugger.h"
1111
#include "lldb/Host/OptionParser.h"
12+
#include "lldb/Interpreter/CommandInterpreter.h"
1213
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
1314
#include "lldb/Interpreter/CommandReturnObject.h"
1415
#include "lldb/Interpreter/OptionArgParser.h"
@@ -147,9 +148,18 @@ class CommandObjectStatsDump : public CommandObjectParsed {
147148
if (!m_options.m_all_targets)
148149
target = m_exe_ctx.GetTargetPtr();
149150

151+
// Check if transcript is requested but transcript saving is disabled
152+
const StatisticsOptions &stats_options = m_options.GetStatisticsOptions();
153+
if (stats_options.GetIncludeTranscript() &&
154+
!GetDebugger().GetCommandInterpreter().GetSaveTranscript()) {
155+
result.AppendWarning(
156+
"transcript requested but none was saved. Enable with "
157+
"'settings set interpreter.save-transcript true'");
158+
}
159+
150160
result.AppendMessageWithFormatv(
151-
"{0:2}", DebuggerStats::ReportStatistics(
152-
GetDebugger(), target, m_options.GetStatisticsOptions()));
161+
"{0:2}",
162+
DebuggerStats::ReportStatistics(GetDebugger(), target, stats_options));
153163
result.SetStatus(eReturnStatusSuccessFinishResult);
154164
}
155165

lldb/source/Commands/Options.td

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,13 +1482,15 @@ let Command = "statistics dump" in {
14821482
"this is turned off unless specified. "
14831483
"In default mode, if both '--targets' and '--modules' are 'true', a list "
14841484
"of module identifiers will be added to the 'targets' section.">;
1485-
def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
1486-
Arg<"Boolean">,
1487-
Desc<"If the setting interpreter.save-transcript is enabled and this "
1488-
"option is 'true', include a JSON array with all commands the user and/or "
1489-
"scripts executed during a debug session. "
1490-
"Defaults to true, unless the '--summary' mode is enabled, in which case "
1491-
"this is turned off unless specified.">;
1485+
def statistics_dump_transcript
1486+
: Option<"transcript", "t">,
1487+
Group<1>,
1488+
Arg<"Boolean">,
1489+
Desc<"If the setting interpreter.save-transcript is enabled and this "
1490+
"option is 'true', include a JSON array with all commands the "
1491+
"user and/or "
1492+
"scripts executed during a debug session. "
1493+
"Defaults to false. ">;
14921494
def statistics_dump_plugins
14931495
: Option<"plugins", "p">,
14941496
Group<1>,

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,30 @@ def test_transcript_happy_path(self):
849849
# The second "statistics dump" in the transcript should have no output
850850
self.assertNotIn("output", transcript[2])
851851

852+
def test_transcript_warning_when_disabled(self):
853+
"""
854+
Test that "statistics dump --transcript=true" shows a warning when
855+
transcript saving is disabled.
856+
"""
857+
self.build()
858+
exe = self.getBuildArtifact("a.out")
859+
target = self.createTestTarget(file_path=exe)
860+
861+
# Ensure transcript saving is disabled (this is the default)
862+
self.runCmd("settings set interpreter.save-transcript false")
863+
864+
# Request transcript in statistics dump and check for warning
865+
interpreter = self.dbg.GetCommandInterpreter()
866+
res = lldb.SBCommandReturnObject()
867+
interpreter.HandleCommand("statistics dump --transcript=true", res)
868+
self.assertTrue(res.Succeeded())
869+
# We should warn about transcript being requested but not saved
870+
self.assertIn(
871+
"transcript requested but none was saved. Enable with "
872+
"'settings set interpreter.save-transcript true'",
873+
res.GetError(),
874+
)
875+
852876
def verify_stats(self, stats, expectation, options):
853877
for field_name in expectation:
854878
idx = field_name.find(".")
@@ -896,7 +920,7 @@ def get_test_cases_for_sections_existence(self):
896920
"targets.frameVariable": True,
897921
"targets.totalSharedLibraryEventHitCount": True,
898922
"modules": True,
899-
"transcript": True,
923+
"transcript": False,
900924
},
901925
},
902926
{ # Summary mode
@@ -983,6 +1007,24 @@ def get_test_cases_for_sections_existence(self):
9831007
"transcript": False,
9841008
},
9851009
},
1010+
{ # Default mode without modules and with transcript
1011+
"command_options": " --modules=false --transcript=true",
1012+
"api_options": {
1013+
"SetIncludeModules": False,
1014+
"SetIncludeTranscript": True,
1015+
},
1016+
"expect": {
1017+
"commands": True,
1018+
"targets": True,
1019+
"targets.moduleIdentifiers": False,
1020+
"targets.breakpoints": True,
1021+
"targets.expressionEvaluation": True,
1022+
"targets.frameVariable": True,
1023+
"targets.totalSharedLibraryEventHitCount": True,
1024+
"modules": False,
1025+
"transcript": True,
1026+
},
1027+
},
9861028
{ # Default mode without modules
9871029
"command_options": " --modules=false",
9881030
"api_options": {
@@ -997,6 +1039,23 @@ def get_test_cases_for_sections_existence(self):
9971039
"targets.frameVariable": True,
9981040
"targets.totalSharedLibraryEventHitCount": True,
9991041
"modules": False,
1042+
"transcript": False,
1043+
},
1044+
},
1045+
{ # Default mode with transcript
1046+
"command_options": " --transcript=true",
1047+
"api_options": {
1048+
"SetIncludeTranscript": True,
1049+
},
1050+
"expect": {
1051+
"commands": True,
1052+
"targets": True,
1053+
"targets.moduleIdentifiers": True,
1054+
"targets.breakpoints": True,
1055+
"targets.expressionEvaluation": True,
1056+
"targets.frameVariable": True,
1057+
"targets.totalSharedLibraryEventHitCount": True,
1058+
"modules": True,
10001059
"transcript": True,
10011060
},
10021061
},

0 commit comments

Comments
 (0)