|
1 | 1 | //! VM execution runner |
2 | 2 |
|
3 | | -use crate::{SourceLineNumber, HintExecutionContext}; |
| 3 | +use crate::{CodeAddress, SourceLineNumber, HintExecutionContext}; |
4 | 4 | use crate::core::{ |
5 | 5 | DIMENSION, F, ONE_VEC_PTR, POSEIDON_16_NULL_HASH_PTR, POSEIDON_24_NULL_HASH_PTR, |
6 | 6 | PUBLIC_INPUT_START, VECTOR_LEN, ZERO_VEC_PTR, |
@@ -104,23 +104,50 @@ pub fn execute_bytecode( |
104 | 104 | panic!("Error during bytecode execution: {err}"); |
105 | 105 | }); |
106 | 106 | if profiler { |
107 | | - print_line_cycle_counts(bytecode, instruction_history); |
| 107 | + print_line_cycle_counts(instruction_history); |
| 108 | + print_instruction_cycle_counts(bytecode, result.pcs.clone()); |
108 | 109 | } |
109 | 110 | result |
110 | 111 | } |
111 | 112 |
|
112 | | -fn print_line_cycle_counts(bytecode: &Bytecode, history: ExecutionHistory) { |
| 113 | +fn print_line_cycle_counts(history: ExecutionHistory) { |
113 | 114 | println!("Line by line cycle counts"); |
114 | 115 | println!("=========================\n"); |
115 | 116 |
|
116 | 117 | let mut gross_cycle_counts: BTreeMap<SourceLineNumber, usize> = BTreeMap::new(); |
117 | | - for (line, cycle_count) in history.lines.iter().zip(history.cycles.iter()) { |
| 118 | + for (line, cycle_count) in history.lines.iter().zip(history.lines_cycles.iter()) { |
118 | 119 | let prev_count = gross_cycle_counts.get(line).unwrap_or(&0); |
119 | 120 | gross_cycle_counts.insert(*line, *prev_count + cycle_count); |
120 | 121 | } |
121 | 122 | for (line, cycle_count) in gross_cycle_counts.iter() { |
122 | 123 | println!("line {line}: {cycle_count} cycles"); |
123 | 124 | } |
| 125 | + println!(""); |
| 126 | +} |
| 127 | + |
| 128 | +fn print_instruction_cycle_counts(bytecode: &Bytecode, pcs: Vec<CodeAddress>) { |
| 129 | + println!("Instruction level cycle counts"); |
| 130 | + println!("=============================="); |
| 131 | + |
| 132 | + let mut gross_cycle_counts: BTreeMap<CodeAddress, usize> = BTreeMap::new(); |
| 133 | + for pc in pcs.iter() { |
| 134 | + let prev_count = gross_cycle_counts.get(pc).unwrap_or(&0); |
| 135 | + gross_cycle_counts.insert(*pc, *prev_count + 1); |
| 136 | + } |
| 137 | + for (pc, cycle_count) in gross_cycle_counts.iter() { |
| 138 | + let instruction = &bytecode.instructions[*pc]; |
| 139 | + let hints = bytecode.hints.get(pc); |
| 140 | + match hints { |
| 141 | + Some(hints) => { |
| 142 | + for hint in hints { |
| 143 | + println!("hint: {hint}"); |
| 144 | + } |
| 145 | + }, |
| 146 | + None => {}, |
| 147 | + } |
| 148 | + println!("pc {pc}: {cycle_count} cycles: {instruction}"); |
| 149 | + } |
| 150 | + println!(""); |
124 | 151 | } |
125 | 152 |
|
126 | 153 | /// Helper function that performs the actual bytecode execution |
|
0 commit comments