51ZTH_EXPORT
void perf_stop()
noexcept;
52ZTH_EXPORT
void perf_mark(
char const* marker, Timestamp
const& t = Timestamp())
noexcept;
54perf_logv(
char const* fmt, va_list args, Timestamp
const& t = Timestamp())
noexcept;
56perf_log(
char const* fmt, ...)
noexcept;
58perf_log(Timestamp
const& t,
char const* fmt, ...)
noexcept;
63ZTH_EXPORT
void perf_abort()
noexcept;
64ZTH_EXPORT
void perf_run_dump(
char const* path =
nullptr)
noexcept;
65ZTH_EXPORT
int perf_vcd(
char const* perf =
nullptr,
char const* vcd =
nullptr)
noexcept;
66ZTH_EXPORT
int perf_vcdf(FILE* perf, FILE* vcd)
noexcept;
73 if(Config::EnablePerfEvent &&
zth_config(PerfSyscall))
77void perf_fiber(Fiber& f)
noexcept;
78void perf_fiber_state(Fiber& f,
int state = -1, Timestamp
const& t = Timestamp()) noexcept;
90template <typename T =
float>
118 idle((
type)(
now - m_current).s());
128 active((
type)(
now - m_current).s());
147 return active(load(), dt_s);
149 return idle(load(), dt_s);
154 m_load = idle(load(), dt_s);
159 m_load = active(load(), dt_s);
168 return ((
type)1 - alpha(dt_s)) * load;
176 type a = alpha(dt_s);
177 return a + ((
type)1 - a) * load;
182 return dt_s / (rc() + dt_s);
205template <
typename T =
float,
size_t Bins = 2,
typename Count = u
int_fast32_t>
219 static_assert(std::numeric_limits<
decltype(m_current)>::max() >= Bins,
"");
225 for(; m_binStart + m_window <
now && b < Bins; b++) {
227 m_current = (m_current + 1U) % Bins;
228 m_bins[m_current] = 0;
229 m_binStart += m_window;
247 type w = (
type)(
now - m_binStart).s() / m_window_s;
257 type first_bin = ((
type)1 - w) * (
type)m_bins[(m_current + 1U) % Bins];
259 type last_bin = (
type)m_bins[m_current];
262 type sum = first_bin + last_bin;
263 for(
decltype(m_current + 0) i = 2; i < Bins; i++)
264 sum += (
type)m_bins[(m_current + i) % Bins];
267 return sum * ((
type)1 / (
type)(Bins - 1)) / m_window_s;
389zth_perf_vcd(
char const* perf =
nullptr,
char const* vcd =
nullptr) noexcept
426ZTH_EXPORT
int zth_perf_vcd(
char const* perf,
char const* vcd);
437#define zth_perf_mark(marker) zth_perf_mark_("" marker)
445#define zth_perf_logv(fmt, args) zth_perf_logv_("" fmt, args)
453#define zth_perf_log(fmt, ...) zth_perf_log_("" fmt, ##__VA_ARGS__)
461#define zth_perf_mark_async(marker, handle) zth_perf_mark_async("" marker, (handle))
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.
#define zth_perf_log(fmt,...)
Put a formatted log string into the perf output.
#define zth_perf_logv(fmt, args)
Put a formatted log string into the perf output.
void zth_perf_start(zth_perf_done_callback_t *f=nullptr) noexcept
Starts recording perf events.
void zth_perf_abort() noexcept
Abort a zth::perf_run().
int zth_perf_vcdf(FILE *perf, FILE *vcd) noexcept
Convert a perf file into VCD.
int zth_perf_vcd(char const *perf=nullptr, char const *vcd=nullptr) noexcept
Convert a perf file into VCD.
void zth_perf_dump(zth_perf_dump_callback_t *f) noexcept
Passes collected perf data to f.
void zth_perf_run(zth_perf_dump_callback_t *f) noexcept
Setup the system to automatically perform perf event recording, dumping, and resuming.
void zth_perf_stop() noexcept
Stops recording perf events.
void zth_perf_async_handle(zth_perf_async_handle_t *handle) noexcept
Returns the handle of the current thread's perf buffer.
#define zth_config(name)
Checks if the given zth::Config field is enabled.
void perf_stop() noexcept
Stops recording perf events.
void perf_async_handle(zth_perf_async_handle_t *handle) noexcept
Returns the handle of the current thread's perf buffer.
void perf_mark(char const *marker, Timestamp const &t=Timestamp()) noexcept
Put a string marker into the perf output.
void perf_abort() noexcept
Abort a zth::perf_run().
void perf_run(zth_perf_dump_callback_t *f) noexcept
Setup the system to automatically perform perf event recording, dumping, and resuming.
void perf_start(zth_perf_done_callback_t *f=nullptr) noexcept
Starts recording perf events.
void perf_dump(zth_perf_dump_callback_t *f) noexcept
Passes collected perf data to f.
void perf_logv(char const *fmt, va_list args, Timestamp const &t=Timestamp()) noexcept
Put a formatted log string into the perf output.
void perf_mark_async(char const *marker, zth_perf_async_handle_t *handle) noexcept
Async-/thread-safe zth::perf_mark().
#define ZTH_CLASS_NEW_DELETE(T)
Define new/delete operators for a class, which are allocator-aware.
void now(struct timespec &ts)
Returns the current timestamp.
void perf_syscall(char const *syscall, Timestamp const &t=Timestamp()) noexcept
Put a syscall into the perf output.
int perf_vcd(char const *perf=nullptr, char const *vcd=nullptr) noexcept
Convert a perf file into VCD.
string format(char const *fmt,...)
Format like sprintf(), but save the result in an zth::string.
int perf_vcdf(FILE *perf, FILE *vcd) noexcept
Convert a perf file into VCD.
void() zth_perf_dump_callback_t(void const *, size_t)
void zth_perf_logv_(char const *fmt, va_list args) noexcept
void zth_perf_mark_async_(char const *marker, zth_perf_async_handle_t *handle) noexcept
void() zth_perf_done_callback_t()
void zth_perf_log_(char const *fmt,...) noexcept
void zth_perf_mark_(char const *marker) noexcept
static bool const EnablePerfEvent
Enable (but not necessarily record) perf.
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.