Skip to content

Commit 1f49714

Browse files
author
Walter Erquinigo
committed
[trace][intelpt] Support system-wide tracing [4] - Support per core tracing on lldb-server
This diffs implements per-core tracing on lldb-server. It also includes tests that ensure that tracing can be initiated from the client and that the jLLDBGetState ppacket returns the list of trace buffers per core. This doesn't include any decoder changes. Finally, this makes some little changes here and there improving the existing code. A specific piece of code that can't reliably be tested is when tracing per core fails due to permissions. In this case we add a troubleshooting message and this is the manual test: ``` /proc/sys/kernel/perf_event_paranoid set to 1 (lldb) process trace start --per-core-tracing error: perf event syscall failed: Permission denied You might need that /proc/sys/kernel/perf_event_paranoid has a value of 0 or -1. `` Differential Revision: https://reviews.llvm.org/D124858
1 parent 8d53f2f commit 1f49714

24 files changed

+471
-122
lines changed

lldb/docs/lldb-gdb-remote.txt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ read packet: OK
245245
// OUTPUT SCHEMA
246246
// {
247247
// "name": <string>,
248-
// Tracing technology name, e.g. intel-pt, arm-coresight.
248+
// Tracing technology name, e.g. intel-pt, arm-etm.
249249
// "description": <string>,
250250
// Description for this technology.
251251
// }
@@ -280,7 +280,7 @@ read packet: {"name":<name>, "description":<description>}/E<error code>;AAAAAAAA
280280
// INPUT SCHEMA
281281
// {
282282
// "type": <string>,
283-
// Tracing technology name, e.g. intel-pt, arm-coresight.
283+
// Tracing technology name, e.g. intel-pt, arm-etm.
284284
//
285285
// /* thread tracing only */
286286
// "tids"?: [<decimal integer>],
@@ -369,8 +369,9 @@ read packet: {"name":<name>, "description":<description>}/E<error code>;AAAAAAAA
369369
// /* process tracing only */
370370
// "processBufferSizeLimit": <decimal integer>,
371371
// Maximum total buffer size per process in bytes.
372-
// This limit applies to the sum of the sizes of all trace buffers for
373-
// the current process, excluding the ones started with "thread tracing".
372+
// This limit applies to the sum of the sizes of all thread or core
373+
// buffers for the current process, excluding the ones started with
374+
// "thread tracing".
374375
//
375376
// If "perCoreTracing" is false, whenever a thread is attempted to be
376377
// traced due to "process tracing" and the limit would be reached, the
@@ -421,7 +422,7 @@ read packet: OK/E<error code>;AAAAAAAAA
421422
//
422423
// {
423424
// "type": <string>
424-
// Tracing technology name, e.g. intel-pt, arm-coresight.
425+
// Tracing technology name, e.g. intel-pt, arm-etm.
425426
//
426427
// /* thread trace stopping only */
427428
// "tids": [<decimal integer>]
@@ -455,7 +456,7 @@ read packet: OK/E<error code>;AAAAAAAAA
455456
// INPUT SCHEMA
456457
// {
457458
// "type": <string>
458-
// Tracing technology name, e.g. intel-pt, arm-coresight.
459+
// Tracing technology name, e.g. intel-pt, arm-etm.
459460
// }
460461
//
461462
// OUTPUT SCHEMA
@@ -481,10 +482,23 @@ read packet: OK/E<error code>;AAAAAAAAA
481482
// Size in bytes of this thread data.
482483
// },
483484
// ],
485+
// "cores"?: [
486+
// "id": <decimal integer>,
487+
// Identifier for this CPU logical core.
488+
// "binaryData": [
489+
// {
490+
// "kind": <string>,
491+
// Identifier for some binary data related to this thread to
492+
// fetch with the jLLDBTraceGetBinaryData packet.
493+
// "size": <decimal integer>,
494+
// Size in bytes of this cpu core data.
495+
// },
496+
// ]
497+
// ],
484498
// "counters"?: {
485499
// "info_kind": {...parameters specific to the provided counter info kind},
486-
// Each entry includes information related to counters associated with the trace.
487-
// They are described below.
500+
// Each entry includes information related to counters associated with
501+
// the trace. They are described below.
488502
// }
489503
// }
490504
//
@@ -494,6 +508,12 @@ read packet: OK/E<error code>;AAAAAAAAA
494508
//
495509
// INTEL PT
496510
//
511+
// If per-core process tracing is enabled, "tracedThreads" will contain all
512+
// the threads of the process without any trace buffers. Besides that, the
513+
// "cores" field will also be returned with per core trace buffers.
514+
// A side effect of per-core tracing is that all the threads of unrelated
515+
// processes will also be traced, thus polluting the tracing data.
516+
//
497517
// Binary data kinds:
498518
// - traceBuffer: trace buffer for a thread or a core.
499519
// - procfsCpuInfo: contents of the /proc/cpuinfo file.
@@ -536,9 +556,11 @@ read packet: {...object}/E<error code>;AAAAAAAAA
536556
//
537557
// {
538558
// "type": <string>,
539-
// Tracing technology name, e.g. intel-pt, arm-coresight.
559+
// Tracing technology name, e.g. intel-pt, arm-etm.
540560
// "kind": <string>,
541561
// Identifier for the data.
562+
// "coreId": <Optional decimal>,
563+
// Core id in decimal if the data belongs to a CPU core.
542564
// "tid"?: <Optional decimal>,
543565
// Tid in decimal if the data belongs to a thread.
544566
// "offset": <decimal>,

lldb/include/lldb/Utility/TraceGDBRemotePackets.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,25 @@ llvm::json::Value toJSON(const TraceBinaryData &packet);
109109
struct TraceThreadState {
110110
lldb::tid_t tid;
111111
/// List of binary data objects for this thread.
112-
std::vector<TraceBinaryData> binaryData;
112+
std::vector<TraceBinaryData> binary_data;
113113
};
114114

115115
bool fromJSON(const llvm::json::Value &value, TraceThreadState &packet,
116116
llvm::json::Path path);
117117

118118
llvm::json::Value toJSON(const TraceThreadState &packet);
119119

120+
struct TraceCoreState {
121+
lldb::core_id_t core_id;
122+
/// List of binary data objects for this core.
123+
std::vector<TraceBinaryData> binary_data;
124+
};
125+
126+
bool fromJSON(const llvm::json::Value &value, TraceCoreState &packet,
127+
llvm::json::Path path);
128+
129+
llvm::json::Value toJSON(const TraceCoreState &packet);
130+
120131
/// Interface for different algorithms used to convert trace
121132
/// counters into different units.
122133
template <typename ToType> class TraceCounterConversion {
@@ -143,8 +154,9 @@ using TraceTscConversionUP =
143154
std::unique_ptr<TraceCounterConversion<std::chrono::nanoseconds>>;
144155

145156
struct TraceGetStateResponse {
146-
std::vector<TraceThreadState> tracedThreads;
147-
std::vector<TraceBinaryData> processBinaryData;
157+
std::vector<TraceThreadState> traced_threads;
158+
std::vector<TraceBinaryData> process_binary_data;
159+
llvm::Optional<std::vector<TraceCoreState>> cores;
148160
};
149161

150162
bool fromJSON(const llvm::json::Value &value, TraceGetStateResponse &packet,

lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct TraceIntelPTStartRequest : TraceStartRequest {
4848

4949
/// Whether to have a trace buffer per thread or per cpu core.
5050
llvm::Optional<bool> per_core_tracing;
51+
52+
bool IsPerCoreTracing() const;
5153
};
5254

5355
bool fromJSON(const llvm::json::Value &value, TraceIntelPTStartRequest &packet,

lldb/include/lldb/lldb-types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef int32_t break_id_t;
8989
typedef int32_t watch_id_t;
9090
typedef void *opaque_compiler_type_t;
9191
typedef uint64_t queue_id_t;
92+
typedef uint32_t core_id_t; // CPU core id
9293
} // namespace lldb
9394

9495
#endif // LLDB_LLDB_TYPES_H

lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ def setUp(self):
3333
if 'intel-pt' not in configuration.enabled_plugins:
3434
self.skipTest("The intel-pt test plugin is not enabled")
3535

36+
def skipIfPerCoreTracingIsNotSupported(self):
37+
def is_supported():
38+
try:
39+
with open("/proc/sys/kernel/perf_event_paranoid", "r") as permissions:
40+
value = int(permissions.readlines()[0])
41+
if value <= 0:
42+
return True
43+
except:
44+
return False
45+
if not is_supported():
46+
self.skipTest("Per core tracing is not supported. You need "
47+
"/proc/sys/kernel/perf_event_paranoid to be 0 or -1.")
48+
3649
def getTraceOrCreate(self):
3750
if not self.target().GetTrace().IsValid():
3851
error = lldb.SBError()
@@ -110,7 +123,7 @@ def traceStopProcess(self):
110123
else:
111124
self.expect("process trace stop")
112125

113-
def traceStopThread(self, thread=None, error=False):
126+
def traceStopThread(self, thread=None, error=False, substrs=None):
114127
if self.USE_SB_API:
115128
thread = thread if thread is not None else self.thread()
116129
self.assertSBError(self.target().GetTrace().Stop(thread), error)
@@ -119,4 +132,4 @@ def traceStopThread(self, thread=None, error=False):
119132
command = "thread trace stop"
120133
if thread is not None:
121134
command += " " + str(thread.GetIndexID())
122-
self.expect(command, error=error)
135+
self.expect(command, error=error, substrs=substrs)

lldb/source/Plugins/Process/Linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_lldb_library(lldbPluginProcessLinux
22
IntelPTCollector.cpp
33
IntelPTSingleBufferTrace.cpp
4+
IntelPTMultiCoreTrace.cpp
45
NativeProcessLinux.cpp
56
NativeRegisterContextLinux.cpp
67
NativeRegisterContextLinux_arm.cpp

0 commit comments

Comments
 (0)