[Xfce4-commits] <xfce4-diskperf-plugin:master> Add support for FreeBSD (bug #10350)

Landry Breuil noreply at xfce.org
Sat Sep 14 10:16:01 CEST 2013


Updating branch refs/heads/master
         to 0faba9adc585a02071b4ab1d8761413b4cc35a9a (commit)
       from b1167d15ad443ac1b97a4c1f360e5e345d25747a (commit)

commit 0faba9adc585a02071b4ab1d8761413b4cc35a9a
Author: Danilo Egea <daniloegea at yahoo.com.br>
Date:   Sat Sep 14 10:13:23 2013 +0200

    Add support for FreeBSD (bug #10350)

 panel-plugin/devperf.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++
 panel-plugin/main.c    |   17 ++++++----
 2 files changed, 98 insertions(+), 7 deletions(-)

diff --git a/panel-plugin/devperf.c b/panel-plugin/devperf.c
index 4f7bbf2..45391d5 100644
--- a/panel-plugin/devperf.c
+++ b/panel-plugin/devperf.c
@@ -225,6 +225,94 @@ int main ()
 
 	/**************************	Linux End	***************/
 
+#elif defined(__FreeBSD__)
+
+#include <sys/disk.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <devstat.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h>
+#include <syslog.h>
+#include <stdarg.h>
+
+#define MAXNAMELEN 256
+
+int DevPerfInit ()
+{
+	return (0);
+}
+
+int DevCheckStatAvailability(char const **strptr)
+{
+	return (0);
+}
+
+int DevGetPerfData (const void *p_pvDevice, struct devperf_t *perf)
+{
+	struct timeval tv;
+	struct timespec ts;
+	struct statinfo stats;
+	struct devinfo dinfo;
+	struct devstat dev;
+	kvm_t *kd = NULL;
+	int i, found = 0;
+	char *check_dev = (char *) p_pvDevice;
+
+	memset(&stats, 0, sizeof(stats));
+	memset(&dinfo, 0, sizeof(dinfo));
+	stats.dinfo = &dinfo;
+
+	if(devstat_getdevs(kd, &stats) == -1) {
+		syslog(0, "DISKPERF: getdevs fail");
+	}
+
+	for(found = 0, i = 0; i < (stats.dinfo)->numdevs; i++) {
+		char dev_name[MAXNAMELEN];
+		dev = (stats.dinfo)->devices[i];
+		snprintf(dev_name, MAXNAMELEN-1, "%s%d",
+				dev.device_name, dev.unit_number);
+		if ((check_dev != NULL) && (strcmp(check_dev, dev_name) != 0))
+			continue;
+		else {
+			found = 1;
+			break;
+		}
+
+	}
+
+	if(check_dev != NULL && found) {
+		perf->wbytes = dev.bytes[DEVSTAT_WRITE];
+		perf->rbytes = dev.bytes[DEVSTAT_READ];
+		gettimeofday (&tv, 0);
+		perf->timestamp_ns = (uint64_t)1000ull * 1000ull * 1000ull *
+			tv.tv_sec + 1000ull * tv.tv_usec;
+		perf->qlen = dev.start_count - dev.end_count;
+		// I'm not sure about rbusy and wbusy calculation
+		bintime2timespec(&dev.busy_time, &ts);
+		perf->rbusy_ns = (uint64_t) ts.tv_nsec;
+		perf->wbusy_ns = perf->rbusy_ns;
+	}
+
+	return (0);
+}
+
+#if 0				/* Standalone test purpose */
+int main ()
+{
+    struct devperf_t oPerf;
+    DevGetPerfData ((void*)"ada0", &oPerf);
+    printf ("%lu\t%lu\n", oPerf.rbytes, oPerf.wbytes);
+    return (0);
+}
+#endif
+
+
 
 #elif defined(__NetBSD__)
 	/**************************************************************/
diff --git a/panel-plugin/main.c b/panel-plugin/main.c
index 87e4d9c..6d49b28 100644
--- a/panel-plugin/main.c
+++ b/panel-plugin/main.c
@@ -86,7 +86,7 @@ typedef enum monitor_bar_order_t {
 typedef struct param_t {
     /* Configurable parameters */
     char            acDevice[64];
-#if  !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if  !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
     dev_t           st_rdev;
 #endif
     int             fTitleDisplayed;
@@ -172,7 +172,7 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin)
     struct param_t *poConf = &(p_poPlugin->oConf.oParam);
     struct monitor_t *poMonitor = &(p_poPlugin->oMonitor);
     struct perfbar_t *poPerf = poMonitor->aoPerfBar;
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
     struct stat     oStat;
 #endif
     uint64_t        iInterval_ns, rbytes, wbytes, iRBusy_ns, iWBusy_ns;
@@ -185,7 +185,7 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin)
     rbytes = wbytes = iRBusy_ns = iWBusy_ns = -1;
     memset (&oPerf, 0, sizeof (oPerf));
     oPerf.qlen = -1;
-#if defined (__NetBSD__) || defined(__OpenBSD__) || defined(__sun__)
+#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__sun__)
     status = DevGetPerfData (poConf->acDevice, &oPerf);
 #else
     if (poConf->st_rdev == 0)
@@ -429,7 +429,7 @@ static diskperf_t *diskperf_create_control (XfcePanelPlugin *plugin)
     struct diskperf_t *poPlugin;
     struct param_t *poConf;
     struct monitor_t *poMonitor;
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
     struct stat     oStat;
     int             status;
 #endif
@@ -444,6 +444,9 @@ static diskperf_t *diskperf_create_control (XfcePanelPlugin *plugin)
 #if defined(__NetBSD__) || defined(__OpenBSD__)
     strncpy (poConf->acDevice, "wd0", 64);
     strncpy (poConf->acTitle, "wd0", 16);
+#elif defined(__FreeBSD__)
+    strncpy (poConf->acDevice, "ada0", 64);
+    strncpy (poConf->acTitle, "ada0", 16);
 #elif defined(__sun__)
     strncpy (poConf->acDevice, "sd0", 64);
     strncpy (poConf->acTitle, "sd0", 16);
@@ -517,7 +520,7 @@ static void diskperf_read_config (XfcePanelPlugin *plugin,
     struct param_t *poConf = &(poPlugin->oConf.oParam);
     struct monitor_t *poMonitor = &(poPlugin->oMonitor);
     Widget_t       *pw2ndBar = poPlugin->oMonitor.awProgressBar + 1;
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
     struct stat     oStat;
     int             status;
 #endif
@@ -534,7 +537,7 @@ static void diskperf_read_config (XfcePanelPlugin *plugin,
     if ((value = xfce_rc_read_entry (rc, (CONF_DEVICE), NULL))) {
         memset (poConf->acDevice, 0, sizeof (poConf->acDevice));
         strncpy (poConf->acDevice, value, sizeof (poConf->acDevice) - 1);
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
         status = stat (poConf->acDevice, &oStat);
         poConf->st_rdev = (status == -1 ? 0 : oStat.st_rdev);
 #endif
@@ -666,7 +669,7 @@ static void SetDevice (Widget_t p_wTF, void *p_pvPlugin)
     struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
     struct param_t *poConf = &(poPlugin->oConf.oParam);
     const char     *pcDevice = gtk_entry_get_text (GTK_ENTRY (p_wTF));
-#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
     struct stat     oStat;
     int             status;
 


More information about the Xfce4-commits mailing list