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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
apt update
apt install -y libgala-dev libgee-0.8-dev libglib2.0-dev libgranite-7-dev libgtk-4-dev libadwaita-1-dev \
libdbus-glib-1-dev libgtop2-dev libwingpanel-9-dev libudisks2-dev \
libdbus-glib-1-dev libgtop2-dev libgudev-1.0-dev libwingpanel-9-dev libudisks2-dev \
libxnvctrl0 libxnvctrl-dev libcurl4-gnutls-dev libflatpak-dev libjson-glib-dev \
liblivechart-2-dev libsystemd-dev libpci-dev \
meson valac sassc git
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
apt update
apt install -y libgala-dev libgee-0.8-dev libglib2.0-dev libgranite-7-dev libgtk-4-dev libadwaita-1-dev \
libdbus-glib-1-dev libgtop2-dev libwingpanel-9-dev libudisks2-dev \
libdbus-glib-1-dev libgtop2-dev libgudev-1.0-dev libwingpanel-9-dev libudisks2-dev \
libxnvctrl0 libxnvctrl-dev libcurl4-gnutls-dev libflatpak-dev libjson-glib-dev \
liblivechart-2-dev libpci-dev \
meson valac sassc git \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ libgtk-4-dev
libgee-0.8-dev
libgranite-7-dev
libgtop2-dev
libgudev-1.0-dev
libadwaita-1-dev
libudisks2-dev
libjson-glib-dev
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ app_dependencies = [
dependency('gio-2.0'),
dependency('gobject-2.0'),
dependency('libgtop-2.0'),
dependency('gudev-1.0'),
dependency('libadwaita-1', version: '>=1.0.0'),
dependency('libsystemd'),
dependency('gtk4-x11'),
Expand Down
18 changes: 17 additions & 1 deletion src/Resources/Memory.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,29 @@ namespace Monitor {

public void update () {
GTop.get_mem (out mem);
total = (double) (mem.total);
var total_physical_memory = get_total_physical_memory ();
total = (double) (total_physical_memory > 0 ? total_physical_memory : mem.total);
Comment on lines -49 to +50

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understand correctly that you used GUdev to get "accurate total physical available memory size"? Could you tell me the differences of values between GTop and GUdev?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GUDev code gets you the actual installed physical memory size, meaning if your computer has 16 GiB it will get this exact number in bytes.

GTop on the other hand returns the "user accessible" memory size which is lower than what GUDev returns due to things like memory being reserved for kernel buffer cache, iGPU memory etc.

The switch from using GTop (still remains as fallback) to GUDev is shown in the before-after screenshots where you can see the "total memory" is lower with GTop used before.

used = (double) mem.user;
shared = (double) (mem.shared);
buffer = (double) (mem.buffer);
cached = (double) (mem.cached);
locked = (double) (mem.locked);
}

private uint64 get_total_physical_memory () {
uint64 mem_total = 0;

GUdev.Client client = new GUdev.Client ({"dmi"});
GUdev.Device? device = client.query_by_sysfs_path ("/sys/devices/virtual/dmi/id");

if (device != null) {
uint64 devices = device.get_property_as_uint64 ("MEMORY_ARRAY_NUM_DEVICES");
for (int item = 0; item < devices; item++) {
mem_total += device.get_property_as_uint64 ("MEMORY_DEVICE_%d_SIZE".printf (item));
}
}

return mem_total;
}
}
}
34 changes: 34 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Monitor.Utils {
const int BITS_IN_BYTES = 8;
const int MHZ_IN_GHZ = 1000;
const int IEC_UNIT_BASE = 1024;
const int NON_IEC_UNIT_BASE = 1000;

const string NOT_AVAILABLE = (_("N/A"));
const string NO_DATA = "\u2014";
Expand Down Expand Up @@ -74,6 +76,38 @@ public class Monitor.Utils.Strings {
format_size (speed_in_bytes_per_second * BITS_IN_BYTES, BITS | ONLY_UNIT)
);
}

public static string format_memory_size (uint64 size_in_bytes) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave some comments for what you're doing in this method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryonakano added comments in efd0235 hope the wording makes for a sensible explanation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mainly to explain the fix in 81392c9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see similar fix in #562

uint64 unit = 1;
while (size_in_bytes >= unit * IEC_UNIT_BASE) {
unit *= IEC_UNIT_BASE;
}

// Adjust size for the second glib format_size () call with ONLY_UNIT flag set and IEC_UNITS flag excluded.
// Prevents mismatch between unit and value due to borderline overlap between IEC_UNIT_BASE (1024) and
// NON_IEC_UNIT_BASE (1000) values, say, if size is somewhere between 1000 and 1024 the result would be
// erroneously shown eg. for size 1020 MB it would have been "1020 GB" this adjustment corrects it
// by avoiding the mismatch thus showing "1020 MB" as intended.
var size_adjusted_for_non_iec_units = size_in_bytes * NON_IEC_UNIT_BASE / IEC_UNIT_BASE;

// If size is a perfect multiple/factor of IEC_UNIT_BASE (1024) then print it as a whole number
// else fall through to use standard glib format_size () to print with one decimal place.
if (size_in_bytes % unit == 0) {
///TRANSLATORS: The first param is the numeric value of memory size.
///The second param is the memory size such as "MB" or "GB" for megabytes or gigabytes.
return _("%llu %s").printf (
size_in_bytes / unit,
format_size (size_adjusted_for_non_iec_units, ONLY_UNIT)
);
}

///TRANSLATORS: The first param is the numeric value (as string) of memory size.
///The second param is the memory size such as "MB" or "GB" for megabytes or gigabytes.
return _("%s %s").printf (
format_size (size_in_bytes, IEC_UNITS | ONLY_VALUE),
format_size (size_adjusted_for_non_iec_units, ONLY_UNIT)
);
}
}

public class Monitor.Utils.Colors : Object {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/ProcessView/ProcessTreeView/ProcessTreeView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public class Monitor.ProcessTreeView : Granite.Bin {
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_memory = item.bind_property ("memory", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
to_val.set_string (format_size (from_val.get_uint64 () * 1024, IEC_UNITS));
to_val.set_string (Utils.Strings.format_memory_size (from_val.get_uint64 () * 1024));
return true;
});
item.bindings.set ("memory", binding_memory);
Expand Down
16 changes: 8 additions & 8 deletions src/Views/SystemView/SystemMemoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public class Monitor.SystemMemoryView : Monitor.WidgetResource {
// memory_chart.update (3, memory.shared_percentage + memory.buffer_percentage + memory.cached_percentage);
// memory_chart.update (3, memory.shared_percentage + memory.buffer_percentage + memory.cached_percentage + memory.locked_percentage);

memory_total_label.text = format_size ((uint64) memory.total, IEC_UNITS);
memory_used_label.text = format_size ((uint64) memory.used, IEC_UNITS);
memory_buffered_label.text = format_size ((uint64) memory.buffer, IEC_UNITS);
memory_cached_label.text = format_size ((uint64) memory.cached, IEC_UNITS);
memory_locked_label.text = format_size ((uint64) memory.locked, IEC_UNITS);
memory_total_label.text = Utils.Strings.format_memory_size ((uint64) memory.total);
memory_used_label.text = Utils.Strings.format_memory_size ((uint64) memory.used);
memory_buffered_label.text = Utils.Strings.format_memory_size ((uint64) memory.buffer);
memory_cached_label.text = Utils.Strings.format_memory_size ((uint64) memory.cached);
memory_locked_label.text = Utils.Strings.format_memory_size ((uint64) memory.locked);

memory_shared_label.text = format_size ((uint64) memory.shared, IEC_UNITS);
memory_shared_label.text = Utils.Strings.format_memory_size ((uint64) memory.shared);

swap_total_label.text = format_size ((uint64) swap.total, IEC_UNITS);
swap_used_label.text = format_size ((uint64) swap.used, IEC_UNITS);
swap_total_label.text = Utils.Strings.format_memory_size ((uint64) swap.total);
swap_used_label.text = Utils.Strings.format_memory_size ((uint64) swap.used);
}

}
Loading