1 //===-- Timer.h -------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Timer_h_
11 #define liblldb_Timer_h_
21 // Other libraries and framework includes
23 #include "lldb/lldb-private.h"
24 #include "llvm/Support/Chrono.h"
26 namespace lldb_private {
28 //----------------------------------------------------------------------
29 /// @class Timer Timer.h "lldb/Core/Timer.h"
30 /// @brief A timer class that simplifies common timing metrics.
32 /// A scoped timer class that allows a variety of pthread mutex
33 /// objects to have a mutex locked when a Timer::Locker
34 /// object is created, and unlocked when it goes out of scope or
35 /// when the Timer::Locker::Reset(pthread_mutex_t *)
36 /// is called. This provides an exception safe way to lock a mutex
38 //----------------------------------------------------------------------
42 //--------------------------------------------------------------
43 /// Default constructor.
44 //--------------------------------------------------------------
45 Timer(const char *category, const char *format, ...)
46 __attribute__((format(printf, 3, 4)));
48 //--------------------------------------------------------------
50 //--------------------------------------------------------------
55 static void SetDisplayDepth(uint32_t depth);
57 static void SetQuiet(bool value);
59 static void DumpCategoryTimes(Stream *s);
61 static void ResetCategoryTimes();
64 using TimePoint = std::chrono::steady_clock::time_point;
65 void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
67 const char *m_category;
68 TimePoint m_total_start;
69 TimePoint::duration m_child_duration{0};
71 static std::atomic<bool> g_quiet;
72 static std::atomic<unsigned> g_display_depth;
75 DISALLOW_COPY_AND_ASSIGN(Timer);
78 } // namespace lldb_private
80 #endif // liblldb_Timer_h_