[Xfce4-commits] [apps/xfce4-taskmanager] 01/01: Improve memory usage on FreeBSD system.

noreply at xfce.org noreply at xfce.org
Sun Jan 8 18:51:12 CET 2017


This is an automated email from the git hooks/post-receive script.

landry pushed a commit to branch master
in repository apps/xfce4-taskmanager.

commit b7eaff7c1a3b7bf707bc12950af08f153766d343
Author: Olivier Duchateau <duchateau.olivier at gmail.com>
Date:   Fri Jan 6 10:36:15 2017 +0100

    Improve memory usage on FreeBSD system.
---
 src/task-manager-freebsd.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c
index 79a8aea..065bc39 100644
--- a/src/task-manager-freebsd.c
+++ b/src/task-manager-freebsd.c
@@ -26,25 +26,39 @@
 
 #include "task-manager.h"
 
+gulong
+get_mem_by_bytes (const gchar *name)
+{
+	gulong buf;
+	gsize len = sizeof (gulong);
+
+	if (sysctlbyname (name, &buf, &len, NULL, 0) < 0)
+		return 0;
+
+	return buf;
+}
+
+guint64
+get_mem_by_pages (const gchar *name)
+{
+	gulong res;
+
+	res = get_mem_by_bytes (name);
+	if (res > 0)
+		res = res * getpagesize ();
+
+	return (guint64) res;
+}
+
 gboolean
 get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free)
 {
 	/* Get memory usage */
 	{
-		gulong total = 0, free = 0, inactive = 0;
-		size_t size;
-
-		size = sizeof (gulong);
-		sysctlbyname ("vm.stats.vm.v_page_count", &total, &size, NULL, 0);
-		size = sizeof (gulong);
-		sysctlbyname ("vm.stats.vm.v_free_count", &free, &size, NULL, 0);
-		size = sizeof (gulong);
-		sysctlbyname ("vm.stats.vm.v_inactive_count", &inactive, &size, NULL, 0);
-
-		*memory_total = total * getpagesize ();
-		*memory_free = free * getpagesize ();
-		*memory_cache = inactive * getpagesize ();
-		*memory_buffers = 0;
+		*memory_total = (guint64) get_mem_by_bytes ("hw.physmem");;
+		*memory_free = get_mem_by_pages ("vm.stats.vm.v_free_count");
+		*memory_cache = get_mem_by_pages ("vm.stats.vm.v_inactive_count");
+		*memory_buffers = (guint64) get_mem_by_bytes ("vfs.bufspace");
 	}
 
 	/* Get swap usage */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list