Skip to content

Commit

Permalink
feat: allow increasing the history size
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Mar 18, 2024
1 parent 5eefa8a commit 6049dee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
36 changes: 19 additions & 17 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::collections::HashMap;

use crate::{config::UiColors, metrics::Metrics, modules::soc::SocInfo, signal};

const HISTORY_CAPACITY: usize = 100;

pub(crate) type History = HashMap<String, signal::Signal<f32>>;

pub(crate) struct TabsState<'a> {
Expand Down Expand Up @@ -88,6 +86,9 @@ pub(crate) struct App<'a> {

/// Store the history of all signals (u64 needed for `Sparkline`).
pub(crate) history: History,

/// Size of the history buffer.
pub(crate) history_size: usize,
}

impl<'a> App<'a> {
Expand All @@ -101,6 +102,7 @@ impl<'a> App<'a> {
metrics: None,
soc_info,
history: HashMap::new(),
history_size,
}
}

Expand Down Expand Up @@ -147,7 +149,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * e_cluster.active_ratio());
Expand All @@ -158,7 +160,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * cpu.active_ratio as f32);
Expand All @@ -168,7 +170,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * cpu.freq_ratio() as f32);
Expand All @@ -181,7 +183,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * p_cluster.active_ratio());
Expand All @@ -192,7 +194,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * cpu.active_ratio as f32);
Expand All @@ -202,7 +204,7 @@ impl<'a> App<'a> {
self.history
.entry(sig_name)
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * cpu.freq_ratio() as f32);
Expand All @@ -212,7 +214,7 @@ impl<'a> App<'a> {
self.history
.entry("gpu_active_percent".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * metrics.gpu.active_ratio as f32);
Expand All @@ -221,15 +223,15 @@ impl<'a> App<'a> {
self.history
.entry("gpu_freq_percent".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * metrics.gpu.freq_ratio() as f32);

self.history
.entry("ane_active_percent".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ 100.0,
))
.push(100.0 * metrics.consumption.ane_w / self.soc_info.max_ane_w as f32);
Expand All @@ -241,31 +243,31 @@ impl<'a> App<'a> {
self.history
.entry("cpu_w".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ self.soc_info.max_cpu_w as f32,
))
.push(metrics.consumption.cpu_w);

self.history
.entry("gpu_w".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ self.soc_info.max_gpu_w as f32,
))
.push(metrics.consumption.gpu_w);

self.history
.entry("ane_w".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ self.soc_info.max_ane_w as f32,
))
.push(metrics.consumption.ane_w);

self.history
.entry("package_w".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ self.soc_info.max_package_w as f32,
))
.push(metrics.consumption.package_w);
Expand All @@ -277,7 +279,7 @@ impl<'a> App<'a> {
self.history
.entry("ram_usage_bytes".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ metrics.memory.ram_total as f32,
))
.push(metrics.memory.ram_used as f32);
Expand All @@ -286,7 +288,7 @@ impl<'a> App<'a> {
self.history
.entry("swap_usage_bytes".to_string())
.or_insert(signal::Signal::with_capacity(
HISTORY_CAPACITY,
self.history_size,
/* max */ metrics.memory.swap_total as f32,
))
.push(metrics.memory.swap_used as f32);
Expand Down
9 changes: 7 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ pub struct RunConfig {
value_parser = clap::value_parser!(u16).range(100..))]
pub sample_rate_ms: u16,

/// Accent color: ASCII code in 0~255.
/// History buffer size: default: 128.
///
/// Number of recent samples to keep in history for each metric.
#[arg(long, default_value = "128")]
pub history_size: usize,

/// Accent color for labels: ASCII code in 0~255, default: green.
#[arg(long, default_value = "2")]
pub accent_color: u8,

Expand Down Expand Up @@ -89,7 +95,6 @@ pub struct UiColors {
/// Gauge background color: ASCII code in 0~255.
pub gauge_bg: u8,
/// History foreground color: ASCII code in 0~255.
pub history_fg: u8,
/// History background color: ASCII code in 0~255.
pub history_bg: u8,
Expand Down
2 changes: 1 addition & 1 deletion src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn run(args: RunConfig) -> Result<()> {
let backend = TermionBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;

let app = App::new(soc_info, args.colors());
let app = App::new(soc_info, args.colors(), args.history_size);

main_ui_loop(
&mut terminal,
Expand Down

0 comments on commit 6049dee

Please sign in to comment.