Skip to content

Commit

Permalink
Enable a way to globally enable/disable COZ tracepoints
Browse files Browse the repository at this point in the history
It can be useful to leave coz tracepoints committed in the code but only
conditionally enable coz.
  • Loading branch information
vlovich committed Oct 21, 2022
1 parent dbda214 commit 38a4721
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/coz.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
#if !defined(COZ_H)
#define COZ_H

/// Embedders can define COZ_ENABLED explicitly to 1 or 0 to globally to
/// enable/disable coz tracepoints at build time without needing to modify code.
/// If set to 0 before including this header for the first time, all macros
/// become noops. This is useful to commit coz tracepoints into a codebase but
/// not require linking against the coz runtime and not having any code bloat
/// nor runtime overhead from using the macros.
#ifndef COZ_ENABLED
#define COZ_ENABLED 1
#endif

#if COZ_ENABLED

#ifndef __USE_GNU
# define __USE_GNU
#endif
Expand Down Expand Up @@ -184,4 +196,17 @@ static void _call_coz_wake_other() {
}
#endif

#else

#define _COZ_NOOP() do {} while(0)
#define COZ_PROGRESS_NAMED(name) _COZ_NOOP()
#define COZ_PROGRESS() _COZ_NOOP()
#define COZ_BEGIN(name) _COZ_NOOP()
#define COZ_END(name) _COZ_NOOP()
#define COZ_PRE_BLOCK() _COZ_NOOP()
#define COZ_POST_BLOCK(skip_delay) _COZ_NOOP()
#define COZ_WAKE_OTHER() _COZ_NOOP()

#endif

#endif

0 comments on commit 38a4721

Please sign in to comment.