added test for libgtop etc. - you will need libgtop 1.0.1 i think or higher as

libgtop-config no-linger has the --cflags etc. :)


SVN revision: 1321
This commit is contained in:
Carsten Haitzler 1999-11-17 15:42:50 +00:00
parent 4d0e20be5b
commit 3798c6a812
7 changed files with 225 additions and 8 deletions

View File

@ -140,6 +140,7 @@ if test "$IMLIB_CONFIG" != "no"; then
fi
if test "$IMLIB_CONFIG" = "no"; then
AC_CHECK_LIB(png, png_get_valid, GRLIBS="$GRLIBS -lpng -lz -lm", ,
@ -161,6 +162,34 @@ if test "$IMLIB_CONFIG" = "no"; then
fi
AC_CHECK_PROG(LIBGTOP_CONFIG, libgtop-config, libgtop-config, no)
if test "$LIBGTOP_CONFIG" != "no"; then
LIBGTOP_CONF_SH="`$LIBGTOP_CONFIG --config`"
if test ! -z "$LIBGTOP_CONF_SH"; then
. $LIBGTOP_CONF_SH
AC_MSG_CHECKING(libgtop-config for the value of CFLAGS)
CFLAGS="$CFLAGS $LIBGTOP_INCS -DHAVE_LIBGTOP"
AC_MSG_RESULT($CFLAGS)
AC_MSG_CHECKING(libgtop-config for the value of LIBS)
GTLIBS="$GTLIBS $LIBGTOP_LIBS $LIBGTOP_EXTRA_LIBS"
AC_MSG_RESULT($GTLIBS)
SAVE_LIBS="$LIBS"
LIBS="$GTLIBS"
AC_MSG_CHECKING(the sanity of new compile/link flags)
AC_TRY_LINK(, , echo "yes", echo "no" ; LIBGTOP_CONFIG="no" ;
AC_WARN(Compile/link failed. Reverting to manual method.)
)
LIBS="$SAVE_LIBS"
fi
fi
# Build test programs?
AC_ARG_WITH(test-programs, [ --with-test-programs Builds the test programs [default=no]],
TEST_PROGS="EppletTest.epplet EppletConfigTest.epplet",TEST_PROGS="")

View File

@ -6,6 +6,12 @@
#include <errno.h>
#include <epplet.h>
#ifdef HAVE_GLIBTOP
#include <glibtop.h>
#include <glibtop/cpu.h>
#include "proc.h"
#endif
int cpus = 0;
double *prev_val = NULL;
int *load_val = NULL;
@ -194,6 +200,28 @@ draw_flame(void)
static void
cb_timer(void *data)
{
#ifdef HAVE_GLIBTOP
glibtop_cpu cpu;
double val, val2;
int i;
glibtop_get_cpu (&cpu);
for (i = 0; i < cpus; i++) {
val = (double)(cpu.xcpu_user[i]+cpu.xcpu_nice[i]+cpu.xcpu_sys[i]);
if (prev_val[i] == 0)
prev_val[i] = val;
val2 = (val - prev_val[i]);
prev_val[i] = val;
val2 *= 10;
if (val2 > 100)
val2 = 100;
load_val[i] = val2;
/* printf ("CPU%d: %ld : %ld : %d : %d\n",i, val, prev_val[i], val2, load_val[i]);*/
}
#else
static FILE *f;
int i;
@ -220,10 +248,13 @@ cb_timer(void *data)
load_val[i] = val2;
}
fclose(f);
}
#endif
draw_flame();
Epplet_paste_buf(buf, win, 0, 0);
Epplet_timer(cb_timer, NULL, 0.1, "TIMER");
}
data = NULL;
}
@ -286,6 +317,22 @@ cb_out(void *data, Window w)
static int
count_cpus(void)
{
#ifdef HAVE_GLIBTOP
int i,c = 0;
int bits;
glibtop_cpu cpu;
glibtop_get_cpu (&cpu);
bits= (int)cpu.xcpu_flags;
for (i=0; i<GLIBTOP_NCPU; i++) {
c += bits&1;
/* printf ("%d: %o - %d\n",i,bits,c ); */
bits>>=1;
}
/* printf ("CPUs: %d\n", c); */
return c;
#else
FILE *f;
char s[256];
@ -313,6 +360,7 @@ count_cpus(void)
return count;
}
exit(1);
#endif
}
static void

View File

@ -1,5 +1,12 @@
#include "epplet.h"
#ifdef HAVE_GLIBTOP
#include <glibtop.h>
#include <glibtop/loadavg.h>
#include <glibtop/cpu.h>
#include "proc.h"
#endif
int cpus = 0;
double *prev_val = NULL;
int *load_val = NULL;
@ -12,6 +19,26 @@ int count_cpus(void);
static void
cb_timer(void *data)
{
#ifdef HAVE_GLIBTOP
/* libgtop only handles total load, not per-CPU load */
glibtop_loadavg loadavg;
double val, val2;
int i;
glibtop_get_loadavg (&loadavg);
val2=loadavg.loadavg[0];
val2 *= 20;
/* printf ("Load: %f\n", val2); */
if (val2 > 100)
val2 = 100;
load_val[0] = val2;
Epplet_gadget_data_changed(load[0]);
#else
static FILE *f;
int i;
@ -39,9 +66,12 @@ cb_timer(void *data)
Epplet_gadget_data_changed(load[i]);
}
fclose(f);
Esync();
Epplet_timer(cb_timer, NULL, 0.333, "TIMER");
}
#endif
Esync();
Epplet_timer(cb_timer, NULL, 0.333, "TIMER");
data = NULL;
}
@ -54,9 +84,26 @@ cb_close(void *data)
exit(0);
}
int
count_cpus(void)
{
#ifdef HAVE_GLIBTOP
int i,c = 0;
int bits;
glibtop_cpu cpu;
glibtop_get_cpu (&cpu);
bits= (int)cpu.xcpu_flags;
for (i=0; i<GLIBTOP_NCPU; i++) {
c += bits&1;
/* printf ("%d: %o - %d\n",i,bits,c ); */
bits>>=1;
}
/* printf ("CPUs: %d\n", c); */
return c;
#else
FILE *f;
char s[256];
@ -84,6 +131,7 @@ count_cpus(void)
return count;
}
exit(1);
#endif
}
int

View File

@ -6,6 +6,13 @@
#include <errno.h>
#include "epplet.h"
#ifdef HAVE_GLIBTOP
#include <glibtop.h>
#include <glibtop/mem.h>
#include <glibtop/swap.h>
#include "proc.h"
#endif
#if 0
# define D(x) do {printf("%10s | %7d: [debug] ", __FILE__, __LINE__); printf x; fflush(stdout);} while (0)
#else
@ -25,10 +32,22 @@ static void out_cb(void *data, Window w);
static void
timer_cb(void *data) {
FILE *fp;
char buff[1024];
unsigned long total, used, buffers, cached;
#ifdef HAVE_GLIBTOP
int check=0;
glibtop_mem mem;
glibtop_swap swap;
glibtop_get_mem (&mem);
total=(unsigned long)mem.total;
used=(unsigned long)mem.used;
buffers=(unsigned long)mem.buffer;
cached=(unsigned long)mem.cached;
#else
FILE *fp;
if ((fp = fopen("/proc/meminfo", "r")) == NULL) {
D(("Failed to open /proc/meminfo -- %s\n", strerror(errno)));
return;
@ -37,6 +56,7 @@ timer_cb(void *data) {
fgets(buff, sizeof(buff), fp);
sscanf(buff, "%*s %lu %lu %*u %*u %lu %lu",
&total, &used, &buffers, &cached);
#endif
used -= (buffers + cached);
mem_val = (int) ((((float) used) / total) * 100.0);
D(("%d = 100 * %lu / %lu\n", (100 * used) / total, used, total));
@ -53,9 +73,24 @@ timer_cb(void *data) {
}
Epplet_change_label(mem_label, buff);
#ifdef HAVE_GLIBTOP
glibtop_get_swap (&swap);
check=0;
do {
total=(unsigned long)swap.total;
used=(unsigned long)swap.used;
} while (swap.total==0 && swap.used==0 && check++<15);
#else
fgets(buff, sizeof(buff), fp);
sscanf(buff, "%*s %lu %lu", &total, &used);
fclose(fp);
#endif
swap_val = (int) ((((float) used) / total) * 100.0);
/*printf ("Swap: %lu %lu %d%%\n", total, used, swap_val); */
D(("Swap: %d%% (%lu/%lu)\n", swap_val, used, total));
Epplet_gadget_data_changed(swap_bar);
if (used < 1024) {
@ -69,7 +104,6 @@ timer_cb(void *data) {
}
Epplet_change_label(swap_label, buff);
fclose(fp);
Esync();
Epplet_timer(timer_cb, NULL, 3.0, "TIMER");
return;

View File

@ -6,6 +6,12 @@
#include <errno.h>
#include "epplet.h"
#ifdef HAVE_GLIBTOP
#include <glibtop.h>
#include <glibtop/uptime.h>
#include "proc.h"
#endif
#if 0
# define D(x) do {printf("%10s | %7d: [debug] ", __FILE__, __LINE__); printf x; fflush(stdout);} while (0)
#else
@ -25,11 +31,21 @@ static void out_cb(void *data, Window w);
static void
timer_cb(void *data) {
FILE *fp;
char buff[1024];
unsigned long days, hours, mins, secs;
double total_secs, delay;
#ifdef HAVE_GLIBTOP
glibtop_uptime uptime;
glibtop_get_uptime(&uptime);
secs = (unsigned long)uptime.uptime;
#else
FILE *fp;
if ((fp = fopen("/proc/uptime", "r")) == NULL) {
D(("Failed to open /proc/uptime -- %s\n", strerror(errno)));
return;
@ -37,6 +53,9 @@ timer_cb(void *data) {
fgets(buff, sizeof(buff), fp);
sscanf(buff, "%lf", &total_secs);
secs = (unsigned long) total_secs;
fclose(fp);
#endif
days = secs / 86400;
secs %= 86400;
@ -56,7 +75,6 @@ timer_cb(void *data) {
Esnprintf(buff, sizeof(buff), "%lu mins", mins);
Epplet_change_label(label4, buff);
fclose(fp);
Esync();
Epplet_timer(timer_cb, NULL, delay, "TIMER");
return;

View File

@ -159,7 +159,7 @@ E-Mountbox-bg.png E-Mountbox-blockdev.png E-Mountbox-cd.png \
E-Mountbox-floppy.png E-Mountbox-zip.png \
E-SD_minitime.png E-SD_standby.png
EXTRA_DIST = ${ICONS} ${ABOUT_DOCS} ${IMAGES}
EXTRA_DIST = ${ICONS} ${ABOUT_DOCS} ${IMAGES} proc.h
install-data-hook:
$(mkinstalldirs) $(EROOT)/epplet_icons

40
epplets/proc.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef __PROC_H__
#define __PROC_H__
#define PROC_CPU_TOTAL 0
#define PROC_CPU_USER 1
#define PROC_CPU_NICE 2
#define PROC_CPU_SYS 3
#define PROC_CPU_IDLE 4
#define PROC_MEM_TOTAL 0
#define PROC_MEM_USER 1
#define PROC_MEM_SHARED 2
#define PROC_MEM_BUF 3
#define PROC_MEM_FREE 4
#define PROC_MEM_USED 5
#define PROC_SWAP_TOTAL 0
#define PROC_SWAP_USED 1
#define PROC_SWAP_FREE 2
#define PROC_CPU_SIZE 5
#define PROC_MEM_SIZE 6
#define PROC_SWAP_SIZE 3
typedef struct _ProcInfo ProcInfo;
struct _ProcInfo {
unsigned cpu [PROC_CPU_SIZE];
unsigned cpu_now [PROC_CPU_SIZE];
unsigned cpu_last [PROC_CPU_SIZE];
unsigned mem [PROC_MEM_SIZE];
unsigned swap [PROC_SWAP_SIZE];
};
void proc_read_cpu (ProcInfo *);
void proc_read_mem (ProcInfo *);
#endif