mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
perf(db): cache ProcessUID::own in memory (#11302)
This commit is contained in:
@@ -7,7 +7,7 @@ use reth_tracing::tracing::error;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
sync::Arc,
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
use sysinfo::{ProcessRefreshKind, RefreshKind, System};
|
||||
|
||||
@@ -91,7 +91,7 @@ impl StorageLockInner {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
struct ProcessUID {
|
||||
/// OS process identifier
|
||||
pid: usize,
|
||||
@@ -102,14 +102,16 @@ struct ProcessUID {
|
||||
impl ProcessUID {
|
||||
/// Creates [`Self`] for the provided PID.
|
||||
fn new(pid: usize) -> Option<Self> {
|
||||
System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()))
|
||||
.process(pid.into())
|
||||
.map(|process| Self { pid, start_time: process.start_time() })
|
||||
let mut system = System::new();
|
||||
let pid2 = sysinfo::Pid::from(pid);
|
||||
system.refresh_process_specifics(pid2, ProcessRefreshKind::new());
|
||||
system.process(pid2).map(|process| Self { pid, start_time: process.start_time() })
|
||||
}
|
||||
|
||||
/// Creates [`Self`] from own process.
|
||||
fn own() -> Self {
|
||||
Self::new(process::id() as usize).expect("own process")
|
||||
static CACHE: OnceLock<ProcessUID> = OnceLock::new();
|
||||
CACHE.get_or_init(|| Self::new(process::id() as usize).expect("own process")).clone()
|
||||
}
|
||||
|
||||
/// Parses [`Self`] from a file.
|
||||
|
||||
Reference in New Issue
Block a user