From fdbc86eeaf9068bcd6844f8547f628aa14e14900 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Fri, 18 Sep 2020 10:27:57 -0400 Subject: [PATCH 1/3] default to USE_PERF_JITEVENTS=1 --- Make.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Make.inc b/Make.inc index df2e522cad09f..46a339fe8f42e 100644 --- a/Make.inc +++ b/Make.inc @@ -82,7 +82,7 @@ endif USE_OPROFILE_JITEVENTS ?= 0 # Set to 1 to enable profiling with perf -USE_PERF_JITEVENTS ?= 0 +USE_PERF_JITEVENTS ?= 1 # assume we don't have LIBSSP support in our compiler, will enable later if likely true HAVE_SSP := 0 From fdfac757dfff129eb92a731ddd5b668700541cca Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 21 Sep 2020 08:20:31 -0400 Subject: [PATCH 2/3] allow users to enable GDB JIT integration on release builds --- doc/src/manual/environment-variables.md | 6 ++++++ src/codegen.cpp | 7 +++---- src/init.c | 11 +++++++++++ src/julia_internal.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/src/manual/environment-variables.md b/doc/src/manual/environment-variables.md index 75079107ea6da..76016017d3ad3 100644 --- a/doc/src/manual/environment-variables.md +++ b/doc/src/manual/environment-variables.md @@ -314,6 +314,12 @@ event listener for just-in-time (JIT) profiling. * [OProfile](http://oprofile.sourceforge.net/news/) (`USE_OPROFILE_JITEVENTS` set to `1` in the build configuration). +### `ENABLE_GDBLISTENER` + +If set to anything besides `0` enables GDB registration of Julia code on release builds. +On debug builds of Julia this is always enabled. Recommended to use with `-g 2`. + + ### `JULIA_LLVM_ARGS` Arguments to be passed to the LLVM backend. diff --git a/src/codegen.cpp b/src/codegen.cpp index 01f4b0086e8bf..be9aaf075858f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7728,10 +7728,9 @@ extern "C" void jl_init_llvm(void) std::string DL = jl_data_layout.getStringRepresentation() + "-ni:10:11:12:13"; jl_data_layout.reset(DL); -// Register GDB event listener -#ifdef JL_DEBUG_BUILD - jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createGDBRegistrationListener()); -#endif + // Register GDB event listener + if(jl_using_gdb_jitevents) + jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createGDBRegistrationListener()); #ifdef JL_USE_INTEL_JITEVENTS if (jl_using_intel_jitevents) diff --git a/src/init.c b/src/init.c index 752db74e691d1..9f54a3ffa8928 100644 --- a/src/init.c +++ b/src/init.c @@ -436,6 +436,8 @@ char jl_using_oprofile_jitevents = 0; // Non-zero if running under OProfile char jl_using_perf_jitevents = 0; #endif +char jl_using_gdb_jitevents = 0; + int isabspath(const char *in) JL_NOTSAFEPOINT { #ifdef _OS_WINDOWS_ @@ -692,6 +694,15 @@ void _julia_init(JL_IMAGE_SEARCH rel) } #endif +#if defined(JL_DEBUG_BUILD) + jl_using_gdb_jitevents = 1; +# else + const char *jit_gdb = getenv("ENABLE_GDBLISTENER"); + if (jit_gdb && atoi(jit_gdb)) { + jl_using_gdb_jitevents = 1; + } +#endif + if ((jl_options.outputo || jl_options.outputbc || jl_options.outputasm) && (jl_options.code_coverage || jl_options.malloc_log)) { jl_error("cannot generate code-coverage or track allocation information while generating a .o, .bc, or .s output file"); diff --git a/src/julia_internal.h b/src/julia_internal.h index 79079504c9bba..85774c745ed9b 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -595,6 +595,7 @@ extern char jl_using_oprofile_jitevents; #ifdef JL_USE_PERF_JITEVENTS extern char jl_using_perf_jitevents; #endif +extern char jl_using_gdb_jitevents; extern size_t jl_arr_xtralloc_limit; // -- init.c -- // From b2220ed2e074b00621693964df13b549e1ad6154 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 21 Sep 2020 12:25:28 -0400 Subject: [PATCH 3/3] Update perf docs a bit --- doc/src/manual/environment-variables.md | 2 ++ doc/src/manual/profile.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/src/manual/environment-variables.md b/doc/src/manual/environment-variables.md index 76016017d3ad3..bdf173453bb4e 100644 --- a/doc/src/manual/environment-variables.md +++ b/doc/src/manual/environment-variables.md @@ -313,6 +313,8 @@ event listener for just-in-time (JIT) profiling. (`USE_INTEL_JITEVENTS` set to `1` in the build configuration), or * [OProfile](http://oprofile.sourceforge.net/news/) (`USE_OPROFILE_JITEVENTS` set to `1` in the build configuration). + * [Perf](https://perf.wiki.kernel.org) (`USE_PERF_JITEVENTS` set to `1` + in the build configuration). This integration is enabled by default. ### `ENABLE_GDBLISTENER` diff --git a/doc/src/manual/profile.md b/doc/src/manual/profile.md index e9bf79016887a..8afadf959dbf1 100644 --- a/doc/src/manual/profile.md +++ b/doc/src/manual/profile.md @@ -342,7 +342,8 @@ Or similary with `perf` : ``` $ ENABLE_JITPROFILING=1 perf record -o /tmp/perf.data --call-graph dwarf ./julia /test/fastmath.jl -$ perf report --call-graph -G +$ perf inject --jit --input /tmp/perf.data --output /tmp/perf-jit.data +$ perf report --call-graph -G -i /tmp/perf-jit.data ``` There are many more interesting things that you can measure about your program, to get a comprehensive list