Skip to content

Commit f21b19e

Browse files
chore(metrics): instrument total_proof_time_ms directly (#1952)
`total_proof_time_ms` can now be measured directly with a span instead of by summing up individual parts, which is more accurate. The increase in times from benchmarks includes some additional setup time.
1 parent f6a0bc1 commit f21b19e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

crates/prof/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ impl MetricDb {
4646
pub fn apply_aggregations(&mut self) {
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);
49+
let total_proof_time = get(PROOF_TIME_LABEL);
50+
if total_proof_time.is_some() {
51+
// We have instrumented total_proof_time_ms
52+
continue;
53+
}
54+
// otherwise, calculate it from sub-components
4955
let execute_metered_time = get(EXECUTE_METERED_TIME_LABEL);
5056
let execute_preflight_time = get(EXECUTE_PREFLIGHT_TIME_LABEL);
5157
let trace_gen_time = get(TRACE_GEN_TIME_LABEL);

crates/vm/src/arch/vm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,9 @@ where
870870
let mut proofs = Vec::with_capacity(segments.len());
871871
let mut state = Some(vm.create_initial_state(exe, input));
872872
for (seg_idx, segment) in segments.into_iter().enumerate() {
873-
let _span = info_span!("prove_segment", segment = seg_idx).entered();
873+
let _segment_span = info_span!("prove_segment", segment = seg_idx).entered();
874+
// We need a separate span so the metric label includes "segment" from _segment_span
875+
let _prove_span = info_span!("total_proof").entered();
874876
let Segment {
875877
instret_start,
876878
num_insns,
@@ -914,6 +916,7 @@ where
914916
<VB::VmConfig as VmExecutionConfig<Val<E::SC>>>::Executor:
915917
PreflightExecutor<Val<E::SC>, VB::RecordArena>,
916918
{
919+
#[instrument(name = "total_proof", skip_all)]
917920
fn prove(
918921
&mut self,
919922
input: impl Into<Streams<Val<E::SC>>>,

docs/crates/metrics.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ For a segment proof, the following metrics are collected:
1616
- `trace_gen_time_ms` (gauge): The time to generate non-cached trace matrices from execution records.
1717
- If this is a segment in a VM with continuations enabled, a `segment: segment_idx` label is added to the metric.
1818
- All metrics collected by [`openvm-stark-backend`](https://github.com/openvm-org/stark-backend/blob/main/docs/metrics.md), in particular `stark_prove_excluding_trace_time_ms` (gauge).
19-
- The `total_proof_time_ms` of the proof is:
20-
- The sum `execute_preflight_time_ms + trace_gen_time_ms + stark_prove_excluding_trace_time_ms` for app proofs. The `execute_metered_time_ms` is excluded for app proofs because it is not run on a per-segment basis.
21-
- The sum `execute_metered_time_ms + execute_preflight_time_ms + trace_gen_time_ms + stark_prove_excluding_trace_time_ms` for non-app proofs.
19+
- The `total_proof_time_ms` of the proof is instrumented directly when possible. Otherwise, it is calculated as:
20+
- The sum `execute_preflight_time_ms + trace_gen_time_ms + stark_prove_excluding_trace_time_ms`. The `execute_metered_time_ms` is excluded for app proofs because it is not run on a per-segment basis.
2221
- `insns` (counter): The total number of instructions executed in the segment.
2322
- `main_cells_used` (counter): The total number of main trace cells used by all chips in the segment. This does not include cells needed to pad rows to power-of-two matrix heights. Only main trace cells, not preprocessed or permutation trace cells, are counted.
2423
- `total_cells_used` (counter): The total number of preprocessed, main, and permutation trace cells used by all chips in the segment. This does not include cells needed to pad rows to power-of-two matrix heights.

0 commit comments

Comments
 (0)