Skip to content

Commit

Permalink
Don't use once_cell where it's not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Nov 6, 2024
1 parent 31c7c40 commit c155fc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/process_data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 5 additions & 6 deletions lib/process_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand All @@ -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<HashMap<libc::uid_t, String>> = Lazy::new(|| unsafe {
static USERS_CACHE: LazyLock<HashMap<libc::uid_t, String>> = LazyLock::new(|| unsafe {
uzers::all_users()
.map(|user| (user.uid(), user.name().to_string_lossy().to_string()))
.collect()
});

static PAGESIZE: Lazy<usize> = Lazy::new(sysconf::pagesize);
static PAGESIZE: LazyLock<usize> = LazyLock::new(sysconf::pagesize);

static NUM_CPUS: Lazy<usize> = Lazy::new(num_cpus::get);
static NUM_CPUS: LazyLock<usize> = LazyLock::new(num_cpus::get);

static RE_UID: Lazy<Regex> = lazy_regex!(r"Uid:\s*(\d+)");

Expand Down

0 comments on commit c155fc8

Please sign in to comment.