mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-04-08 17:05:59 +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",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "beef"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "474a626a67200bd107d44179bb3d4fc61891172d11696609264589be6a0e6a43"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@ -114,6 +120,7 @@ dependencies = [
|
||||
"assert_cmd",
|
||||
"backtrace",
|
||||
"battery",
|
||||
"beef",
|
||||
"cargo-husky",
|
||||
"chrono",
|
||||
"clap",
|
||||
|
@ -18,10 +18,10 @@ path = "src/bin/main.rs"
|
||||
doc = false
|
||||
|
||||
[profile.release]
|
||||
debug = 1
|
||||
lto = true
|
||||
# debug = true
|
||||
# lto = false
|
||||
# debug = 1
|
||||
# lto = true
|
||||
debug = true
|
||||
lto = false
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
||||
|
||||
@ -32,6 +32,7 @@ default = ["fern", "log"]
|
||||
anyhow = "1.0.34"
|
||||
backtrace = "0.3"
|
||||
battery = "0.7.8"
|
||||
beef = "0.4.4"
|
||||
chrono = "0.4.19"
|
||||
crossterm = "0.18.2"
|
||||
ctrlc = { version = "3.1", features = ["termination"] }
|
||||
|
@ -121,7 +121,7 @@ impl DataCollection {
|
||||
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...");
|
||||
let harvested_time = harvested_data.last_collection_time;
|
||||
// trace!("Harvested time: {:?}", harvested_time);
|
||||
@ -129,41 +129,39 @@ impl DataCollection {
|
||||
let mut new_entry = TimedData::default();
|
||||
|
||||
// Network
|
||||
if let Some(network) = &harvested_data.network {
|
||||
if let Some(network) = harvested_data.network {
|
||||
self.eat_network(network, &mut new_entry);
|
||||
}
|
||||
|
||||
// Memory and Swap
|
||||
if let Some(memory) = &harvested_data.memory {
|
||||
if let Some(swap) = &harvested_data.swap {
|
||||
self.eat_memory_and_swap(memory, swap, &mut new_entry);
|
||||
}
|
||||
if let (Some(memory), Some(swap)) = (harvested_data.memory, harvested_data.swap) {
|
||||
self.eat_memory_and_swap(memory, swap, &mut new_entry);
|
||||
}
|
||||
|
||||
// CPU
|
||||
if let Some(cpu) = &harvested_data.cpu {
|
||||
if let Some(cpu) = harvested_data.cpu {
|
||||
self.eat_cpu(cpu, &mut new_entry);
|
||||
}
|
||||
|
||||
// Temp
|
||||
if let Some(temperature_sensors) = &harvested_data.temperature_sensors {
|
||||
if let Some(temperature_sensors) = harvested_data.temperature_sensors {
|
||||
self.eat_temp(temperature_sensors);
|
||||
}
|
||||
|
||||
// Disks
|
||||
if let Some(disks) = &harvested_data.disks {
|
||||
if let Some(io) = &harvested_data.io {
|
||||
if let Some(disks) = harvested_data.disks {
|
||||
if let Some(io) = harvested_data.io {
|
||||
self.eat_disks(disks, io, harvested_time);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -173,7 +171,7 @@ impl DataCollection {
|
||||
}
|
||||
|
||||
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.");
|
||||
// Memory
|
||||
@ -193,11 +191,11 @@ impl DataCollection {
|
||||
}
|
||||
|
||||
// In addition copy over latest data for easy reference
|
||||
self.memory_harvest = memory.clone();
|
||||
self.swap_harvest = swap.clone();
|
||||
self.memory_harvest = memory;
|
||||
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.");
|
||||
// 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)
|
||||
@ -216,10 +214,10 @@ impl DataCollection {
|
||||
};
|
||||
|
||||
// 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.");
|
||||
// Note this only pre-calculates the data points - the names will be
|
||||
// within the local copy of cpu_harvest. Since it's all sequential
|
||||
@ -230,14 +228,14 @@ impl DataCollection {
|
||||
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.");
|
||||
// TODO: [PO] To implement
|
||||
self.temp_harvest = temperature_sensors.to_vec();
|
||||
}
|
||||
|
||||
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.");
|
||||
// TODO: [PO] To implement
|
||||
@ -307,17 +305,17 @@ impl DataCollection {
|
||||
}
|
||||
}
|
||||
|
||||
self.disk_harvest = disks.to_vec();
|
||||
self.io_harvest = io.clone();
|
||||
self.disk_harvest = disks;
|
||||
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.");
|
||||
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.");
|
||||
self.battery_harvest = list_of_batteries.to_vec();
|
||||
self.battery_harvest = list_of_batteries;
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ impl ProcessQuery for ProcWidgetState {
|
||||
break;
|
||||
}
|
||||
} 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 {
|
||||
break;
|
||||
}
|
||||
@ -117,7 +117,7 @@ impl ProcessQuery for ProcWidgetState {
|
||||
break;
|
||||
}
|
||||
} 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 {
|
||||
break;
|
||||
}
|
||||
@ -165,7 +165,9 @@ impl ProcessQuery for ProcWidgetState {
|
||||
}
|
||||
} else if queue_top == "(" {
|
||||
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();
|
||||
|
@ -158,7 +158,7 @@ fn main() -> Result<()> {
|
||||
handle_force_redraws(&mut app);
|
||||
}
|
||||
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
|
||||
// some data (or they need to be re-drawn).
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
use data_harvester::processes::ProcessSorting;
|
||||
use indexmap::IndexSet;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
/// Point is of time, data
|
||||
type Point = (f64, f64);
|
||||
@ -453,7 +453,7 @@ pub fn convert_process_data(
|
||||
// TODO [THREAD]: Thread highlighting and hiding support
|
||||
// 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();
|
||||
|
||||
for process in ¤t_data.process_harvest {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use beef::Cow;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::{borrow::Cow, result};
|
||||
use beef::Cow;
|
||||
use std::result;
|
||||
use thiserror::Error;
|
||||
|
||||
/// A type alias for handling errors related to Bottom.
|
||||
|
Loading…
x
Reference in New Issue
Block a user