Skip to content

Commit c02b303

Browse files
authored
Add swap data to memory info (#499)
feat: add swap data to memory info
1 parent 9f4abe6 commit c02b303

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/Resources/Resources.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Monitor.Resources : Object {
3535
memory.update ();
3636
network.update ();
3737
storage.update ();
38+
swap.update ();
3839

3940
foreach (var gpu in gpu_list) {
4041
gpu.update ();

src/Resources/Swap.vala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public class Monitor.Swap : Object {
2323
}
2424

2525
public Swap () {
26+
update ();
2627
}
2728

28-
private void update () {
29+
public void update () {
2930
GTop.get_swap (out swap);
30-
total = (double) (swap.total / 1024 / 1024) / 1000;
31-
used = (double) (swap.used / 1024 / 1024) / 1000;
31+
total = (double) (swap.total);
32+
used = (double) (swap.used);
3233
}
3334

3435
}

src/Views/SystemView/SystemMemoryView.vala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
public class Monitor.SystemMemoryView : Monitor.WidgetResource {
77
private Chart memory_chart;
88
private Memory memory;
9+
private Swap swap;
910

1011
private LabelRoundy memory_buffered_label = new LabelRoundy (_("Buffered"));
1112
private LabelRoundy memory_cached_label = new LabelRoundy (_("Cached"));
1213
private LabelRoundy memory_locked_label = new LabelRoundy (_("Locked"));
1314
private LabelRoundy memory_total_label = new LabelRoundy (_("Total"));
1415
private LabelRoundy memory_used_label = new LabelRoundy (_("Used"));
1516
private LabelRoundy memory_shared_label = new LabelRoundy (_("Shared"));
17+
private LabelRoundy swap_total_label = new LabelRoundy (_("Swap Total"));
18+
private LabelRoundy swap_used_label = new LabelRoundy (_("Swap Used"));
1619

1720
construct {
1821
title = (_("Memory"));
1922

2023
}
2124

22-
public SystemMemoryView (Memory _memory) {
25+
public SystemMemoryView (Memory _memory, Swap _swap) {
2326
memory = _memory;
27+
swap = _swap;
2428

2529
memory_chart = new Chart (1);
2630
memory_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_300));
@@ -53,6 +57,8 @@ public class Monitor.SystemMemoryView : Monitor.WidgetResource {
5357
grid.attach (memory_buffered_label, 1, 1, 1, 1);
5458
grid.attach (memory_cached_label, 2, 0, 1, 1);
5559
grid.attach (memory_locked_label, 2, 1, 1, 1);
60+
grid.attach (swap_total_label, 3, 0, 1, 1);
61+
grid.attach (swap_used_label, 3, 1, 1, 1);
5662

5763
return grid;
5864
}
@@ -72,6 +78,9 @@ public class Monitor.SystemMemoryView : Monitor.WidgetResource {
7278
memory_locked_label.text = format_size ((uint64) memory.locked, IEC_UNITS);
7379

7480
memory_shared_label.text = format_size ((uint64) memory.shared, IEC_UNITS);
81+
82+
swap_total_label.text = format_size ((uint64) swap.total, IEC_UNITS);
83+
swap_used_label.text = format_size ((uint64) swap.used, IEC_UNITS);
7584
}
7685

7786
}

src/Views/SystemView/SystemView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Monitor.SystemView : Gtk.Box {
2121
resources = _resources;
2222

2323
cpu_view = new SystemCPUView (resources.cpu);
24-
memory_view = new SystemMemoryView (resources.memory);
24+
memory_view = new SystemMemoryView (resources.memory, resources.swap);
2525
network_view = new SystemNetworkView (resources.network);
2626
storage_view = new SystemStorageView (resources.storage);
2727

src/Widgets/Statusbar/Statusbar.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public class Monitor.Statusbar : Granite.Bin {
8181
swap_usage_label.label = ("%d%%").printf (sysres.swap_percentage);
8282
swap_usage_label.tooltip_text = ("%s / %s").printf (
8383
// We get a value in GB, not bytes
84-
format_size ((uint64) sysres.swap_used * 1024 * 1024 * 1024, IEC_UNITS),
85-
format_size ((uint64) sysres.swap_total * 1024 * 1024 * 1024, IEC_UNITS)
84+
format_size ((uint64) sysres.swap_used, IEC_UNITS),
85+
format_size ((uint64) sysres.swap_total, IEC_UNITS)
8686
);
8787
}
8888

0 commit comments

Comments
 (0)