aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp95
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.h59
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.cpp44
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.h42
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTFOptions.td13
5 files changed, 253 insertions, 0 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp
new file mode 100644
index 000000000000..ee8970fb4de2
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp
@@ -0,0 +1,95 @@
+//===-- CommandObjectThreadTraceExportCTF.cpp -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CommandObjectThreadTraceExportCTF.h"
+
+#include "../common/TraceHTR.h"
+#include "lldb/Host/OptionParser.h"
+#include "lldb/Interpreter/CommandOptionArgumentTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Trace.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::ctf;
+using namespace llvm;
+
+// CommandObjectThreadTraceExportCTF
+
+#define LLDB_OPTIONS_thread_trace_export_ctf
+#include "TraceExporterCTFCommandOptions.inc"
+
+Status CommandObjectThreadTraceExportCTF::CommandOptions::SetOptionValue(
+ uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) {
+ Status error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'f': {
+ m_file.assign(std::string(option_arg));
+ break;
+ }
+ case 't': {
+ int64_t thread_index;
+ if (option_arg.empty() || option_arg.getAsInteger(0, thread_index) ||
+ thread_index < 0)
+ error.SetErrorStringWithFormat("invalid integer value for option '%s'",
+ option_arg.str().c_str());
+ else
+ m_thread_index = thread_index;
+ break;
+ }
+ default:
+ llvm_unreachable("Unimplemented option");
+ }
+ return error;
+}
+
+void CommandObjectThreadTraceExportCTF::CommandOptions::OptionParsingStarting(
+ ExecutionContext *execution_context) {
+ m_file.clear();
+ m_thread_index = std::nullopt;
+}
+
+llvm::ArrayRef<OptionDefinition>
+CommandObjectThreadTraceExportCTF::CommandOptions::GetDefinitions() {
+ return llvm::ArrayRef(g_thread_trace_export_ctf_options);
+}
+
+void CommandObjectThreadTraceExportCTF::DoExecute(Args &command,
+ CommandReturnObject &result) {
+ const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
+ Process *process = m_exe_ctx.GetProcessPtr();
+ Thread *thread = m_options.m_thread_index
+ ? process->GetThreadList()
+ .FindThreadByIndexID(*m_options.m_thread_index)
+ .get()
+ : GetDefaultThread();
+
+ if (thread == nullptr) {
+ const uint32_t num_threads = process->GetThreadList().GetSize();
+ size_t tid = m_options.m_thread_index.value_or(LLDB_INVALID_THREAD_ID);
+ result.AppendErrorWithFormatv(
+ "Thread index {0} is out of range (valid values are 1 - {1}).\n", tid,
+ num_threads);
+ } else {
+ auto do_work = [&]() -> Error {
+ Expected<TraceCursorSP> cursor = trace_sp->CreateNewCursor(*thread);
+ if (!cursor)
+ return cursor.takeError();
+ TraceHTR htr(*thread, **cursor);
+ htr.ExecutePasses();
+ return htr.Export(m_options.m_file);
+ };
+
+ if (llvm::Error err = do_work()) {
+ result.AppendErrorWithFormat("%s\n", toString(std::move(err)).c_str());
+ }
+ }
+}
diff --git a/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.h b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.h
new file mode 100644
index 000000000000..1a034e87cfb6
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.h
@@ -0,0 +1,59 @@
+//===-- CommandObjectThreadTraceExportCTF.h -------------------*- C++ //-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTHREADTRACEEXPORTCTF_H
+#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTHREADTRACEEXPORTCTF_H
+
+#include "TraceExporterCTF.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include <optional>
+
+namespace lldb_private {
+namespace ctf {
+
+class CommandObjectThreadTraceExportCTF : public CommandObjectParsed {
+public:
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() { OptionParsingStarting(nullptr); }
+
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override;
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override;
+
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
+
+ std::optional<size_t> m_thread_index;
+ std::string m_file;
+ };
+
+ CommandObjectThreadTraceExportCTF(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "thread trace export ctf",
+ "Export a given thread's trace to Chrome Trace Format",
+ "thread trace export ctf [<ctf-options>]",
+ lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
+ lldb::eCommandProcessMustBeLaunched |
+ lldb::eCommandProcessMustBePaused |
+ lldb::eCommandProcessMustBeTraced),
+ m_options() {}
+
+ Options *GetOptions() override { return &m_options; }
+
+protected:
+ void DoExecute(Args &command, CommandReturnObject &result) override;
+
+ CommandOptions m_options;
+};
+
+} // namespace ctf
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTHREADTRACEEXPORTCTF_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.cpp b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.cpp
new file mode 100644
index 000000000000..e98e2c83e649
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.cpp
@@ -0,0 +1,44 @@
+//===-- TraceExporterCTF.cpp ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "TraceExporterCTF.h"
+
+#include <memory>
+
+#include "CommandObjectThreadTraceExportCTF.h"
+#include "lldb/Core/PluginManager.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::ctf;
+using namespace llvm;
+
+LLDB_PLUGIN_DEFINE(TraceExporterCTF)
+
+//------------------------------------------------------------------
+// PluginInterface protocol
+//------------------------------------------------------------------
+
+static CommandObjectSP
+GetThreadTraceExportCommand(CommandInterpreter &interpreter) {
+ return std::make_shared<CommandObjectThreadTraceExportCTF>(interpreter);
+}
+
+void TraceExporterCTF::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ "Chrome Trace Format Exporter", CreateInstance,
+ GetThreadTraceExportCommand);
+}
+
+void TraceExporterCTF::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+Expected<TraceExporterUP> TraceExporterCTF::CreateInstance() {
+ return std::make_unique<TraceExporterCTF>();
+}
diff --git a/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.h b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.h
new file mode 100644
index 000000000000..74f14fc354d1
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTF.h
@@ -0,0 +1,42 @@
+//===-- TraceExporterCTF.h --------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_TRACE_EXPORTER_CTF_H
+#define LLDB_SOURCE_PLUGINS_TRACE_EXPORTER_CTF_H
+
+#include "lldb/Target/TraceExporter.h"
+
+namespace lldb_private {
+namespace ctf {
+
+/// Trace Exporter Plugin that can produce traces in Chrome Trace Format.
+/// Still in development.
+class TraceExporterCTF : public TraceExporter {
+public:
+ ~TraceExporterCTF() override = default;
+
+ /// PluginInterface protocol
+ /// \{
+ static llvm::Expected<lldb::TraceExporterUP> CreateInstance();
+
+ llvm::StringRef GetPluginName() override {
+ return GetPluginNameStatic();
+ }
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static llvm::StringRef GetPluginNameStatic() { return "ctf"; }
+ /// \}
+};
+
+} // namespace ctf
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_TRACE_EXPORTER_CTF_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTFOptions.td b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTFOptions.td
new file mode 100644
index 000000000000..1919e7184f9b
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/TraceExporter/ctf/TraceExporterCTFOptions.td
@@ -0,0 +1,13 @@
+include "../../../../source/Commands/OptionsBase.td"
+
+let Command = "thread trace export ctf" in {
+ def thread_trace_export_ctf: Option<"tid", "t">,
+ Group<1>,
+ Arg<"ThreadIndex">,
+ Desc<"Export the trace for the specified thread index. Otherwise, the "
+ "currently selected thread will be used.">;
+ def thread_trace_export_file: Option<"file", "f">, Required,
+ Group<1>,
+ Arg<"Filename">,
+ Desc<"Path of the file to export the trace data">;
+}