1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
diff -ruN torsmo-0.18/linux.c torsmo-0.18.new/linux.c
--- torsmo-0.18/linux.c 2004-12-21 14:20:07.000000000 -0700
+++ torsmo-0.18.new/linux.c 2005-06-20 05:46:40.000000000 -0600
@@ -115,7 +115,11 @@
void update_net_stats() {
static int rep;
+ // FIXME: arbitrary size chosen to keep code simple.
+ static float net_rec[15];
+ static float net_trans[15];
unsigned int i;
+ unsigned int curtmp;
char buf[256];
double delta;
@@ -174,9 +178,31 @@
ns->trans += (t - ns->last_read_trans);
ns->last_read_trans = t;
+
+
/* calculate speeds */
- ns->recv_speed = (ns->recv - last_recv) / delta;
- ns->trans_speed = (ns->trans - last_trans) / delta;
+ net_rec[0] = (ns->recv - last_recv) / delta;
+ net_trans[0] = (ns->trans - last_trans) / delta;
+ curtmp = 0;
+ // get an average
+ for (i=0;i<info.net_rec_avg_samples;i++)
+ curtmp += net_rec[i];
+ ns->recv_speed = curtmp / (double)info.net_rec_avg_samples;
+ curtmp = 0;
+ for (i=0;i<info.net_trans_avg_samples;i++)
+ curtmp += net_trans[i];
+ ns->trans_speed = curtmp / (double)info.net_trans_avg_samples;
+ if (info.net_rec_avg_samples > 1) {
+ for (i=info.net_rec_avg_samples;i>1;i--)
+ net_rec[i-1] = net_rec[i-2];
+ }
+ if (info.net_trans_avg_samples > 1) {
+ for (i=info.net_trans_avg_samples;i>1;i--)
+ net_trans[i-1] = net_trans[i-2];
+ }
+ //printf("net %i %i\n", info.net_trans_avg_samples, info.net_rec_avg_samples);
+
+
}
/* fclose(net_dev_fp); net_dev_fp = NULL; */
@@ -193,8 +219,12 @@
static FILE *stat_fp;
static void update_stat() {
+ // FIXME: arbitrary size?
+ static double cpu_val[15];
static int rep;
char buf[256];
+ int i;
+ double curtmp;
if (stat_fp == NULL)
stat_fp = open_file("/proc/stat", &rep);
@@ -228,10 +258,16 @@
if (clock_ticks == 0)
clock_ticks = sysconf(_SC_CLK_TCK);
-
- info.cpu_usage = (cpu_user+cpu_nice+cpu_system - last_cpu_sum) / delta
- / (double) clock_ticks / info.cpu_count;
+ curtmp = 0;
+ cpu_val[0] = (cpu_user+cpu_nice+cpu_system-last_cpu_sum) / delta / (double) clock_ticks / info.cpu_count;
+ for (i=0;i<info.cpu_avg_samples;i++)
+ curtmp += cpu_val[i];
+ info.cpu_usage = curtmp / info.cpu_avg_samples;
last_cpu_sum = cpu_user+cpu_nice+cpu_system;
+ for (i=info.cpu_avg_samples;i>1;i--)
+ cpu_val[i-1] = cpu_val[i-2];
+ //printf("cpu %i\n", info.cpu_avg_samples);
+
}
}
diff -ruN torsmo-0.18/torsmo.c torsmo-0.18.new/torsmo.c
--- torsmo-0.18/torsmo.c 2004-12-21 15:14:46.000000000 -0700
+++ torsmo-0.18.new/torsmo.c 2005-06-20 05:46:42.000000000 -0600
@@ -61,6 +61,8 @@
static long default_fg_color, default_bg_color, default_out_color;
+static int cpu_avg_samples, net_rec_avg_samples, net_trans_avg_samples;
+
#ifdef OWN_WINDOW
/* create own window or draw stuff to root? */
static int own_window;
@@ -1841,6 +1843,9 @@
fork_to_background = 0;
border_margin = 3;
border_width = 1;
+ info.cpu_avg_samples = 4;
+ info.net_rec_avg_samples = 4;
+ info.net_trans_avg_samples = 4;
default_fg_color = WhitePixel(display, screen);
default_bg_color = BlackPixel(display, screen);
default_out_color = BlackPixel(display, screen);
@@ -1975,6 +1980,46 @@
else
CONF_ERR
}
+ CONF("cpu_avg_samples") {
+ if(value) {
+ cpu_avg_samples = strtol(value, 0, 0);
+ if (cpu_avg_samples < 1 || cpu_avg_samples > 14)
+ CONF_ERR
+ else
+ info.cpu_avg_samples = cpu_avg_samples;
+ }
+ else
+ CONF_ERR
+ }
+ CONF("net_rec_avg_samples") {
+ if(value) {
+ net_rec_avg_samples = strtol(value, 0, 0);
+ if (net_rec_avg_samples < 1 || net_rec_avg_samples > 14) {
+ CONF_ERR
+ }
+ else
+ info.net_rec_avg_samples = net_rec_avg_samples;
+ }
+ else
+ CONF_ERR
+ }
+ CONF("net_trans_avg_samples") {
+ if(value) {
+ net_trans_avg_samples = strtol(value, 0, 0);
+ if (net_trans_avg_samples < 1 || net_trans_avg_samples > 14)
+ CONF_ERR
+ else
+ info.net_trans_avg_samples = net_trans_avg_samples;
+ }
+ else
+ CONF_ERR
+ }
+
+
+
+
+
+
#ifdef XDBE
CONF("double_buffer") {
use_xdbe = string_to_bool(value);
diff -ruN torsmo-0.18/torsmo.h torsmo-0.18.new/torsmo.h
--- torsmo-0.18/torsmo.h 2004-12-21 14:49:17.000000000 -0700
+++ torsmo-0.18.new/torsmo.h 2005-06-20 05:47:29.000000000 -0600
@@ -30,6 +30,7 @@
struct cpu_stat {
unsigned int user, nice, system, idle, iowait, irq, softirq;
+ int cpu_avg_samples;
};
enum {
@@ -71,6 +72,9 @@
float cpu_usage;
struct cpu_stat cpu_summed;
unsigned int cpu_count;
+ unsigned int cpu_avg_samples;
+
+ unsigned int net_rec_avg_samples, net_trans_avg_samples;
float loadavg[3];
diff -ruN torsmo-0.18/torsmorc.sample torsmo-0.18.new/torsmorc.sample
--- torsmo-0.18/torsmorc.sample 2004-12-21 14:56:12.000000000 -0700
+++ torsmo-0.18.new/torsmorc.sample 2005-06-20 05:50:09.000000000 -0600
@@ -75,6 +75,14 @@
# set to yes if you want all text to be in uppercase
uppercase no
+# number of cpu samples to average
+cpu_avg_samples 4
+
+# number of net samples to average
+net_rec_avg_samples 4 # receiving
+net_trans_avg_samples # transmitting
+
+
# boinc (seti) dir
# seti_dir /opt/seti
diff -ruN torsmo-0.18/x11.c torsmo-0.18.new/x11.c
--- torsmo-0.18/x11.c 2004-12-21 15:19:55.000000000 -0700
+++ torsmo-0.18.new/x11.c 2005-06-20 04:47:00.000000000 -0600
@@ -64,15 +64,6 @@
XFree(buf); buf = 0;
- /* get workarea */
- if (XGetWindowProperty(display, root, ATOM(_NET_WORKAREA), desktop*4, 4,
- False, XA_CARDINAL, &type, &format, &nitems, &bytes, &buf) ==
- Success && type == XA_CARDINAL) {
- workarea[0] = ((long *) buf)[0];
- workarea[1] = ((long *) buf)[1];
- workarea[2] = ((long *) buf)[2];
- workarea[3] = ((long *) buf)[3];
- }
}
if (buf) { XFree(buf); buf = 0; }
|