Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: instrument julia to get per-method-instance llvm optimization timings #31616

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,19 @@ function which(m::Module, s::Symbol)
return binding_module(m, s)
end

"""
which(tt::TupleType)
"""
function which(tt::Type{Tuple})
m = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), tt, typemax(UInt))
if m === nothing
error("no unique matching method found for the specified signature")
end
return m.func::Method
end



# function reflection
"""
nameof(f::Function) -> Symbol
Expand Down
5 changes: 4 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ SRCS += anticodegen
LLVM_LIBS := support
endif

uprobes.h : uprobes.d
dtrace -h -s uprobes.d

# headers are used for dependency tracking, while public headers will be part of the dist
UV_HEADERS :=
HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h tls.h locks.h atomics.h julia_internal.h options.h timing.h)
HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h uprobes.h julia_assert.h julia_threads.h tls.h locks.h atomics.h julia_internal.h options.h timing.h)
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h tls.h locks.h atomics.h julia_gcext.h)
ifeq ($(USE_SYSTEM_LIBUV),0)
UV_HEADERS += uv.h
Expand Down
31 changes: 31 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ using namespace llvm;
#include "processor.h"
#include "julia_assert.h"

#include "uprobes.h"

// LLVM version compatibility macros
legacy::PassManager *jl_globalPM;

Expand Down Expand Up @@ -1040,6 +1042,32 @@ const char *name_from_method_instance(jl_method_instance_t *mi)
return jl_is_method(mi->def.method) ? jl_symbol_name(mi->def.method->name) : "top-level scope";
}

struct CompileTiming {
CompileTiming(jl_method_instance_t *mi) :mi(mi) {
if (jl_is_method(mi->def.method)) {
JULIA_COMPILE_START();
}
}
~CompileTiming() {
if (jl_is_method(mi->def.method)) {
ios_t str_;
ios_mem(&str_, 300);
JL_STREAM* str = (JL_STREAM*)&str_;

//jl_printf(str, "%s.%s, ", jl_symbol_name(mi->def.method->module->name), jl_symbol_name(mi->def.method->name));

//jl_static_show_func_sig(str, mi->specTypes);
jl_static_show(str, mi->specTypes);

str_.buf[str_.size] = 0;
JULIA_COMPILE_END(str_.buf);

ios_close(&str_);
}
}
jl_method_instance_t *mi;
};

// this generates llvm code for the lambda info
// and adds the result to the jitlayers
// (and the shadow module), but doesn't yet compile
Expand Down Expand Up @@ -1080,6 +1108,9 @@ jl_code_instance_t *jl_compile_linfo(jl_method_instance_t *mi, jl_code_info_t *s

// Codegen lock held in this block
{
// Instrument the time spent in this block for this method instance
CompileTiming _c(mi);

// Step 1: Re-check if this was already compiled (it may have been while
// we waited at the lock).
if (!jl_is_method(mi->def.method)) {
Expand Down
2 changes: 1 addition & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
// #define OBJPROFILE

// Automatic Instrumenting Profiler
//#define ENABLE_TIMINGS
#define ENABLE_TIMINGS


// method dispatch profiling --------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/uprobes.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider julia {
probe compile__start();
probe compile__end(char*);
};