Expose optional checkpoint clone and suffix proof timings
This commit is contained in:
1 parent
67396827a9
commit
c8f7a0cbe6
7 files changed
+170
-27
No files matched your search
@@ -1,6 +1,8 @@
|
||||
use std::cell::Cell;
|
||||
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use std::hash::{BuildHasher, RandomState};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use hashbrown::{HashMap, hash_map::RawEntryMut};
|
||||
|
||||
@@ -44,7 +46,9 @@ mod scheduling;
|
||||
mod specials;
|
||||
mod statistics;
|
||||
mod continuation;
|
||||
pub use continuation::{ClosedSourceChange, RelocatedShipoutSuffix, SuffixKernelTimings};
|
||||
pub use continuation::{
|
||||
ClosedSourceChange, RelocatedShipoutSuffix, SuffixKernelTimings, SuffixStateProofTimings,
|
||||
};
|
||||
mod xdv_annotation;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
@@ -337,6 +341,14 @@ pub enum CheckpointDecision {
|
||||
ReplayFailed(String),
|
||||
}
|
||||
|
||||
/// Time spent cloning live kernel state while resuming or capturing checkpoints.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct CheckpointCloneTimings {
|
||||
pub restore: Duration,
|
||||
pub capture: Duration,
|
||||
pub captures: usize,
|
||||
}
|
||||
|
||||
/// A live, in-memory kernel continuation at an entry-file command boundary.
|
||||
/// The host must validate dependencies and replay all prefix effects before
|
||||
/// resumption. The checkpoint itself validates the entry bytes already loaded.
|
||||
@@ -437,7 +449,7 @@ impl EntryCheckpoint {
|
||||
files: &mut impl SourceProvider,
|
||||
cancellation: Cancellation,
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
self.resume_observed(source, None, files, cancellation, None, None,
|
||||
self.resume_observed(source, None, files, cancellation, None, None, None,
|
||||
|_, _, _, _| CheckpointDecision::Continue)
|
||||
.expect("ordinary resume cannot reject a cached suffix")
|
||||
}
|
||||
@@ -460,7 +472,8 @@ impl EntryCheckpoint {
|
||||
cancellation,
|
||||
Some(line_break_cache),
|
||||
previous,
|
||||
Executor::entry_observer(self.incoming_state, select, |slot, entry, files| {
|
||||
None,
|
||||
Executor::entry_observer(self.incoming_state, None, select, |slot, entry, files| {
|
||||
capture(slot, entry, files);
|
||||
CheckpointDecision::Continue
|
||||
}),
|
||||
@@ -476,11 +489,19 @@ impl EntryCheckpoint {
|
||||
cancellation: Cancellation,
|
||||
line_break_cache: Arc<super::LineBreakCache>,
|
||||
previous: Option<&Execution>,
|
||||
timings: Option<&mut CheckpointCloneTimings>,
|
||||
select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
self.resume_observed(source, nested, files, cancellation, Some(line_break_cache), previous,
|
||||
Executor::entry_observer(self.incoming_state, select, capture))
|
||||
let measured = timings.is_some().then(Cell::default);
|
||||
let result = self.resume_observed(
|
||||
source, nested, files, cancellation, Some(line_break_cache), previous, measured.as_ref(),
|
||||
Executor::entry_observer(self.incoming_state, measured.as_ref(), select, capture),
|
||||
);
|
||||
if let Some((timings, measured)) = timings.zip(measured) {
|
||||
*timings = measured.into_inner();
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn resume_observed<F: SourceProvider>(
|
||||
@@ -491,6 +512,7 @@ impl EntryCheckpoint {
|
||||
cancellation: Cancellation,
|
||||
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
|
||||
previous: Option<&Execution>,
|
||||
timings: Option<&Cell<CheckpointCloneTimings>>,
|
||||
capture_boundary: impl FnMut(&mut Executor, usize, bool, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
if !self.accepts_entry(&source)
|
||||
@@ -501,7 +523,14 @@ impl EntryCheckpoint {
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let mut executor = self.executor.clone().with_cancellation(cancellation);
|
||||
let started = timings.is_some().then(Instant::now);
|
||||
let executor = self.executor.clone();
|
||||
if let Some((timings, started)) = timings.zip(started) {
|
||||
let mut measured = timings.get();
|
||||
measured.restore += started.elapsed();
|
||||
timings.set(measured);
|
||||
}
|
||||
let mut executor = executor.with_cancellation(cancellation);
|
||||
executor.reads.advance_epoch();
|
||||
executor.line_break_cache = line_break_cache;
|
||||
let previous_len = self.executor.sources[self.entry].data.len();
|
||||
@@ -3962,7 +3991,7 @@ impl Executor {
|
||||
let result = self.run_observed(
|
||||
file,
|
||||
files,
|
||||
Self::entry_observer(incoming_state, select, |slot, entry, files| {
|
||||
Self::entry_observer(incoming_state, None, select, |slot, entry, files| {
|
||||
capture(slot, entry, files);
|
||||
CheckpointDecision::Continue
|
||||
}),
|
||||
@@ -3972,6 +4001,7 @@ impl Executor {
|
||||
|
||||
fn entry_observer<F: SourceProvider, S>(
|
||||
incoming_state: u64,
|
||||
timings: Option<&Cell<CheckpointCloneTimings>>,
|
||||
mut select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F) -> CheckpointDecision,
|
||||
) -> impl FnMut(&mut Self, usize, bool, &mut F) -> CheckpointDecision {
|
||||
@@ -4016,7 +4046,14 @@ impl Executor {
|
||||
return CheckpointDecision::Continue;
|
||||
}
|
||||
engine.events.seal_prefix();
|
||||
let started = timings.is_some().then(Instant::now);
|
||||
let mut executor = engine.clone();
|
||||
if let Some((timings, started)) = timings.zip(started) {
|
||||
let mut measured = timings.get();
|
||||
measured.capture += started.elapsed();
|
||||
measured.captures += 1;
|
||||
timings.set(measured);
|
||||
}
|
||||
// Any subsequent read belongs to the suffix, even if it
|
||||
// happens before the next logical TeX execution step.
|
||||
engine.reads.advance_epoch();
|
||||
|
||||
Reference in new issue
Block a user