jj10306 created this revision. jj10306 added reviewers: wallace, davidca. Herald added a subscriber: mgorny. Herald added a project: All. jj10306 requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Minor refactor and renaming: - Rename `IntelPTManager` class and files to `IntelPTCollector` - Change `TraceCursor::GetTimestampCounter` API to general trace counter API, `GetCounter` First of a series of smaller diffs that split https://reviews.llvm.org/D120595 up. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121711 Files: lldb/include/lldb/Target/TraceCursor.h lldb/include/lldb/lldb-enumerations.h lldb/source/Plugins/Process/Linux/CMakeLists.txt lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp lldb/source/Plugins/Process/Linux/IntelPTCollector.h lldb/source/Plugins/Process/Linux/IntelPTManager.cpp lldb/source/Plugins/Process/Linux/IntelPTManager.h lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp lldb/source/Plugins/Process/Linux/NativeProcessLinux.h lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h lldb/source/Target/TraceInstructionDumper.cpp lldb/unittests/Process/Linux/CMakeLists.txt lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp lldb/unittests/Process/Linux/IntelPTManagerTests.cpp
Index: lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp =================================================================== --- lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp +++ lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp @@ -1,4 +1,4 @@ -//===-- IntelPTManagerTests.cpp -------------------------------------------===// +//===-- IntelPTCollectorTests.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ #include "gtest/gtest.h" -#include "IntelPTManager.h" +#include "IntelPTCollector.h" #include "llvm/ADT/ArrayRef.h" Index: lldb/unittests/Process/Linux/CMakeLists.txt =================================================================== --- lldb/unittests/Process/Linux/CMakeLists.txt +++ lldb/unittests/Process/Linux/CMakeLists.txt @@ -1,5 +1,5 @@ add_lldb_unittest(TraceIntelPTTests - IntelPTManagerTests.cpp + IntelPTCollectorTests.cpp LINK_LIBS lldbPluginProcessLinux Index: lldb/source/Target/TraceInstructionDumper.cpp =================================================================== --- lldb/source/Target/TraceInstructionDumper.cpp +++ lldb/source/Target/TraceInstructionDumper.cpp @@ -183,7 +183,7 @@ if (m_show_tsc) { s.Printf("[tsc="); - if (Optional<uint64_t> timestamp = m_cursor_up->GetTimestampCounter()) + if (Optional<uint64_t> timestamp = m_cursor_up->GetCounter(lldb::eTraceCounterTSC)) s.Printf("0x%016" PRIx64, *timestamp); else s.Printf("unavailable"); Index: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h =================================================================== --- lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h +++ lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h @@ -28,7 +28,7 @@ lldb::addr_t GetLoadAddress() override; - llvm::Optional<uint64_t> GetTimestampCounter() override; + llvm::Optional<uint64_t> GetCounter(lldb::TraceCounter counter_type) override; lldb::TraceInstructionControlFlowType GetInstructionControlFlowType() override; Index: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp =================================================================== --- lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp +++ lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp @@ -85,8 +85,11 @@ return m_decoded_thread_sp->GetInstructions()[m_pos].GetLoadAddress(); } -Optional<uint64_t> TraceCursorIntelPT::GetTimestampCounter() { - return m_decoded_thread_sp->GetInstructions()[m_pos].GetTimestampCounter(); +Optional<uint64_t> TraceCursorIntelPT::GetCounter(lldb::TraceCounter counter_type) { + switch (counter_type) { + case lldb::eTraceCounterTSC: + return m_decoded_thread_sp->GetInstructions()[m_pos].GetTimestampCounter(); + } } TraceInstructionControlFlowType Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.h =================================================================== --- lldb/source/Plugins/Process/Linux/NativeProcessLinux.h +++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.h @@ -20,7 +20,7 @@ #include "lldb/Utility/FileSpec.h" #include "lldb/lldb-types.h" -#include "IntelPTManager.h" +#include "IntelPTCollector.h" #include "NativeThreadLinux.h" #include "Plugins/Process/POSIX/NativeProcessELF.h" #include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h" @@ -241,7 +241,7 @@ Status PopulateMemoryRegionCache(); /// Manages Intel PT process and thread traces. - IntelPTManager m_intel_pt_manager; + IntelPTCollector m_intel_pt_collector; // Handle a clone()-like event. bool MonitorClone(NativeThreadLinux &parent, lldb::pid_t child_pid, Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -312,7 +312,7 @@ const ArchSpec &arch, MainLoop &mainloop, llvm::ArrayRef<::pid_t> tids) : NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch), - m_main_loop(mainloop), m_intel_pt_manager(pid) { + m_main_loop(mainloop), m_intel_pt_collector(pid) { if (m_terminal_fd != -1) { Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK); assert(status.Success()); @@ -983,7 +983,7 @@ e; // Save the error, but still attempt to detach from other threads. } - m_intel_pt_manager.Clear(); + m_intel_pt_collector.Clear(); return error; } @@ -1666,7 +1666,7 @@ Status NativeProcessLinux::NotifyTracersOfNewThread(lldb::tid_t tid) { Log *log = GetLog(POSIXLog::Thread); - Status error(m_intel_pt_manager.OnThreadCreated(tid)); + Status error(m_intel_pt_collector.OnThreadCreated(tid)); if (error.Fail()) LLDB_LOG(log, "Failed to trace a new thread with intel-pt, tid = {0}. {1}", tid, error.AsCString()); @@ -1675,7 +1675,7 @@ Status NativeProcessLinux::NotifyTracersOfThreadDestroyed(lldb::tid_t tid) { Log *log = GetLog(POSIXLog::Thread); - Status error(m_intel_pt_manager.OnThreadDestroyed(tid)); + Status error(m_intel_pt_collector.OnThreadDestroyed(tid)); if (error.Fail()) LLDB_LOG(log, "Failed to stop a destroyed thread with intel-pt, tid = {0}. {1}", @@ -1938,7 +1938,7 @@ } llvm::Expected<TraceSupportedResponse> NativeProcessLinux::TraceSupported() { - if (IntelPTManager::IsSupported()) + if (IntelPTCollector::IsSupported()) return TraceSupportedResponse{"intel-pt", "Intel Processor Trace"}; return NativeProcessProtocol::TraceSupported(); } @@ -1951,7 +1951,7 @@ std::vector<lldb::tid_t> process_threads; for (auto &thread : m_threads) process_threads.push_back(thread->GetID()); - return m_intel_pt_manager.TraceStart(*request, process_threads); + return m_intel_pt_collector.TraceStart(*request, process_threads); } else return request.takeError(); } @@ -1961,19 +1961,19 @@ Error NativeProcessLinux::TraceStop(const TraceStopRequest &request) { if (request.type == "intel-pt") - return m_intel_pt_manager.TraceStop(request); + return m_intel_pt_collector.TraceStop(request); return NativeProcessProtocol::TraceStop(request); } Expected<json::Value> NativeProcessLinux::TraceGetState(StringRef type) { if (type == "intel-pt") - return m_intel_pt_manager.GetState(); + return m_intel_pt_collector.GetState(); return NativeProcessProtocol::TraceGetState(type); } Expected<std::vector<uint8_t>> NativeProcessLinux::TraceGetBinaryData( const TraceGetBinaryDataRequest &request) { if (request.type == "intel-pt") - return m_intel_pt_manager.GetBinaryData(request); + return m_intel_pt_collector.GetBinaryData(request); return NativeProcessProtocol::TraceGetBinaryData(request); } Index: lldb/source/Plugins/Process/Linux/IntelPTCollector.h =================================================================== --- lldb/source/Plugins/Process/Linux/IntelPTCollector.h +++ lldb/source/Plugins/Process/Linux/IntelPTCollector.h @@ -1,4 +1,4 @@ -//===-- IntelPTManager.h -------------------------------------- -*- C++ -*-===// +//===-- IntelPTCollector.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. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_IntelPTManager_H_ -#define liblldb_IntelPTManager_H_ +#ifndef liblldb_IntelPTCollector_H_ +#define liblldb_IntelPTCollector_H_ #include "lldb/Utility/Status.h" #include "lldb/Utility/TraceIntelPTGDBRemotePackets.h" @@ -203,9 +203,9 @@ }; /// Main class that manages intel-pt process and thread tracing. -class IntelPTManager { +class IntelPTCollector { public: - IntelPTManager(lldb::pid_t pid) : m_pid(pid), m_thread_traces(pid) {} + IntelPTCollector(lldb::pid_t pid) : m_pid(pid), m_thread_traces(pid) {} static bool IsSupported(); @@ -260,4 +260,4 @@ } // namespace process_linux } // namespace lldb_private -#endif // liblldb_IntelPTManager_H_ +#endif // liblldb_IntelPTCollector_H_ Index: lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp +++ lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp @@ -1,4 +1,4 @@ -//===-- IntelPTManager.cpp ------------------------------------------------===// +//===-- IntelPTCollector.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,7 +14,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/MathExtras.h" -#include "IntelPTManager.h" +#include "IntelPTCollector.h" #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" #include "lldb/Host/linux/Support.h" #include "lldb/Utility/StreamString.h" @@ -564,15 +564,15 @@ return m_thread_traces; } -/// IntelPTManager +/// IntelPTCollector -Error IntelPTManager::TraceStop(lldb::tid_t tid) { +Error IntelPTCollector::TraceStop(lldb::tid_t tid) { if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid)) return m_process_trace->TraceStop(tid); return m_thread_traces.TraceStop(tid); } -Error IntelPTManager::TraceStop(const TraceStopRequest &request) { +Error IntelPTCollector::TraceStop(const TraceStopRequest &request) { if (request.IsProcessTracing()) { Clear(); return Error::success(); @@ -585,7 +585,7 @@ } } -Error IntelPTManager::TraceStart( +Error IntelPTCollector::TraceStart( const TraceIntelPTStartRequest &request, const std::vector<lldb::tid_t> &process_threads) { if (request.IsProcessTracing()) { @@ -609,13 +609,13 @@ } } -Error IntelPTManager::OnThreadCreated(lldb::tid_t tid) { +Error IntelPTCollector::OnThreadCreated(lldb::tid_t tid) { if (!IsProcessTracingEnabled()) return Error::success(); return m_process_trace->TraceStart(tid); } -Error IntelPTManager::OnThreadDestroyed(lldb::tid_t tid) { +Error IntelPTCollector::OnThreadDestroyed(lldb::tid_t tid) { if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid)) return m_process_trace->TraceStop(tid); else if (m_thread_traces.TracesThread(tid)) @@ -623,7 +623,7 @@ return Error::success(); } -Expected<json::Value> IntelPTManager::GetState() const { +Expected<json::Value> IntelPTCollector::GetState() const { Expected<ArrayRef<uint8_t>> cpu_info = IntelPTThreadTrace::GetCPUInfo(); if (!cpu_info) return cpu_info.takeError(); @@ -646,14 +646,14 @@ } Expected<const IntelPTThreadTrace &> -IntelPTManager::GetTracedThread(lldb::tid_t tid) const { +IntelPTCollector::GetTracedThread(lldb::tid_t tid) const { if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid)) return m_process_trace->GetThreadTraces().GetTracedThread(tid); return m_thread_traces.GetTracedThread(tid); } Expected<std::vector<uint8_t>> -IntelPTManager::GetBinaryData(const TraceGetBinaryDataRequest &request) const { +IntelPTCollector::GetBinaryData(const TraceGetBinaryDataRequest &request) const { if (request.kind == "threadTraceBuffer") { if (Expected<const IntelPTThreadTrace &> trace = GetTracedThread(*request.tid)) @@ -668,9 +668,9 @@ request.kind.c_str()); } -void IntelPTManager::ClearProcessTracing() { m_process_trace = None; } +void IntelPTCollector::ClearProcessTracing() { m_process_trace = None; } -bool IntelPTManager::IsSupported() { +bool IntelPTCollector::IsSupported() { Expected<uint32_t> intel_pt_type = GetOSEventType(); if (!intel_pt_type) { llvm::consumeError(intel_pt_type.takeError()); @@ -679,11 +679,11 @@ return true; } -bool IntelPTManager::IsProcessTracingEnabled() const { +bool IntelPTCollector::IsProcessTracingEnabled() const { return (bool)m_process_trace; } -void IntelPTManager::Clear() { +void IntelPTCollector::Clear() { ClearProcessTracing(); m_thread_traces.Clear(); } Index: lldb/source/Plugins/Process/Linux/CMakeLists.txt =================================================================== --- lldb/source/Plugins/Process/Linux/CMakeLists.txt +++ lldb/source/Plugins/Process/Linux/CMakeLists.txt @@ -1,5 +1,5 @@ add_lldb_library(lldbPluginProcessLinux - IntelPTManager.cpp + IntelPTCollector.cpp NativeProcessLinux.cpp NativeRegisterContextLinux.cpp NativeRegisterContextLinux_arm.cpp Index: lldb/include/lldb/lldb-enumerations.h =================================================================== --- lldb/include/lldb/lldb-enumerations.h +++ lldb/include/lldb/lldb-enumerations.h @@ -1141,6 +1141,12 @@ eSaveCoreStackOnly = 3, }; +// Type of counter values in a trace. +enum TraceCounter { + // Timestamp counter, like the one offered by Intel CPUs (TSC). + eTraceCounterTSC, +}; + } // namespace lldb #endif // LLDB_LLDB_ENUMERATIONS_H Index: lldb/include/lldb/Target/TraceCursor.h =================================================================== --- lldb/include/lldb/Target/TraceCursor.h +++ lldb/include/lldb/Target/TraceCursor.h @@ -180,14 +180,15 @@ /// LLDB_INVALID_ADDRESS. virtual lldb::addr_t GetLoadAddress() = 0; - /// Get the timestamp counter associated with the current instruction. - /// Modern Intel, ARM and AMD processors support this counter. However, a - /// trace plugin might decide to use a different time unit instead of an - /// actual TSC. + /// Get the hardware counter of a given type associated with the current instruction. + /// Each architecture might support different counters. It might happen that only some + /// instructions of an entire trace have a given counter associated with them. /// + /// \param[in] counter_type + /// The counter type /// \return - /// The timestamp or \b llvm::None if not available. - virtual llvm::Optional<uint64_t> GetTimestampCounter() = 0; + /// The value of the counter or \b llvm::None if not available. + virtual llvm::Optional<uint64_t> GetCounter(lldb::TraceCounter counter_type) = 0; /// \return /// The \a lldb::TraceInstructionControlFlowType categories the
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits