]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Timer.h
MFV r319950: 5220 L2ARC does not support devices that do not provide 512B access
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / Timer.h
1 //===-- Timer.h -------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Timer_h_
11 #define liblldb_Timer_h_
12
13 // C Includes
14 #include <stdarg.h>
15 #include <stdio.h>
16
17 // C++ Includes
18 #include <atomic>
19 #include <mutex>
20
21 // Other libraries and framework includes
22 // Project includes
23 #include "lldb/lldb-private.h"
24 #include "llvm/Support/Chrono.h"
25
26 namespace lldb_private {
27
28 //----------------------------------------------------------------------
29 /// @class Timer Timer.h "lldb/Core/Timer.h"
30 /// @brief A timer class that simplifies common timing metrics.
31 ///
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
37 /// in a scope.
38 //----------------------------------------------------------------------
39
40 class Timer {
41 public:
42   //--------------------------------------------------------------
43   /// Default constructor.
44   //--------------------------------------------------------------
45   Timer(const char *category, const char *format, ...)
46       __attribute__((format(printf, 3, 4)));
47
48   //--------------------------------------------------------------
49   /// Destructor
50   //--------------------------------------------------------------
51   ~Timer();
52
53   void Dump();
54
55   static void SetDisplayDepth(uint32_t depth);
56
57   static void SetQuiet(bool value);
58
59   static void DumpCategoryTimes(Stream *s);
60
61   static void ResetCategoryTimes();
62
63 protected:
64   using TimePoint = std::chrono::steady_clock::time_point;
65   void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
66
67   const char *m_category;
68   TimePoint m_total_start;
69   TimePoint::duration m_child_duration{0};
70
71   static std::atomic<bool> g_quiet;
72   static std::atomic<unsigned> g_display_depth;
73
74 private:
75   DISALLOW_COPY_AND_ASSIGN(Timer);
76 };
77
78 } // namespace lldb_private
79
80 #endif // liblldb_Timer_h_