[Xfce4-commits] <xfce4-systemload-plugin:master> Add support for Solaris from bug #5743
Landry Breuil
noreply at xfce.org
Wed Apr 18 15:40:01 CEST 2012
Updating branch refs/heads/master
to 386c890da02e05ad4a777ee8b61b689cf3200a00 (commit)
from fab9ca17478782a4e6fb3595440718e58f075e03 (commit)
commit 386c890da02e05ad4a777ee8b61b689cf3200a00
Author: Landry Breuil <landry at rhaalovely.net>
Date: Wed Apr 18 15:36:47 2012 +0200
Add support for Solaris from bug #5743
panel-plugin/cpu.c | 56 +++++++++++++++++++++++++++++++++++++++++
panel-plugin/memswap.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++-
panel-plugin/uptime.c | 28 ++++++++++++++++++++
3 files changed, 147 insertions(+), 2 deletions(-)
diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index 28cf561..5fb3466 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -252,6 +252,62 @@ gulong read_cpuload(void)
return cpu_used;
}
+#elif defined(__sun__)
+
+#include <kstat.h>
+kstat_ctl_t *kc;
+gulong cpu_used;
+gulong oldtotal = 0;
+gulong oldused = 0;
+
+void init_stats()
+{
+ kc = kstat_open();
+}
+
+gulong read_cpuload()
+{
+ gulong used, total;
+ kstat_t *ksp;
+ kstat_named_t *knp;
+
+ if (!kc)
+ {
+ init_stats();
+ }
+ kstat_chain_update(kc);
+ used = 0;
+ total = 0;
+ for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next)
+ {
+ if (!strcmp(ksp->ks_module, "cpu") && !strcmp(ksp->ks_name, "sys"))
+ {
+ kstat_read(kc, ksp, NULL);
+ knp = kstat_data_lookup(ksp, "cpu_ticks_user");
+ used += knp->value.ui64;
+ total += knp->value.ui64;
+ knp = kstat_data_lookup(ksp, "cpu_ticks_kernel");
+ used += knp->value.ui64;
+ total += knp->value.ui64;
+ knp = kstat_data_lookup(ksp, "cpu_ticks_idle");
+ total += knp->value.ui64;
+ }
+ }
+
+ printf("CPU: %d %d %d %d\n", used, oldused, total, oldtotal);
+
+ if ((total - oldtotal) != 0)
+ {
+ cpu_used = (100 * (double)(used - oldused)) / (double)(total - oldtotal);
+ }
+ else
+ {
+ cpu_used = 0;
+ }
+ oldused = used;
+ oldtotal = total;
+ return cpu_used;
+}
#else
#error "Your platform is not yet supported"
diff --git a/panel-plugin/memswap.c b/panel-plugin/memswap.c
index 09bab7e..f45d328 100644
--- a/panel-plugin/memswap.c
+++ b/panel-plugin/memswap.c
@@ -466,7 +466,68 @@ gint read_memswap(gulong *mem, gulong *swap, gulong *MT, gulong *MU, gulong *ST,
return 0;
}
+#elif defined (__sun__)
+
+#include <sys/stat.h>
+#include <sys/swap.h>
+#include <kstat.h>
+kstat_ctl_t *kc;
+
+static size_t MTotal = 0;
+static size_t MFree = 0;
+static size_t MUsed = 0;
+static size_t STotal = 0;
+static size_t SFree = 0;
+static size_t SUsed = 0;
+
+void mem_init_stats()
+{
+ kc = kstat_open();
+}
+
+gint read_memswap(gulong *mem, gulong *swap, gulong *MT, gulong *MU, gulong *ST, gulong *SU)
+{
+ long pagesize;
+ struct anoninfo swapinfo;
+ kstat_t *ksp;
+ kstat_named_t *knp;
+
+ pagesize = (long)(sysconf(_SC_PAGESIZE));
+
+ /* FIXME use real numbers, not fake data */
+ if (!kc)
+ {
+ mem_init_stats();
+ }
+
+ if (ksp = kstat_lookup(kc, "unix", 0, "system_pages"))
+ {
+ kstat_read(kc, ksp, NULL);
+ knp = kstat_data_lookup(ksp, "physmem");
+ MTotal = (pagesize * knp->value.ui64) >> 10;
+ knp = kstat_data_lookup(ksp, "freemem");
+ MUsed = MTotal - ((pagesize * knp->value.ui64) >> 10);
+ }
+ if (swapctl(SC_AINFO, &swapinfo) == 0) {
+ STotal = (swapinfo.ani_max * pagesize) >> 10;
+ SUsed = ((swapinfo.ani_max - swapinfo.ani_free) * pagesize) >> 10;
+ *swap = SUsed * 100 / STotal;
+ } else {
+ STotal = 0;
+ SUsed = 0;
+ *swap = 0;
+ }
+
+ *mem = MUsed * 100 / MTotal;
+
+ *MT = MTotal;
+ *MU = MUsed;
+ *ST = STotal;
+ *SU = SUsed;
+
+ return 0;
+}
+
#else
-#error "Your platform is not yet support"
+#error "Your platform is not yet supported"
#endif
-
diff --git a/panel-plugin/uptime.c b/panel-plugin/uptime.c
index 0de895d..3ddad35 100644
--- a/panel-plugin/uptime.c
+++ b/panel-plugin/uptime.c
@@ -111,4 +111,32 @@ gulong read_uptime(void)
return uptime;
}
+#elif defined(__sun__)
+
+#include <kstat.h>
+
+gulong read_uptime()
+{
+ kstat_ctl_t *kc;
+ kstat_t *ks;
+ kstat_named_t *boottime;
+ time_t now;
+ gulong uptime;
+
+ if (((kc = kstat_open()) != 0) && ((ks = kstat_lookup(kc, "unix", 0, "system_misc")) != NULL) && (kstat_read(kc, ks, NULL) != -1) && ((boottime = kstat_data_lookup(ks, "boot_time")) != NULL)) {
+ time(&now);
+ uptime = now - boottime->value.ul;
+ kstat_close(kc);
+ }
+ else
+ {
+ g_warning("Cannot get boot_time");
+ uptime = 0;
+ }
+
+ return uptime;
+}
+
+#else
+#error "Your platform is not yet supported"
#endif
More information about the Xfce4-commits
mailing list