Skip to content

Commit

Permalink
perf: lock-free cycle counter increment
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Jan 4, 2025
1 parent e12cc8d commit 2bbc8fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions benchmarks/examples/regex_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn main() {

let data = include_str!("../programs/regex/regex_email.txt");

let timer = std::time::Instant::now();
executor
.execute(exe.clone(), StdIn::from_bytes(data.as_bytes()))
.unwrap();
println!("execute_time: {:?}", timer.elapsed());
}
4 changes: 3 additions & 1 deletion crates/vm/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod cycle_tracker;

#[derive(Clone, Debug, Default)]
pub struct VmMetrics {
pub cycle_count: usize,
pub chip_heights: Vec<(String, usize)>,
/// Maps (dsl_ir, opcode) to number of times opcode was executed
pub counts: BTreeMap<(Option<String>, String), usize>,
Expand Down Expand Up @@ -42,7 +43,7 @@ where
opcode: VmOpcode,
dsl_instr: Option<String>,
) {
counter!("total_cycles").increment(1u64);
self.metrics.cycle_count += 1;

if self.system_config().profiling {
let executor = self.chip_complex.inventory.get_executor(opcode).unwrap();
Expand All @@ -60,6 +61,7 @@ where
}

pub fn finalize_metrics(&mut self) {
counter!("total_cycles").absolute(self.metrics.cycle_count as u64);
counter!("main_cells_used")
.absolute(self.current_trace_cells().into_iter().sum::<usize>() as u64);

Expand Down

0 comments on commit 2bbc8fc

Please sign in to comment.