@@ -78,6 +78,9 @@ extern uint32_t jl_timing_print_limit;
7878#define jl_timing_block_exit_task (ct , ptls ) ((jl_timing_block_t *)NULL)
7979#define jl_pop_timing_block (blk )
8080
81+ #define jl_timing_counter_inc (counter , value )
82+ #define jl_timing_counter_dec (counter , value )
83+
8184#define jl_profile_lock_init (lock , name )
8285#define jl_profile_lock_start_wait (lock )
8386#define jl_profile_lock_acquired (lock )
@@ -181,6 +184,10 @@ void jl_timing_puts(jl_timing_block_t *cur_block, const char *str);
181184 X(NATIVE_Create) \
182185
183186
187+ #define JL_TIMING_COUNTERS \
188+ X(Invalidations) \
189+
190+
184191enum jl_timing_owners {
185192#define X(name) JL_TIMING_ ## name,
186193 JL_TIMING_OWNERS
@@ -195,6 +202,13 @@ enum jl_timing_events {
195202 JL_TIMING_EVENT_LAST
196203};
197204
205+ enum jl_timing_counter_types {
206+ #define X(name) JL_TIMING_COUNTER_ ## name,
207+ JL_TIMING_COUNTERS
208+ #undef X
209+ JL_TIMING_COUNTER_LAST
210+ };
211+
198212/**
199213 * Timing back-ends differ in terms of whether they support nested
200214 * and asynchronous events.
@@ -404,6 +418,44 @@ struct jl_timing_suspend_cpp_t {
404418 _jl_timing_suspend_ctor(&__timing_suspend, #subsystem, ct)
405419#endif
406420
421+ // Counting
422+ #ifdef USE_ITTAPI
423+ #define _ITTAPI_COUNTER_MEMBER __itt_counter ittapi_counter;
424+ #else
425+ #define _ITTAPI_COUNTER_MEMBER
426+ #endif
427+
428+ #ifdef USE_TIMING_COUNTS
429+ #define _COUNTS_MEMBER _Atomic(uint64_t) basic_counter;
430+ #else
431+ #define _COUNTS_MEMBER
432+ #endif
433+
434+ typedef struct {
435+ _ITTAPI_COUNTER_MEMBER
436+ _COUNTS_MEMBER
437+ } jl_timing_counter_t ;
438+
439+ JL_DLLEXPORT extern jl_timing_counter_t jl_timing_counters [JL_TIMING_COUNTER_LAST ];
440+
441+ static inline void jl_timing_counter_inc (int counter , uint64_t val ) JL_NOTSAFEPOINT {
442+ #ifdef USE_ITTAPI
443+ __itt_counter_inc_delta (jl_timing_counters [counter ].ittapi_counter , val );
444+ #endif
445+ #ifdef USE_TIMING_COUNTS
446+ jl_atomic_fetch_add_relaxed (& jl_timing_counters [counter ].basic_counter , val );
447+ #endif
448+ }
449+
450+ static inline void jl_timing_counter_dec (int counter , uint64_t val ) JL_NOTSAFEPOINT {
451+ #ifdef USE_ITTAPI
452+ __itt_counter_dec_delta (jl_timing_counters [counter ].ittapi_counter , val );
453+ #endif
454+ #ifdef USE_TIMING_COUNTS
455+ jl_atomic_fetch_add_relaxed (& jl_timing_counters [counter ].basic_counter , - (int64_t )val );
456+ #endif
457+ }
458+
407459// Locking profiling
408460static inline void jl_profile_lock_init (jl_mutex_t * lock , const char * name ) {
409461#ifdef USE_ITTAPI
0 commit comments