[Pkg-wmaker-commits] [wmbubble] 33/207: Fix bursty updates on graphs. Kill ROLLVALUE define (But we should check whether *BSD/Solaris makes getting the load average slow). Don't calculate the moving average of memory utilization or load in the graph itself. Rename roll_membuffer (which had nothing to do with rolling anything) to "rarely_render_seconary" (which is what it actually does), also make it scale with requested FPS. Make memory numbers autorange. Fix/add some comments. Work around emacs's C-mode not understanding #if / while { / #else / while { #endif
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Mon Aug 24 04:17:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmbubble.
commit eed3fa6b4f9869a7760720faab1f3afd412192c8
Author: Robert Jacobs <rnjacobs at mit.edu>
Date: Thu Jul 28 17:48:27 2011 -0700
Fix bursty updates on graphs. Kill ROLLVALUE define (But we should
check whether *BSD/Solaris makes getting the load average slow). Don't
calculate the moving average of memory utilization or load in the
graph itself. Rename roll_membuffer (which had nothing to do with
rolling anything) to "rarely_render_seconary" (which is what it
actually does), also make it scale with requested FPS. Make memory
numbers autorange. Fix/add some comments. Work around emacs's C-mode
not understanding #if / while { / #else / while { #endif
---
bubblemon.c | 103 +++++++++++++++++++++-------------------------------
include/bubblemon.h | 2 +-
sys_freebsd.c | 18 +++------
sys_linux.c | 10 ++---
sys_netbsd.c | 28 ++++++--------
sys_openbsd.c | 28 ++++++--------
sys_sunos.c | 31 +++++++---------
7 files changed, 87 insertions(+), 133 deletions(-)
diff --git a/bubblemon.c b/bubblemon.c
index 2ad9f9a..eee738b 100644
--- a/bubblemon.c
+++ b/bubblemon.c
@@ -100,7 +100,7 @@ static void draw_cpudigit(int what, unsigned char *whither);
static void render_secondary(void);
static void realtime_alpha_blend_of_cpu_usage(int cpu, int proximity);
-static void roll_membuffer(void);
+static void rarely_render_secondary(void);
static void roll_history(void);
static void draw_datetime(unsigned char *display);
@@ -367,10 +367,14 @@ int main(int argc, char **argv) {
#ifdef PRO
start = time(NULL);
- while (cnt--) {
+#endif
+ while (
+#ifdef PRO
+ cnt--
#else
- while (1) {
+ 1
#endif
+ ) {
while (XPending(wmxp_display)) {
XNextEvent(wmxp_display,&event);
switch (event.type) {
@@ -521,18 +525,14 @@ static void bubblemon_update(int proximity) {
/* Find out the CPU load */
loadPercentage = system_cpu();
- /* get loadavg */
- if (memscreen_enabled)
- system_loadavg();
-
/*
The bubblebuf is made up of int8s (0..2), correspodning to the enum. A
pixel in the bubblebuf is accessed using the formula bubblebuf[row * w
+ column].
*/
- /* y coordinates are counted from here multiplied by 256
- to get actual screen coordinate, divide by 256 */
+ /* y coordinates are counted from here multiplied by MULTIPLIER
+ to get actual screen coordinate, use REALY */
waterlevel_max = 0;
waterlevel_min = MAKEY(BOX_SIZE);
@@ -897,11 +897,6 @@ static void render_secondary(void) {
char percent[4];
char number[8];
int i;
- /* mem: 2, 24
- * mem %: 38, 24
- * swap: 2, 43
- * 38, 43
- * digits: 0, 60 and 0, 69 */
/* make a clean buffer with blank spaces. */
memcpy(bm.mem_buf, bm.screen_type ? load_screen.pixel_data : mem_screen.pixel_data,
@@ -914,11 +909,11 @@ static void render_secondary(void) {
sprintf(number, "%02d", bm.loadavg[i].f);
draw_string(number, 1+(4*4+2+1)*i + 4*2 + 2, 9, 0);
}
- /* copy history graph from previous rollover */
- memcpy(bm.mem_buf + 19 * BOX_SIZE * 3, bm.his_bufb, BOX_SIZE * 33 * 3);
+ /* render memory graph */
+ draw_history(BOX_SIZE-4, 31, bm.memhist, &bm.mem_buf[19*BOX_SIZE*3]);
} else {
/* draw memory */
- if (memscreen_megabytes)
+ if (memscreen_megabytes || bm.mem_used > (999999<<10))
snprintf(number, 8, "%6lluM", bm.mem_used >> 20);
else
snprintf(number, 8, "%6lluK", bm.mem_used >> 10);
@@ -927,7 +922,7 @@ static void render_secondary(void) {
draw_string(percent, 39, 2, (bm.mem_percent > 90) ? 1 : 0);
/* draw swap */
- if (memscreen_megabytes)
+ if (memscreen_megabytes || bm.swap_used > (999999<<10))
snprintf(number, 8, "%6lluM", bm.swap_used >> 20);
else
snprintf(number, 8, "%6lluK", bm.swap_used >> 10);
@@ -935,15 +930,19 @@ static void render_secondary(void) {
draw_string(number, 3, 11, (bm.swap_percent > 90) ? 1 : 0);
draw_string(percent, 39, 11, (bm.swap_percent > 90) ? 1 : 0);
- /* copy history graph from previous rollover */
- memcpy(bm.mem_buf + 21 * BOX_SIZE * 3, bm.his_bufa, BOX_SIZE * 31 * 3);
+ /* render load average graph */
+ draw_history(BOX_SIZE-4, 33, bm.history, &bm.mem_buf[21*BOX_SIZE*3]);
}
}
-static void roll_membuffer(void) {
+static void rarely_render_secondary(void) {
static int delay;
+ int divisor;
+
+ divisor = 500000 / delay_time;
+ if (divisor == 0) divisor = 1;
- if (++delay < 30)
+ if (++delay < divisor)
return;
delay = 0;
@@ -951,48 +950,28 @@ static void roll_membuffer(void) {
}
static void roll_history(void) {
- static int update, doit;
-
- if (--doit <= 0) {
- doit = ROLLVALUE; /* how many redraws before we sample new data */
- if (--update <= 0) {
- /* reset counter; 5 = the number of samples to average into one point on
- the bar graph. Probably should be configurable. */
- update = 5;
-
- /* roll history buffers, averaging last 5 samples */
- if (bm.hisadd)
- bm.history[BOX_SIZE-4] /= bm.hisadd;
- if (bm.memadd)
- bm.memhist[BOX_SIZE-4] /= bm.memadd;
-
- memmove(&bm.history[0], &bm.history[1], sizeof(bm.history));
- memmove(&bm.memhist[0], &bm.memhist[1], sizeof(bm.memhist));
-
- bm.history[BOX_SIZE-4] = 0;
- bm.hisadd = 0;
- bm.memhist[BOX_SIZE-4] = 0;
- bm.memadd = 0;
-
- /* refresh backgrounds */
- memcpy(bm.his_bufa, mem_screen.pixel_data + 21 * BOX_SIZE * 3, 31 * BOX_SIZE * 3);
- memcpy(bm.his_bufb, load_screen.pixel_data + 19 * BOX_SIZE * 3, 33 * BOX_SIZE * 3);
-
- /* render memory graph */
- draw_history(BOX_SIZE-4, 31, bm.memhist, bm.his_bufa);
- /* render load average graph */
- draw_history(BOX_SIZE-4, 33, bm.history, bm.his_bufb);
+ static int his_count, load_his_accumulator, mem_his_accumulator;
+ /* Per C standard, those are all initialized to 0 */
- }
+ if (his_count > 5) {
+ /* roll history buffers, averaging last 5 samples */
+ bm.history[BOX_SIZE-4] = load_his_accumulator / his_count;
+ bm.memhist[BOX_SIZE-4] = mem_his_accumulator / his_count;
- /* do load average history update */
- bm.history[BOX_SIZE-4] += bm.loadavg[0].f + (bm.loadavg[0].i * 100);
- bm.hisadd++;
+ memmove(&bm.history[0], &bm.history[1], sizeof(bm.history));
+ memmove(&bm.memhist[0], &bm.memhist[1], sizeof(bm.memhist));
- /* do memory history update */
- bm.memhist[BOX_SIZE-4] += bm.mem_percent;
- bm.memadd++;
+ his_count = load_his_accumulator = mem_his_accumulator = 0;
}
+
+ system_loadavg();
+
+ /* do load average history update */
+ load_his_accumulator += bm.loadavg[0].f + (bm.loadavg[0].i * 100);
+ /* do memory history update */
+ mem_his_accumulator += bm.mem_percent;
+
+ his_count++;
}
static void draw_cpudigit(int what, unsigned char *whither) {
@@ -1157,7 +1136,7 @@ static void realtime_alpha_blend_of_cpu_usage(int cpu, int proximity) {
if (!bm.picture_lock)
memblend -= 36;
if (memblend < GRAPHMINBLEND) {
- roll_membuffer();
+ rarely_render_secondary();
memblend = GRAPHMINBLEND;
}
}
@@ -1165,7 +1144,7 @@ static void realtime_alpha_blend_of_cpu_usage(int cpu, int proximity) {
} else {
blend += 4*6;
if (bm.picture_lock)
- roll_membuffer();
+ rarely_render_secondary();
if (memscreen_enabled && !bm.picture_lock)
memblend += 60;
diff --git a/include/bubblemon.h b/include/bubblemon.h
index 3957d57..ebfb601 100644
--- a/include/bubblemon.h
+++ b/include/bubblemon.h
@@ -32,6 +32,7 @@
#define GRAPHMINBLEND 40
#define GRAPHMAXBLEND 256
+/* duckblend is actually the opacity of the water over the duck */
#define DUCKBLEND 100
#define MULTIPLIER 4096.0
@@ -39,7 +40,6 @@
#define REALY(y) ((y) >> POWER2)
#define MAKEY(y) ((y) << POWER2)
#define MAKE_INTEGER(x) ((int)((x)*MULTIPLIER+0.5))
-#define ROLLVALUE 1 /* frequency of history rollover */
#include <X11/Xlib.h>
diff --git a/sys_freebsd.c b/sys_freebsd.c
index 348f84a..48d70cd 100644
--- a/sys_freebsd.c
+++ b/sys_freebsd.c
@@ -183,11 +183,8 @@ int system_memory(void)
void system_loadavg(void)
{
- static int avg_delay;
-
- if (avg_delay-- <= 0) {
struct loadavg loadinfo;
- int i, mib[2];
+ int i, mib[2];
size_t size;
mib[0] = CTL_VM;
@@ -195,14 +192,11 @@ void system_loadavg(void)
size = sizeof (loadinfo);
if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0)
- for (i = 0; i < 3; i++) {
- bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
- bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
- loadinfo.fscale / 2) / loadinfo.fscale) % 100;
- }
-
- avg_delay = ROLLVALUE;
- }
+ for (i = 0; i < 3; i++) {
+ bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
+ bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
+ loadinfo.fscale / 2) / loadinfo.fscale) % 100;
+ }
}
/* ex:set ts=8: */
diff --git a/sys_linux.c b/sys_linux.c
index 6834cd9..d64180d 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -190,14 +190,10 @@ int system_memory(void)
void system_loadavg(void)
{
- FILE *avg;
- static int avg_delay;
- if (avg_delay-- <= 0) {
+ FILE *avg;
avg = fopen("/proc/loadavg", "r");
fscanf(avg, "%d.%d %d.%d %d.%d", &bm.loadavg[0].i, &bm.loadavg[0].f,
- &bm.loadavg[1].i, &bm.loadavg[1].f,
- &bm.loadavg[2].i, &bm.loadavg[2].f);
+ &bm.loadavg[1].i, &bm.loadavg[1].f,
+ &bm.loadavg[2].i, &bm.loadavg[2].f);
fclose(avg);
- avg_delay = ROLLVALUE;
- }
}
diff --git a/sys_netbsd.c b/sys_netbsd.c
index 2bf4a1c..777ba0a 100644
--- a/sys_netbsd.c
+++ b/sys_netbsd.c
@@ -108,23 +108,17 @@ int system_memory(void)
void system_loadavg(void)
{
- static int avg_delay;
-
- if (avg_delay-- <= 0) {
- struct loadavg loadinfo;
- int i;
- int mib[] = { CTL_VM, VM_LOADAVG };
- size_t size = sizeof (loadinfo);
-
- if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0)
- for (i = 0; i < 3; i++) {
- bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
- bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
- loadinfo.fscale / 2) / loadinfo.fscale) % 100;
- }
-
- avg_delay = ROLLVALUE;
- }
+ struct loadavg loadinfo;
+ int i;
+ int mib[] = { CTL_VM, VM_LOADAVG };
+ size_t size = sizeof (loadinfo);
+
+ if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0)
+ for (i = 0; i < 3; i++) {
+ bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
+ bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
+ loadinfo.fscale / 2) / loadinfo.fscale) % 100;
+ }
}
/* ex:set sw=4 ts=4: */
diff --git a/sys_openbsd.c b/sys_openbsd.c
index 98f9ea2..3112851 100644
--- a/sys_openbsd.c
+++ b/sys_openbsd.c
@@ -106,23 +106,17 @@ int system_memory(void)
void system_loadavg(void)
{
- static int avg_delay;
-
- if (avg_delay-- <= 0) {
- struct loadavg loadinfo;
- int i;
- int mib[] = { CTL_VM, VM_LOADAVG };
- size_t size = sizeof (loadinfo);
-
- if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0)
- for (i = 0; i < 3; i++) {
- bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
- bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
- loadinfo.fscale / 2) / loadinfo.fscale) % 100;
- }
-
- avg_delay = ROLLVALUE;
- }
+ struct loadavg loadinfo;
+ int i;
+ int mib[] = { CTL_VM, VM_LOADAVG };
+ size_t size = sizeof (loadinfo);
+
+ if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) >= 0)
+ for (i = 0; i < 3; i++) {
+ bm.loadavg[i].i = loadinfo.ldavg[i] / loadinfo.fscale;
+ bm.loadavg[i].f = ((loadinfo.ldavg[i] * 100 +
+ loadinfo.fscale / 2) / loadinfo.fscale) % 100;
+ }
}
/* ex:set sw=4 ts=4: */
diff --git a/sys_sunos.c b/sys_sunos.c
index f39c4e6..5d1c4c9 100644
--- a/sys_sunos.c
+++ b/sys_sunos.c
@@ -225,25 +225,22 @@ void system_loadavg(void)
return;
}
- if (avg_delay-- <= 0) {
- GetCPULoadAverage(&one_m, &five_m, &fift_m);
-
- if (dbg_print_cpu) {
- static int i = 0;
- if (0 == (i % dbg_print_cpu))
- printf("loadavg: %0.2f %0.2f %0.2f\n",
- one_m, five_m, fift_m);
- i++;
- }
+ GetCPULoadAverage(&one_m, &five_m, &fift_m);
- bm.loadavg[0].i = floor(one_m);
- bm.loadavg[0].f = 100 * (one_m - floor(one_m));
- bm.loadavg[1].i = floor(five_m);
- bm.loadavg[1].f = 100 * (five_m - floor(five_m));
- bm.loadavg[2].i = floor(fift_m);
- bm.loadavg[2].f = 100 * (fift_m - floor(fift_m));
- avg_delay = ROLLVALUE;
+ if (dbg_print_cpu) {
+ static int i = 0;
+ if (0 == (i % dbg_print_cpu))
+ printf("loadavg: %0.2f %0.2f %0.2f\n",
+ one_m, five_m, fift_m);
+ i++;
}
+
+ bm.loadavg[0].i = floor(one_m);
+ bm.loadavg[0].f = 100 * (one_m - floor(one_m));
+ bm.loadavg[1].i = floor(five_m);
+ bm.loadavg[1].f = 100 * (five_m - floor(five_m));
+ bm.loadavg[2].i = floor(fift_m);
+ bm.loadavg[2].f = 100 * (fift_m - floor(fift_m));
}
static void GetMemoryStats(u_int64_t *pMemMax, u_int64_t *pMemFree)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbubble.git
More information about the Pkg-wmaker-commits
mailing list