Skip to main content

ic_memory/runtime/
diagnostics.rs

1use super::{MemoryRuntime, RuntimeDiagnosticError};
2use crate::{DiagnosticExport, RecoveredLedger, physical::CommitSnapshotDiagnostic};
3use ic_platform::stable_structures::Memory;
4
5impl<M: Memory> MemoryRuntime<M> {
6    /// Export this runtime's recovered ledger and live virtual-memory sizes.
7    pub fn diagnostic_export(&self) -> Result<DiagnosticExport, RuntimeDiagnosticError> {
8        if !self.is_bootstrapped() {
9            return Err(RuntimeDiagnosticError::NotBootstrapped);
10        }
11        let recovered = self.ledger_record_from_memory()?.recover()?;
12        Ok(self.recovered_diagnostic_export(recovered))
13    }
14
15    /// Diagnose protected commit recovery from this runtime's ledger memory.
16    ///
17    /// This operation is available before bootstrap when the stable-cell
18    /// envelope is readable or the ledger memory is empty.
19    pub fn commit_recovery_diagnostic(
20        &self,
21    ) -> Result<CommitSnapshotDiagnostic, RuntimeDiagnosticError> {
22        let record = self.ledger_record_from_memory()?;
23        Ok(record.diagnostic())
24    }
25
26    fn recovered_diagnostic_export(&self, recovered: RecoveredLedger) -> DiagnosticExport {
27        DiagnosticExport::from_owned_ledger(recovered.into_ledger())
28            .with_memory_sizes(|record| self.memory_size_pages(record.slot().id()))
29    }
30}