Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Managers/ProcessDRM.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Monitor.ProcessDRM : GLib.Object {
private uint64 delta_ccs = 0;
private uint64 delta_total_ccs = 0;

public double gpu_percentage { get; private set; }
public double gpu_percentage { get; private set; default = 0; }

private int pid;
private int update_interval;
Expand Down Expand Up @@ -99,7 +99,6 @@ public class Monitor.ProcessDRM : GLib.Object {

public void update () {
if (drm_files.size == 0) {
gpu_percentage = 0;
return;
}

Expand Down Expand Up @@ -138,7 +137,7 @@ public class Monitor.ProcessDRM : GLib.Object {
}

private void calculate_percentage_ns (ref uint64 engine, ref uint64 last_engine) {
if (last_engine != 0) {
if (last_engine != 0 && engine >= last_engine) {
// Since values in the files are in nanoseconds, it is also needed to convert
// the interval to nanoseconds (10^9)
gpu_percentage = 100 * ((double) (engine - last_engine)) / (update_interval * 1e9);
Expand Down
4 changes: 2 additions & 2 deletions src/Models/ProcessRowData.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
public class Monitor.ProcessRowData : GLib.Object {
public Icon icon { get; set; }
public string name { get; set; }
public int cpu { get; set; }
public double cpu { get; set; }
public uint64 memory { get; set; }
public int gpu { get; set; }
public double gpu { get; set; }
public int pid { get; set; }
public string cmd { get; set; }
public Gee.HashMap<string, Binding> bindings = new Gee.HashMap<string, Binding> ();
Expand Down
8 changes: 4 additions & 4 deletions src/Models/TreeViewModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public class Monitor.TreeViewModel : GLib.Object {
var row = new ProcessRowData () {
icon = process.icon,
name = process.application_name,
cpu = (int) process.cpu_percentage,
cpu = process.cpu_percentage,
memory = process.mem_usage,
gpu = (int) process.gpu_percentage,
gpu = process.gpu_percentage,
pid = process.stat.pid,
cmd = process.command
};
Expand Down Expand Up @@ -111,9 +111,9 @@ public class Monitor.TreeViewModel : GLib.Object {
}

var item = (ProcessRowData) store.get_item (pos);
item.cpu = (int) process.cpu_percentage;
item.cpu = process.cpu_percentage;
item.memory = process.mem_usage;
item.gpu = (int) process.gpu_percentage;
item.gpu = process.gpu_percentage;
sorter.changed (DIFFERENT);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Views/ProcessView/ProcessTreeView/ProcessTreeView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public class Monitor.ProcessTreeView : Granite.Bin {
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_cpu = item.bind_property ("cpu", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
int percentage = from_val.get_int ();
to_val.set_string ("%.0f%%".printf (percentage));
double percentage = from_val.get_double ();
to_val.set_string ("%.2f%%".printf (percentage));
return true;
});
item.bindings.set ("cpu", binding_cpu);
Expand Down Expand Up @@ -165,8 +165,8 @@ public class Monitor.ProcessTreeView : Granite.Bin {
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_gpu = item.bind_property ("gpu", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
int percentage = from_val.get_int ();
to_val.set_string ("%.0f%%".printf (percentage));
double percentage = from_val.get_double ();
to_val.set_string ("%.2f%%".printf (percentage));
return true;
});
item.bindings.set ("gpu", binding_gpu);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process_drm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void test_process_drm () {

drm.update ();

assert (drm.gpu_percentage == -1.0);
assert (drm.gpu_percentage < 0);
});
}

Expand Down
Loading