26 using Clock = std::chrono::steady_clock;
29 static constexpr size_t No_Parent = std::numeric_limits<size_t>::max();
45 bool empty()
const {
return spans_.empty(); }
46 const auto&
spans()
const {
return spans_; }
53 void start(std::string_view name) {
54 auto parent = stack_.empty() ?
No_Parent : stack_.back();
55 stack_.emplace_back(spans_.size());
56 spans_.emplace_back(std::string(name), Clock::now(), Clock::time_point{}, stack_.size() - 1, parent);
61 auto id = stack_.back();
63 spans_[id].stop = Clock::now();
67 void count(std::string_view key, uint64_t n = 1) {
68 if (stack_.empty() || n == 0)
return;
69 auto& counters = spans_[stack_.back()].counters;
70 for (
auto& [k, v] : counters) {
76 counters.emplace_back(std::string(key), n);
83 void summary(std::ostream&)
const;
85 void tree(std::ostream&)
const;
Records wall-clock timings for (possibly nested) Phase runs and reports them in various formats.
std::chrono::steady_clock Clock
void stop()
Marks the end of the most recently started Phase run.
const auto & spans() const
void chrome_trace(std::ostream &) const
Dumps all Spans as Chrome Trace Event Format JSON.
void start(std::string_view name)
void count(std::string_view key, uint64_t n=1)
Adds n to counter key of the currently running Span; no-op if no Span is running or n is 0.
void summary(std::ostream &) const
static constexpr size_t No_Parent
void tree(std::ostream &) const
Prints the Spans as an indented tree, preserving the order in which Phasees ran.
This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vecto...
size_t depth
Nesting level; a root Phase has depth 0.
size_t parent
Index of the enclosing Span in Profiler::spans, or Profiler::No_Parent for a root.
Vector< std::pair< std::string, uint64_t > > counters
Custom counters reported by the Phase (insertion order).