xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TaskTimer.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1*bdd1243dSDimitry Andric //===-- TaskTimer.cpp -----------------------------------------------------===//
2*bdd1243dSDimitry Andric //
3*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bdd1243dSDimitry Andric //
7*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
8*bdd1243dSDimitry Andric 
981ad6265SDimitry Andric #include "TaskTimer.h"
1081ad6265SDimitry Andric 
1181ad6265SDimitry Andric using namespace lldb;
1281ad6265SDimitry Andric using namespace lldb_private;
1381ad6265SDimitry Andric using namespace lldb_private::trace_intel_pt;
1481ad6265SDimitry Andric using namespace llvm;
1581ad6265SDimitry Andric 
ForEachTimedTask(std::function<void (const std::string & event,std::chrono::milliseconds duration)> callback)1681ad6265SDimitry Andric void ScopedTaskTimer::ForEachTimedTask(
1781ad6265SDimitry Andric     std::function<void(const std::string &event,
1881ad6265SDimitry Andric                        std::chrono::milliseconds duration)>
1981ad6265SDimitry Andric         callback) {
2081ad6265SDimitry Andric   for (const auto &kv : m_timed_tasks) {
2181ad6265SDimitry Andric     callback(kv.first, kv.second);
2281ad6265SDimitry Andric   }
2381ad6265SDimitry Andric }
2481ad6265SDimitry Andric 
ForThread(lldb::tid_t tid)2581ad6265SDimitry Andric ScopedTaskTimer &TaskTimer::ForThread(lldb::tid_t tid) {
2681ad6265SDimitry Andric   auto it = m_thread_timers.find(tid);
2781ad6265SDimitry Andric   if (it == m_thread_timers.end())
2881ad6265SDimitry Andric     it = m_thread_timers.try_emplace(tid, ScopedTaskTimer{}).first;
2981ad6265SDimitry Andric   return it->second;
3081ad6265SDimitry Andric }
3181ad6265SDimitry Andric 
ForGlobal()3281ad6265SDimitry Andric ScopedTaskTimer &TaskTimer::ForGlobal() { return m_global_timer; }
33