JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.87k stars 5.49k forks source link

Generate machine readable output from ENABLE_TIMINGS? #36447

Open NHDaly opened 4 years ago

NHDaly commented 4 years ago

Can we modify ENABLE_TIMINGS to generate machine readable output, rather than dumping to stdout?

It would be really nice if we could start tracking these metrics in our build farm so we can track growth in our compilation time over time! :)


Ideally, it would be great if this kind of breakdown of timings was more accessible in julia itself, on an ad-hoc basic like @time, etc, but as a first step just being able to dump these logs to a CSV would be a nice incremental win.

rbvermaa commented 4 years ago

Previously, I used a hack, where I exposed the print_timings to julia and parsed the stderr output.

function timing()
    s = ""
    mktemp() do tmp, io
        try
            redirect_stderr(io) do
                ccall(:jl_print_timings, Cvoid, ())
            end
            s = read(tmp, String)
        catch
        end
    end
    lines = split(strip(s), '\n')
    res = Dict{String, Int64}()
    length(s) == 0 && return res

    for l in map(split, lines)
        res[l[1]] = parse(Int64, l[5])
    end
    res
end

However, would it be possible to just expose the jl_timing_data and jl_timing_names somehow directly in julia?

NHDaly commented 4 years ago

Also also, it would be amazing if we could toggle this as a startup option, rather than as a compile-time option when building julia!

NHDaly commented 3 years ago

Since julia often spawns several processes in the course of a given run (e.g. to precompile a package module), any given run may emit several separate traces from ENABLE_TIMINGS. In order to not clobber each other, this setting could save the results to a filename that includes the name of the current julia process, much like how --track-allocation behaves :)