Skip to content

Commit be8d0d4

Browse files
chore: cleanup metrics (#1947)
- rename `execute_e3_time_ms` to `execute_preflight_time_ms` and now it includes `memory_finalize_time_ms`. - the `single_trace_gen` info spans are skipped if record is empty just to reduce log verbosity
1 parent 9629ac1 commit be8d0d4

File tree

11 files changed

+69
-38
lines changed

11 files changed

+69
-38
lines changed

crates/prof/src/aggregate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl AggregateMetrics {
355355
metric_name, summary.avg, "-", "-", "-",
356356
)?;
357357
} else if metric_name == EXECUTE_E1_INSN_MI_S_LABEL
358-
|| metric_name == EXECUTE_E3_INSN_MI_S_LABEL
358+
|| metric_name == EXECUTE_PREFLIGHT_INSN_MI_S_LABEL
359359
|| metric_name == EXECUTE_METERED_INSN_MI_S_LABEL
360360
{
361361
// skip sum because it is misleading
@@ -469,8 +469,8 @@ pub const EXECUTE_E1_TIME_LABEL: &str = "execute_e1_time_ms";
469469
pub const EXECUTE_E1_INSN_MI_S_LABEL: &str = "execute_e1_insn_mi/s";
470470
pub const EXECUTE_METERED_TIME_LABEL: &str = "execute_metered_time_ms";
471471
pub const EXECUTE_METERED_INSN_MI_S_LABEL: &str = "execute_metered_insn_mi/s";
472-
pub const EXECUTE_E3_TIME_LABEL: &str = "execute_e3_time_ms";
473-
pub const EXECUTE_E3_INSN_MI_S_LABEL: &str = "execute_e3_insn_mi/s";
472+
pub const EXECUTE_PREFLIGHT_TIME_LABEL: &str = "execute_preflight_time_ms";
473+
pub const EXECUTE_PREFLIGHT_INSN_MI_S_LABEL: &str = "execute_preflight_insn_mi/s";
474474
pub const TRACE_GEN_TIME_LABEL: &str = "trace_gen_time_ms";
475475
pub const MEM_FIN_TIME_LABEL: &str = "memory_finalize_time_ms";
476476
pub const BOUNDARY_FIN_TIME_LABEL: &str = "boundary_finalize_time_ms";
@@ -486,8 +486,8 @@ pub const VM_METRIC_NAMES: &[&str] = &[
486486
EXECUTE_E1_INSN_MI_S_LABEL,
487487
EXECUTE_METERED_TIME_LABEL,
488488
EXECUTE_METERED_INSN_MI_S_LABEL,
489-
EXECUTE_E3_TIME_LABEL,
490-
EXECUTE_E3_INSN_MI_S_LABEL,
489+
EXECUTE_PREFLIGHT_TIME_LABEL,
490+
EXECUTE_PREFLIGHT_INSN_MI_S_LABEL,
491491
TRACE_GEN_TIME_LABEL,
492492
MEM_FIN_TIME_LABEL,
493493
BOUNDARY_FIN_TIME_LABEL,

crates/prof/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use eyre::Result;
55
use memmap2::Mmap;
66

77
use crate::{
8-
aggregate::{EXECUTE_E3_TIME_LABEL, EXECUTE_METERED_TIME_LABEL},
8+
aggregate::{EXECUTE_METERED_TIME_LABEL, EXECUTE_PREFLIGHT_TIME_LABEL},
99
types::{Labels, Metric, MetricDb, MetricsFile},
1010
};
1111

@@ -47,14 +47,20 @@ impl MetricDb {
4747
for metrics in self.flat_dict.values_mut() {
4848
let get = |key: &str| metrics.iter().find(|m| m.name == key).map(|m| m.value);
4949
let execute_metered_time = get(EXECUTE_METERED_TIME_LABEL);
50-
let execute_e3_time = get(EXECUTE_E3_TIME_LABEL);
50+
let execute_preflight_time = get(EXECUTE_PREFLIGHT_TIME_LABEL);
5151
let trace_gen_time = get(TRACE_GEN_TIME_LABEL);
5252
let prove_excl_trace_time = get(PROVE_EXCL_TRACE_TIME_LABEL);
53-
if let (Some(execute_e3_time), Some(trace_gen_time), Some(prove_excl_trace_time)) =
54-
(execute_e3_time, trace_gen_time, prove_excl_trace_time)
55-
{
53+
if let (
54+
Some(execute_preflight_time),
55+
Some(trace_gen_time),
56+
Some(prove_excl_trace_time),
57+
) = (
58+
execute_preflight_time,
59+
trace_gen_time,
60+
prove_excl_trace_time,
61+
) {
5662
let total_time = execute_metered_time.unwrap_or(0.0)
57-
+ execute_e3_time
63+
+ execute_preflight_time
5864
+ trace_gen_time
5965
+ prove_excl_trace_time;
6066
metrics.push(Metric::new(PROOF_TIME_LABEL.to_string(), total_time));

crates/prof/src/summary.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::Itertools;
55

66
use crate::{
77
aggregate::{
8-
AggregateMetrics, EXECUTE_E3_TIME_LABEL, EXECUTE_METERED_TIME_LABEL, INSNS_LABEL,
8+
AggregateMetrics, EXECUTE_METERED_TIME_LABEL, EXECUTE_PREFLIGHT_TIME_LABEL, INSNS_LABEL,
99
MAIN_CELLS_USED_LABEL, PROOF_TIME_LABEL, PROVE_EXCL_TRACE_TIME_LABEL, TRACE_GEN_TIME_LABEL,
1010
},
1111
types::MdTableCell,
@@ -169,8 +169,8 @@ impl AggregateMetrics {
169169
.get(EXECUTE_METERED_TIME_LABEL)
170170
.map(|s| s.sum.val)
171171
.unwrap_or(0.0);
172-
let execute_e3 = stats
173-
.get(EXECUTE_E3_TIME_LABEL)
172+
let execute_preflight = stats
173+
.get(EXECUTE_PREFLIGHT_TIME_LABEL)
174174
.map(|s| s.sum.val)
175175
.unwrap_or(0.0);
176176
// If total_proof_time_ms is not available, compute it from components
@@ -184,9 +184,12 @@ impl AggregateMetrics {
184184
.unwrap_or(0.0);
185185
println!(
186186
"{} {} {} {}",
187-
execute_metered, execute_e3, trace_gen, stark_prove
187+
execute_metered, execute_preflight, trace_gen, stark_prove
188188
);
189-
MdTableCell::new(execute_metered + execute_e3 + trace_gen + stark_prove, None)
189+
MdTableCell::new(
190+
execute_metered + execute_preflight + trace_gen + stark_prove,
191+
None,
192+
)
190193
};
191194
println!("{}", self.total_proof_time.val);
192195
let par_proof_time_ms = if let Some(proof_stats) = stats.get(PROOF_TIME_LABEL) {
@@ -197,8 +200,8 @@ impl AggregateMetrics {
197200
.get(EXECUTE_METERED_TIME_LABEL)
198201
.map(|s| s.max.val)
199202
.unwrap_or(0.0);
200-
let execute_e3 = stats
201-
.get(EXECUTE_E3_TIME_LABEL)
203+
let execute_preflight = stats
204+
.get(EXECUTE_PREFLIGHT_TIME_LABEL)
202205
.map(|s| s.max.val)
203206
.unwrap_or(0.0);
204207
let trace_gen = stats
@@ -209,7 +212,10 @@ impl AggregateMetrics {
209212
.get(PROVE_EXCL_TRACE_TIME_LABEL)
210213
.map(|s| s.max.val)
211214
.unwrap_or(0.0);
212-
MdTableCell::new(execute_metered + execute_e3 + trace_gen + stark_prove, None)
215+
MdTableCell::new(
216+
execute_metered + execute_preflight + trace_gen + stark_prove,
217+
None,
218+
)
213219
};
214220
let cells_used = stats
215221
.get(MAIN_CELLS_USED_LABEL)

crates/vm/src/arch/extensions.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ use rustc_hash::FxHashMap;
3535
use tracing::info_span;
3636

3737
use super::{GenerationError, PhantomSubExecutor, SystemConfig};
38-
use crate::system::{
39-
memory::{BOUNDARY_AIR_OFFSET, MERKLE_AIR_OFFSET},
40-
phantom::PhantomExecutor,
41-
SystemAirInventory, SystemChipComplex, SystemRecords,
38+
use crate::{
39+
arch::Arena,
40+
system::{
41+
memory::{BOUNDARY_AIR_OFFSET, MERKLE_AIR_OFFSET},
42+
phantom::PhantomExecutor,
43+
SystemAirInventory, SystemChipComplex, SystemRecords,
44+
},
4245
};
4346

4447
/// Global AIR ID in the VM circuit verifying key.
@@ -641,6 +644,7 @@ pub enum ChipInventoryError {
641644
impl<SC, RA, PB, SCC> VmChipComplex<SC, RA, PB, SCC>
642645
where
643646
SC: StarkGenericConfig,
647+
RA: Arena,
644648
PB: ProverBackend,
645649
SCC: SystemChipComplex<RA, PB>,
646650
{
@@ -692,9 +696,12 @@ where
692696
.chain(
693697
zip(self.inventory.chips.iter().enumerate().rev(), record_arenas).map(
694698
|((insertion_idx, chip), records)| {
695-
let air_name = self.inventory.airs.ext_airs[insertion_idx].name();
696-
info_span!("single_trace_gen", air = air_name)
697-
.in_scope(|| chip.generate_proving_ctx(records))
699+
// Only create a span if record is not empty:
700+
let _span = (!records.is_empty()).then(|| {
701+
let air_name = self.inventory.airs.ext_airs[insertion_idx].name();
702+
info_span!("single_trace_gen", air = air_name).entered()
703+
});
704+
chip.generate_proving_ctx(records)
698705
},
699706
),
700707
)

crates/vm/src/arch/interpreter_preflight.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ where
114114
}
115115
}
116116

117-
/// Macro for executing with a compile-time span name for better tracing performance
117+
/// Macro for executing and emitting metrics for instructions/s and number of instructions executed.
118+
/// Does not include any tracing span.
118119
#[macro_export]
119120
macro_rules! execute_spanned {
120121
($name:literal, $executor:expr, $state:expr) => {{
@@ -123,7 +124,7 @@ macro_rules! execute_spanned {
123124
#[cfg(feature = "metrics")]
124125
let start_instret = $state.instret;
125126

126-
let result = tracing::info_span!($name).in_scope(|| $executor.execute_from_state($state));
127+
let result = $executor.execute_from_state($state);
127128

128129
#[cfg(feature = "metrics")]
129130
{

crates/vm/src/arch/record_arena.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub trait Arena {
1515
/// Currently `width` always refers to the main trace width.
1616
fn with_capacity(height: usize, width: usize) -> Self;
1717

18+
fn is_empty(&self) -> bool;
19+
1820
/// Only used for metric collection purposes. Intended usage is that for a record arena that
1921
/// corresponds to a single trace matrix, this function can extract the current number of used
2022
/// rows of the corresponding trace matrix. This is currently expected to work only for
@@ -117,6 +119,10 @@ impl<F: Field> Arena for MatrixRecordArena<F> {
117119
}
118120
}
119121

122+
fn is_empty(&self) -> bool {
123+
self.trace_offset == 0
124+
}
125+
120126
#[cfg(feature = "metrics")]
121127
fn current_trace_height(&self) -> usize {
122128
self.trace_offset / self.width
@@ -244,6 +250,10 @@ impl Arena for DenseRecordArena {
244250
let size_bytes = height * (width * size_of::<u32>());
245251
Self::with_byte_capacity(size_bytes)
246252
}
253+
254+
fn is_empty(&self) -> bool {
255+
self.allocated().is_empty()
256+
}
247257
}
248258

249259
// =================== Helper Functions =================================

crates/vm/src/arch/vm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ where
388388
///
389389
/// This function should rarely be called on its own. Users are advised to call
390390
/// [`prove`](Self::prove) directly.
391+
#[instrument(name = "execute_preflight", skip_all)]
391392
pub fn execute_preflight(
392393
&self,
393394
exe: &VmExe<Val<E::SC>>,
@@ -444,7 +445,7 @@ where
444445
metrics: state.metrics,
445446
};
446447
let mut exec_state = VmExecState::new(vm_state, ctx);
447-
execute_spanned!("execute_e3", instance, &mut exec_state)?;
448+
execute_spanned!("execute_preflight", instance, &mut exec_state)?;
448449
let filtered_exec_frequencies = instance.handler.filtered_execution_frequencies();
449450
let touched_memory = exec_state
450451
.vm_state
@@ -1256,6 +1257,8 @@ mod vm_metrics {
12561257
total_cells_used +=
12571258
width.total_width(<E::SC as StarkGenericConfig>::Challenge::D) * *height;
12581259
}
1260+
tracing::debug!(?heights);
1261+
tracing::info!(main_cells_used, total_cells_used);
12591262
counter!("main_cells_used").absolute(main_cells_used as u64);
12601263
counter!("total_cells_used").absolute(total_cells_used as u64);
12611264

crates/vm/src/system/memory/merkle/trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
};
2828

2929
impl<const CHUNK: usize, F: PrimeField32> MemoryMerkleChip<CHUNK, F> {
30-
#[instrument(name = "merkle_finalize", skip_all)]
30+
#[instrument(name = "merkle_finalize", level = "debug", skip_all)]
3131
pub(crate) fn finalize(
3232
&mut self,
3333
initial_memory: &MemoryImage,

crates/vm/src/system/memory/persistent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<const CHUNK: usize, F: PrimeField32> PersistentBoundaryChip<F, CHUNK> {
207207
}
208208
}
209209

210-
#[instrument(name = "boundary_finalize", skip_all)]
210+
#[instrument(name = "boundary_finalize", level = "debug", skip_all)]
211211
pub(crate) fn finalize<H>(
212212
&mut self,
213213
initial_memory: &MemoryImage,

crates/vm/src/system/memory/volatile/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<F: PrimeField32> VolatileBoundaryChip<F> {
219219
}
220220
/// Volatile memory requires the starting and final memory to be in equipartition with block
221221
/// size `1`. When block size is `1`, then the `label` is the same as the address pointer.
222-
#[instrument(name = "boundary_finalize", skip_all)]
222+
#[instrument(name = "boundary_finalize", level = "debug", skip_all)]
223223
pub fn finalize(&mut self, final_memory: TimestampedEquipartition<F, 1>) {
224224
self.final_memory = Some(final_memory);
225225
}

0 commit comments

Comments
 (0)