1 //===-- Timer.h -------------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Timer_h_
10 #define liblldb_Timer_h_
12 #include "lldb/lldb-defines.h"
13 #include "llvm/Support/Chrono.h"
17 namespace lldb_private {
20 /// \class Timer Timer.h "lldb/Utility/Timer.h"
21 /// A timer class that simplifies common timing metrics.
27 explicit Category(const char *category_name);
32 std::atomic<uint64_t> m_nanos;
33 std::atomic<uint64_t> m_nanos_total;
34 std::atomic<uint64_t> m_count;
35 std::atomic<Category *> m_next;
37 DISALLOW_COPY_AND_ASSIGN(Category);
40 /// Default constructor.
41 Timer(Category &category, const char *format, ...)
42 __attribute__((format(printf, 3, 4)));
49 static void SetDisplayDepth(uint32_t depth);
51 static void SetQuiet(bool value);
53 static void DumpCategoryTimes(Stream *s);
55 static void ResetCategoryTimes();
58 using TimePoint = std::chrono::steady_clock::time_point;
59 void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
62 TimePoint m_total_start;
63 TimePoint::duration m_child_duration{0};
65 static std::atomic<bool> g_quiet;
66 static std::atomic<unsigned> g_display_depth;
69 DISALLOW_COPY_AND_ASSIGN(Timer);
72 } // namespace lldb_private
74 #endif // liblldb_Timer_h_