LLDB mainline
|
#include "TraceIntelPTBundleSaver.h"
#include "PerfContextSwitchDecoder.h"
#include "TraceIntelPT.h"
#include "TraceIntelPTConstants.h"
#include "TraceIntelPTJSONStructs.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadList.h"
#include "lldb/lldb-types.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/JSON.h"
#include <fstream>
#include <iostream>
#include <optional>
#include <sstream>
#include <string>
Go to the source code of this file.
Functions | |
static std::string | GetRelativePath (const FileSpec &directory, const FileSpec &path) |
Strip the directory component from the given path . | |
static llvm::Error | WriteBytesToDisk (FileSpec &output_file, ArrayRef< uint8_t > data) |
Write a stream of bytes from data to the given output file. | |
static Expected< FileSpec > | SaveTraceBundleDescription (const llvm::json::Value &trace_bundle_description, const FileSpec &directory) |
Save the trace bundle description JSON object inside the given directory as a file named trace.json. | |
static llvm::Expected< std::vector< JSONThread > > | BuildThreadsSection (Process &process, FileSpec directory) |
Build the threads sub-section of the trace bundle description file. | |
static Expected< std::optional< FileSpec > > | WriteContextSwitchTrace (TraceIntelPT &trace_ipt, lldb::cpu_id_t cpu_id, const FileSpec &cpus_dir, bool compact) |
static Expected< FileSpec > | WriteIntelPTTrace (TraceIntelPT &trace_ipt, lldb::cpu_id_t cpu_id, const FileSpec &cpus_dir) |
static llvm::Expected< std::optional< std::vector< JSONCpu > > > | BuildCpusSection (TraceIntelPT &trace_ipt, FileSpec directory, bool compact) |
static llvm::Expected< std::vector< JSONModule > > | BuildModulesSection (Process &process, FileSpec directory) |
Build modules sub-section of the trace bundle. | |
static llvm::Expected< JSONProcess > | BuildProcessSection (Process &process, const FileSpec &directory) |
Build the processes section of the trace bundle description object. | |
static llvm::Expected< std::vector< JSONProcess > > | BuildProcessesSection (TraceIntelPT &trace_ipt, const FileSpec &directory) |
See BuildProcessSection() | |
static llvm::Expected< JSONKernel > | BuildKernelSection (TraceIntelPT &trace_ipt, const FileSpec &directory) |
|
static |
Definition at line 194 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), lldb_private::trace_intel_pt::JSONCpu::context_switch_trace, lldb_private::FileSpec::GetPath(), GetRelativePath(), lldb_private::Trace::GetTracedCpus(), lldb_private::trace_intel_pt::JSONCpu::id, lldb_private::trace_intel_pt::JSONCpu::ipt_trace, WriteContextSwitchTrace(), and WriteIntelPTTrace().
Referenced by lldb_private::trace_intel_pt::TraceIntelPTBundleSaver::SaveToDisk().
|
static |
Definition at line 337 of file TraceIntelPTBundleSaver.cpp.
References BuildModulesSection(), lldb_private::Trace::GetAllProcesses(), lldb_private::Process::GetID(), lldb_private::trace_intel_pt::kDefaultKernelProcessID, lldb_private::trace_intel_pt::JSONModule::load_address, and lldb_private::trace_intel_pt::JSONModule::system_path.
Referenced by lldb_private::trace_intel_pt::TraceIntelPTBundleSaver::SaveToDisk().
|
static |
Build modules sub-section of the trace bundle.
The original modules will be copied over to the <directory/modules> folder. Invalid modules are skipped. Copying the modules has the benefit of making these directories self-contained, as the raw traces and modules are part of the output directory and can be sent to another machine, where lldb can load them and replicate exactly the same trace session.
[in] | process | The process being traced. |
[in] | directory | The directory where the modules files will be saved when building the modules section. Example: If a module libbar.so exists in the path /usr/lib/foo/libbar.so, then it will be copied to <directory>/modules/usr/lib/foo/libbar.so. |
Definition at line 247 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), lldb_private::ConstString::AsCString(), lldb_private::ObjectFile::GetBaseAddress(), lldb_private::FileSpec::GetDirectory(), lldb_private::Target::GetImages(), lldb_private::Address::GetLoadAddress(), lldb_private::ModuleList::GetModuleAtIndex(), lldb_private::FileSpec::GetPath(), GetRelativePath(), lldb_private::Target::GetSectionLoadList(), lldb_private::ModuleList::GetSize(), lldb_private::Process::GetTarget(), lldb_private::SectionLoadList::IsEmpty(), lldb_private::Address::IsValid(), and LLDB_INVALID_ADDRESS.
Referenced by BuildKernelSection(), and BuildProcessSection().
|
static |
Definition at line 324 of file TraceIntelPTBundleSaver.cpp.
References BuildProcessSection(), and lldb_private::Trace::GetAllProcesses().
Referenced by lldb_private::trace_intel_pt::TraceIntelPTBundleSaver::SaveToDisk().
|
static |
Build the processes section of the trace bundle description object.
Besides returning the processes information, this method saves to disk all modules and raw traces corresponding to the traced threads of the given process.
[in] | process | The process being traced. |
[in] | directory | The directory where files will be saved when building the processes section. |
Definition at line 305 of file TraceIntelPTBundleSaver.cpp.
References BuildModulesSection(), BuildThreadsSection(), lldb_private::Target::GetArchitecture(), lldb_private::Process::GetID(), lldb_private::Process::GetTarget(), and lldb_private::ArchSpec::GetTriple().
Referenced by BuildProcessesSection().
|
static |
Build the threads sub-section of the trace bundle description file.
Any associated binary files are created inside the given directory.
[in] | process | The process being traced. |
[in] | directory | The directory where files will be saved when building the threads section. |
Definition at line 98 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), lldb_private::FileSpec::GetPath(), GetRelativePath(), lldb_private::Process::GetTarget(), lldb_private::Target::GetTrace(), lldb_private::trace_intel_pt::JSONThread::ipt_trace, lldb_private::IntelPTDataKinds::kIptTrace, lldb_private::Process::Threads(), lldb_private::trace_intel_pt::JSONThread::tid, and WriteBytesToDisk().
Referenced by BuildProcessSection().
Strip the directory
component from the given path
.
It assumes that directory
is a prefix of path
.
Definition at line 36 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::GetPath().
Referenced by BuildCpusSection(), BuildModulesSection(), and BuildThreadsSection().
|
static |
Save the trace bundle description JSON object inside the given directory as a file named trace.json.
[in] | trace_bundle_description | The trace bundle description as JSON Object. |
[in] | directory | The directory where the JSON file will be saved. |
Definition at line 71 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), and lldb_private::FileSpec::GetPath().
Referenced by lldb_private::trace_intel_pt::TraceIntelPTBundleSaver::SaveToDisk().
|
static |
Write a stream of bytes from data
to the given output file.
It creates or overwrites the output file, but not append.
Definition at line 43 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::GetPath().
Referenced by BuildThreadsSection(), WriteContextSwitchTrace(), and WriteIntelPTTrace().
|
static |
compact
flag is present, or the FileSpec of the trace file on disk. Definition at line 138 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), lldb_private::trace_intel_pt::FilterProcessesFromContextSwitchTrace(), lldb_private::Trace::GetAllProcesses(), lldb_private::IntelPTDataKinds::kPerfContextSwitchTrace, lldb_private::Trace::OnCpuBinaryDataRead(), and WriteBytesToDisk().
Referenced by BuildCpusSection().
|
static |
Definition at line 177 of file TraceIntelPTBundleSaver.cpp.
References lldb_private::FileSpec::AppendPathComponent(), lldb_private::IntelPTDataKinds::kIptTrace, lldb_private::Trace::OnCpuBinaryDataRead(), and WriteBytesToDisk().
Referenced by BuildCpusSection().