[Xfce4-commits] <xfce4-cpugraph-plugin:master> Merge branch 'taskbranch/bug-6721'

Florian Rivoal noreply at xfce.org
Sun Oct 10 06:22:04 CEST 2010


Updating branch refs/heads/master
         to d080dffa1af3dc8c1e45115dd1f489b0e128aff8 (commit)
       from 7ed44cb4ff4c7385d8ad8afac42bfd9ba8c854df (commit)

commit d080dffa1af3dc8c1e45115dd1f489b0e128aff8
Merge: 7ed44cb4ff4c7385d8ad8afac42bfd9ba8c854df b06e8d7db4b93cfa643e2ad5a0ef60307b99df83
Author: Florian Rivoal <frivoal at xfce.org>
Date:   Sun Oct 10 12:55:23 2010 +0900

    Merge branch 'taskbranch/bug-6721'

commit b06e8d7db4b93cfa643e2ad5a0ef60307b99df83
Author: Florian Rivoal <frivoal at xfce.org>
Date:   Sun Oct 10 12:48:32 2010 +0900

    Update the documentation
    
    Mention Solaris support in the README file.

commit f7b418caac951462ec13462d06168321427d0efe
Author: Florian Rivoal <frivoal at xfce.org>
Date:   Sun Oct 10 12:33:09 2010 +0900

    Update copyright notices
    
    Add Peter Tribble's name and copyright notice to the AUTHOR file, and
    to the COPYING file.

commit 71a1d163c5d31f78e91fb9d2f5bdc9ffb2dd017a
Author: Peter Tribble <peter.tribble at gmail.com>
Date:   Thu Oct 7 00:37:25 2010 +0900

    Add Solaris support
    
    Extends the platform specific code to support Solaris, with multicore
    support. Patch from Peter Tribble.

 AUTHORS           |    1 +
 COPYING           |    1 +
 README            |    6 ++--
 panel-plugin/os.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 5fd3bf2..30720c9 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -3,3 +3,4 @@ gatopeich <gatoguan-os at yahoo.com>
 lidiriel <lidiriel at coriolys.org>
 Angelo Miguel Arrifano <miknix at gmail.com>
 Florian Rivoal <frivoal at gmail.com>
+Peter Tribble <peter.tribble at gmail.com>
diff --git a/COPYING b/COPYING
index bbd575e..fbcd809 100644
--- a/COPYING
+++ b/COPYING
@@ -5,6 +5,7 @@ Copyright (c) gatopeich <gatoguan-os at yahoo.com>
 Copyright (c) 2007-2008 Angelo Arrifano <miknix at gmail.com>
 Copyright (c) 2007-2008 Lidiriel <lidiriel at coriolys.org>
 Copyright (c) 2010 Florian Rivoal <frivoal at gmail.com>
+Copyright (c) 2010 Peter Tribble <peter.tribble at gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
diff --git a/README b/README
index a074c65..431863c 100644
--- a/README
+++ b/README
@@ -2,9 +2,9 @@ CPU Graph plugin for the XFce4 panel.
 
 This plugin displays an graph from your latest system load.
 
-Currently supporting Linux, FreeBSD, NetBSD and OpenBSD, and GNU/kFreeBSD.
-The *BSD support is derived from Riccardo's <riccardo.persichetti at tin.it>
-system load plugin.
+Currently supporting Linux, FreeBSD, NetBSD and OpenBSD, GNU/kFreeBSD and
+Solaris. The *BSD support is derived from Riccardo's
+<riccardo.persichetti at tin.it> system load plugin.
 
 i18n support is up to 15 fully supported languages, with another 20 partially
 supported languages.
diff --git a/panel-plugin/os.c b/panel-plugin/os.c
index 2655448..3962949 100644
--- a/panel-plugin/os.c
+++ b/panel-plugin/os.c
@@ -6,6 +6,7 @@
  *  Copyright (c) 2007-2008 Angelo Arrifano <miknix at gmail.com>
  *  Copyright (c) 2007-2008 Lidiriel <lidiriel at coriolys.org>
  *  Copyright (c) 2010 Florian Rivoal <frivoal at gmail.com>
+ *  Copyright (c) 2010 Peter Tribble <peter.tribble at gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -61,6 +62,11 @@
 #include <sys/sysctl.h>
 #endif
 
+#if defined (__sun__)
+#include <kstat.h>
+static kstat_ctl_t *kc;
+#endif
+
 #if defined (__linux__) || defined (__FreeBSD_kernel__)
 guint detect_cpu_number()
 {
@@ -234,6 +240,68 @@ gboolean read_cpu_data( CpuData *data, guint nb_cpu)
 	data[0].load /= nb_cpu;
 	return TRUE;
 }
+
+#elif defined (__sun__)
+static void init_stats()
+{
+	kc = kstat_open();
+}
+
+guint detect_cpu_number()
+{
+	kstat_t *ksp;
+	kstat_named_t *knp;
+
+	if( !kc )
+		init_stats();
+
+	if( !(ksp = kstat_lookup( kc, "unix", 0, "system_misc" )) )
+		return 0;
+	else
+		kstat_read( kc, ksp, NULL );
+		knp = kstat_data_lookup( ksp, "ncpus" );
+		return knp->value.ui32;
+}
+
+gboolean read_cpu_data( CpuData *data, guint nb_cpu )
+{
+	kstat_t *ksp;
+	kstat_named_t *knp;
+	guint64 used, total;
+	gint i;
+	data[0].load = 0;
+
+	if( !kc )
+		init_stats();
+
+	i = 1;
+	for( ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next )
+	{
+		if( !g_strcmp0( ksp->ks_module, "cpu" ) && !g_strcmp0( ksp->ks_name, "sys" ) )
+		{
+			kstat_read( kc, ksp, NULL );
+			knp = kstat_data_lookup( ksp, "cpu_nsec_user" );
+			used = knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_intr" );
+			used += knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_kernel" );
+			used += knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_idle" );
+			total = used + knp->value.ul;
+			if( total - data[i].previous_total != 0 )
+				data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total);
+			else
+				data[i].load = 0;
+			data[i].previous_used = used;
+			data[i].previous_total = total;
+			data[0].load += data[i].load;
+			i++;
+		}
+	}
+
+	data[0].load /= nb_cpu;
+	return TRUE;
+}
 #else
 #error "Your OS is not supported."
 #endif



More information about the Xfce4-commits mailing list