Skip to content

Commit ed12565

Browse files
committed
Count invalidations
1 parent 09adbe3 commit ed12565

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/gf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ static void do_nothing_with_codeinst(jl_code_instance_t *ci) {}
16421642
// recursively invalidate cached methods that had an edge to a replaced method
16431643
static void invalidate_method_instance(void (*f)(jl_code_instance_t*), jl_method_instance_t *replaced, size_t max_world, int depth)
16441644
{
1645+
jl_timing_counter_inc(JL_TIMING_COUNTER_Invalidations, 1);
16451646
if (_jl_debug_method_invalidation) {
16461647
jl_value_t *boxeddepth = NULL;
16471648
JL_GC_PUSH1(&boxeddepth);

src/timing.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const char *jl_timing_names[(int)JL_TIMING_LAST] =
4848
#undef X
4949
};
5050

51+
JL_DLLEXPORT jl_timing_counter_t jl_timing_counters[JL_TIMING_COUNTER_LAST];
52+
5153
#ifdef USE_ITTAPI
5254
JL_DLLEXPORT __itt_event jl_timing_ittapi_events[(int)JL_TIMING_EVENT_LAST];
5355
#endif
@@ -60,11 +62,22 @@ void jl_print_timings(void)
6062
root_time -= jl_timing_counts[i];
6163
}
6264
jl_timing_counts[0] = root_time;
65+
fprintf(stderr, "\nJULIA TIMINGS\n");
6366
for (int i = 0; i < JL_TIMING_LAST; i++) {
6467
if (jl_timing_counts[i] != 0)
6568
fprintf(stderr, "%-25s : %5.2f %% %" PRIu64 "\n", jl_timing_names[i],
6669
100 * (((double)jl_timing_counts[i]) / total_time), jl_timing_counts[i]);
6770
}
71+
72+
fprintf(stderr, "\nJULIA COUNTERS\n");
73+
uint64_t val = 0;
74+
#ifdef USE_TIMING_COUNTS
75+
#define X(name) val = jl_atomic_load_relaxed(&jl_timing_counters[(int)JL_TIMING_COUNTER_##name].basic_counter); \
76+
if (val != 0) \
77+
fprintf(stderr, "%-25s : %" PRIu64 "\n", #name, val);
78+
JL_TIMING_COUNTERS
79+
#undef X
80+
#endif
6881
}
6982

7083
void jl_init_timing(void)
@@ -78,6 +91,10 @@ void jl_init_timing(void)
7891
#ifdef USE_ITTAPI
7992
#define X(name) jl_timing_ittapi_events[i++] = __itt_event_create(#name, strlen(#name));
8093
JL_TIMING_EVENTS
94+
#undef X
95+
i = 0;
96+
#define X(name) jl_timing_counters[i++].ittapi_counter = __itt_counter_create(#name, "julia.runtime");
97+
JL_TIMING_COUNTERS
8198
#undef X
8299
#endif
83100
}

src/timing.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
184191
enum 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
408460
static inline void jl_profile_lock_init(jl_mutex_t *lock, const char *name) {
409461
#ifdef USE_ITTAPI

0 commit comments

Comments
 (0)