Translate logical step counts when replaying native suffixes
This commit is contained in:
1 parent
9a6c162b46
commit
465a574124
8 files changed
+337
-86
No files matched your search
@@ -145,6 +145,110 @@ pub struct StatisticsReport {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Maps monotone step counts after one command boundary onto another.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct StepOffset {
|
||||
previous: usize,
|
||||
current: usize,
|
||||
}
|
||||
|
||||
impl StepOffset {
|
||||
pub fn new(previous: usize, current: usize) -> Self {
|
||||
Self { previous, current }
|
||||
}
|
||||
|
||||
pub fn is_identity(self) -> bool {
|
||||
self.previous == self.current
|
||||
}
|
||||
|
||||
pub fn apply(self, steps: usize) -> Option<usize> {
|
||||
self.current.checked_add(steps.checked_sub(self.previous)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl StatisticsReport {
|
||||
pub(super) fn new(phase: StatisticsPhase, destination: WriteDestination, span: Span) -> Self {
|
||||
let text = phase.text();
|
||||
Self { phase, destination, text, span }
|
||||
}
|
||||
|
||||
pub fn with_step_offset(&self, offset: StepOffset) -> Option<Self> {
|
||||
let mut phase = self.phase.clone();
|
||||
match &mut phase {
|
||||
StatisticsPhase::Shipout { before, after } => {
|
||||
before.steps = offset.apply(before.steps)?;
|
||||
after.steps = offset.apply(after.steps)?;
|
||||
}
|
||||
StatisticsPhase::End { usage, .. } => usage.steps = offset.apply(usage.steps)?,
|
||||
}
|
||||
let report = Self::new(phase, self.destination, self.span);
|
||||
if let StatisticsPhase::End { usage, .. } = &report.phase
|
||||
&& usage.diagnostic_bytes_generated.checked_add(report.text.len())? > usage.token_limit
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(report)
|
||||
}
|
||||
}
|
||||
|
||||
impl StatisticsPhase {
|
||||
fn text(&self) -> String {
|
||||
match self {
|
||||
Self::Shipout { before, after } => {
|
||||
format!(
|
||||
"Route-D resources at shipout: active records {} -> {}; retained records {} -> {}; token cells {} -> {}; retained pages {}.\n",
|
||||
before.active_material.records(),
|
||||
after.active_material.records(),
|
||||
before.retained_material.records(),
|
||||
after.retained_material.records(),
|
||||
before.macro_token_cells + before.token_list_cells,
|
||||
after.macro_token_cells + after.token_list_cells,
|
||||
after.retained_shipouts
|
||||
)
|
||||
}
|
||||
Self::End { success, usage } => {
|
||||
let mut text = format!(
|
||||
"Route-D resource usage at core execution end ({}):\n {} steps out of {}\n {} source files, {} source payload bytes, {} active mouth payload bytes\n {} command entries, {} control-name bytes\n {} macro bindings, {} unique macro bodies, {} macro token cells\n {} token-list cells, {} saved entries\n {} active material records, {} retained material records, {} retained pages\n {} font instances, {} font parameter cells, {} TFM resources / {} source bytes\n {} hyphenation exceptions\n stack peaks: {} input, {} group, {} box, {} math, {} conditional, {} scanner, {} expansion\n",
|
||||
if *success { "success" } else { "failure" },
|
||||
usage.steps,
|
||||
usage.step_limit,
|
||||
usage.source_files,
|
||||
usage.source_payload_bytes,
|
||||
usage.mouth_payload_bytes,
|
||||
usage.state.command_entries,
|
||||
usage.state.control_name_bytes,
|
||||
usage.state.macro_bindings,
|
||||
usage.unique_macro_bodies,
|
||||
usage.macro_token_cells,
|
||||
usage.token_list_cells,
|
||||
usage.state.save_entries,
|
||||
usage.active_material.records(),
|
||||
usage.retained_material.records(),
|
||||
usage.retained_shipouts,
|
||||
usage.state.font_instances,
|
||||
usage.state.font_parameter_cells,
|
||||
usage.state.tfm_resources,
|
||||
usage.state.tfm_resource_bytes,
|
||||
usage.state.hyphenation_exceptions,
|
||||
usage.stack_peaks.input_frames,
|
||||
usage.stack_peaks.groups,
|
||||
usage.stack_peaks.box_frames,
|
||||
usage.stack_peaks.math_frames,
|
||||
usage.stack_peaks.conditionals,
|
||||
usage.stack_peaks.scanner_depth,
|
||||
usage.stack_peaks.expansion_depth
|
||||
);
|
||||
if let Some(h) = &usage.host {
|
||||
text.push_str(&format!(" host resources: {} reads / {} bytes; {} lookups / {} misses / {} errors; {} stream reads / {} bytes\n",h.resource_reads,h.resource_bytes_read,h.lookups,h.negative_lookups,h.failed_lookups,h.stream_read_calls,h.stream_bytes_read));
|
||||
} else {
|
||||
text.push_str(" host resource telemetry unavailable\n");
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) enum Ownership {
|
||||
Active,
|
||||
|
||||
Reference in new issue
Block a user