summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-10-01 01:46:09 -0400
committerGitHub <noreply@github.com>2020-10-01 01:46:09 -0400
commita5b95ae8b26c720892cfe2dfbe3b52a6f6eaf546 (patch)
tree73fb7740b099ab0b1ca656f6fe48abb7658f91e1 /src/app
parent5b33e8d6b4b28c6a64e017bc137bd4897cf9cb74 (diff)
bug: use cmdline for Linux proc name if >=15 chars (#261)
This was the cause of some process names getting cut off and looking weird for Linux (and Linux only, I'm not directly responsible for the other OSes). This also adds spaces in between command line flags. Before, they were usually separated by either spaces (which looked fine) or null terminators (which meant it looked like something was broken).
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_harvester.rs2
-rw-r--r--src/app/data_harvester/processes.rs41
2 files changed, 37 insertions, 6 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index bd0c98e0..285c4823 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -122,8 +122,10 @@ impl Default for DataCollector {
impl DataCollector {
pub fn init(&mut self) {
self.mem_total_kb = self.sys.get_total_memory();
+ trace!("Total memory in KB: {}", self.mem_total_kb);
if self.widgets_to_harvest.use_battery {
+ trace!("First run battery vec creation.");
if let Ok(battery_manager) = Manager::new() {
if let Ok(batteries) = battery_manager.batteries() {
let battery_list: Vec<Battery> = batteries.filter_map(Result::ok).collect();
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 64988338..62789146 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -11,6 +11,9 @@ use std::collections::{hash_map::RandomState, HashMap};
#[cfg(not(target_os = "linux"))]
use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
+/// Maximum character length of a /proc/<PID>/stat process name.
+const MAX_STAT_NAME_LEN: usize = 15;
+
// TODO: Add value so we know if it's sorted ascending or descending by default?
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum ProcessSorting {
@@ -251,7 +254,9 @@ fn read_proc<S: core::hash::BuildHasher>(
.entry(pid)
.or_insert_with(|| PrevProcDetails::new(pid));
let stat_results = read_path_contents(&pid_stat.proc_stat_path)?;
- let name = stat_results
+
+ // truncated_name may potentially be cut! Hence why we do the bit of code after...
+ let truncated_name = stat_results
.splitn(2, '(')
.collect::<Vec<_>>()
.last()
@@ -261,12 +266,36 @@ fn read_proc<S: core::hash::BuildHasher>(
.last()
.ok_or(BottomError::MinorError)?
.to_string();
- let command = {
- let cmd = read_path_contents(&pid_stat.proc_cmdline_path)?; // FIXME: [PROC] Use full proc name all the time
- if cmd.trim().is_empty() {
- format!("[{}]", name)
+ let (command, name) = {
+ let cmd = read_path_contents(&pid_stat.proc_cmdline_path)?;
+ let trimmed_cmd = cmd.trim();
+ if trimmed_cmd.is_empty() {
+ (format!("[{}]", truncated_name), truncated_name)
} else {
- cmd
+ // We split by spaces and null terminators.
+ let separated_strings = trimmed_cmd
+ .split_terminator(|c| c == '\0' || c == ' ')
+ .collect::<Vec<&str>>();
+
+ (
+ separated_strings.join(" "),
+ if truncated_name.len() >= MAX_STAT_NAME_LEN {
+ if let Some(first_part) = separated_strings.first() {
+ // We're only interested in the executable part... not the file path.
+ // That's for command.
+ first_part
+ .split('/')
+ .collect::<Vec<_>>()
+ .last()
+ .unwrap_or(&truncated_name.as_str())
+ .to_string()
+ } else {
+ truncated_name
+ }
+ } else {
+ truncated_name
+ },
+ )
}
};
let stat = stat_results