[PERF] Runtime Telemetry Hot Path
This commit is contained in:
parent
698a076632
commit
e672e4d6b6
@ -17,10 +17,17 @@ use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
type ResidentMap<T> = HashMap<AssetId, ResidentEntry<T>>;
|
||||
type StagedValue<T> = (Arc<T>, usize);
|
||||
type StagingMap<T> = HashMap<HandleId, StagedValue<T>>;
|
||||
|
||||
type AssetTable = HashMap<AssetId, AssetEntry>;
|
||||
type HandleTable = HashMap<HandleId, LoadHandleInfo>;
|
||||
|
||||
const GLYPH_BANK_PALETTE_COUNT_V1: usize = 64;
|
||||
const GLYPH_BANK_COLORS_PER_PALETTE: usize = 16;
|
||||
const GLYPH_BANK_PALETTE_BYTES_V1: usize =
|
||||
GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * std::mem::size_of::<u16>();
|
||||
GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * size_of::<u16>();
|
||||
|
||||
/// Resident metadata for a decoded/materialized asset inside a BankPolicy.
|
||||
#[derive(Debug)]
|
||||
@ -54,10 +61,10 @@ impl<T> ResidentEntry<T> {
|
||||
/// This is internal to the AssetManager and not visible to peripherals.
|
||||
pub struct BankPolicy<T> {
|
||||
/// Dedup table: asset_id -> resident entry (value + telemetry).
|
||||
pub resident: Arc<RwLock<HashMap<AssetId, ResidentEntry<T>>>>,
|
||||
pub resident: Arc<RwLock<ResidentMap<T>>>,
|
||||
|
||||
/// Staging area: handle -> value ready to commit.
|
||||
pub staging: Arc<RwLock<HashMap<HandleId, (Arc<T>, usize)>>>,
|
||||
pub staging: Arc<RwLock<StagingMap<T>>>,
|
||||
|
||||
/// Total bytes currently in resident storage.
|
||||
pub used_bytes: Arc<AtomicUsize>,
|
||||
@ -119,7 +126,7 @@ impl<T> BankPolicy<T> {
|
||||
}
|
||||
|
||||
/// Take staged value (used by commit path).
|
||||
pub fn take_staging(&self, handle: HandleId) -> Option<(Arc<T>, usize)> {
|
||||
pub fn take_staging(&self, handle: HandleId) -> Option<StagedValue<T>> {
|
||||
let entry = self.staging.write().unwrap().remove(&handle);
|
||||
if let Some((_, bytes)) = entry.as_ref() {
|
||||
self.inflight_bytes.fetch_sub(*bytes, Ordering::Relaxed);
|
||||
@ -136,8 +143,8 @@ impl<T> BankPolicy<T> {
|
||||
}
|
||||
|
||||
pub struct AssetManager {
|
||||
assets: Arc<RwLock<HashMap<AssetId, AssetEntry>>>,
|
||||
handles: Arc<RwLock<HashMap<HandleId, LoadHandleInfo>>>,
|
||||
assets: Arc<RwLock<AssetTable>>,
|
||||
handles: Arc<RwLock<HandleTable>>,
|
||||
next_handle_id: Mutex<HandleId>,
|
||||
assets_data: Arc<RwLock<AssetsPayloadSource>>,
|
||||
|
||||
@ -476,7 +483,11 @@ impl AssetManager {
|
||||
bank_arc,
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
gfx_policy.stage(handle_id, resident_arc, entry_clone.decoded_size as usize);
|
||||
gfx_policy.stage(
|
||||
handle_id,
|
||||
resident_arc,
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
@ -500,8 +511,11 @@ impl AssetManager {
|
||||
bank_arc,
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
sound_policy
|
||||
.stage(handle_id, resident_arc, entry_clone.decoded_size as usize);
|
||||
sound_policy.stage(
|
||||
handle_id,
|
||||
resident_arc,
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
|
||||
@ -10,12 +10,7 @@ pub struct LogService {
|
||||
|
||||
impl LogService {
|
||||
pub fn new(capacity: usize) -> Self {
|
||||
Self {
|
||||
events: VecDeque::with_capacity(capacity),
|
||||
capacity,
|
||||
next_seq: 0,
|
||||
logs_count: 0,
|
||||
}
|
||||
Self { events: VecDeque::with_capacity(capacity), capacity, next_seq: 0, logs_count: 0 }
|
||||
}
|
||||
|
||||
pub fn log(
|
||||
|
||||
@ -180,10 +180,7 @@ impl Certifier {
|
||||
LogLevel::Warn,
|
||||
LogSource::Pos,
|
||||
0xCA07,
|
||||
format!(
|
||||
"Cert: Log pressure exceeded limit ({} > {})",
|
||||
telemetry.logs_count, limit
|
||||
),
|
||||
format!("Cert: Log pressure exceeded limit ({} > {})", telemetry.logs_count, limit),
|
||||
);
|
||||
violations += 1;
|
||||
}
|
||||
|
||||
@ -149,7 +149,8 @@ impl VirtualMachineRuntime {
|
||||
self.telemetry_current.logs_count = self.log_service.logs_count;
|
||||
self.log_service.reset_count();
|
||||
|
||||
self.telemetry_current.host_cpu_time_us = start.elapsed().as_micros() as u64;
|
||||
self.telemetry_current.host_cpu_time_us =
|
||||
start.elapsed().as_micros() as u64;
|
||||
|
||||
let ts_ms = self.boot_time.elapsed().as_millis() as u64;
|
||||
self.telemetry_current.violations = self.certifier.evaluate(
|
||||
|
||||
@ -2,8 +2,8 @@ use crate::call_frame::CallFrame;
|
||||
use crate::object::{ObjectHeader, ObjectKind};
|
||||
use prometeu_bytecode::{HeapRef, Value};
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
/// Internal stored object: header plus opaque payload bytes.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user