mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-26 07:04:51 +02:00
refactor: More minor optimization changes (#353)
- Move data rather than cloning during data transferring step - Try using beef?
This commit is contained in:
parent
766fe25c55
commit
5d7697d3da
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -100,6 +100,12 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "beef"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "474a626a67200bd107d44179bb3d4fc61891172d11696609264589be6a0e6a43"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -114,6 +120,7 @@ dependencies = [
|
|||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"battery",
|
"battery",
|
||||||
|
"beef",
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -18,10 +18,10 @@ path = "src/bin/main.rs"
|
|||||||
doc = false
|
doc = false
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = 1
|
# debug = 1
|
||||||
lto = true
|
# lto = true
|
||||||
# debug = true
|
debug = true
|
||||||
# lto = false
|
lto = false
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ default = ["fern", "log"]
|
|||||||
anyhow = "1.0.34"
|
anyhow = "1.0.34"
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
battery = "0.7.8"
|
battery = "0.7.8"
|
||||||
|
beef = "0.4.4"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
crossterm = "0.18.2"
|
crossterm = "0.18.2"
|
||||||
ctrlc = { version = "3.1", features = ["termination"] }
|
ctrlc = { version = "3.1", features = ["termination"] }
|
||||||
|
@ -121,7 +121,7 @@ impl DataCollection {
|
|||||||
self.timed_data_vec.drain(0..remove_index);
|
self.timed_data_vec.drain(0..remove_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eat_data(&mut self, harvested_data: &Data) {
|
pub fn eat_data(&mut self, harvested_data: Box<Data>) {
|
||||||
// trace!("Eating data now...");
|
// trace!("Eating data now...");
|
||||||
let harvested_time = harvested_data.last_collection_time;
|
let harvested_time = harvested_data.last_collection_time;
|
||||||
// trace!("Harvested time: {:?}", harvested_time);
|
// trace!("Harvested time: {:?}", harvested_time);
|
||||||
@ -129,41 +129,39 @@ impl DataCollection {
|
|||||||
let mut new_entry = TimedData::default();
|
let mut new_entry = TimedData::default();
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
if let Some(network) = &harvested_data.network {
|
if let Some(network) = harvested_data.network {
|
||||||
self.eat_network(network, &mut new_entry);
|
self.eat_network(network, &mut new_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memory and Swap
|
// Memory and Swap
|
||||||
if let Some(memory) = &harvested_data.memory {
|
if let (Some(memory), Some(swap)) = (harvested_data.memory, harvested_data.swap) {
|
||||||
if let Some(swap) = &harvested_data.swap {
|
self.eat_memory_and_swap(memory, swap, &mut new_entry);
|
||||||
self.eat_memory_and_swap(memory, swap, &mut new_entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPU
|
// CPU
|
||||||
if let Some(cpu) = &harvested_data.cpu {
|
if let Some(cpu) = harvested_data.cpu {
|
||||||
self.eat_cpu(cpu, &mut new_entry);
|
self.eat_cpu(cpu, &mut new_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temp
|
// Temp
|
||||||
if let Some(temperature_sensors) = &harvested_data.temperature_sensors {
|
if let Some(temperature_sensors) = harvested_data.temperature_sensors {
|
||||||
self.eat_temp(temperature_sensors);
|
self.eat_temp(temperature_sensors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disks
|
// Disks
|
||||||
if let Some(disks) = &harvested_data.disks {
|
if let Some(disks) = harvested_data.disks {
|
||||||
if let Some(io) = &harvested_data.io {
|
if let Some(io) = harvested_data.io {
|
||||||
self.eat_disks(disks, io, harvested_time);
|
self.eat_disks(disks, io, harvested_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processes
|
// Processes
|
||||||
if let Some(list_of_processes) = &harvested_data.list_of_processes {
|
if let Some(list_of_processes) = harvested_data.list_of_processes {
|
||||||
self.eat_proc(list_of_processes);
|
self.eat_proc(list_of_processes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Battery
|
// Battery
|
||||||
if let Some(list_of_batteries) = &harvested_data.list_of_batteries {
|
if let Some(list_of_batteries) = harvested_data.list_of_batteries {
|
||||||
self.eat_battery(list_of_batteries);
|
self.eat_battery(list_of_batteries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +171,7 @@ impl DataCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn eat_memory_and_swap(
|
fn eat_memory_and_swap(
|
||||||
&mut self, memory: &mem::MemHarvest, swap: &mem::MemHarvest, new_entry: &mut TimedData,
|
&mut self, memory: mem::MemHarvest, swap: mem::MemHarvest, new_entry: &mut TimedData,
|
||||||
) {
|
) {
|
||||||
// trace!("Eating mem and swap.");
|
// trace!("Eating mem and swap.");
|
||||||
// Memory
|
// Memory
|
||||||
@ -193,11 +191,11 @@ impl DataCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In addition copy over latest data for easy reference
|
// In addition copy over latest data for easy reference
|
||||||
self.memory_harvest = memory.clone();
|
self.memory_harvest = memory;
|
||||||
self.swap_harvest = swap.clone();
|
self.swap_harvest = swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_network(&mut self, network: &network::NetworkHarvest, new_entry: &mut TimedData) {
|
fn eat_network(&mut self, network: network::NetworkHarvest, new_entry: &mut TimedData) {
|
||||||
// trace!("Eating network.");
|
// trace!("Eating network.");
|
||||||
// FIXME [NETWORKING; CONFIG]: The ability to config this?
|
// FIXME [NETWORKING; CONFIG]: The ability to config this?
|
||||||
// FIXME [NETWORKING]: Support bits, support switching between decimal and binary units (move the log part to conversion and switch on the fly)
|
// FIXME [NETWORKING]: Support bits, support switching between decimal and binary units (move the log part to conversion and switch on the fly)
|
||||||
@ -216,10 +214,10 @@ impl DataCollection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// In addition copy over latest data for easy reference
|
// In addition copy over latest data for easy reference
|
||||||
self.network_harvest = network.clone();
|
self.network_harvest = network;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_cpu(&mut self, cpu: &[cpu::CpuData], new_entry: &mut TimedData) {
|
fn eat_cpu(&mut self, cpu: Vec<cpu::CpuData>, new_entry: &mut TimedData) {
|
||||||
// trace!("Eating CPU.");
|
// trace!("Eating CPU.");
|
||||||
// Note this only pre-calculates the data points - the names will be
|
// Note this only pre-calculates the data points - the names will be
|
||||||
// within the local copy of cpu_harvest. Since it's all sequential
|
// within the local copy of cpu_harvest. Since it's all sequential
|
||||||
@ -230,14 +228,14 @@ impl DataCollection {
|
|||||||
self.cpu_harvest = cpu.to_vec();
|
self.cpu_harvest = cpu.to_vec();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_temp(&mut self, temperature_sensors: &[temperature::TempHarvest]) {
|
fn eat_temp(&mut self, temperature_sensors: Vec<temperature::TempHarvest>) {
|
||||||
// trace!("Eating temps.");
|
// trace!("Eating temps.");
|
||||||
// TODO: [PO] To implement
|
// TODO: [PO] To implement
|
||||||
self.temp_harvest = temperature_sensors.to_vec();
|
self.temp_harvest = temperature_sensors.to_vec();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_disks(
|
fn eat_disks(
|
||||||
&mut self, disks: &[disks::DiskHarvest], io: &disks::IOHarvest, harvested_time: Instant,
|
&mut self, disks: Vec<disks::DiskHarvest>, io: disks::IOHarvest, harvested_time: Instant,
|
||||||
) {
|
) {
|
||||||
// trace!("Eating disks.");
|
// trace!("Eating disks.");
|
||||||
// TODO: [PO] To implement
|
// TODO: [PO] To implement
|
||||||
@ -307,17 +305,17 @@ impl DataCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.disk_harvest = disks.to_vec();
|
self.disk_harvest = disks;
|
||||||
self.io_harvest = io.clone();
|
self.io_harvest = io;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_proc(&mut self, list_of_processes: &[processes::ProcessHarvest]) {
|
fn eat_proc(&mut self, list_of_processes: Vec<processes::ProcessHarvest>) {
|
||||||
// trace!("Eating proc.");
|
// trace!("Eating proc.");
|
||||||
self.process_harvest = list_of_processes.to_vec();
|
self.process_harvest = list_of_processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_battery(&mut self, list_of_batteries: &[batteries::BatteryHarvest]) {
|
fn eat_battery(&mut self, list_of_batteries: Vec<batteries::BatteryHarvest>) {
|
||||||
// trace!("Eating batteries.");
|
// trace!("Eating batteries.");
|
||||||
self.battery_harvest = list_of_batteries.to_vec();
|
self.battery_harvest = list_of_batteries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ impl ProcessQuery for ProcWidgetState {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if COMPARISON_LIST.contains(&queue_top.to_lowercase().as_str()) {
|
} else if COMPARISON_LIST.contains(&queue_top.to_lowercase().as_str()) {
|
||||||
return Err(QueryError("Comparison not valid here".into()));
|
return Err(QueryError(beef::Cow::borrowed("Comparison not valid here")));
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ impl ProcessQuery for ProcWidgetState {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if COMPARISON_LIST.contains(&queue_top.to_lowercase().as_str()) {
|
} else if COMPARISON_LIST.contains(&queue_top.to_lowercase().as_str()) {
|
||||||
return Err(QueryError("Comparison not valid here".into()));
|
return Err(QueryError(beef::Cow::borrowed("Comparison not valid here")));
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -165,7 +165,9 @@ impl ProcessQuery for ProcWidgetState {
|
|||||||
}
|
}
|
||||||
} else if queue_top == "(" {
|
} else if queue_top == "(" {
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
return Err(QueryError("Missing closing parentheses".into()));
|
return Err(QueryError(beef::Cow::borrowed(
|
||||||
|
"Missing closing parentheses",
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut list_of_ors = VecDeque::new();
|
let mut list_of_ors = VecDeque::new();
|
||||||
|
@ -158,7 +158,7 @@ fn main() -> Result<()> {
|
|||||||
handle_force_redraws(&mut app);
|
handle_force_redraws(&mut app);
|
||||||
}
|
}
|
||||||
BottomEvent::Update(data) => {
|
BottomEvent::Update(data) => {
|
||||||
app.data_collection.eat_data(&data);
|
app.data_collection.eat_data(data);
|
||||||
|
|
||||||
// This thing is required as otherwise, some widgets can't draw correctly w/o
|
// This thing is required as otherwise, some widgets can't draw correctly w/o
|
||||||
// some data (or they need to be re-drawn).
|
// some data (or they need to be re-drawn).
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use data_harvester::processes::ProcessSorting;
|
use data_harvester::processes::ProcessSorting;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use std::collections::{HashMap, HashSet, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
|
||||||
/// Point is of time, data
|
/// Point is of time, data
|
||||||
type Point = (f64, f64);
|
type Point = (f64, f64);
|
||||||
@ -453,7 +453,7 @@ pub fn convert_process_data(
|
|||||||
// TODO [THREAD]: Thread highlighting and hiding support
|
// TODO [THREAD]: Thread highlighting and hiding support
|
||||||
// For macOS see https://github.com/hishamhm/htop/pull/848/files
|
// For macOS see https://github.com/hishamhm/htop/pull/848/files
|
||||||
|
|
||||||
let mut complete_pid_set: HashSet<Pid> =
|
let mut complete_pid_set: fnv::FnvHashSet<Pid> =
|
||||||
existing_converted_process_data.keys().copied().collect();
|
existing_converted_process_data.keys().copied().collect();
|
||||||
|
|
||||||
for process in ¤t_data.process_harvest {
|
for process in ¤t_data.process_harvest {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
use beef::Cow;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::{borrow::Cow, result};
|
use beef::Cow;
|
||||||
|
use std::result;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// A type alias for handling errors related to Bottom.
|
/// A type alias for handling errors related to Bottom.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user