summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-12-23 04:35:42 -0500
committerGitHub <noreply@github.com>2023-12-23 04:35:42 -0500
commita1168cac67088504c01ecdcde8c5d0cc50252126 (patch)
treee86a0b49e5aef2a0aefb5a2ec5da21d16e30b4e7 /src/app
parent854f3aed957dc149f27aa069e3e2a73eda693e01 (diff)
refactor: remove once_cell (#1361)
* refactor: remove once_cell * some missing fixes
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_farmer.rs7
-rw-r--r--src/app/data_harvester/nvidia.rs7
-rw-r--r--src/app/data_harvester/processes/linux/process.rs6
3 files changed, 10 insertions, 10 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index 46eb32f2..73881a4b 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -364,13 +364,12 @@ impl DataCollection {
let io_device = {
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
- use once_cell::sync::Lazy;
+ use std::sync::OnceLock;
use regex::Regex;
// Must trim one level further for macOS!
- static DISK_REGEX: Lazy<Regex> =
- Lazy::new(|| Regex::new(r"disk\d+").unwrap());
- if let Some(new_name) = DISK_REGEX.find(checked_name) {
+ static DISK_REGEX: OnceLock<Regex> = OnceLock::new();
+ if let Some(new_name) = DISK_REGEX.get_or_init(|| Regex::new(r"disk\d+").unwrap()).find(checked_name) {
io.get(new_name.as_str())
} else {
None
diff --git a/src/app/data_harvester/nvidia.rs b/src/app/data_harvester/nvidia.rs
index 964ccc5a..0acb7dcb 100644
--- a/src/app/data_harvester/nvidia.rs
+++ b/src/app/data_harvester/nvidia.rs
@@ -1,8 +1,9 @@
+use std::sync::OnceLock;
+
use hashbrown::HashMap;
use nvml_wrapper::enum_wrappers::device::TemperatureSensor;
use nvml_wrapper::enums::device::UsedGpuMemory;
use nvml_wrapper::{error::NvmlError, Nvml};
-use once_cell::sync::Lazy;
use crate::app::Filter;
@@ -10,7 +11,7 @@ use crate::app::layout_manager::UsedWidgets;
use crate::data_harvester::memory::MemHarvest;
use crate::data_harvester::temperature::{is_temp_filtered, TempHarvest, TemperatureType};
-pub static NVML_DATA: Lazy<Result<Nvml, NvmlError>> = Lazy::new(Nvml::init);
+pub static NVML_DATA: OnceLock<Result<Nvml, NvmlError>> = OnceLock::new();
pub struct GpusData {
pub memory: Option<Vec<(String, MemHarvest)>>,
@@ -23,7 +24,7 @@ pub struct GpusData {
pub fn get_nvidia_vecs(
temp_type: &TemperatureType, filter: &Option<Filter>, widgets_to_harvest: &UsedWidgets,
) -> Option<GpusData> {
- if let Ok(nvml) = &*NVML_DATA {
+ if let Ok(nvml) = NVML_DATA.get_or_init(Nvml::init) {
if let Ok(num_gpu) = nvml.device_count() {
let mut temp_vec = Vec::with_capacity(num_gpu as usize);
let mut mem_vec = Vec::with_capacity(num_gpu as usize);
diff --git a/src/app/data_harvester/processes/linux/process.rs b/src/app/data_harvester/processes/linux/process.rs
index 95182c82..6841b0d5 100644
--- a/src/app/data_harvester/processes/linux/process.rs
+++ b/src/app/data_harvester/processes/linux/process.rs
@@ -5,11 +5,11 @@ use std::{
fs::File,
io::{self, BufRead, BufReader, Read},
path::PathBuf,
+ sync::OnceLock,
};
use anyhow::anyhow;
use libc::uid_t;
-use once_cell::sync::Lazy;
use rustix::{
fd::OwnedFd,
fs::{Mode, OFlags},
@@ -18,7 +18,7 @@ use rustix::{
use crate::Pid;
-static PAGESIZE: Lazy<u64> = Lazy::new(|| rustix::param::page_size() as u64);
+static PAGESIZE: OnceLock<u64> = OnceLock::new();
#[inline]
fn next_part<'a>(iter: &mut impl Iterator<Item = &'a str>) -> Result<&'a str, io::Error> {
@@ -103,7 +103,7 @@ impl Stat {
/// Returns the Resident Set Size in bytes.
#[inline]
pub fn rss_bytes(&self) -> u64 {
- self.rss * *PAGESIZE
+ self.rss * PAGESIZE.get_or_init(|| rustix::param::page_size() as u64)
}
}