Skip to content

Commit

Permalink
Fix CI build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samin-cf committed Nov 3, 2024
1 parent cc7c945 commit a4e7bd8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
40 changes: 40 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,46 @@ pub(crate) mod system;
#[cfg(feature = "user")]
pub(crate) mod user;

/// Type containing read and written bytes.
///
/// It is returned by [`Process::disk_usage`][crate::Process::disk_usage] and [`Disk::usage`][crate::Disk::usage].
///
#[cfg_attr(not(all(feature = "system", feature = "disk")), doc = "```ignore")]
/// ```no_run
/// use sysinfo::{Disks, System};
///
/// let s = System::new_all();
/// for (pid, process) in s.processes() {
/// let disk_usage = process.disk_usage();
/// println!("[{}] read bytes : new/total => {}/{} B",
/// pid,
/// disk_usage.read_bytes,
/// disk_usage.total_read_bytes,
/// );
/// println!("[{}] written bytes: new/total => {}/{} B",
/// pid,
/// disk_usage.written_bytes,
/// disk_usage.total_written_bytes,
/// );
/// }
///
/// let disks = Disks::new_with_refreshed_list();
/// for disk in disks.list() {
/// println!("[{:?}] disk usage: {:?}", disk.name(), disk.usage());
/// }
/// ```
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd)]
pub struct DiskUsage {
/// Total number of written bytes.
pub total_written_bytes: u64,
/// Number of written bytes since the last refresh.
pub written_bytes: u64,
/// Total number of read bytes.
pub total_read_bytes: u64,
/// Number of read bytes since the last refresh.
pub read_bytes: u64,
}

macro_rules! xid {
($(#[$outer:meta])+ $name:ident, $type:ty $(, $trait:ty)?) => {
#[cfg(any(feature = "system", feature = "user"))]
Expand Down
39 changes: 1 addition & 38 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;
use std::path::Path;
use std::str::FromStr;

use crate::common::DiskUsage;
use crate::{CpuInner, Gid, ProcessInner, SystemInner, Uid};

/// Structs containing system's information such as processes, memory and CPU.
Expand Down Expand Up @@ -938,44 +939,6 @@ pub struct CGroupLimits {
pub rss: u64,
}

/// Type containing read and written bytes.
///
/// It is returned by [`Process::disk_usage`][crate::Process::disk_usage].
///
/// ⚠️ Files might be cached in memory by your OS, meaning that reading/writing them might not
/// increase the `read_bytes`/`written_bytes` values. You can find more information about it
/// in the `proc_pid_io` manual (`man proc_pid_io` on unix platforms).
///
/// ```no_run
/// use sysinfo::System;
///
/// let s = System::new_all();
/// for (pid, process) in s.processes() {
/// let disk_usage = process.disk_usage();
/// println!("[{}] read bytes : new/total => {}/{} B",
/// pid,
/// disk_usage.read_bytes,
/// disk_usage.total_read_bytes,
/// );
/// println!("[{}] written bytes: new/total => {}/{} B",
/// pid,
/// disk_usage.written_bytes,
/// disk_usage.total_written_bytes,
/// );
/// }
/// ```
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd)]
pub struct DiskUsage {
/// Total number of written bytes.
pub total_written_bytes: u64,
/// Number of written bytes since the last refresh.
pub written_bytes: u64,
/// Total number of read bytes.
pub total_read_bytes: u64,
/// Number of read bytes since the last refresh.
pub read_bytes: u64,
}

/// Enum describing the different status of a process.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProcessStatus {
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ pub use crate::common::disk::{Disk, DiskKind, Disks};
pub use crate::common::network::{IpNetwork, MacAddr, NetworkData, Networks};
#[cfg(feature = "system")]
pub use crate::common::system::{
get_current_pid, CGroupLimits, Cpu, CpuRefreshKind, DiskUsage, LoadAvg, MemoryRefreshKind, Pid,
Process, ProcessRefreshKind, ProcessStatus, ProcessesToUpdate, RefreshKind, Signal, System,
ThreadKind, UpdateKind,
get_current_pid, CGroupLimits, Cpu, CpuRefreshKind, LoadAvg, MemoryRefreshKind, Pid, Process,
ProcessRefreshKind, ProcessStatus, ProcessesToUpdate, RefreshKind, Signal, System, ThreadKind,
UpdateKind,
};
#[cfg(feature = "user")]
pub use crate::common::user::{Group, Groups, User, Users};
Expand All @@ -87,6 +87,9 @@ pub use crate::common::{Gid, Uid};
#[cfg(feature = "system")]
pub use crate::sys::{MINIMUM_CPU_UPDATE_INTERVAL, SUPPORTED_SIGNALS};

#[cfg(any(feature = "system", feature = "disk"))]
pub use crate::common::DiskUsage;

#[cfg(feature = "user")]
pub(crate) use crate::common::user::GroupInner;
#[cfg(feature = "user")]
Expand Down
3 changes: 3 additions & 0 deletions src/unix/apple/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl DiskInner {
}

pub(crate) fn refresh(&mut self) -> bool {
#[cfg(target_os = "macos")]
let Some((read_bytes, written_bytes)) = self
.bsd_name
.as_ref()
Expand All @@ -81,6 +82,8 @@ impl DiskInner {
sysinfo_debug!("Failed to update disk i/o stats");
return false;
};
#[cfg(not(target_os = "macos"))]
let (read_bytes, written_bytes) = (0, 0);

self.old_read_bytes = self.read_bytes;
self.old_written_bytes = self.written_bytes;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/freebsd/disk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{Disk, DiskKind};
use crate::{Disk, DiskKind, DiskUsage};

use std::ffi::{OsStr, OsString};
use std::os::unix::ffi::OsStringExt;
Expand Down
2 changes: 1 addition & 1 deletion src/unknown/disk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{Disk, DiskKind};
use crate::{Disk, DiskKind, DiskUsage};

use std::{ffi::OsStr, path::Path};

Expand Down

0 comments on commit a4e7bd8

Please sign in to comment.