From e66b44e71a77318c012cde3827dd86c42edee4f5 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 13 Dec 2022 13:38:59 +0100 Subject: [PATCH] Make it possible to enable rr's chaos mode. --- src/BugReporting.jl | 37 ++++++++++++++++++++++++++++--------- test/rr.jl | 15 +++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/BugReporting.jl b/src/BugReporting.jl index a486c53..113a1f2 100644 --- a/src/BugReporting.jl +++ b/src/BugReporting.jl @@ -148,7 +148,7 @@ function compress_trace(trace_directory::String, output_file::String) end function rr_record(julia_cmd::Cmd, julia_args...; rr_flags=default_rr_record_flags, - trace_dir=default_rr_trace_dir(), timeout=0, extras=false) + trace_dir=default_rr_trace_dir(), timeout=0, chaos=false, extras=false) check_rr_available() check_perf_event_paranoid(; rr_flags=rr_flags) @@ -159,6 +159,10 @@ function rr_record(julia_cmd::Cmd, julia_args...; rr_flags=default_rr_record_fla # and shouldn't leak into the record environment (where we may load another Python) delete!(new_env, "PYTHONHOME") + if chaos + 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)) @@ -293,8 +297,7 @@ function get_sourcecode(commit) return dir end -function replay(trace_url=default_rr_trace_dir(); gdb_commands=[], gdb_flags=``, - rr_replay_flags=``) +function get_trace_dir(trace_url) # download remote traces if startswith(trace_url, "s3://") trace_url = string("https://s3.amazonaws.com/julialang-dumps/", trace_url[6:end]) @@ -315,7 +318,18 @@ function replay(trace_url=default_rr_trace_dir(); gdb_commands=[], gdb_flags=``, if !isdir(trace_url) error("Invalid trace location: $(trace_url)") end - trace_dir = find_latest_trace(trace_url) + find_latest_trace(trace_url) +end + +function read_trace_info(trace_url=default_rr_trace_dir();) + trace_dir = get_trace_dir(trace_url) + json = read(`$(rr()) traceinfo $trace_dir`, String) + JSON.parse(json) +end + +function replay(trace_url=default_rr_trace_dir(); gdb_commands=[], gdb_flags=``, + rr_replay_flags=``) + trace_dir = get_trace_dir(trace_url) # read Julia-specific metadata from the trace if ispath(joinpath(trace_dir, "julia_metadata.json")) @@ -483,12 +497,17 @@ function make_interactive_report(report_arg, ARGS=[]) # split the report specification into the type and any modifiers report_type, report_modifiers... = split(report_arg, ',') timeout = 0 + chaos = false for report_modifier in report_modifiers - option, value = split(report_modifier, '=') + option, values... = split(report_modifier, '=') if option == "timeout" - timeout = parse_time(value) + length(values) == 1 || error("Invalid report option: $(report_modifier)") + timeout = parse_time(value[1]) + elseif option == "chaos" + length(values) == 0 || error("Invalid report option: $(report_modifier)") + chaos = true else - error("Unknown report option: $(option)") + error("Unknown report option: $(report_modifier)") end end @@ -508,11 +527,11 @@ function make_interactive_report(report_arg, ARGS=[]) cmd = `$cmd --history-file=no` if report_type == "rr-local" - proc = rr_record(cmd, ARGS...; timeout=timeout, extras=true) + proc = rr_record(cmd, ARGS...; timeout=timeout, chaos=chaos, extras=true) handle_child_error(proc) elseif report_type == "rr" mktempdir() do trace_dir - proc = rr_record(cmd, ARGS...; trace_dir=trace_dir, timeout=timeout, extras=true) + proc = rr_record(cmd, ARGS...; trace_dir=trace_dir, timeout=timeout, chaos=chaos, extras=true) "Preparing trace for upload (if your trace is large this may take a few minutes)..." rr_pack(trace_dir) params = get_upload_params() diff --git a/test/rr.jl b/test/rr.jl index de71832..bf039c5 100644 --- a/test/rr.jl +++ b/test/rr.jl @@ -227,4 +227,19 @@ end @test success(proc) @test contains(output.stdout, "Starting sleep") end + + # Test that we can enable chaos mode + mktempdir() do temp_trace_dir + proc, output = withenv("_RR_TRACE_DIR" => temp_trace_dir) do + cmd = ```$(Base.julia_cmd()) --project=$(dirname(@__DIR__)) + --bug-report=rr-local,chaos + --eval "42"``` + communicate(cmd) + end + success(proc) || println(output.stderr) + @test success(proc) + + trace_info = BugReporting.read_trace_info(temp_trace_dir) + @test get(trace_info, "chaosMode", missing) == true + end end