wallace created this revision. wallace added a reviewer: jj10306. Herald added a project: All. wallace requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
In order to open perf events per core, we need to first get the list of core ids available in the system. So I'm adding a function that does that by parsing /proc/cpuinfo. That seems to be the simplest and most portable way to do that. Besides that, I made a few refactors and renames to reflect better that the cpu info that we use in lldb-server comes from procfs. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D124573 Files: lldb/docs/lldb-gdb-remote.txt lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp lldb/source/Plugins/Process/Linux/Perf.cpp lldb/source/Plugins/Process/Linux/Perf.h lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.cpp lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp
Index: lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp =================================================================== --- lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp +++ lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp @@ -13,6 +13,9 @@ namespace lldb_private { +const char *IntelPTDataKinds::kProcFsCpuInfo = "procFsCpuInfo"; +const char *IntelPTDataKinds::kThreadTraceBuffer = "threadTraceBuffer"; + bool fromJSON(const json::Value &value, TraceIntelPTStartRequest &packet, Path path) { ObjectMapper o(value, path); Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.cpp =================================================================== --- lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.cpp +++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.cpp @@ -48,8 +48,8 @@ return json_intel_pt_trace.takeError(); llvm::Expected<JSONTraceSessionBase> json_session_description = - TraceSessionSaver::BuildProcessesSection(*live_process, - "threadTraceBuffer", directory); + TraceSessionSaver::BuildProcessesSection( + *live_process, IntelPTDataKinds::kThreadTraceBuffer, directory); if (!json_session_description) return json_session_description.takeError(); Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp =================================================================== --- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp +++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp @@ -81,7 +81,8 @@ for (const ThreadPostMortemTraceSP &thread : traced_threads) { m_thread_decoders.emplace(thread->GetID(), std::make_unique<ThreadDecoder>(thread, *this)); - SetPostMortemThreadDataFile(thread->GetID(), "threadTraceBuffer", + SetPostMortemThreadDataFile(thread->GetID(), + IntelPTDataKinds::kThreadTraceBuffer, thread->GetTraceFile()); } } @@ -179,7 +180,8 @@ } Expected<pt_cpu> TraceIntelPT::GetCPUInfoForLiveProcess() { - Expected<std::vector<uint8_t>> cpu_info = GetLiveProcessBinaryData("cpuInfo"); + Expected<std::vector<uint8_t>> cpu_info = + GetLiveProcessBinaryData(IntelPTDataKinds::kProcFsCpuInfo); if (!cpu_info) return cpu_info.takeError(); @@ -393,7 +395,8 @@ Error TraceIntelPT::OnThreadBufferRead(lldb::tid_t tid, OnBinaryDataReadCallback callback) { - return OnThreadBinaryDataRead(tid, "threadTraceBuffer", callback); + return OnThreadBinaryDataRead(tid, IntelPTDataKinds::kThreadTraceBuffer, + callback); } TaskTimer &TraceIntelPT::GetTimer() { return m_task_timer; } Index: lldb/source/Plugins/Process/Linux/Perf.h =================================================================== --- lldb/source/Plugins/Process/Linux/Perf.h +++ lldb/source/Plugins/Process/Linux/Perf.h @@ -76,7 +76,7 @@ /// \return /// The content of /proc/cpuinfo and cache it if errors didn't happen. -llvm::Expected<llvm::ArrayRef<uint8_t>> GetCPUInfo(); +llvm::Expected<llvm::ArrayRef<uint8_t>> GetProcFsCpuInfo(); /// \return /// A list of available logical core ids given the contents of Index: lldb/source/Plugins/Process/Linux/Perf.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/Perf.cpp +++ lldb/source/Plugins/Process/Linux/Perf.cpp @@ -22,7 +22,7 @@ using namespace process_linux; using namespace llvm; -Expected<ArrayRef<uint8_t>> lldb_private::process_linux::GetCPUInfo() { +Expected<ArrayRef<uint8_t>> lldb_private::process_linux::GetProcFsCpuInfo() { static Optional<std::vector<uint8_t>> cpu_info; if (!cpu_info) { auto buffer_or_error = errorOrToExpected(getProcFile("cpuinfo")); @@ -63,7 +63,7 @@ static Optional<std::vector<int>> logical_cores_ids; if (!logical_cores_ids) { // We find the actual list of core ids by parsing /proc/cpuinfo - Expected<ArrayRef<uint8_t>> cpuinfo = GetCPUInfo(); + Expected<ArrayRef<uint8_t>> cpuinfo = GetProcFsCpuInfo(); if (!cpuinfo) return cpuinfo.takeError(); Index: lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp +++ lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp @@ -415,7 +415,7 @@ TraceThreadState IntelPTThreadTrace::GetState() const { return {static_cast<int64_t>(m_tid), - {TraceBinaryData{"threadTraceBuffer", + {TraceBinaryData{IntelPTDataKinds::kThreadTraceBuffer, static_cast<int64_t>(GetTraceBufferSize())}}}; } @@ -577,13 +577,13 @@ } Expected<json::Value> IntelPTCollector::GetState() const { - Expected<ArrayRef<uint8_t>> cpu_info = GetCPUInfo(); + Expected<ArrayRef<uint8_t>> cpu_info = GetProcFsCpuInfo(); if (!cpu_info) return cpu_info.takeError(); TraceGetStateResponse state; - state.processBinaryData.push_back( - {"cpuInfo", static_cast<int64_t>(cpu_info->size())}); + state.processBinaryData.push_back({IntelPTDataKinds::kProcFsCpuInfo, + static_cast<int64_t>(cpu_info->size())}); std::vector<TraceThreadState> thread_states = m_thread_traces.GetThreadStates(); @@ -607,14 +607,14 @@ Expected<std::vector<uint8_t>> IntelPTCollector::GetBinaryData(const TraceGetBinaryDataRequest &request) const { - if (request.kind == "threadTraceBuffer") { + if (request.kind == IntelPTDataKinds::kThreadTraceBuffer) { if (Expected<const IntelPTThreadTrace &> trace = GetTracedThread(*request.tid)) return trace->GetIntelPTBuffer(request.offset, request.size); else return trace.takeError(); - } else if (request.kind == "cpuInfo") { - return GetCPUInfo(); + } else if (request.kind == IntelPTDataKinds::kProcFsCpuInfo) { + return GetProcFsCpuInfo(); } return createStringError(inconvertibleErrorCode(), "Unsuported trace binary data kind: %s", Index: lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h =================================================================== --- lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h +++ lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h @@ -18,6 +18,12 @@ /// See docs/lldb-gdb-remote.txt for more information. namespace lldb_private { +// List of data kinds used by jLLDBGetState and jLLDBGetBinaryData. +struct IntelPTDataKinds { + static const char *kProcFsCpuInfo; + static const char *kThreadTraceBuffer; +}; + /// jLLDBTraceStart gdb-remote packet /// \{ struct TraceIntelPTStartRequest : TraceStartRequest { Index: lldb/docs/lldb-gdb-remote.txt =================================================================== --- lldb/docs/lldb-gdb-remote.txt +++ lldb/docs/lldb-gdb-remote.txt @@ -467,7 +467,7 @@ // // Binary data kinds: // - threadTraceBuffer: trace buffer for a thread. -// - cpuInfo: contents of the /proc/cpuinfo file. +// - procFsCpuInfo: contents of the /proc/cpuinfo file. // // Counter info kinds: // tsc-perf-zero-conversion: @@ -522,7 +522,7 @@ // // Binary data kinds: // - threadTraceBuffer: trace buffer for a thread. -// - cpuInfo: contents of the /proc/cpuinfo file. +// - procFsCpuInfo: contents of the /proc/cpuinfo file. //---------------------------------------------------------------------- send packet: jLLDBTraceGetBinaryData:{"type":<type>,"kind":<query>,"tid":<tid>,"offset":<offset>,"size":<size>}]
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits