Skip to content

Commit

Permalink
Add compress_trace(); a helper method for compressing traces (#31)
Browse files Browse the repository at this point in the history
* Add `compress_trace()`; a helper method for compressing traces

* Fix tests
  • Loading branch information
staticfloat authored Apr 9, 2021
1 parent 7dd520c commit d6598c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
19 changes: 19 additions & 0 deletions src/BugReporting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ function rr_pack(trace_directory)
end
end

# Helper function to compress a trace into a `.tar.zst` file
function compress_trace(trace_directory::String, output_file::String)
# Ensure it's packed
rr_pack(trace_directory)

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

# Feed the tarball into that waiting process
Tar.create(trace_directory, proc)

# Ensure everything closes nicely
close(proc.in)
wait(proc)
return nothing
end

function rr_record(args...; trace_dir=nothing)
check_rr_available()
check_perf_event_paranoid()
Expand Down
47 changes: 29 additions & 18 deletions test/rr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,35 @@ using BugReporting, Test, Pkg
trace_files = readdir(joinpath(temp_trace_dir,"latest-trace"))
@test !isempty(filter(f -> startswith(f, "mmap_pack_"), trace_files))

# Test that we can replay that trace: (just send in `continue` immediately to let it run)
new_stdout_rd, new_stdout_wr = Base.redirect_stdout()
new_stderr_rd, new_stderr_wr = Base.redirect_stderr()
new_stdin_rd, new_stdin_wr = Base.redirect_stdin()
write(new_stdin_wr, "continue\nquit\ny")
BugReporting.rr_replay(temp_trace_dir)
Base.redirect_stdout(old_stdout)
Base.redirect_stderr(old_stderr)
Base.redirect_stdin(old_stdin)
close(new_stdout_wr)
close(new_stderr_wr)
close(new_stdin_rd)

rr_stdout = String(read(new_stdout_rd))
rr_stderr = String(read(new_stderr_rd))
# Test that we can compress that trace directory
mktempdir() do temp_out_dir
tarzst_path = joinpath(temp_out_dir, "trace.tar.zst")
BugReporting.compress_trace(temp_trace_dir, tarzst_path)
@test isfile(tarzst_path)
end

# Test that Julia spat out what we expect, still.
@test occursin(msg, rr_stdout)
@test isempty(rr_stderr)
# Redirect `HOME` to a directory that we know doesn't contain a `.gdbinit` file,
# as that can screw up the `isempty(rr_stderr)` test below
withenv("HOME" => temp_trace_dir) do
# Test that we can replay that trace: (just send in `continue` immediately to let it run)
new_stdout_rd, new_stdout_wr = Base.redirect_stdout()
new_stderr_rd, new_stderr_wr = Base.redirect_stderr()
new_stdin_rd, new_stdin_wr = Base.redirect_stdin()
write(new_stdin_wr, "continue\nquit\ny")
BugReporting.replay(temp_trace_dir)
Base.redirect_stdout(old_stdout)
Base.redirect_stderr(old_stderr)
Base.redirect_stdin(old_stdin)
close(new_stdout_wr)
close(new_stderr_wr)
close(new_stdin_rd)

rr_stdout = String(read(new_stdout_rd))
rr_stderr = String(read(new_stderr_rd))

# Test that Julia spat out what we expect, still.
@test occursin(msg, rr_stdout)
@test isempty(rr_stderr)
end
end
end

0 comments on commit d6598c3

Please sign in to comment.