]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/Timer.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / 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 #include "lldb/lldb-defines.h" // for DISALLOW_COPY_AND_ASSIGN
14 #include "llvm/Support/Chrono.h"
15 #include <atomic>
16 #include <stdint.h> // for uint32_t
17
18 namespace lldb_private {
19 class Stream;
20
21 //----------------------------------------------------------------------
22 /// @class Timer Timer.h "lldb/Utility/Timer.h"
23 /// A timer class that simplifies common timing metrics.
24 //----------------------------------------------------------------------
25
26 class Timer {
27 public:
28   class Category {
29   public:
30     explicit Category(const char *category_name);
31
32   private:
33     friend class Timer;
34     const char *m_name;
35     std::atomic<uint64_t> m_nanos;
36     std::atomic<Category *> m_next;
37
38     DISALLOW_COPY_AND_ASSIGN(Category);
39   };
40
41   //--------------------------------------------------------------
42   /// Default constructor.
43   //--------------------------------------------------------------
44   Timer(Category &category, const char *format, ...)
45       __attribute__((format(printf, 3, 4)));
46
47   //--------------------------------------------------------------
48   /// Destructor
49   //--------------------------------------------------------------
50   ~Timer();
51
52   void Dump();
53
54   static void SetDisplayDepth(uint32_t depth);
55
56   static void SetQuiet(bool value);
57
58   static void DumpCategoryTimes(Stream *s);
59
60   static void ResetCategoryTimes();
61
62 protected:
63   using TimePoint = std::chrono::steady_clock::time_point;
64   void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
65
66   Category &m_category;
67   TimePoint m_total_start;
68   TimePoint::duration m_child_duration{0};
69
70   static std::atomic<bool> g_quiet;
71   static std::atomic<unsigned> g_display_depth;
72
73 private:
74   DISALLOW_COPY_AND_ASSIGN(Timer);
75 };
76
77 } // namespace lldb_private
78
79 #endif // liblldb_Timer_h_