Skip to content

Commit

Permalink
Merge pull request #196 from nokyan/cpu-time
Browse files Browse the repository at this point in the history
Cpu time
  • Loading branch information
nokyan authored Apr 7, 2024
2 parents 1a06382 + bc0d492 commit 688485a
Show file tree
Hide file tree
Showing 14 changed files with 932 additions and 626 deletions.
12 changes: 12 additions & 0 deletions data/net.nokyan.Resources.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@
<default>false</default>
<summary>Display GPU memory usage in Processes view</summary>
</key>
<key name="processes-show-total-cpu-time" type="b">
<default>false</default>
<summary>Display total CPU time in Processes view</summary>
</key>
<key name="processes-show-user-cpu-time" type="b">
<default>false</default>
<summary>Display user CPU time in Processes view</summary>
</key>
<key name="processes-show-system-cpu-time" type="b">
<default>false</default>
<summary>Display system CPU time in Processes view</summary>
</key>
<key name="show-logical-cpus" type="b">
<default>false</default>
<summary>Display logical CPU graphs in Processor view</summary>
Expand Down
27 changes: 27 additions & 0 deletions data/resources/ui/dialogs/process_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@
<property name="title" translatable="yes">Video Decoder</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="total_cpu_time">
<style>
<class name="property"/>
</style>
<property name="subtitle-selectable">true</property>
<property name="title" translatable="yes">Total CPU Time</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="user_cpu_time">
<style>
<class name="property"/>
</style>
<property name="subtitle-selectable">true</property>
<property name="title" translatable="yes">User CPU Time</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="system_cpu_time">
<style>
<class name="property"/>
</style>
<property name="subtitle-selectable">true</property>
<property name="title" translatable="yes">System CPU Time</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
15 changes: 15 additions & 0 deletions data/resources/ui/dialogs/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@
<property name="title" translatable="yes">Video Decoder</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="processes_show_total_cpu_time_row">
<property name="title" translatable="yes">Total CPU Time</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="processes_show_user_cpu_time_row">
<property name="title" translatable="yes">User CPU Time</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="processes_show_system_cpu_time_row">
<property name="title" translatable="yes">System CPU Time</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
9 changes: 6 additions & 3 deletions lib/process_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ pub struct ProcessData {
proc_path: PathBuf,
pub comm: String,
pub commandline: String,
pub cpu_time: u64,
pub user_cpu_time: u64,
pub system_cpu_time: u64,
pub cpu_time_timestamp: u64,
pub memory_usage: usize,
pub starttime: u64, // in clock ticks, see man proc(5)!
Expand Down Expand Up @@ -244,7 +245,8 @@ impl ProcessData {
let comm = comm.replace('\n', "");

// -2 to accommodate for only collecting after the second item (which is the executable name as mentioned above)
let cpu_time = stat[13 - 2].parse::<u64>()? + stat[14 - 2].parse::<u64>()?;
let user_cpu_time = stat[13 - 2].parse::<u64>()?;
let system_cpu_time = stat[14 - 2].parse::<u64>()?;

let cpu_time_timestamp = unix_as_millis();

Expand Down Expand Up @@ -285,7 +287,8 @@ impl ProcessData {
uid,
comm,
commandline,
cpu_time,
user_cpu_time,
system_cpu_time,
cpu_time_timestamp,
memory_usage,
starttime,
Expand Down
Loading

0 comments on commit 688485a

Please sign in to comment.