File indexing completed on 2026-05-10 08:42:58
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_UTILITY_TIMER_H
0010 #define LLDB_UTILITY_TIMER_H
0011
0012 #include "lldb/lldb-defines.h"
0013 #include "llvm/Support/Chrono.h"
0014 #include <atomic>
0015 #include <cstdint>
0016
0017 namespace lldb_private {
0018 class Stream;
0019
0020
0021
0022
0023 class Timer {
0024 public:
0025 class Category {
0026 public:
0027 explicit Category(const char *category_name);
0028 llvm::StringRef GetName() { return m_name; }
0029
0030 private:
0031 friend class Timer;
0032 const char *m_name;
0033 std::atomic<uint64_t> m_nanos;
0034 std::atomic<uint64_t> m_nanos_total;
0035 std::atomic<uint64_t> m_count;
0036 std::atomic<Category *> m_next;
0037
0038 Category(const Category &) = delete;
0039 const Category &operator=(const Category &) = delete;
0040 };
0041
0042
0043 Timer(Category &category, const char *format, ...)
0044 #if !defined(_MSC_VER)
0045
0046 __attribute__((format(printf, 3, 4)))
0047 #endif
0048 ;
0049
0050
0051 ~Timer();
0052
0053 void Dump();
0054
0055 static void SetDisplayDepth(uint32_t depth);
0056
0057 static void SetQuiet(bool value);
0058
0059 static void DumpCategoryTimes(Stream &s);
0060
0061 static void ResetCategoryTimes();
0062
0063 protected:
0064 using TimePoint = std::chrono::steady_clock::time_point;
0065 void ChildDuration(TimePoint::duration dur) { m_child_duration += dur; }
0066
0067 Category &m_category;
0068 TimePoint m_total_start;
0069 TimePoint::duration m_child_duration{0};
0070
0071 static std::atomic<bool> g_quiet;
0072 static std::atomic<unsigned> g_display_depth;
0073
0074 private:
0075 Timer(const Timer &) = delete;
0076 const Timer &operator=(const Timer &) = delete;
0077 };
0078
0079 }
0080
0081
0082
0083 #define LLDB_SCOPED_TIMER() \
0084 static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
0085 ::lldb_private::Timer _scoped_timer(_cat, "%s", LLVM_PRETTY_FUNCTION)
0086 #define LLDB_SCOPED_TIMERF(...) \
0087 static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
0088 ::lldb_private::Timer _scoped_timer(_cat, __VA_ARGS__)
0089
0090 #endif