Skip to content

Commit

Permalink
improve profiler's reporting interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Aug 14, 2023
1 parent f88dc68 commit 9243d6e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 35 deletions.
11 changes: 5 additions & 6 deletions triton-vm/benches/prove_fib_100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ fn prove_fib_100(criterion: &mut Criterion) {
group.finish();

println!("Writing report ...");
let cycle_count = aet.processor_trace.nrows();
let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(
Some(cycle_count),
Some(padded_height),
Some(fri.domain.length),
);
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}

Expand Down
11 changes: 5 additions & 6 deletions triton-vm/benches/prove_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ fn prove_halt(criterion: &mut Criterion) {
group.finish();

println!("Writing report ...");
let cycle_count = aet.processor_trace.nrows();
let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(
Some(cycle_count),
Some(padded_height),
Some(fri.domain.length),
);
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}

Expand Down
10 changes: 5 additions & 5 deletions triton-vm/benches/verify_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ fn verify_halt(criterion: &mut Criterion) {
profiler.finish();
let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(
Some(aet.processor_trace.nrows()),
Some(padded_height),
Some(fri.domain.length),
);
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);

let bench_id = BenchmarkId::new("VerifyHalt", 0);
let mut group = criterion.benchmark_group("verify_halt");
Expand Down
52 changes: 38 additions & 14 deletions triton-vm/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ impl TritonProfiler {
self.total_time = self.timer.elapsed();
}

pub fn report(
&mut self,
cycle_count: Option<usize>,
padded_height: Option<usize>,
fri_domain_len: Option<usize>,
) -> Report {
pub fn report(&mut self) -> Report {
assert!(!self.profile.is_empty(), "Nothing to report on.");
assert!(
self.stack.is_empty(),
Expand Down Expand Up @@ -189,9 +184,9 @@ impl TritonProfiler {
name: self.name.clone(),
total_time: self.total_time,
category_times,
cycle_count,
padded_height,
fri_domain_len,
cycle_count: None,
padded_height: None,
fri_domain_len: None,
}
}

Expand Down Expand Up @@ -417,6 +412,21 @@ pub struct Report {
}

impl Report {
pub fn with_cycle_count(mut self, cycle_count: usize) -> Self {
self.cycle_count = Some(cycle_count);
self
}

pub fn with_padded_height(mut self, padded_height: usize) -> Self {
self.padded_height = Some(padded_height);
self
}

pub fn with_fri_domain_len(mut self, fri_domain_len: usize) -> Self {
self.fri_domain_len = Some(fri_domain_len);
self
}

fn display_time_aligned(time: Duration) -> String {
let unaligned_time = format!("{time:.2?}");
let time_components: Vec<_> = unaligned_time.split('.').collect();
Expand Down Expand Up @@ -706,7 +716,7 @@ pub mod triton_profiler_tests {
}

profiler.finish();
println!("{}", profiler.report(None, None, None));
println!("{}", profiler.report());
}

#[test]
Expand All @@ -717,9 +727,23 @@ pub mod triton_profiler_tests {
prof_stop!(profiler, "clk_freq_test");
let mut profiler = profiler.unwrap();
profiler.finish();
println!("{}", profiler.report(None, None, None));
println!("{}", profiler.report(Some(0), Some(0), Some(0)));
println!("{}", profiler.report(Some(10), Some(12), Some(13)));

let report_with_no_optionals = profiler.report();
println!("{report_with_no_optionals}");

let report_with_optionals_set_to_0 = profiler
.report()
.with_cycle_count(0)
.with_padded_height(0)
.with_fri_domain_len(0);
println!("{report_with_optionals_set_to_0}");

let report_with_optionals_set = profiler
.report()
.with_cycle_count(10)
.with_padded_height(12)
.with_fri_domain_len(32);
println!("{report_with_optionals_set}");
}

#[test]
Expand Down Expand Up @@ -758,6 +782,6 @@ pub mod triton_profiler_tests {
}

profiler.finish();
println!("{}", profiler.report(None, None, None));
println!("{}", profiler.report());
}
}
20 changes: 16 additions & 4 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,10 @@ pub(crate) mod triton_stark_tests {

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(None, Some(padded_height), Some(fri.domain.length));
let report = profiler
.report()
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}

Expand Down Expand Up @@ -1842,7 +1845,10 @@ pub(crate) mod triton_stark_tests {

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(None, Some(padded_height), Some(fri.domain.length));
let report = profiler
.report()
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}

Expand Down Expand Up @@ -1889,7 +1895,10 @@ pub(crate) mod triton_stark_tests {

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(None, Some(padded_height), Some(fri.domain.length));
let report = profiler
.report()
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}

Expand All @@ -1907,7 +1916,10 @@ pub(crate) mod triton_stark_tests {

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(None, Some(padded_height), Some(fri.domain.length));
let report = profiler
.report()
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
}
}
Expand Down

0 comments on commit 9243d6e

Please sign in to comment.