Enlightenment CVS committal

Author  : manowarrior
Project : e_modules
Module  : cpu

Dir     : e_modules/cpu


Modified Files:
        e_mod_main.c 


Log Message:

Cpu now works on FreeBSD. Thanks to sndev for the help and to Stanislav Sedov 
for the patch (don't ask why am I commiting this..)

===================================================================
RCS file: /cvs/e/e_modules/cpu/e_mod_main.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- e_mod_main.c        3 Sep 2006 02:01:42 -0000       1.25
+++ e_mod_main.c        10 Sep 2006 18:00:31 -0000      1.26
@@ -1,6 +1,12 @@
 #include <e.h>
 #include "e_mod_main.h"
 
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/resource.h>
+#endif
+
 typedef struct _Instance Instance;
 typedef struct _Cpu Cpu;
 
@@ -196,25 +202,56 @@
    char tmp[4];
    int cpu = -1;
 
+#ifdef __FreeBSD__
+   cpu = 1;
+#else
    if (!(f = fopen("/proc/stat", "r"))) return cpu;
 
    while (fscanf(f, "cp%s %*u %*u %*u %*u %*u %*u %*u %*u\n", (char *) &tmp) 
== 1)
      cpu++;
 
    fclose(f);
+#endif
+
    return cpu;
 }
 
 static int
 _get_cpu_load(void) 
 {
+#ifdef __FreeBSD__
+   long cp_time[CPUSTATES];
+   static long old_used, old_tot;
+   long new_used, new_tot;
+   size_t len;
+#else
    FILE *stat;
    static unsigned long old_u[4], old_n[4], old_s[4], old_i[4], old_wa[4], 
old_hi[4], old_si[4];
    unsigned long new_u, new_n, new_s, new_i, new_wa = 0, new_hi = 0, new_si = 
0, dummy2, ticks_past;
    int tmp_u = 0, tmp_n = 0, tmp_s = 0;
    char dummy[16];
    int i = 0;
+#endif
+
+#ifdef __FreeBSD__
+   len = sizeof(cp_time);
+
+   if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) < 0)
+     {
+       warn("sysctl()");
+       return 0;
+     }
+
+   new_used = cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_SYS];
+   new_tot = new_used + cp_time[CP_IDLE];
+
+   cpu_stats[0] = 100 * (float)(new_used - old_used) / (float)(new_tot - 
old_tot);
+
+   old_tot = new_tot;
+   old_used = new_used; 
    
+   cpu_stats[0]=(cpu_stats[0]>100?100:cpu_stats[0]);
+#else
    if (!(stat = fopen("/proc/stat", "r"))) return -1;
 
    /* since if there are more than 1 CPUs, the first entry is the summary:
@@ -264,6 +301,7 @@
        i++;
      }
    fclose (stat);
+#endif
    return 0;
 }
 



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to