Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Sep 14, 2022
1 parent 557cd72 commit 4ba5e1b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/data_harvester/cpu/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::VecDeque;

use sysinfo::{LoadAvg, ProcessorExt, System, SystemExt};
use sysinfo::{LoadAvg, System, SystemExt};

use super::{CpuData, CpuHarvest, PastCpuTotal, PastCpuWork};
use crate::app::data_harvester::cpu::LoadAvgHarvest;
Expand All @@ -25,7 +25,7 @@ pub async fn get_cpu_data_list(
.collect();

if show_average_cpu {
let cpu = sys.global_processor_info();
let cpu = sys.global_cpu_info();

cpu_deque.push_front(CpuData {
cpu_prefix: "AVG".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/data_harvester/processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct ProcessHarvest {

/// This is the *effective* user ID of the process. This is only used on Unix platforms.
#[cfg(target_family = "unix")]
pub uid: libc::uid_t,
pub uid: Option<libc::uid_t>,

/// This is the process' user. This is only used on Unix platforms.
#[cfg(target_family = "unix")]
Expand Down
2 changes: 1 addition & 1 deletion src/app/data_harvester/processes/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn read_proc(
total_read_bytes,
total_write_bytes,
process_state,
uid,
uid: Some(uid),
user: user_table
.get_uid_to_username_mapping(uid)
.map(Into::into)
Expand Down
20 changes: 12 additions & 8 deletions src/app/data_harvester/processes/macos_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use std::io;

use super::ProcessHarvest;
use sysinfo::{PidExt, ProcessExt, ProcessStatus, ProcessorExt, System, SystemExt};
use sysinfo::{CpuExt, PidExt, ProcessExt, ProcessStatus, System, SystemExt};

use crate::data_harvester::processes::UserTable;

Expand All @@ -14,8 +14,8 @@ pub fn get_process_data(
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
let mut process_vector: Vec<ProcessHarvest> = Vec::new();
let process_hashmap = sys.processes();
let cpu_usage = sys.global_processor_info().cpu_usage() as f64 / 100.0;
let num_processors = sys.processors().len() as f64;
let cpu_usage = sys.global_cpu_info().cpu_usage() as f64 / 100.0;
let num_processors = sys.cpus().len() as f64;
for process_val in process_hashmap.values() {
let name = if process_val.name().is_empty() {
let process_cmd = process_val.cmd();
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn get_process_data(
let ps = process_val.status();
(ps.to_string(), convert_process_status_to_char(ps))
};
let uid = process_val.uid;
let uid = process_val.user_id().map(|u| **u);
process_vector.push(ProcessHarvest {
pid: process_val.pid().as_u32() as _,
parent_pid: process_val.parent().map(|p| p.as_u32() as _),
Expand All @@ -84,10 +84,14 @@ pub fn get_process_data(
total_write_bytes: disk_usage.total_written_bytes,
process_state,
uid,
user: user_table
.get_uid_to_username_mapping(uid)
.map(Into::into)
.unwrap_or_else(|_| "N/A".into()),
user: uid
.and_then(|uid| {
user_table
.get_uid_to_username_mapping(uid)
.map(Into::into)
.ok()
})
.unwrap_or_else(|| "N/A".into()),
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/data_harvester/processes/windows.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Process data collection for Windows. Uses sysinfo.
use super::ProcessHarvest;
use sysinfo::{PidExt, ProcessExt, ProcessorExt, System, SystemExt};
use sysinfo::{CpuExt, PidExt, ProcessExt, System, SystemExt};

pub fn get_process_data(
sys: &System, use_current_cpu_total: bool, mem_total_kb: u64,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
let mut process_vector: Vec<ProcessHarvest> = Vec::new();
let process_hashmap = sys.processes();
let cpu_usage = sys.global_processor_info().cpu_usage() as f64 / 100.0;
let num_processors = sys.processors().len() as f64;
let cpu_usage = sys.global_cpu_info().cpu_usage() as f64 / 100.0;
let num_processors = sys.cpus().len() as f64;
for process_val in process_hashmap.values() {
let name = if process_val.name().is_empty() {
let process_cmd = process_val.cmd();
Expand Down

0 comments on commit 4ba5e1b

Please sign in to comment.