7#include <guanaqo/export.h>
10#if GUANAQO_WITH_PERFETTO
19 ::perfetto::Category(
"trace").SetDescription(
20 "General trace events for regions of code"),
21 ::perfetto::Category(
"gflops").SetDescription(
22 "Counts the total number of floating point operations"),
23 ::perfetto::Category(
"pcm").SetDescription(
24 "Performance counters for CPU metrics"));
32namespace fs = std::filesystem;
40GUANAQO_EXPORT std::unique_ptr<::perfetto::TracingSession>
44abort_tracing(std::unique_ptr<::perfetto::TracingSession> tracing_session);
47stop_tracing(std::unique_ptr<::perfetto::TracingSession> tracing_session,
48 const fs::path &output_path);
54 static thread_local auto thread_id = ::perfetto::base::GetThreadId();
66#if GUANAQO_WITH_PCM_TRACING
68GUANAQO_EXPORT
struct ScopedLinalgCounters {
90 TRACE_COUNTER(
"gflops",
100#define GUANAQO_TRACE_LINALG_PRIVATE(name, gflops, uid) \
101 ::guanaqo::trace::ScopedLinalgCounters GUANAQO_CONCATENATE_TOKENS(ctr_, \
103 ::guanaqo::trace::get_thread_gflop_count() += (gflops); \
104 TRACE_EVENT("gflops", name, \
105 GUANAQO_CONCATENATE_TOKENS(ctr_, uid).parent_track)
107#define GUANAQO_TRACE_LINALG_IMPL(name, gflops) \
108 GUANAQO_TRACE_LINALG_PRIVATE(name, gflops, __COUNTER__)
110#define GUANAQO_TRACE_INSTANT_IMPL(name, instance) \
111 TRACE_EVENT_INSTANT("trace", name, "instance", instance)
113#define GUANAQO_TRACE_REGION_IMPL(name, instance) \
114 TRACE_EVENT("trace", name, "instance", instance)
119#define GUANAQO_TRACE_LINALG(name, gflops) \
120 PERFETTO_USE_CATEGORIES_FROM_NAMESPACE_SCOPED(guanaqo::trace); \
121 GUANAQO_TRACE_LINALG_IMPL(name, gflops)
123#define GUANAQO_TRACE_INSTANT(name, instance) \
124 PERFETTO_USE_CATEGORIES_FROM_NAMESPACE_SCOPED(guanaqo::trace); \
125 GUANAQO_TRACE_INSTANT_IMPL(name, instance)
127#define GUANAQO_TRACE_REGION(name, instance) \
128 PERFETTO_USE_CATEGORIES_FROM_NAMESPACE_SCOPED(guanaqo::trace); \
129 GUANAQO_TRACE_REGION_IMPL(name, instance)
132#define GUANAQO_TRACE(name, instance, ...) \
133 PERFETTO_USE_CATEGORIES_FROM_NAMESPACE_SCOPED(guanaqo::trace); \
134 GUANAQO_TRACE_REGION(name, instance)
136#define GUANAQO_TRACE_STATIC_STR(s) \
137 ::perfetto::StaticString { s }
Performance counter snapshots and scoped collectors.
std::unique_ptr< detail::ScopedCounters > start_counters()
May return null if PCM is not available.
void stop_tracing(std::unique_ptr<::perfetto::TracingSession > tracing_session, const fs::path &output_path)
Stop the tracing session and write the trace data to the specified output file.
void abort_tracing(std::unique_ptr<::perfetto::TracingSession > tracing_session)
Stop the tracing session and discard the trace data.
std::unique_ptr<::perfetto::TracingSession > start_tracing(uint32_t memory_kb=128 *1024)
Start a new tracing session with the specified buffer size in KiB.
uint64_t & get_thread_gflop_count()
Get a reference to the thread-local GFLOP counter.
void initialize_tracing()
Initialize Perfetto for in-process tracing and register guanaqo's track event categories.
inline ::perfetto::base::PlatformThreadId get_thread_id_fast()
PERFETTO_USE_CATEGORIES_FROM_NAMESPACE(guanaqo::trace)
PERFETTO_DEFINE_CATEGORIES_IN_NAMESPACE(guanaqo::trace, ::perfetto::Category("trace").SetDescription("General trace events for regions of code"), ::perfetto::Category("gflops").SetDescription("Counts the total number of floating point operations"), ::perfetto::Category("pcm").SetDescription("Performance counters for CPU metrics"))
Token concatenation and argument-counting helpers.
::perfetto::ThreadTrack parent_track
ScopedLinalgCounters(const ScopedLinalgCounters &)=delete
void trace_gflops() const
ScopedLinalgCounters & operator=(const ScopedLinalgCounters &)=delete