Go to the documentation of this file.
26 #ifdef MTR_BUILDING_WITH_CMAKE
27 #include "minitrace_export.h"
29 #define MINITRACE_EXPORT
39 #define INTERNAL_MINITRACE_BUFFER_SIZE 1000000
91 #define MTR_MAX_ARGS 1
104 #define MTR_BEGIN(c, n) internal_mtr_raw_event(c, n, 'B', nullptr)
105 #define MTR_END(c, n) internal_mtr_raw_event(c, n, 'E', nullptr)
106 #define MTR_SCOPE(c, n) MTRScopedTrace ____mtr_scope(c, n)
107 #define MTR_SCOPE_LIMIT(c, n, l) MTRScopedTraceLimit ____mtr_scope(c, n, l)
110 #define MTR_START(c, n, id) internal_mtr_raw_event(c, n, 'S', (void *)(id))
111 #define MTR_STEP(c, n, id, step) internal_mtr_raw_event_arg(c, n, 'T', (void *)(id), MTR_ARG_TYPE_STRING_CONST, "step", (void *)(step))
112 #define MTR_FINISH(c, n, id) internal_mtr_raw_event(c, n, 'F', (void *)(id))
115 #define MTR_FLOW_START(c, n, id) internal_mtr_raw_event(c, n, 's', (void *)(id))
116 #define MTR_FLOW_STEP(c, n, id, step) internal_mtr_raw_event_arg(c, n, 't', (void *)(id), MTR_ARG_TYPE_STRING_CONST, "step", (void *)(step))
117 #define MTR_FLOW_FINISH(c, n, id) internal_mtr_raw_event(c, n, 'f', (void *)(id))
126 #define MTR_BEGIN_C(c, n, aname, astrval) internal_mtr_raw_event_arg(c, n, 'B', 0, MTR_ARG_TYPE_STRING_CONST, aname, (void *)(astrval))
127 #define MTR_END_C(c, n, aname, astrval) internal_mtr_raw_event_arg(c, n, 'E', 0, MTR_ARG_TYPE_STRING_CONST, aname, (void *)(astrval))
128 #define MTR_SCOPE_C(c, n, aname, astrval) MTRScopedTraceArg ____mtr_scope(c, n, MTR_ARG_TYPE_STRING_CONST, aname, (void *)(astrval))
130 #define MTR_BEGIN_S(c, n, aname, astrval) internal_mtr_raw_event_arg(c, n, 'B', 0, MTR_ARG_TYPE_STRING_COPY, aname, (void *)(astrval))
131 #define MTR_END_S(c, n, aname, astrval) internal_mtr_raw_event_arg(c, n, 'E', 0, MTR_ARG_TYPE_STRING_COPY, aname, (void *)(astrval))
132 #define MTR_SCOPE_S(c, n, aname, astrval) MTRScopedTraceArg ____mtr_scope(c, n, MTR_ARG_TYPE_STRING_COPY, aname, (void *)(astrval))
134 #define MTR_BEGIN_I(c, n, aname, aintval) internal_mtr_raw_event_arg(c, n, 'B', 0, MTR_ARG_TYPE_INT, aname, (void*)(intptr_t)(aintval))
135 #define MTR_END_I(c, n, aname, aintval) internal_mtr_raw_event_arg(c, n, 'E', 0, MTR_ARG_TYPE_INT, aname, (void*)(intptr_t)(aintval))
136 #define MTR_SCOPE_I(c, n, aname, aintval) MTRScopedTraceArg ____mtr_scope(c, n, MTR_ARG_TYPE_INT, aname, (void*)(intptr_t)(aintval))
139 #define MTR_INSTANT(c, n) internal_mtr_raw_event(c, n, 'I', nullptr)
140 #define MTR_INSTANT_C(c, n, aname, astrval) internal_mtr_raw_event_arg(c, n, 'I', 0, MTR_ARG_TYPE_STRING_CONST, aname, (void *)(astrval))
141 #define MTR_INSTANT_I(c, n, aname, aintval) internal_mtr_raw_event_arg(c, n, 'I', 0, MTR_ARG_TYPE_INT, aname, (void *)(aintval))
144 #define MTR_COUNTER(c, n, val) internal_mtr_raw_event_arg(c, n, 'C', 0, MTR_ARG_TYPE_INT, n, (void *)(intptr_t)(val))
148 #define MTR_META_PROCESS_NAME(n) internal_mtr_raw_event_arg("", "process_name", 'M', 0, MTR_ARG_TYPE_STRING_COPY, "name", (void *)(n))
149 #define MTR_META_THREAD_NAME(n) internal_mtr_raw_event_arg("", "thread_name", 'M', 0, MTR_ARG_TYPE_STRING_COPY, "name", (void *)(n))
150 #define MTR_META_THREAD_SORT_INDEX(i) internal_mtr_raw_event_arg("", "thread_sort_index", 'M', 0, MTR_ARG_TYPE_INT, "sort_index", (void *)(i))
154 #define MTR_BEGIN(c, n)
155 #define MTR_END(c, n)
156 #define MTR_SCOPE(c, n)
157 #define MTR_START(c, n, id)
158 #define MTR_STEP(c, n, id, step)
159 #define MTR_FINISH(c, n, id)
160 #define MTR_FLOW_START(c, n, id)
161 #define MTR_FLOW_STEP(c, n, id, step)
162 #define MTR_FLOW_FINISH(c, n, id)
163 #define MTR_INSTANT(c, n)
165 #define MTR_BEGIN_C(c, n, aname, astrval)
166 #define MTR_END_C(c, n, aname, astrval)
167 #define MTR_SCOPE_C(c, n, aname, astrval)
169 #define MTR_BEGIN_S(c, n, aname, astrval)
170 #define MTR_END_S(c, n, aname, astrval)
171 #define MTR_SCOPE_S(c, n, aname, astrval)
173 #define MTR_BEGIN_I(c, n, aname, aintval)
174 #define MTR_END_I(c, n, aname, aintval)
175 #define MTR_SCOPE_I(c, n, aname, aintval)
177 #define MTR_INSTANT(c, n)
178 #define MTR_INSTANT_C(c, n, aname, astrval)
179 #define MTR_INSTANT_I(c, n, aname, aintval)
182 #define MTR_COUNTER(c, n, val)
186 #define MTR_META_PROCESS_NAME(n)
188 #define MTR_META_THREAD_NAME(n)
189 #define MTR_META_THREAD_SORT_INDEX(i)
195 #define MTR_BEGIN_FUNC() MTR_BEGIN(__FILE__, __FUNCTION__)
196 #define MTR_END_FUNC() MTR_END(__FILE__, __FUNCTION__)
197 #define MTR_SCOPE_FUNC() MTR_SCOPE(__FILE__, __FUNCTION__)
198 #define MTR_INSTANT_FUNC() MTR_INSTANT(__FILE__, __FUNCTION__)
199 #define MTR_SCOPE_FUNC_LIMIT_S(l) MTRScopedTraceLimit ____mtr_scope(__FILE__, __FUNCTION__, l)
200 #define MTR_SCOPE_FUNC_LIMIT_MS(l) MTRScopedTraceLimit ____mtr_scope(__FILE__, __FUNCTION__, (double)l * 0.000001)
203 #define MTR_BEGIN_FUNC_S(aname, arg) MTR_BEGIN_S(__FILE__, __FUNCTION__, aname, arg)
204 #define MTR_END_FUNC_S(aname, arg) MTR_END_S(__FILE__, __FUNCTION__, aname, arg)
205 #define MTR_SCOPE_FUNC_S(aname, arg) MTR_SCOPE_S(__FILE__, __FUNCTION__, aname, arg)
207 #define MTR_BEGIN_FUNC_C(aname, arg) MTR_BEGIN_C(__FILE__, __FUNCTION__, aname, arg)
208 #define MTR_END_FUNC_C(aname, arg) MTR_END_C(__FILE__, __FUNCTION__, aname, arg)
209 #define MTR_SCOPE_FUNC_C(aname, arg) MTR_SCOPE_C(__FILE__, __FUNCTION__, aname, arg)
211 #define MTR_BEGIN_FUNC_I(aname, arg) MTR_BEGIN_I(__FILE__, __FUNCTION__, aname, arg)
212 #define MTR_END_FUNC_I(aname, arg) MTR_END_I(__FILE__, __FUNCTION__, aname, arg)
213 #define MTR_SCOPE_FUNC_I(aname, arg) MTR_SCOPE_I(__FILE__, __FUNCTION__, aname, arg)
220 class MTRScopedTrace {
222 MTRScopedTrace(
const char *
category,
const char *name)
223 : category_(
category), name_(name) {
231 const char *category_;
238 class MTRScopedTraceLimit {
240 MTRScopedTraceLimit(
const char *
category,
const char *name,
double limit_s)
241 : category_(
category), name_(name), limit_(limit_s) {
244 ~MTRScopedTraceLimit() {
246 if (end_time - start_time_ >= limit_) {
252 const char *category_;
258 class MTRScopedTraceArg {
260 MTRScopedTraceArg(
const char *
category,
const char *name,
mtr_arg_type arg_type,
const char *arg_name,
void *arg_value)
261 : category_(
category), name_(name) {
264 ~MTRScopedTraceArg() {
269 const char *category_;
MINITRACE_EXPORT void mtr_start(void)
MINITRACE_EXPORT void mtr_register_sigint_handler(void)
MINITRACE_EXPORT void internal_mtr_raw_event_arg(const char *category, const char *name, char ph, void *id, mtr_arg_type arg_type, const char *arg_name, void *arg_value)
constexpr lexy::code_point::general_category_t category[]
MINITRACE_EXPORT void internal_mtr_raw_event(const char *category, const char *name, char ph, void *id)
MINITRACE_EXPORT void mtr_init(const char *json_file)
MINITRACE_EXPORT void mtr_init_from_stream(void *stream)
MINITRACE_EXPORT void mtr_flush(void)
MINITRACE_EXPORT void mtr_shutdown(void)
@ MTR_ARG_TYPE_STRING_COPY
MINITRACE_EXPORT void mtr_stop(void)
@ MTR_ARG_TYPE_STRING_CONST
MINITRACE_EXPORT double mtr_time_s(void)
const MINITRACE_EXPORT char * mtr_pool_string(const char *str)