From c155fc88124b5d8e4d02de7442eac50e33082bf0 Mon Sep 17 00:00:00 2001 From: nokyan Date: Wed, 6 Nov 2024 18:52:28 +0100 Subject: [PATCH] Don't use once_cell where it's not needed --- Cargo.lock | 1 - lib/process_data/Cargo.toml | 1 - lib/process_data/src/lib.rs | 11 +++++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f17de1fb..444921b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1289,7 +1289,6 @@ dependencies = [ "num_cpus", "nutype", "nvml-wrapper", - "once_cell", "serde", "syscalls", "sysconf", diff --git a/lib/process_data/Cargo.toml b/lib/process_data/Cargo.toml index c1970ad1..786b6329 100644 --- a/lib/process_data/Cargo.toml +++ b/lib/process_data/Cargo.toml @@ -24,7 +24,6 @@ libc = "0.2.159" num_cpus = "1.16.0" nutype = { version = "0.5.0", features = ["serde"] } nvml-wrapper = "0.10.0" -once_cell = "1.20.1" serde = { version = "1.0.210", features = ["serde_derive"] } syscalls = { version = "0.6.18", features = ["all"] } sysconf = "0.3.4" diff --git a/lib/process_data/src/lib.rs b/lib/process_data/src/lib.rs index e855c14a..b2f83d2a 100644 --- a/lib/process_data/src/lib.rs +++ b/lib/process_data/src/lib.rs @@ -2,13 +2,12 @@ pub mod pci_slot; use anyhow::{bail, Context, Result}; use glob::glob; -use lazy_regex::{lazy_regex, Regex}; +use lazy_regex::{lazy_regex, Lazy, Regex}; use nutype::nutype; use nvml_wrapper::enums::device::UsedGpuMemory; use nvml_wrapper::error::NvmlError; use nvml_wrapper::struct_wrappers::device::{ProcessInfo, ProcessUtilizationSample}; use nvml_wrapper::{Device, Nvml}; -use once_cell::sync::Lazy; use pci_slot::PciSlot; use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, HashMap, HashSet}; @@ -17,7 +16,7 @@ use std::io::{Read, Write}; use std::os::linux::fs::MetadataExt; use std::path::Path; use std::str::FromStr; -use std::sync::RwLock; +use std::sync::{LazyLock, RwLock}; use std::{path::PathBuf, time::SystemTime}; const STAT_OFFSET: usize = 2; // we split the stat contents where the executable name ends, which is the second element @@ -27,15 +26,15 @@ const STAT_SYSTEM_CPU_TIME: usize = 14 - STAT_OFFSET; const STAT_NICE: usize = 18 - STAT_OFFSET; const STAT_STARTTIME: usize = 21 - STAT_OFFSET; -static USERS_CACHE: Lazy> = Lazy::new(|| unsafe { +static USERS_CACHE: LazyLock> = LazyLock::new(|| unsafe { uzers::all_users() .map(|user| (user.uid(), user.name().to_string_lossy().to_string())) .collect() }); -static PAGESIZE: Lazy = Lazy::new(sysconf::pagesize); +static PAGESIZE: LazyLock = LazyLock::new(sysconf::pagesize); -static NUM_CPUS: Lazy = Lazy::new(num_cpus::get); +static NUM_CPUS: LazyLock = LazyLock::new(num_cpus::get); static RE_UID: Lazy = lazy_regex!(r"Uid:\s*(\d+)");