LLDB  mainline
TraceIntelPTMultiCpuDecoder.h
Go to the documentation of this file.
1 //===-- TraceIntelPTMultiCpuDecoder.h ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTMULTICPUDECODER_H
10 #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTMULTICPUDECODER_H
11 
12 #include "LibiptDecoder.h"
14 #include "ThreadDecoder.h"
15 #include "forward-declarations.h"
16 
17 namespace lldb_private {
18 namespace trace_intel_pt {
19 
20 /// Class used to decode a multi-cpu Intel PT trace. It assumes that each
21 /// thread could have potentially been executed on different cpu cores. It uses
22 /// a context switch trace per CPU with timestamps to identify which thread owns
23 /// each Intel PT decoded instruction and in which order. It also assumes that
24 /// the Intel PT data and context switches might have gaps in their traces due
25 /// to contention or race conditions. Finally, it assumes that a tid is not
26 /// repeated twice for two different threads because of the shortness of the
27 /// intel pt trace.
28 ///
29 /// This object should be recreated after every stop in the case of live
30 /// processes.
32 public:
33  /// \param[in] TraceIntelPT
34  /// The trace object to be decoded
36 
37  /// \return
38  /// A \a DecodedThread for the \p thread by decoding its instructions on all
39  /// CPUs, sorted by TSCs. An \a llvm::Error is returned if the decoder
40  /// couldn't be properly set up.
41  llvm::Expected<DecodedThreadSP> Decode(Thread &thread);
42 
43  /// \return
44  /// \b true if the given \p tid is managed by this decoder, regardless of
45  /// whether there's tracing data associated to it or not.
46  bool TracesThread(lldb::tid_t tid) const;
47 
48  /// \return
49  /// The number of continuous executions found for the given \p tid.
51 
52  /// \return
53  /// The number of PSB blocks for a given thread in all cores.
54  size_t GePSBBlocksCountForThread(lldb::tid_t tid) const;
55 
56  /// \return
57  /// The total number of continuous executions found across CPUs.
58  size_t GetTotalContinuousExecutionsCount() const;
59 
60  /// \return
61  /// The number of psb blocks in all cores that couldn't be matched with a
62  /// thread execution coming from context switch traces.
63  size_t GetUnattributedPSBBlocksCount() const;
64 
65  /// \return
66  /// The total number of PSB blocks in all cores.
67  size_t GetTotalPSBBlocksCount() const;
68 
69 private:
70  /// Traverse the context switch traces and the basic intel pt continuous
71  /// subtraces and produce a list of continuous executions for each process and
72  /// thread.
73  ///
74  /// See \a DoCorrelateContextSwitchesAndIntelPtTraces.
75  ///
76  /// Any errors are stored in \a m_setup_error.
78 
79  /// Produce a mapping from thread ids to the list of continuos executions with
80  /// their associated intel pt subtraces.
81  llvm::Expected<
82  llvm::DenseMap<lldb::tid_t, std::vector<IntelPTThreadContinousExecution>>>
84 
86 
87  std::weak_ptr<TraceIntelPT> m_trace_wp;
88  std::set<lldb::tid_t> m_tids;
89  llvm::Optional<
90  llvm::DenseMap<lldb::tid_t, std::vector<IntelPTThreadContinousExecution>>>
92  llvm::DenseMap<lldb::tid_t, DecodedThreadSP> m_decoded_threads;
93  /// This variable will be non-None if a severe error happened during the setup
94  /// of the decoder and we don't want decoding to be reattempted.
95  llvm::Optional<std::string> m_setup_error;
97  uint64_t m_total_psb_blocks = 0;
98 };
99 
100 } // namespace trace_intel_pt
101 } // namespace lldb_private
102 
103 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTMULTICPUDECODER_H
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GetUnattributedPSBBlocksCount
size_t GetUnattributedPSBBlocksCount() const
Definition: TraceIntelPTMultiCpuDecoder.cpp:212
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::Decode
llvm::Expected< DecodedThreadSP > Decode(Thread &thread)
Definition: TraceIntelPTMultiCpuDecoder.cpp:38
PerfContextSwitchDecoder.h
LibiptDecoder.h
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GetTotalPSBBlocksCount
size_t GetTotalPSBBlocksCount() const
Definition: TraceIntelPTMultiCpuDecoder.cpp:216
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::TracesThread
bool TracesThread(lldb::tid_t tid) const
Definition: TraceIntelPTMultiCpuDecoder.cpp:34
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GePSBBlocksCountForThread
size_t GePSBBlocksCountForThread(lldb::tid_t tid) const
Definition: TraceIntelPTMultiCpuDecoder.cpp:200
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_decoded_threads
llvm::DenseMap< lldb::tid_t, DecodedThreadSP > m_decoded_threads
Definition: TraceIntelPTMultiCpuDecoder.h:92
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GetTotalContinuousExecutionsCount
size_t GetTotalContinuousExecutionsCount() const
Definition: TraceIntelPTMultiCpuDecoder.cpp:190
lldb_private::Thread
Definition: Thread.h:61
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_continuous_executions_per_thread
llvm::Optional< llvm::DenseMap< lldb::tid_t, std::vector< IntelPTThreadContinousExecution > > > m_continuous_executions_per_thread
Definition: TraceIntelPTMultiCpuDecoder.h:91
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::TraceIntelPTMultiCpuDecoder
TraceIntelPTMultiCpuDecoder(TraceIntelPTSP trace_sp)
Definition: TraceIntelPTMultiCpuDecoder.cpp:20
forward-declarations.h
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GetNumContinuousExecutionsForThread
size_t GetNumContinuousExecutionsForThread(lldb::tid_t tid) const
Definition: TraceIntelPTMultiCpuDecoder.cpp:180
lldb_private::trace_intel_pt::TraceIntelPTSP
std::shared_ptr< TraceIntelPT > TraceIntelPTSP
Definition: forward-declarations.h:20
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::DoCorrelateContextSwitchesAndIntelPtTraces
llvm::Expected< llvm::DenseMap< lldb::tid_t, std::vector< IntelPTThreadContinousExecution > > > DoCorrelateContextSwitchesAndIntelPtTraces()
Produce a mapping from thread ids to the list of continuos executions with their associated intel pt ...
Definition: TraceIntelPTMultiCpuDecoder.cpp:93
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_setup_error
llvm::Optional< std::string > m_setup_error
This variable will be non-None if a severe error happened during the setup of the decoder and we don'...
Definition: TraceIntelPTMultiCpuDecoder.h:95
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_unattributed_psb_blocks
uint64_t m_unattributed_psb_blocks
Definition: TraceIntelPTMultiCpuDecoder.h:96
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::CorrelateContextSwitchesAndIntelPtTraces
llvm::Error CorrelateContextSwitchesAndIntelPtTraces()
Traverse the context switch traces and the basic intel pt continuous subtraces and produce a list of ...
Definition: TraceIntelPTMultiCpuDecoder.cpp:157
ThreadDecoder.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_trace_wp
std::weak_ptr< TraceIntelPT > m_trace_wp
Definition: TraceIntelPTMultiCpuDecoder.h:87
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::GetTrace
TraceIntelPTSP GetTrace()
Definition: TraceIntelPTMultiCpuDecoder.cpp:30
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder
Class used to decode a multi-cpu Intel PT trace.
Definition: TraceIntelPTMultiCpuDecoder.h:31
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_total_psb_blocks
uint64_t m_total_psb_blocks
Definition: TraceIntelPTMultiCpuDecoder.h:97
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::trace_intel_pt::TraceIntelPTMultiCpuDecoder::m_tids
std::set< lldb::tid_t > m_tids
Definition: TraceIntelPTMultiCpuDecoder.h:88