Skip to content

Commit

Permalink
Add per-method record of time spent in generic lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
kpamnany committed Nov 23, 2023
1 parent d50bfd2 commit 0999d36
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2933,14 +2933,19 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
JL_DLLEXPORT jl_value_t *jl_apply_generic(jl_value_t *F, jl_value_t **args, uint32_t nargs)
{
size_t world = jl_current_task->world_age;
#ifdef JL_DISPATCH_LOG_BOXES
uint64_t t0 = jl_hrtime();
#endif
jl_method_instance_t *mfunc = jl_lookup_generic_(F, args, nargs,
jl_int32hash_fast(jl_return_address()),
world);
JL_GC_PROMISE_ROOTED(mfunc);

#ifdef JL_DISPATCH_LOG_BOXES
jl_method_t *def = mfunc->def.method;
if (jl_is_method(def)) {
def->num_dynamic_dispatches++;
def->dynamic_dispatch_ns += (jl_hrtime() - t0);
}
#endif
return _jl_invoke(F, args, nargs, mfunc, world);
Expand All @@ -2951,12 +2956,21 @@ JL_DLLEXPORT uint64_t jl_get_num_dynamic_dispatches(jl_method_t *m)
{
return m->num_dynamic_dispatches;
}
JL_DLLEXPORT uint64_t jl_get_dynamic_dispatch_ns(jl_method_t *m)
{
return m->dynamic_dispatch_ns;
}
#else
JL_DLLEXPORT uint64_t jl_get_num_dynamic_dispatches(jl_method_t *m)
{
jl_error("not logging");
return 0;
}
JL_DLLEXPORT uint64_t jl_get_dynamic_dispatch_ns(jl_method_t *m)
{
jl_error("not logging");
return 0;
}
#endif

static jl_method_match_t *_gf_invoke_lookup(jl_value_t *types JL_PROPAGATES_ROOT, jl_value_t *mt, size_t world, size_t *min_valid, size_t *max_valid)
Expand Down
10 changes: 6 additions & 4 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_method_type =
jl_new_datatype(jl_symbol("Method"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(30,
jl_perm_symsvec(31,
"name",
"module",
"file",
Expand Down Expand Up @@ -2630,8 +2630,9 @@ void jl_init_types(void) JL_GC_DISABLED
"is_for_opaque_closure",
"constprop",
"purity",
"num_dynamic_dispatches"),
jl_svec(30,
"num_dynamic_dispatches",
"dynamic_dispatch_ns"),
jl_svec(31,
jl_symbol_type,
jl_module_type,
jl_symbol_type,
Expand Down Expand Up @@ -2661,7 +2662,8 @@ void jl_init_types(void) JL_GC_DISABLED
jl_bool_type,
jl_uint8_type,
jl_uint8_type,
jl_int32_type),
jl_int32_type,
jl_uint64_type),
jl_emptysvec,
0, 1, 10);
//const static uint32_t method_constfields[1] = { 0x03fc065f }; // (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<9)|(1<<10)|(1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)|(1<<25);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ typedef struct _jl_method_t {
_jl_purity_overrides_t purity;

uint32_t num_dynamic_dispatches;
uint64_t dynamic_dispatch_ns;

// hidden fields:
// lock for modifications to the method
Expand Down
1 change: 1 addition & 0 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module)
m->constprop = 0;
#ifdef JL_DISPATCH_LOG_BOXES
m->num_dynamic_dispatches = 0;
m->dynamic_dispatch_ns = 0;
#endif
JL_MUTEX_INIT(&m->writelock);
return m;
Expand Down

0 comments on commit 0999d36

Please sign in to comment.