diff --git a/Project.toml b/Project.toml index fb9d125..71043a9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,3 +1,4 @@ [deps] DocOpt = "968ba79b-81e4-546f-ab3a-2eecfa62a9db" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..4777be1 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,4 @@ +VTUNE_DIR := /opt/intel/oneapi/vtune/latest + +itt.so: itt.c + gcc -shared -fPIC $< -I$(VTUNE_DIR)/include -L$(VTUNE_DIR)/lib64 -l:libittnotify.a -o $@ diff --git a/lib/itt.c b/lib/itt.c new file mode 100644 index 0000000..1d22b2d --- /dev/null +++ b/lib/itt.c @@ -0,0 +1,17 @@ +#include + +__itt_domain* gc_domain = 0; +__itt_string_handle* handle_main = 0; + +void init() { + gc_domain = __itt_domain_create("org.julialang.gc"); + handle_main = __itt_string_handle_create("collect"); +} + +void gc_begin() { + __itt_task_begin(gc_domain, __itt_null, __itt_null, handle_main); +} + +void gc_end() { + __itt_task_end(gc_domain); +} diff --git a/utils.jl b/utils.jl index 93a32cb..c971b75 100644 --- a/utils.jl +++ b/utils.jl @@ -2,6 +2,24 @@ using Pkg Pkg.instantiate() # It is dumb that I have to do this using Serialization +module ITT + import Libdl + const GC_LIB = joinpath(@__DIR__, "lib/itt.so") + + function __init__() + lib = Libdl.dlopen(GC_LIB) + sym_init = Libdl.dlsym(lib, :init) + sym_begin = Libdl.dlsym(lib, :gc_begin) + sym_end = Libdl.dlsym(lib, :gc_end) + + ccall(sym_init, Cvoid, ()) + ccall(:jl_gc_set_cb_pre_gc, Cvoid, (Ptr{Cvoid}, Cint), + sym_begin, true) + ccall(:jl_gc_set_cb_post_gc, Cvoid, (Ptr{Cvoid}, Cint), + sym_end, true) + end +end + macro gctime(ex) fc = isdefined(Base.Experimental, Symbol("@force_compile")) ? :(Base.Experimental.@force_compile) :