Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 206 additions & 92 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zenith"
version = "0.14.3"
version = "0.15.0"
authors = ["Benjamin Vaisvil"]
edition = "2018"
description = "Similar to top or htop but with CPU, Network Usage, and Disk Usage charts."
Expand Down Expand Up @@ -29,7 +29,7 @@ heim = { git = "https://github.com/bvaisvil/heim.git", branch = "zenith_changes"
futures = "0.3.31"
gumdrop = { version = "~0.8.1", features = ["default_expr"] }
chrono = "~0.4.39"
sysinfo = { git = "https://github.com/bvaisvil/sysinfo.git", branch = "zenith_changes_15.1_mem_fix" }
sysinfo = "0.37"
dirs-next = "2.0.0"
serde = { version = "~1.0.217", features = ["derive"] }
serde_derive = "~1.0.217"
Expand All @@ -44,3 +44,4 @@ nvml-wrapper = { version = "0.10.0", optional = true }
unicode-width = "0.2.0"
[target.'cfg(target_os = "linux")'.dependencies]
linux-taskstats = { version = "0.7.0", default-features = false }
procfs = "0.17"
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

#[macro_use]
Expand Down Expand Up @@ -160,6 +160,7 @@ fn create_geometry(
geometry
}

#[allow(clippy::too_many_arguments)]
fn start_zenith(
rate: u64,
cpu_height: u16,
Expand Down
17 changes: 9 additions & 8 deletions src/metrics/disk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

use crate::util::percent_of;
use futures::StreamExt;
use heim::disk::{io_counters, IoCounters};
Expand All @@ -11,7 +12,7 @@ use std::fs::{canonicalize, read_link};
use std::ops;
use std::path::PathBuf;
use std::time::Duration;
use sysinfo::{Disk, DiskExt};
use sysinfo::Disk;

#[derive(PartialEq, Copy, Clone, Debug)]
pub struct IoMetrics {
Expand Down Expand Up @@ -81,11 +82,11 @@ impl ZDisk {

pub fn from_disk(d: &Disk) -> ZDisk {
ZDisk {
mount_point: d.get_mount_point().to_path_buf(),
available_bytes: d.get_available_space(),
size_bytes: d.get_total_space(),
name: get_device_name(d.get_name()),
file_system: String::from_utf8_lossy(d.get_file_system()).into_owned(),
mount_point: d.mount_point().to_path_buf(),
available_bytes: d.available_space(),
size_bytes: d.total_space(),
name: get_device_name(d.name()),
file_system: d.file_system().to_string_lossy().into_owned(),
previous_io: IoMetrics {
read_bytes: 0,
write_bytes: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/graphics/device.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

pub trait GraphicsExt {
Expand Down
5 changes: 3 additions & 2 deletions src/metrics/graphics/graphics_none.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

use crate::metrics::graphics::device::GraphicsDevice;
use crate::metrics::graphics::device::GraphicsExt;
use crate::metrics::CPUTimeApp;
Expand Down
10 changes: 7 additions & 3 deletions src/metrics/graphics/graphics_nvidia.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

use crate::metrics::graphics::device::*;
use crate::metrics::histogram::HistogramKind;
use crate::metrics::CPUTimeApp;
use nvml::device::Device;
use nvml::enum_wrappers::device::{Clock, TemperatureSensor, TemperatureThreshold};
use nvml::struct_wrappers::device::ProcessUtilizationSample;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::fmt;

impl From<&ProcessUtilizationSample> for GraphicsDeviceProcess {
Expand Down Expand Up @@ -199,7 +201,9 @@ impl GraphicsExt for CPUTimeApp {
fn update_gpu_utilization(&mut self) {
for d in &mut self.gfx_devices.iter().skip(1) {
for p in &d.processes {
let proc = self.process_map.get_mut(&p.pid);
let proc = self
.process_map
.get_mut(&p.pid.try_into().expect("negative pid makes no sense"));
if let Some(proc) = proc {
proc.gpu_usage =
(p.sm_utilization + p.dec_utilization + p.enc_utilization) as u64;
Expand Down
5 changes: 3 additions & 2 deletions src/metrics/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Copyright 2019-2020, Benjamin Vaisvil and the zenith contributors
/*!
* Copyright 2019-2026, Benjamin Vaisvil and the zenith contributors
*/

use crate::restore_terminal;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
Expand Down
109 changes: 109 additions & 0 deletions src/metrics/memory_mac.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#[allow(deprecated)]
use libc::{c_int, c_void, mach_host_self, mach_port_t, sysctlbyname};
use std::convert::TryInto;
use std::ffi::CString;
use std::mem;

const HOST_VM_INFO64: c_int = 4;
const HOST_VM_INFO64_COUNT: u32 =
(mem::size_of::<vm_statistics64>() / mem::size_of::<c_int>()) as u32;
const KERN_SUCCESS: c_int = 0;

#[repr(C)]
struct vm_statistics64 {
free_count: u32,
active_count: u32,
inactive_count: u32,
wire_count: u32,
zero_fill_count: u64,
reactivations: u64,
pageins: u64,
pageouts: u64,
faults: u64,
cow_faults: u64,
lookups: u64,
hits: u64,
purges: u64,
purgeable_count: u32,
speculative_count: u32,
decompressions: u64,
compressions: u64,
swapins: u64,
swapouts: u64,
compressor_page_count: u32,
throttled_count: u32,
external_page_count: u32,
internal_page_count: u32,
total_uncompressed_pages_in_compressor: u64,
}

extern "C" {
fn host_statistics64(
host_priv: mach_port_t,
flavor: c_int,
host_info_out: *mut c_int,
host_info_outCnt: *mut u32,
) -> c_int;

fn host_page_size(host: mach_port_t, out_page_size: *mut usize) -> c_int;
}

fn get_vm_page_pageable_internal_count() -> Option<u64> {
let mut buf: Vec<u8> = vec![0; 8];
let c = CString::new("vm.page_pageable_internal_count").ok()?;
let mut len: usize = 8;
unsafe {
if sysctlbyname(
c.as_ptr(),
buf.as_mut_ptr() as *mut c_void,
&mut len,
std::ptr::null_mut(),
0,
) != 0
{
return None;
}
Some(u64::from_ne_bytes(buf[..8].try_into().ok()?))
}
}

pub fn get_macos_memory_used() -> Option<u64> {
unsafe {
#[allow(deprecated)]
let host_port = mach_host_self();
let mut vm_stat: vm_statistics64 = mem::zeroed();
let mut count = HOST_VM_INFO64_COUNT;

let ret = host_statistics64(
host_port,
HOST_VM_INFO64,
&mut vm_stat as *mut _ as *mut c_int,
&mut count,
);

if ret != KERN_SUCCESS {
return None;
}

// Get page size using host_page_size, fallback to sysconf
let mut page_size: usize = 0;
let res = host_page_size(host_port, &mut page_size);
if res != KERN_SUCCESS {
page_size = libc::sysconf(libc::_SC_PAGESIZE) as usize;
}

// Get pageable internal count for accurate app memory
let pageable_internal = get_vm_page_pageable_internal_count()?;

let app_mem = pageable_internal.saturating_sub(vm_stat.purgeable_count as u64);
let wired_mem = vm_stat.wire_count as u64;
let compressed_mem = vm_stat.compressor_page_count as u64;

Some(
app_mem
.saturating_add(compressed_mem)
.saturating_add(wired_mem)
.saturating_mul(page_size as u64),
)
}
}
Loading
Loading