Skip to content

Commit

Permalink
trace-compile: color recompilation yellow (#55763)
Browse files Browse the repository at this point in the history
Marks recompilation of a method that produced a `precompile` statement
as yellow, or if color isn't supported adds a trailing comment: `#
recompilation`.

The coloring matches the `@time_imports` coloring. i.e. an excerpt of
```
% ./julia --start=no --trace-compile=stderr --trace-compile-timing -e "using InteractiveUtils; @time @time_imports using Plots"
```
![Screenshot 2024-09-13 at 5 04
24 PM](https://github.com/user-attachments/assets/85bd99e0-586e-4070-994f-2d845be0d9e7)
  • Loading branch information
IanButterworth authored Sep 16, 2024
1 parent 753296e commit 5aad761
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ variables. ([#53742]).
* `--project=@temp` starts Julia with a temporary environment.
* New `--trace-compile-timing` option to report how long each method reported by `--trace-compile` took
to compile, in ms. ([#54662])
* `--trace-compile` now prints recompiled methods in yellow or with a trailing comment if color is not supported ([#55763])

Multi-threading changes
-----------------------
Expand Down
3 changes: 2 additions & 1 deletion doc/man/julia.1
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ Generate an incremental output file (rather than complete)

.TP
--trace-compile={stderr|name}
Print precompile statements for methods compiled during execution or save to a path
Print precompile statements for methods compiled during execution or save to stderr or a path.
Methods that were recompiled are printed in yellow or with a trailing comment if color is not supported

.TP
--trace-compile-timing=
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/command-line-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ The following is a complete list of command-line switches available when launchi
|`--output-bc <name>` |Generate LLVM bitcode (.bc)|
|`--output-asm <name>` |Generate an assembly file (.s)|
|`--output-incremental={yes\|no*}` |Generate an incremental output file (rather than complete)|
|`--trace-compile={stderr\|name}` |Print precompile statements for methods compiled during execution or save to a path|
|`--trace-compile={stderr\|name}` |Print precompile statements for methods compiled during execution or save to stderr or a path. Methods that were recompiled are printed in yellow or with a trailing comment if color is not supported|
|`--trace-compile-timing` |If --trace-compile is enabled show how long each took to compile in ms|
|`--image-codegen` |Force generate code in imaging mode|
|`--permalloc-pkgimg={yes\|no*}` |Copy the data section of package images into memory|
Expand Down
21 changes: 16 additions & 5 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ jl_code_instance_t *jl_method_inferred_with_abi(jl_method_instance_t *mi JL_PROP

jl_mutex_t precomp_statement_out_lock;

static void record_precompile_statement(jl_method_instance_t *mi, double compilation_time)
static void record_precompile_statement(jl_method_instance_t *mi, double compilation_time, int is_recompile)
{
static ios_t f_precompile;
static JL_STREAM* s_precompile = NULL;
Expand All @@ -2539,11 +2539,22 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila
}
}
if (!jl_has_free_typevars(mi->specTypes)) {
if (is_recompile && s_precompile == JL_STDERR && jl_options.color != JL_OPTIONS_COLOR_OFF)
jl_printf(s_precompile, "\e[33m");
if (jl_options.trace_compile_timing)
jl_printf(s_precompile, "#= %6.1f ms =# ", compilation_time / 1e6);
jl_printf(s_precompile, "precompile(");
jl_static_show(s_precompile, mi->specTypes);
jl_printf(s_precompile, ")\n");
jl_printf(s_precompile, ")");
if (is_recompile) {
if (s_precompile == JL_STDERR && jl_options.color != JL_OPTIONS_COLOR_OFF) {
jl_printf(s_precompile, "\e[0m");
}
else {
jl_printf(s_precompile, " # recompile");
}
}
jl_printf(s_precompile, "\n");
if (s_precompile != JL_STDERR)
ios_flush(&f_precompile);
}
Expand Down Expand Up @@ -2674,7 +2685,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
// unspec is probably not specsig, but might be using specptr
jl_atomic_store_relaxed(&codeinst->specsigflags, specsigflags & ~0b1); // clear specsig flag
jl_mi_cache_insert(mi, codeinst);
record_precompile_statement(mi, 0);
record_precompile_statement(mi, 0, 0);
return codeinst;
}
}
Expand All @@ -2691,7 +2702,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
0, 1, ~(size_t)0, 0, jl_nothing, 0, NULL);
jl_atomic_store_release(&codeinst->invoke, jl_fptr_interpret_call);
jl_mi_cache_insert(mi, codeinst);
record_precompile_statement(mi, 0);
record_precompile_statement(mi, 0, 0);
return codeinst;
}
if (compile_option == JL_OPTIONS_COMPILE_OFF) {
Expand Down Expand Up @@ -2740,7 +2751,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
codeinst = NULL;
}
else if (did_compile && codeinst->owner == jl_nothing) {
record_precompile_statement(mi, compile_time);
record_precompile_statement(mi, compile_time, is_recompile);
}
JL_GC_POP();
}
Expand Down
4 changes: 3 additions & 1 deletion src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ static const char opts_hidden[] =
" --output-incremental={yes|no*} Generate an incremental output file (rather than\n"
" complete)\n"
" --trace-compile={stderr|name} Print precompile statements for methods compiled\n"
" during execution or save to a path\n"
" during execution or save to stderr or a path. Methods that\n"
" were recompiled are printed in yellow or with a trailing\n"
" comment if color is not supported\n"
" --trace-compile-timing If --trace-compile is enabled show how long each took to\n"
" compile in ms\n"
" --image-codegen Force generate code in imaging mode\n"
Expand Down

0 comments on commit 5aad761

Please sign in to comment.