54 explicit Backtrace(
size_t skip = 0,
size_t maxDepth = 128);
85 void printPartial(
size_t start, ssize_t end = -1,
int color = -1)
const;
86 void print(
int color = -1)
const;
87 void printDelta(
Backtrace const& other,
int color = -1)
const;
102template <
bool Enable = Config::EnablePerfEvent>
115 ,
str(strdup(fiber_.name().
c_str()))
153 if(vasprintf(&
str, fmt, args) == -1)
164 if(vasprintf(&
str, fmt, args) == -1)
200# pragma GCC diagnostic push
201# pragma GCC diagnostic ignored "-Wunused-parameter"
239 va_list args) noexcept
255# pragma GCC diagnostic pop
271# if __cplusplus >= 201103L
273template <
typename... Args>
294# define zth_perf_event(...) zth::perf_event(__VA_ARGS__)
297inline void perf_event(PerfEvent<>
const& event)
noexcept
299 if(!Config::EnablePerfEvent ||
unlikely(!perf_eventBuffer)) {
306 perf_eventBuffer->push_back(event);
313 zth_assert(perf_eventBuffer->size() <= Config::PerfEventBufferSize);
315 if(
unlikely(perf_eventBuffer->size() >= Config::PerfEventBufferThresholdToTriggerVCDWrite))
316 perf_flushEventBuffer();
319# define zth_perf_event(...) zth::perf_event(PerfEvent<>(__VA_ARGS__))
328 if(Config::EnablePerfEvent)
338 if(!Config::EnablePerfEvent)
352perf_logv(
char const* fmt, va_list args)
354 if(Config::EnablePerfEvent)
363 if(Config::EnablePerfEvent &&
zth_config(PerfSyscall))
377template <
typename T =
float>
432 type dt_s = (
type)(now - m_current).s();
469 return dt_s / (
rc() + dt_s);
492template <
typename T =
float,
size_t Bins = 2,
typename Count = u
int_fast32_t>
506 static_assert(std::numeric_limits<
decltype(m_current)>::max() >= Bins,
"");
512 for(; m_binStart + m_window < now && b < Bins; b++) {
514 m_current = (m_current + 1U) % Bins;
515 m_bins[m_current] = 0;
516 m_binStart += m_window;
534 type w = (
type)(now - m_binStart).s() / m_window_s;
544 type first_bin = ((
type)1 - w) * (
type)m_bins[(m_current + 1U) % Bins];
546 type last_bin = (
type)m_bins[m_current];
549 type sum = first_bin + last_bin;
550 for(
decltype(m_current + 0) i = 2; i < Bins; i++)
551 sum += (
type)m_bins[(m_current + i) % Bins];
554 return sum * ((
type)1 / (
type)(Bins - 1)) / m_window_s;
619#define zth_perf_mark(marker) zth_perf_mark_("" marker)
Timestamp const & t0() const noexcept
bool truncated() const noexcept
vector_type< void * >::type bt_type
bt_type const & bt() const noexcept
Timestamp const & t1() const noexcept
uint64_t fiberId() const noexcept
Fiber * fiber() const noexcept
Measure the rate of some event in Hz.
void operator()(Timestamp const &now=Timestamp::now()) noexcept
void event(Timestamp const &now=Timestamp::now()) noexcept
type rate(Timestamp const &now=Timestamp::now()) const noexcept
EventRate(type window=1) noexcept
Measure the load of some activity.
void setRc(type rc) noexcept
type idle(type load, type dt_s) const noexcept
type active(type load, type dt_s) const noexcept
type load(Timestamp const &now) const noexcept
void idle(type dt_s) noexcept
void stop(Timestamp const &now=Timestamp::now()) noexcept
void start(Timestamp const &now=Timestamp::now()) noexcept
type load() const noexcept
void active(type dt_s) noexcept
type alpha(type dt_s) const noexcept
bool isActive() const noexcept
Convenient wrapper around struct timespec that contains a time interval.
Convenient wrapper around struct timespec that contains an absolute timestamp.
Keeps track of a process-wide unique ID within the type T.
void zth_perf_log(char const *fmt,...)
Put a formatted log string into the perf output.
void zth_perf_logv(char const *fmt, va_list args)
Put a formatted log string into the perf output.
#define zth_config(name)
Checks if the given zth::Config field is enabled.
void perf_mark(char const *marker)
Put a string marker into the perf output.
#define zth_perf_event(...)
Construct a zth::PerfEvent with provided parameters, and forward it to the perf buffer for later proc...
void perf_logv(char const *fmt, va_list args)
Put a formatted log string into the perf output.
#define ZTH_CLASS_NEW_DELETE(T)
Define new/delete operators for a class, which are allocator-aware.
#define ZTH_TLS_DECLARE(type, var)
perf_eventBuffer_type * perf_eventBuffer
void perf_flushEventBuffer() noexcept
void perf_event(Args &&... args) noexcept
UniqueID< Fiber > const & currentFiberID() noexcept
string format(char const *fmt,...)
Format like sprintf(), but save the result in an zth::string.
void perf_syscall(char const *syscall, Timestamp const &t=Timestamp())
Put a syscall into the perf output.
vector_type< PerfEvent<> >::type perf_eventBuffer_type
void zth_perf_mark_(char const *marker)
constexpr PerfEvent() noexcept
constexpr PerfEvent(UniqueID< Fiber > const &fiber_, string const &str_, Timestamp const &t_=Timestamp()) noexcept
constexpr PerfEvent(UniqueID< Fiber > const &fiber_, char const *marker, Timestamp const &t_=Timestamp()) noexcept
constexpr PerfEvent(UniqueID< Fiber > const &fiber_) noexcept
void release() const noexcept
constexpr PerfEvent(UniqueID< Fiber > const &fiber_, int state, Timestamp const &t_=Timestamp()) noexcept
An event to be processed by perf_event().
PerfEvent(UniqueID< Fiber > const &fiber_, char const *marker, Timestamp const &t_=Timestamp::now()) noexcept
constexpr PerfEvent() noexcept
PerfEvent(UniqueID< Fiber > const &fiber_, string const &str_, Timestamp const &t_=Timestamp::now())
PerfEvent(UniqueID< Fiber > const &fiber_)
PerfEvent(UniqueID< Fiber > const &fiber_, int state, Timestamp const &t_=Timestamp::now()) noexcept
std::vector type using Config::Allocator::type.
std::vector< T, typename Config::Allocator< T >::type > type
#define zth_assert(expr)
assert(), but better integrated in Zth.
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.