summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-04-04 20:48:19 -0400
committerGitHub <noreply@github.com>2021-04-04 20:48:19 -0400
commit405ce64a02fd55ebb383ce797910b2ec82dc97b4 (patch)
treed9d0fd65000fd21c14a45f05dac97dbf89108350 /src/app
parent476aaff45c64af95cbcf486bab5bfe53c8897b97 (diff)
refactor: Switch from fnv to fxhash (#444)
Switches to fxhash from fnv, which should be a bit faster.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_harvester.rs6
-rw-r--r--src/app/data_harvester/processes.rs12
2 files changed, 9 insertions, 9 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 207bb23a..989fcf6c 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -3,7 +3,7 @@
use std::time::Instant;
#[cfg(target_os = "linux")]
-use fnv::FnvHashMap;
+use fxhash::FxHashMap;
#[cfg(not(target_os = "linux"))]
use sysinfo::{System, SystemExt};
@@ -85,7 +85,7 @@ pub struct DataCollector {
#[cfg(target_os = "linux")]
previous_average_cpu_time: Option<(cpu::PastCpuWork, cpu::PastCpuTotal)>,
#[cfg(target_os = "linux")]
- pid_mapping: FnvHashMap<crate::Pid, processes::PrevProcDetails>,
+ pid_mapping: FxHashMap<crate::Pid, processes::PrevProcDetails>,
#[cfg(target_os = "linux")]
prev_idle: f64,
#[cfg(target_os = "linux")]
@@ -116,7 +116,7 @@ impl DataCollector {
#[cfg(target_os = "linux")]
previous_average_cpu_time: None,
#[cfg(target_os = "linux")]
- pid_mapping: FnvHashMap::default(),
+ pid_mapping: FxHashMap::default(),
#[cfg(target_os = "linux")]
prev_idle: 0_f64,
#[cfg(target_os = "linux")]
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 52e80c27..e2efea79 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -12,7 +12,7 @@ use crate::utils::error;
use crate::utils::error::BottomError;
#[cfg(target_os = "linux")]
-use fnv::{FnvHashMap, FnvHashSet};
+use fxhash::{FxHashMap, FxHashSet};
#[cfg(not(target_os = "linux"))]
use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
@@ -338,9 +338,9 @@ fn get_uid_and_gid(path: &Path) -> (Option<u32>, Option<u32>) {
#[allow(clippy::too_many_arguments)]
#[cfg(target_os = "linux")]
fn read_proc(
- pid: Pid, cpu_usage: f64, cpu_fraction: f64,
- pid_mapping: &mut FnvHashMap<Pid, PrevProcDetails>, use_current_cpu_total: bool,
- time_difference_in_secs: u64, mem_total_kb: u64, page_file_kb: u64,
+ pid: Pid, cpu_usage: f64, cpu_fraction: f64, pid_mapping: &mut FxHashMap<Pid, PrevProcDetails>,
+ use_current_cpu_total: bool, time_difference_in_secs: u64, mem_total_kb: u64,
+ page_file_kb: u64,
) -> error::Result<ProcessHarvest> {
use std::io::prelude::*;
use std::io::BufReader;
@@ -491,13 +491,13 @@ fn read_proc(
#[cfg(target_os = "linux")]
pub fn get_process_data(
prev_idle: &mut f64, prev_non_idle: &mut f64,
- pid_mapping: &mut FnvHashMap<Pid, PrevProcDetails>, use_current_cpu_total: bool,
+ pid_mapping: &mut FxHashMap<Pid, PrevProcDetails>, use_current_cpu_total: bool,
time_difference_in_secs: u64, mem_total_kb: u64, page_file_kb: u64,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
// TODO: [PROC THREADS] Add threads
if let Ok((cpu_usage, cpu_fraction)) = cpu_usage_calculation(prev_idle, prev_non_idle) {
- let mut pids_to_clear: FnvHashSet<Pid> = pid_mapping.keys().cloned().collect();
+ let mut pids_to_clear: FxHashSet<Pid> = pid_mapping.keys().cloned().collect();
let process_vector: Vec<ProcessHarvest> = std::fs::read_dir("/proc")?
.filter_map(|dir| {
if let Ok(dir) = dir {