summaryrefslogtreecommitdiffstats
path: root/src/widgets/process_table/proc_widget_data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/process_table/proc_widget_data.rs')
-rw-r--r--src/widgets/process_table/proc_widget_data.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/widgets/process_table/proc_widget_data.rs b/src/widgets/process_table/proc_widget_data.rs
index 418d9997..e234d8ec 100644
--- a/src/widgets/process_table/proc_widget_data.rs
+++ b/src/widgets/process_table/proc_widget_data.rs
@@ -181,6 +181,10 @@ pub struct ProcWidgetData {
pub num_similar: u64,
pub disabled: bool,
pub time: Duration,
+ #[cfg(feature = "gpu")]
+ pub gpu_mem_usage: MemUsage,
+ #[cfg(feature = "gpu")]
+ pub gpu_usage: u32,
}
impl ProcWidgetData {
@@ -216,6 +220,14 @@ impl ProcWidgetData {
num_similar: 1,
disabled: false,
time: process.time,
+ #[cfg(feature = "gpu")]
+ gpu_mem_usage: if is_mem_percent {
+ MemUsage::Percent(process.gpu_mem_percent)
+ } else {
+ MemUsage::Bytes(process.gpu_mem)
+ },
+ #[cfg(feature = "gpu")]
+ gpu_usage: process.gpu_util,
}
}
@@ -248,6 +260,18 @@ impl ProcWidgetData {
self.wps += other.wps;
self.total_read += other.total_read;
self.total_write += other.total_write;
+ #[cfg(feature = "gpu")]
+ {
+ self.gpu_mem_usage = match (&self.gpu_mem_usage, &other.gpu_mem_usage) {
+ (MemUsage::Percent(a), MemUsage::Percent(b)) => MemUsage::Percent(a + b),
+ (MemUsage::Bytes(a), MemUsage::Bytes(b)) => MemUsage::Bytes(a + b),
+ (MemUsage::Percent(_), MemUsage::Bytes(_))
+ | (MemUsage::Bytes(_), MemUsage::Percent(_)) => {
+ unreachable!("trying to add together two different memory usage types!")
+ }
+ };
+ self.gpu_usage += other.gpu_usage;
+ }
}
fn to_string(&self, column: &ProcColumn) -> String {
@@ -264,6 +288,10 @@ impl ProcWidgetData {
ProcColumn::State => self.process_char.to_string(),
ProcColumn::User => self.user.clone(),
ProcColumn::Time => format_time(self.time),
+ #[cfg(feature = "gpu")]
+ ProcColumn::GpuMem | ProcColumn::GpuMemPercent => self.gpu_mem_usage.to_string(),
+ #[cfg(feature = "gpu")]
+ ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage),
}
}
}
@@ -298,6 +326,10 @@ impl DataToCell<ProcColumn> for ProcWidgetData {
}
ProcColumn::User => self.user.clone(),
ProcColumn::Time => format_time(self.time),
+ #[cfg(feature = "gpu")]
+ ProcColumn::GpuMem | ProcColumn::GpuMemPercent => self.gpu_mem_usage.to_string(),
+ #[cfg(feature = "gpu")]
+ ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage),
},
calculated_width,
))