10#include "llvm/Support/ManagedStatic.h"
11#include "llvm/Support/Signposts.h"
26#define TIMER_INDENT_AMOUNT 2
29typedef std::vector<Timer *> TimerStack;
34static llvm::ManagedStatic<llvm::SignpostEmitter>
Signposts;
39 static std::mutex *g_file_mutex_ptr =
new std::mutex();
40 return *g_file_mutex_ptr;
44 static thread_local TimerStack g_stack;
49 m_nanos.store(0, std::memory_order_release);
51 m_count.store(0, std::memory_order_release);
55 }
while (!
g_categories.compare_exchange_weak(expected,
this));
65 stack.push_back(
this);
73 va_start(args, format);
74 ::vfprintf(stdout, format, args);
78 ::fprintf(stdout,
"\n");
83 using namespace std::chrono;
85 auto stop_time = steady_clock::now();
94 ::fprintf(stdout,
"%*s%.9f sec (%.9f sec)\n",
96 duration<double>(total_dur).count(),
97 duration<double>(timer_dur).count());
100 assert(stack.back() ==
this);
103 stack.back()->ChildDuration(total_dur);
120 uint64_t nanos_total;
127 return lhs.nanos > rhs.nanos;
132 i->m_nanos.store(0, std::memory_order_release);
133 i->m_nanos_total.store(0, std::memory_order_release);
134 i->m_count.store(0, std::memory_order_release);
139 std::vector<Stats> sorted;
141 uint64_t nanos = i->m_nanos.load(std::memory_order_acquire);
143 uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire);
144 uint64_t count = i->m_count.load(std::memory_order_acquire);
145 Stats stats{i->m_name, nanos, nanos_total, count};
146 sorted.push_back(stats);
155 for (
const auto &stats : sorted)
156 s.
Printf(
"%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64
158 stats.nanos / 1000000000., stats.nanos_total / 1000000000.,
159 (stats.nanos_total - stats.nanos) / 1000000000., stats.count,
static constexpr Log::Category g_categories[]
static llvm::ManagedStatic< llvm::SignpostEmitter > Signposts
Allows llvm::Timer to emit signposts when supported.
static TimerStack & GetTimerStackForCurrentThread()
#define TIMER_INDENT_AMOUNT
static std::mutex & GetFileMutex()
static bool CategoryMapIteratorSortCriterion(const Stats &lhs, const Stats &rhs)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
std::atomic< Category * > m_next
std::atomic< uint64_t > m_nanos
std::atomic< uint64_t > m_nanos_total
Category(const char *category_name)
llvm::StringRef GetName()
std::atomic< uint64_t > m_count
static void ResetCategoryTimes()
static std::atomic< bool > g_quiet
TimePoint::duration m_child_duration
static std::atomic< unsigned > g_display_depth
static void SetQuiet(bool value)
static void SetDisplayDepth(uint32_t depth)
Timer(Category &category, const char *format,...) __attribute__((format(printf
Default constructor.
static void DumpCategoryTimes(Stream &s)
A class that represents a running process on the host machine.