diff --git a/lldb/source/Plugins/Trace/intel-pt/TaskTimer.h b/lldb/source/Plugins/Trace/intel-pt/TaskTimer.h --- a/lldb/source/Plugins/Trace/intel-pt/TaskTimer.h +++ b/lldb/source/Plugins/Trace/intel-pt/TaskTimer.h @@ -35,9 +35,9 @@ /// /// \return /// The return value of the task. - template R TimeTask(llvm::StringRef name, std::function task) { + template auto TimeTask(llvm::StringRef name, C task) { auto start = std::chrono::steady_clock::now(); - R result = task(); + auto result = task(); auto end = std::chrono::steady_clock::now(); std::chrono::milliseconds duration = std::chrono::duration_cast(end - start); diff --git a/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp b/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp --- a/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp @@ -35,9 +35,8 @@ } llvm::Expected ThreadDecoder::DoDecode() { - return m_trace.GetTimer() - .ForThread(m_thread_sp->GetID()) - .TimeTask>( + return m_trace.GetThreadTimer(m_thread_sp->GetID()) + .TimeTask( "Decoding instructions", [&]() -> Expected { DecodedThreadSP decoded_thread_sp = std::make_shared(m_thread_sp); diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h @@ -157,6 +157,14 @@ /// The timer object for this trace. TaskTimer &GetTimer(); + /// \return + /// The ScopedTaskTimer object for the given thread in this trace. + ScopedTaskTimer &GetThreadTimer(lldb::tid_t tid); + + /// \return + /// The global copedTaskTimer object for this trace. + ScopedTaskTimer &GetGlobalTimer(); + TraceIntelPTSP GetSharedPtr(); private: diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp @@ -199,10 +199,10 @@ std::chrono::milliseconds duration) { s.Format(" {0}: {1:2}s\n", name, duration.count() / 1000.0); }; - GetTimer().ForThread(tid).ForEachTimedTask(print_duration); + GetThreadTimer(tid).ForEachTimedTask(print_duration); s << "\n Timing for global tasks:\n"; - GetTimer().ForGlobal().ForEachTimedTask(print_duration); + GetGlobalTimer().ForEachTimedTask(print_duration); } // Instruction events stats @@ -507,3 +507,11 @@ } TaskTimer &TraceIntelPT::GetTimer() { return GetUpdatedStorage().task_timer; } + +ScopedTaskTimer &TraceIntelPT::GetThreadTimer(lldb::tid_t tid) { + return GetTimer().ForThread(tid); +} + +ScopedTaskTimer &TraceIntelPT::GetGlobalTimer() { + return GetTimer().ForGlobal(); +} diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp @@ -39,30 +39,35 @@ if (Error err = CorrelateContextSwitchesAndIntelPtTraces()) return std::move(err); - auto it = m_decoded_threads.find(thread.GetID()); - if (it != m_decoded_threads.end()) - return it->second; - - DecodedThreadSP decoded_thread_sp = - std::make_shared(thread.shared_from_this()); - TraceIntelPTSP trace_sp = GetTrace(); - Error err = trace_sp->OnAllCpusBinaryDataRead( - IntelPTDataKinds::kIptTrace, - [&](const DenseMap> &buffers) -> Error { - auto it = m_continuous_executions_per_thread->find(thread.GetID()); - if (it != m_continuous_executions_per_thread->end()) - return DecodeSystemWideTraceForThread(*decoded_thread_sp, *trace_sp, - buffers, it->second); - - return Error::success(); + return trace_sp + ->GetThreadTimer(thread.GetID()) + .TimeTask("Decoding instructions", [&]() -> Expected { + auto it = m_decoded_threads.find(thread.GetID()); + if (it != m_decoded_threads.end()) + return it->second; + + DecodedThreadSP decoded_thread_sp = + std::make_shared(thread.shared_from_this()); + + Error err = trace_sp->OnAllCpusBinaryDataRead( + IntelPTDataKinds::kIptTrace, + [&](const DenseMap> &buffers) -> Error { + auto it = + m_continuous_executions_per_thread->find(thread.GetID()); + if (it != m_continuous_executions_per_thread->end()) + return DecodeSystemWideTraceForThread( + *decoded_thread_sp, *trace_sp, buffers, it->second); + + return Error::success(); + }); + if (err) + return std::move(err); + + m_decoded_threads.try_emplace(thread.GetID(), decoded_thread_sp); + return decoded_thread_sp; }); - if (err) - return std::move(err); - - m_decoded_threads.try_emplace(thread.GetID(), decoded_thread_sp); - return decoded_thread_sp; } static Expected> @@ -153,7 +158,7 @@ if (m_continuous_executions_per_thread) return Error::success(); - Error err = GetTrace()->GetTimer().ForGlobal().TimeTask( + Error err = GetTrace()->GetGlobalTimer().TimeTask( "Context switch and Intel PT traces correlation", [&]() -> Error { if (auto correlation = DoCorrelateContextSwitchesAndIntelPtTraces()) { m_continuous_executions_per_thread.emplace(std::move(*correlation));