LLDB  mainline
Timer.h
Go to the documentation of this file.
1 //===-- Timer.h -------------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_Timer_h_
10 #define liblldb_Timer_h_
11 
12 #include "lldb/lldb-defines.h"
13 #include "llvm/Support/Chrono.h"
14 #include <atomic>
15 #include <stdint.h>
16 
17 namespace lldb_private {
18 class Stream;
19 
20 /// \class Timer Timer.h "lldb/Utility/Timer.h"
21 /// A timer class that simplifies common timing metrics.
22 
23 class Timer {
24 public:
25  class Category {
26  public:
27  explicit Category(const char *category_name);
28 
29  private:
30  friend class Timer;
31  const char *m_name;
32  std::atomic<uint64_t> m_nanos;
33  std::atomic<Category *> m_next;
34 
35  DISALLOW_COPY_AND_ASSIGN(Category);
36  };
37 
38  /// Default constructor.
39  Timer(Category &category, const char *format, ...)
40  __attribute__((format(printf, 3, 4)));
41 
42  /// Destructor
43  ~Timer();
44 
45  void Dump();
46 
47  static void SetDisplayDepth(uint32_t depth);
48 
49  static void SetQuiet(bool value);
50 
51  static void DumpCategoryTimes(Stream *s);
52 
53  static void ResetCategoryTimes();
54 
55 protected:
56  using TimePoint = std::chrono::steady_clock::time_point;
57  void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
58 
61  TimePoint::duration m_child_duration{0};
62 
63  static std::atomic<bool> g_quiet;
64  static std::atomic<unsigned> g_display_depth;
65 
66 private:
67  DISALLOW_COPY_AND_ASSIGN(Timer);
68 };
69 
70 } // namespace lldb_private
71 
72 #endif // liblldb_Timer_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
TimePoint m_total_start
Definition: Timer.h:60
void ChildDuration(TimePoint::duration dur)
Definition: Timer.h:57
static void SetDisplayDepth(uint32_t depth)
Definition: Timer.cpp:98
A timer class that simplifies common timing metrics.
Definition: Timer.h:23
Category & m_category
Definition: Timer.h:59
static void ResetCategoryTimes()
Definition: Timer.cpp:111
static void DumpCategoryTimes(Stream *s)
Definition: Timer.cpp:116
static std::atomic< unsigned > g_display_depth
Definition: Timer.h:64
static std::atomic< bool > g_quiet
Definition: Timer.h:63
TimePoint::duration m_child_duration
Definition: Timer.h:61
Category(const char *category_name)
Definition: Timer.cpp:42
std::chrono::steady_clock::time_point TimePoint
Definition: Timer.h:56
static void SetQuiet(bool value)
Definition: Timer.cpp:50