Skip to content

Commit

Permalink
Stop using deprecated JLLWrappers methods (#141)
Browse files Browse the repository at this point in the history
Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Tim Besard <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent 8002f33 commit 07aee48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 58 deletions.
106 changes: 53 additions & 53 deletions src/BugReporting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ end
function rr_pack(trace_directory)
check_rr_available()

rr() do rr_path
for dir in collect_inner_traces(trace_directory)
@debug("rr pack'ing $(dir)")
output = read(`$rr_path pack $(dir)`, String)
isempty(output) || print(output)
end
for dir in collect_inner_traces(trace_directory)
@debug("rr pack'ing $(dir)")
output = readchomp(`$(rr()) pack $(dir)`)
isempty(output) || print(output)
end
end

Expand All @@ -134,9 +132,7 @@ function compress_trace(trace_directory::String, output_file::String)
rr_pack(trace_directory)

# Start up our `zstdmt` process to write out to that file
proc = zstdmt() do zstdp
open(pipeline(`$(zstdp) --quiet - -o $(output_file)`, stderr=stderr), "r+")
end
proc = open(pipeline(`$(zstdmt()) --quiet - -o $(output_file)`, stderr=stderr), "r+")

# Feed the tarball into that waiting process
Tar.create(trace_directory, proc)
Expand All @@ -163,41 +159,38 @@ function rr_record(julia_cmd::Cmd, julia_args...; rr_flags=default_rr_record_fla
rr_flags = `--chaos $rr_flags`
end

proc = rr() do rr_path
rr_cmd = `$(rr_path) record $rr_flags $julia_cmd $julia_args`
cmd = ignorestatus(setenv(rr_cmd, new_env))

proc = run(cmd, stdin, stdout, stderr; wait=false)

exit_on_sigint(false)
@sync begin
t1 = @async while process_running(proc)
try
wait(proc)
catch err
isa(err, InterruptException) || throw(err)
println("Interrupting the process...")
kill(proc, Base.SIGINT)
Timer(2) do timer
process_running(proc) || return
println("Terminating the process...")
kill(proc, Base.SIGTERM)
end
Timer(5) do timer
process_running(proc) || return
println("Killing the process...")
kill(proc, Base.SIGKILL)
end
rr_cmd = `$(rr()) record $rr_flags $julia_cmd $julia_args`
cmd = ignorestatus(setenv(rr_cmd, new_env))

proc = run(cmd, stdin, stdout, stderr; wait=false)

exit_on_sigint(false)
@sync begin
t1 = @async while process_running(proc)
try
wait(proc)
catch err
isa(err, InterruptException) || throw(err)
println("Interrupting the process...")
kill(proc, Base.SIGINT)
Timer(2) do timer
process_running(proc) || return
println("Terminating the process...")
kill(proc, Base.SIGTERM)
end
Timer(5) do timer
process_running(proc) || return
println("Killing the process...")
kill(proc, Base.SIGKILL)
end
end
end

if timeout > 0
@async Timer(timeout) do timer
istaskdone(t1) || Base.throwto(t1, InterruptException())
end
if timeout > 0
@async Timer(timeout) do timer
istaskdone(t1) || Base.throwto(t1, InterruptException())
end
end
return proc
end

if extras
Expand Down Expand Up @@ -233,9 +226,7 @@ function rr_record(julia_cmd::Cmd, julia_args...; rr_flags=default_rr_record_fla
end

function decompress_rr_trace(trace_file, out_dir)
proc = zstdmt() do zstdp
open(`$zstdp --quiet --stdout -d $trace_file`, "r+")
end
proc = open(`$(zstdmt()) --quiet --stdout -d $trace_file`, "r+")
Tar.extract(proc, out_dir)
return nothing
end
Expand Down Expand Up @@ -328,6 +319,23 @@ function read_trace_info(trace_url=default_rr_trace_dir();)
JSON.parse(json)
end

# workaround for https://github.com/JuliaLang/julia/issues/39282
function rr_with_gdb_env(; pathsep=':')
path = String[]
libpath = String[]
if rr_jll.is_available()
union!(path, rr_jll.PATH_list)
union!(libpath, rr_jll.LIBPATH_list)
end
if GDB_jll.is_available()
union!(path, GDB_jll.PATH_list)
union!(libpath, GDB_jll.LIBPATH_list)
end
union!(path, split(get(ENV, "PATH", ""), pathsep))
union!(libpath, split(get(ENV, "LD_LIBRARY_PATH", ""), pathsep))
return addenv(rr(), "PATH" => join(path, pathsep), "LD_LIBRARY_PATH" => join(libpath, pathsep))
end

function replay(trace_url=default_rr_trace_dir(); gdb_commands=[], gdb_flags=``,
rr_replay_flags=``)
trace_dir, remote = get_trace_dir(trace_url)
Expand Down Expand Up @@ -393,11 +401,7 @@ function replay(trace_url=default_rr_trace_dir(); gdb_commands=[], gdb_flags=``,
end

# replay with rr
proc = rr() do rr_path
gdb() do gdb_path
run(`$rr_path replay $rr_replay_flags -d $gdb_path $trace_dir -- $gdb_args`)
end
end
proc = run(`$(rr_with_gdb_env()) replay $rr_replay_flags -d $(gdb().exec) $trace_dir -- $gdb_args`)

# clean-up
if @isdefined(source_code) && source_code !== nothing
Expand Down Expand Up @@ -437,9 +441,7 @@ end

function read_comp_dir(binary_path)
# TODO: use libelf instead of grepping the human-readable output of readelf
elf_dump = eu_readelf() do eu_readelf_path
read(`$eu_readelf_path --debug-dump=info $binary_path`, String)
end
elf_dump = readchomp(`$(eu_readelf()) --debug-dump=info $binary_path`)

current_comp_dir = nothing
for line in split(elf_dump, '\n')
Expand Down Expand Up @@ -655,9 +657,7 @@ function upload_rr_trace(trace_directory, url; access_key_id, secret_access_key,
# TODO: stream (peak/s5cmd#182)
tarball = joinpath(dir, "trace.tar")
Tar.create(trace_directory, tarball)
zstdmt() do zstdp
run(`$zstdp --quiet $tarball`)
end
run(`$(zstdmt()) --quiet $tarball`)

# Upload
# TODO: progress bar (peak/s5cmd#51)
Expand Down
9 changes: 4 additions & 5 deletions test/rr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ end
# Test that Julia spat out what we expect on stdout and stderr
@test occursin(msg, output.stdout)
stderr_lines = split(output.stderr, "\n")
filter!(stderr_lines) do line
!contains(line, "Loading BugReporting package...") && !isempty(line)
end
if !isempty(stderr_lines)
filter!(!isempty, stderr_lines)
@test contains(popfirst!(stderr_lines), "Loading BugReporting package...")
if length(stderr_lines) > 1
@error "Unexpected output on standard error:\n" * output.stderr
end
@test isempty(stderr_lines)
@test length(stderr_lines) <= 1

test_replay(temp_trace_dir)

Expand Down

0 comments on commit 07aee48

Please sign in to comment.