[trace] [intel pt] Create a "thread trace dump stats" command

When the user types that command 'thread trace dump info' and there's a running Trace session in LLDB, a raw trace in bytes should be printed; the command 'thread trace dump info all' should print the info for all the threads.

Original Author: hanbingwang

Reviewed By: clayborg, wallace

Differential Revision: https://reviews.llvm.org/D105717
This commit is contained in:
Walter Erquinigo
2021-07-21 09:49:15 -07:00
parent d71062fbda
commit 345ace026b
10 changed files with 190 additions and 10 deletions

View File

@@ -2138,6 +2138,83 @@ protected:
std::map<lldb::tid_t, std::unique_ptr<TraceInstructionDumper>> m_dumpers;
};
// CommandObjectTraceDumpInfo
#define LLDB_OPTIONS_thread_trace_dump_info
#include "CommandOptions.inc"
class CommandObjectTraceDumpInfo : public CommandObjectIterateOverThreads {
public:
class CommandOptions : public Options {
public:
CommandOptions() : Options() { OptionParsingStarting(nullptr); }
~CommandOptions() override = default;
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
case 'v': {
m_verbose = true;
break;
}
default:
llvm_unreachable("Unimplemented option");
}
return error;
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_verbose = false;
}
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::makeArrayRef(g_thread_trace_dump_info_options);
}
// Instance variables to hold the values for command options.
bool m_verbose;
};
bool DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = m_exe_ctx.GetTargetRef();
result.GetOutputStream().Printf(
"Trace technology: %s\n",
target.GetTrace()->GetPluginName().AsCString());
return CommandObjectIterateOverThreads::DoExecute(command, result);
}
CommandObjectTraceDumpInfo(CommandInterpreter &interpreter)
: CommandObjectIterateOverThreads(
interpreter, "thread trace dump info",
"Dump the traced information for one or more threads. If no "
"threads are specified, show the current thread. Use the "
"thread-index \"all\" to see all threads.",
nullptr,
eCommandRequiresProcess | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
eCommandProcessMustBeTraced),
m_options() {}
~CommandObjectTraceDumpInfo() override = default;
Options *GetOptions() override { return &m_options; }
protected:
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
ThreadSP thread_sp =
m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
trace_sp->DumpTraceInfo(*thread_sp, result.GetOutputStream(),
m_options.m_verbose);
return true;
}
CommandOptions m_options;
};
// CommandObjectMultiwordTraceDump
class CommandObjectMultiwordTraceDump : public CommandObjectMultiword {
public:
@@ -2150,6 +2227,8 @@ public:
LoadSubCommand(
"instructions",
CommandObjectSP(new CommandObjectTraceDumpInstructions(interpreter)));
LoadSubCommand(
"info", CommandObjectSP(new CommandObjectTraceDumpInfo(interpreter)));
}
~CommandObjectMultiwordTraceDump() override = default;
};