@@ -202,10 +202,20 @@ bool _o2_lock_free_stack_push(_o2_lock_free_stack& stack, const int& value, bool
202202bool _o2_lock_free_stack_pop (_o2_lock_free_stack& stack, int & value, bool spin = false );
203203void * _o2_log_create (char const * name, int stacktrace);
204204void _o2_signpost_event_emit (_o2_log_t * log, _o2_signpost_id_t id, char const * name, char const * const format, ...);
205+ void _o2_singpost_action (_o2_log_t * log, void (*callback)(void *));
205206void _o2_signpost_interval_begin (_o2_log_t * log, _o2_signpost_id_t id, char const * name, char const * const format, ...);
206207void _o2_signpost_interval_end (_o2_log_t * log, _o2_signpost_id_t id, char const * name, char const * const format, ...);
207208void _o2_log_set_stacktrace (_o2_log_t * log, int stacktrace);
208209
210+ // Helper to invoke a callback when the signpost is enabled. The callback
211+ // gets passed some previously stored context (nullptr for now).
212+ // TODO: I use a separate function because in the future this might change and I might
213+ // allow to store some context as part of the activity.
214+ inline void _o2_signpost_action (_o2_log_t * log, void (*callback)(void *))
215+ {
216+ callback (nullptr );
217+ }
218+
209219// This generates a unique id for a signpost. Do not use this directly, use O2_SIGNPOST_ID_GENERATE instead.
210220// Notice that this is only valid on a given computer.
211221// This is guaranteed to be unique at 5 GHz for at least 63 years, if my math is correct.
@@ -488,6 +498,17 @@ void o2_debug_log_set_stacktrace(_o2_log_t* log, int stacktrace)
488498})
489499#define O2_SIGNPOST_ID_FROM_POINTER (name, log, pointer ) _o2_signpost_id_t name = _o2_signpost_id_make_with_pointer(private_o2_log_##log, pointer)
490500#define O2_SIGNPOST_ID_GENERATE (name, log ) _o2_signpost_id_t name = _o2_signpost_id_generate_local(private_o2_log_##log)
501+
502+ // Execute the provided callback if the log is enabled. Useful e.g. to dump IgProf profiles
503+ // only if the signpost is enabled or to add remote telemetry for certain events.
504+ #define O2_SIGNPOST_ACTION (log, callback ) __extension__({ \
505+ if (O2_BUILTIN_UNLIKELY (O2_SIGNPOST_ENABLED_MAC (log))) { \
506+ _o2_signpost_action (private_o2_log_##log, callback); \
507+ } else if (O2_BUILTIN_UNLIKELY (private_o2_log_##log->stacktrace )) { \
508+ _o2_signpost_action (private_o2_log_##log, callback); \
509+ } \
510+ })
511+
491512// In case Instruments is attached, we switch to the Apple signpost API otherwise, both one
492513// mac and on linux we use our own implementation, using the logger. We can use the same ids because
493514// they are compatible between the two implementations, we also use remove_engineering_type to remove
0 commit comments