Package: wmmon
Version: 1.4-4
Severity: minor
Tags: patch

wmmon reads the CPU counters from /proc/stat. As the number of jiffies
grows, a single-precision float gets unable to distinguish the low-order
digits. As a result, after some uptime, the display gets unreliable, up
to the point where CPU usage is shown only as either maximum or zero.

The attached patch improves the precision by using double instead of
float, thus giving a much bigger margin, unlikely to suffer from this
problem in a lifetime.
diff -ru wmcpu-1.4-orig/wmcpu.c wmcpu-1.4/wmcpu.c
--- wmcpu-1.4-orig/wmcpu.c	2005-12-24 00:41:14.000000000 +0100
+++ wmcpu-1.4/wmcpu.c	2012-04-23 14:30:32.000000000 +0200
@@ -110,8 +110,8 @@
 	FILE *fp;
 	char str[128];
 
-	static float cpustat[4];	/* remember the statistics read last time */
-	float info[4];
+	static double cpustat[4];	/* remember the statistics read last time */
+	double info[4];
 
 	int old_mins = -1;
 
@@ -175,11 +175,11 @@
 
 	if ((fp = fopen("/proc/stat", "r")) != NULL) {
 		long int CPUuser, CPUnice, CPUsyst;
-		fscanf(fp, "%127s%f%f%f%f", str, info, info + 1, info + 2, info + 3);
+		fscanf(fp, "%127s%lf%lf%lf%lf", str, info, info + 1, info + 2, info + 3);
 		fclose(fp);
 
 		if (cpustat[0] != 0) {
-			float fields[4], total = 0.0;
+			double fields[4], total = 0.0;
 			for (i = 0; i < 4; i++) {
 				fields[i] = info[i] - cpustat[i];
 				total += fields[i];

Reply via email to