Skip to content

Commit ff1ce49

Browse files
committed
more data
1 parent 5a992af commit ff1ce49

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

lldb/include/lldb/Core/Telemetry.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,6 @@ template <typename Info> struct ScopedDispatcher {
151151
debugger = debugger;
152152
}
153153

154-
155-
template typename<T>
156-
T GetIfEnable(llvm::unique_function<T(TelemetryManager*)> callable,
157-
T default_value) {
158-
TelemetryManager *manager = TelemetryManager::GetInstanceIfEnabled();
159-
if (!manager)
160-
return default_value;
161-
return callable(manager);
162-
}
163-
164154
void SetDebugger(Debugger *debugger) { debugger = debugger; }
165155

166156
void SetFinalCallback(llvm::unique_function<void(Info *info)> final_callback) {

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,16 +1886,18 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
18861886
CommandReturnObject &result,
18871887
bool force_repeat_command) {
18881888
lldb_private::telemetry::ScopedDispatcher<
1889-
lldb_private::telemetry:CommandInfo> helper;
1890-
const int command_id = helper.GetIfEnable<int>([](lldb_private::telemetry::TelemetryManager* ins){
1891-
return ins->MakeNextCommandId(); }, 0);
1889+
lldb_private::telemetry:CommandInfo> helper(m_debugger);
1890+
lldb_private::telemetry::TelemetryManager *ins = lldb_private::telemetry::TelemetryManager::GetInstanceOrDummy();
1891+
const int command_id = ins->MakeNextCommandId();
1892+
18921893

18931894
std::string command_string(command_line);
18941895
std::string original_command_string(command_string);
18951896
std::string real_original_command_string(command_string);
1897+
std::string parsed_command_args;
1898+
CommandObject *cmd_obj = nullptr;
18961899

1897-
helper.DispatchIfEnable([&](lldb_private::telemetry:CommandInfo* info,
1898-
lldb_private::telemetry::TelemetryManager* ins){
1900+
helper.DispatchIfEnable([&](lldb_private::telemetry:CommandInfo* info){
18991901
info.command_id = command_id;
19001902
if (Target* target = GetExecutionContext().GetTargetPtr()) {
19011903
// If we have a target attached to this command, then get the UUID.
@@ -1905,6 +1907,26 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
19051907
}
19061908
if (ins->GetConfig()->m_collect_original_command)
19071909
info.original_command = original_command_string;
1910+
// The rest (eg., command_name, args, etc) hasn't been parsed yet;
1911+
// Those will be collected by the on-exit-callback.
1912+
});
1913+
1914+
helper.DispatchOnExit([&](lldb_private::telemetry:CommandInfo* info) {
1915+
// TODO: this is logging the time the command-handler finishes.
1916+
// But we may want a finer-grain durations too?
1917+
// (ie., the execute_time recorded below?)
1918+
1919+
info.command_id = command_id;
1920+
llvm::StringRef command_name =
1921+
cmd_obj ? cmd_obj->GetCommandName() : "<not found>";
1922+
info.command_name = command_name.str();
1923+
info.ret_status = result.GetStatus();
1924+
if (llvm::StringRef error_data = result.GetErrorData();
1925+
!error_data.empty())
1926+
info.error_data = error_data.str();
1927+
1928+
if (ins->GetConfig()->m_collect_original_command)
1929+
info.args = parsed_command_args;
19081930
});
19091931

19101932
Log *log = GetLog(LLDBLog::Commands);
@@ -2011,7 +2033,7 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
20112033
// From 1 above, we can determine whether the Execute function wants raw
20122034
// input or not.
20132035

2014-
CommandObject *cmd_obj = ResolveCommandImpl(command_string, result);
2036+
cmd_obj = ResolveCommandImpl(command_string, result);
20152037

20162038
// We have to preprocess the whole command string for Raw commands, since we
20172039
// don't know the structure of the command. For parsed commands, we only
@@ -2073,37 +2095,36 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
20732095
if (add_to_history)
20742096
m_command_history.AppendString(original_command_string);
20752097

2076-
std::string remainder;
20772098
const std::size_t actual_cmd_name_len = cmd_obj->GetCommandName().size();
20782099
if (actual_cmd_name_len < command_string.length())
2079-
remainder = command_string.substr(actual_cmd_name_len);
2100+
parsed_command_args = command_string.substr(actual_cmd_name_len);
20802101

20812102
// Remove any initial spaces
2082-
size_t pos = remainder.find_first_not_of(k_white_space);
2103+
size_t pos = parsed_command_args.find_first_not_of(k_white_space);
20832104
if (pos != 0 && pos != std::string::npos)
2084-
remainder.erase(0, pos);
2105+
parsed_command_args.erase(0, pos);
20852106

20862107
LLDB_LOGF(
20872108
log, "HandleCommand, command line after removing command name(s): '%s'",
2088-
remainder.c_str());
2109+
parsed_command_args.c_str());
20892110

20902111
// To test whether or not transcript should be saved, `transcript_item` is
20912112
// used instead of `GetSaveTranscript()`. This is because the latter will
20922113
// fail when the command is "settings set interpreter.save-transcript true".
20932114
if (transcript_item) {
20942115
transcript_item->AddStringItem("commandName", cmd_obj->GetCommandName());
2095-
transcript_item->AddStringItem("commandArguments", remainder);
2116+
transcript_item->AddStringItem("commandArguments", parsed_command_args);
20962117
}
20972118

20982119
ElapsedTime elapsed(execute_time);
20992120
cmd_obj->SetOriginalCommandString(real_original_command_string);
21002121
// Set the indent to the position of the command in the command line.
2101-
pos = real_original_command_string.rfind(remainder);
2122+
pos = real_original_command_string.rfind(parsed_command_args);
21022123
std::optional<uint16_t> indent;
21032124
if (pos != std::string::npos)
21042125
indent = pos;
21052126
result.SetDiagnosticIndent(indent);
2106-
cmd_obj->Execute(remainder.c_str(), result);
2127+
cmd_obj->Execute(parsed_command_args.c_str(), result);
21072128
}
21082129

21092130
LLDB_LOGF(log, "HandleCommand, command %s",

0 commit comments

Comments
 (0)