1use crate::{BuckyErrorCode, BuckyResult};
2
3use once_cell::sync::OnceCell;
4use std::sync::Arc;
5
6pub trait PerfIsolate: Send + Sync {
7 fn begin_request(&self, id: &str, key: &str);
8 fn end_request(&self, id: &str, key: &str, err: BuckyErrorCode, bytes: Option<u32>);
9
10 fn acc(&self, id: &str, err: BuckyErrorCode, size: Option<u64>);
11
12 fn action(
13 &self,
14 id: &str,
15 err: BuckyErrorCode,
16 name: &str,
17 value: &str,
18 );
19
20 fn record(&self, id: &str, total: u64, total_size: Option<u64>);
21}
22
23pub type PerfIsolateRef = Arc<Box<dyn PerfIsolate>>;
24
25#[async_trait::async_trait]
26pub trait PerfManager: Send + Sync {
27 async fn flush(&self) -> BuckyResult<()>;
28 fn get_isolate(&self, id: &str) -> PerfIsolateRef;
29}
30
31pub static PERF_MANGER: OnceCell<Box<dyn PerfManager>> = OnceCell::new();