#ifndef __DISPATCH_SHIMS_PERFMON__
#define __DISPATCH_SHIMS_PERFMON__
#if DISPATCH_PERF_MON
#if DISPATCH_INTROSPECTION
#error invalid configuration
#endif
typedef enum {
perfmon_thread_no_trace = 0,
perfmon_thread_event_no_steal, perfmon_thread_event_steal, perfmon_thread_worker_non_oc, perfmon_thread_worker_oc, perfmon_thread_manager,
} perfmon_thread_type;
DISPATCH_ALWAYS_INLINE
static inline void
_dispatch_perfmon_workitem_inc(void)
{
unsigned long cnt;
cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
_dispatch_thread_setspecific(dispatch_bcounter_key, (void *)++cnt);
}
DISPATCH_ALWAYS_INLINE
static inline void
_dispatch_perfmon_workitem_dec(void)
{
unsigned long cnt;
cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
_dispatch_thread_setspecific(dispatch_bcounter_key, (void *)--cnt);
}
#define DISPATCH_PERF_MON_ARGS_PROTO , uint64_t perfmon_start
#define DISPATCH_PERF_MON_ARGS , perfmon_start
#define DISPATCH_PERF_MON_VAR uint64_t perfmon_start;
#define DISPATCH_PERF_MON_VAR_INIT uint64_t perfmon_start = 0;
#define _dispatch_perfmon_start_impl(trace) ({ \
if (trace) _dispatch_ktrace0(DISPATCH_PERF_MON_worker_thread_start); \
perfmon_start = _dispatch_uptime(); \
})
#define _dispatch_perfmon_start() \
DISPATCH_PERF_MON_VAR _dispatch_perfmon_start_impl(true)
#define _dispatch_perfmon_start_notrace() \
DISPATCH_PERF_MON_VAR _dispatch_perfmon_start_impl(false)
#define _dispatch_perfmon_end(thread_type) \
_dispatch_queue_merge_stats(perfmon_start, true, thread_type)
#define _dispatch_perfmon_end_notrace() \
_dispatch_queue_merge_stats(perfmon_start, false, perfmon_thread_no_trace)
void _dispatch_queue_merge_stats(uint64_t start, bool trace, perfmon_thread_type type);
#else
#define DISPATCH_PERF_MON_ARGS_PROTO
#define DISPATCH_PERF_MON_ARGS
#define DISPATCH_PERF_MON_VAR
#define DISPATCH_PERF_MON_VAR_INIT
#define _dispatch_perfmon_workitem_inc()
#define _dispatch_perfmon_workitem_dec()
#define _dispatch_perfmon_start_impl(trace)
#define _dispatch_perfmon_start()
#define _dispatch_perfmon_end(thread_type)
#define _dispatch_perfmon_start_notrace()
#define _dispatch_perfmon_end_notrace()
#endif // DISPATCH_PERF_MON
#endif