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_
13 #include "lldb/lldb-defines.h" // for DISALLOW_COPY_AND_ASSIGN
14 #include "llvm/Support/Chrono.h"
16 #include <stdint.h> // for uint32_t
18 namespace lldb_private {
21 //----------------------------------------------------------------------
22 /// @class Timer Timer.h "lldb/Utility/Timer.h"
23 /// @brief A timer class that simplifies common timing metrics.
24 //----------------------------------------------------------------------
30 explicit Category(const char *category_name);
35 std::atomic<uint64_t> m_nanos;
36 std::atomic<Category *> m_next;
38 DISALLOW_COPY_AND_ASSIGN(Category);
41 //--------------------------------------------------------------
42 /// Default constructor.
43 //--------------------------------------------------------------
44 Timer(Category &category, const char *format, ...)
45 __attribute__((format(printf, 3, 4)));
47 //--------------------------------------------------------------
49 //--------------------------------------------------------------
54 static void SetDisplayDepth(uint32_t depth);
56 static void SetQuiet(bool value);
58 static void DumpCategoryTimes(Stream *s);
60 static void ResetCategoryTimes();
63 using TimePoint = std::chrono::steady_clock::time_point;
64 void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
67 TimePoint m_total_start;
68 TimePoint::duration m_child_duration{0};
70 static std::atomic<bool> g_quiet;
71 static std::atomic<unsigned> g_display_depth;
74 DISALLOW_COPY_AND_ASSIGN(Timer);
77 } // namespace lldb_private
79 #endif // liblldb_Timer_h_