Add an rbpf-cli option to dump the program execution trace (#29289)

This commit is contained in:
Dmitri Makarov 2022-12-15 20:08:00 -05:00 committed by GitHub
parent ff8bb5362c
commit acb7eb226b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -157,6 +157,14 @@ before execting it in the virtual machine.",
.takes_value(true)
.possible_values(["json", "json-compact"]),
)
.arg(
Arg::new("trace")
.help("Output instruction trace")
.short('t')
.long("trace")
.takes_value(true)
.value_name("FILE"),
)
.get_matches();
let loader_id = bpf_loader::id();
@ -297,6 +305,23 @@ before execting it in the virtual machine.",
}
let (instruction_count, result) = vm.execute_program(matches.value_of("use").unwrap() != "jit");
let duration = Instant::now() - start_time;
if matches.occurrences_of("trace") > 0 {
let trace_log = vm.env.context_object_pointer.trace_log.as_slice();
if matches.value_of("trace").unwrap() == "stdout" {
analysis
.analyze()
.disassemble_trace_log(&mut std::io::stdout(), trace_log)
.unwrap();
} else {
analysis
.analyze()
.disassemble_trace_log(
&mut File::create(matches.value_of("trace").unwrap()).unwrap(),
trace_log,
)
.unwrap();
}
}
drop(vm);
let output = Output {