Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 96601
Collapse All | Expand All

(-)torsmo-0.18/linux.c (-5 / +41 lines)
Lines 115-121 Link Here
115
115
116
void update_net_stats() {
116
void update_net_stats() {
117
  static int rep;
117
  static int rep;
118
  // FIXME: arbitrary size chosen to keep code simple.
119
  static float net_rec[15];
120
  static float net_trans[15];
118
  unsigned int i;
121
  unsigned int i;
122
  unsigned int curtmp;
119
  char buf[256];
123
  char buf[256];
120
  double delta;
124
  double delta;
121
125
Lines 174-182 Link Here
174
      ns->trans += (t - ns->last_read_trans);
178
      ns->trans += (t - ns->last_read_trans);
175
    ns->last_read_trans = t;
179
    ns->last_read_trans = t;
176
180
181
182
    
177
    /* calculate speeds */
183
    /* calculate speeds */
178
    ns->recv_speed = (ns->recv - last_recv) / delta;
184
    net_rec[0] = (ns->recv - last_recv) / delta;
179
    ns->trans_speed = (ns->trans - last_trans) / delta;
185
    net_trans[0] = (ns->trans - last_trans) / delta;
186
    curtmp = 0;
187
    // get an average
188
    for (i=0;i<info.net_rec_avg_samples;i++)
189
	curtmp += net_rec[i];
190
    ns->recv_speed = curtmp / (double)info.net_rec_avg_samples;
191
    curtmp = 0;
192
    for (i=0;i<info.net_trans_avg_samples;i++)
193
	curtmp += net_trans[i];
194
    ns->trans_speed = curtmp / (double)info.net_trans_avg_samples;
195
    if (info.net_rec_avg_samples > 1) {
196
      for (i=info.net_rec_avg_samples;i>1;i--)
197
	    net_rec[i-1] = net_rec[i-2];
198
    }
199
    if (info.net_trans_avg_samples > 1) {
200
      for (i=info.net_trans_avg_samples;i>1;i--)
201
	    net_trans[i-1] = net_trans[i-2];
202
    }
203
	//printf("net %i %i\n", info.net_trans_avg_samples, info.net_rec_avg_samples);
204
    
205
    
180
  }
206
  }
181
207
182
  /* fclose(net_dev_fp); net_dev_fp = NULL; */
208
  /* fclose(net_dev_fp); net_dev_fp = NULL; */
Lines 193-200 Link Here
193
static FILE *stat_fp;
219
static FILE *stat_fp;
194
220
195
static void update_stat() {
221
static void update_stat() {
222
  // FIXME: arbitrary size?
223
  static double cpu_val[15];
196
  static int rep;
224
  static int rep;
197
  char buf[256];
225
  char buf[256];
226
  int i;
227
  double curtmp;
198
228
199
  if (stat_fp == NULL)
229
  if (stat_fp == NULL)
200
    stat_fp = open_file("/proc/stat", &rep);
230
    stat_fp = open_file("/proc/stat", &rep);
Lines 228-237 Link Here
228
258
229
    if (clock_ticks == 0)
259
    if (clock_ticks == 0)
230
      clock_ticks = sysconf(_SC_CLK_TCK);
260
      clock_ticks = sysconf(_SC_CLK_TCK);
231
261
    curtmp = 0;
232
    info.cpu_usage = (cpu_user+cpu_nice+cpu_system - last_cpu_sum) / delta
262
    cpu_val[0] = (cpu_user+cpu_nice+cpu_system-last_cpu_sum) / delta / (double) clock_ticks / info.cpu_count;
233
      / (double) clock_ticks / info.cpu_count;
263
    for (i=0;i<info.cpu_avg_samples;i++)
264
	    curtmp += cpu_val[i];
265
    info.cpu_usage = curtmp / info.cpu_avg_samples;
234
    last_cpu_sum = cpu_user+cpu_nice+cpu_system;
266
    last_cpu_sum = cpu_user+cpu_nice+cpu_system;
267
    for (i=info.cpu_avg_samples;i>1;i--)
268
	    cpu_val[i-1] = cpu_val[i-2];
269
    //printf("cpu %i\n", info.cpu_avg_samples);
270
	    
235
  }
271
  }
236
}
272
}
237
273
(-)torsmo-0.18/torsmo.c (+45 lines)
Lines 61-66 Link Here
61
61
62
static long default_fg_color, default_bg_color, default_out_color;
62
static long default_fg_color, default_bg_color, default_out_color;
63
63
64
static int cpu_avg_samples, net_rec_avg_samples, net_trans_avg_samples;
65
64
#ifdef OWN_WINDOW
66
#ifdef OWN_WINDOW
65
/* create own window or draw stuff to root? */
67
/* create own window or draw stuff to root? */
66
static int own_window;
68
static int own_window;
Lines 1841-1846 Link Here
1841
  fork_to_background = 0;
1843
  fork_to_background = 0;
1842
  border_margin = 3;
1844
  border_margin = 3;
1843
  border_width = 1;
1845
  border_width = 1;
1846
  info.cpu_avg_samples = 4;
1847
  info.net_rec_avg_samples = 4;
1848
  info.net_trans_avg_samples = 4;
1844
  default_fg_color = WhitePixel(display, screen);
1849
  default_fg_color = WhitePixel(display, screen);
1845
  default_bg_color = BlackPixel(display, screen);
1850
  default_bg_color = BlackPixel(display, screen);
1846
  default_out_color = BlackPixel(display, screen);
1851
  default_out_color = BlackPixel(display, screen);
Lines 1975-1980 Link Here
1975
      else
1980
      else
1976
        CONF_ERR
1981
        CONF_ERR
1977
    }
1982
    }
1983
    CONF("cpu_avg_samples") {
1984
      if(value) {
1985
        cpu_avg_samples = strtol(value, 0, 0);
1986
	if (cpu_avg_samples < 1 || cpu_avg_samples > 14)
1987
		CONF_ERR
1988
	else
1989
		info.cpu_avg_samples = cpu_avg_samples;
1990
      }
1991
      else
1992
        CONF_ERR
1993
    }
1994
    CONF("net_rec_avg_samples") {
1995
      if(value) {
1996
        net_rec_avg_samples = strtol(value, 0, 0);
1997
      	if (net_rec_avg_samples < 1 || net_rec_avg_samples > 14) {
1998
		CONF_ERR
1999
	}
2000
	else
2001
		info.net_rec_avg_samples = net_rec_avg_samples;
2002
      }
2003
      else
2004
        CONF_ERR
2005
    }
2006
    CONF("net_trans_avg_samples") {
2007
      if(value) {
2008
        net_trans_avg_samples = strtol(value, 0, 0);
2009
       	if (net_trans_avg_samples < 1 || net_trans_avg_samples > 14)
2010
		CONF_ERR
2011
	else
2012
		info.net_trans_avg_samples = net_trans_avg_samples;
2013
      }
2014
      else
2015
        CONF_ERR
2016
    }
2017
2018
2019
2020
2021
2022
    
1978
#ifdef XDBE
2023
#ifdef XDBE
1979
    CONF("double_buffer") {
2024
    CONF("double_buffer") {
1980
      use_xdbe = string_to_bool(value);
2025
      use_xdbe = string_to_bool(value);
(-)torsmo-0.18/torsmo.h (+4 lines)
Lines 30-35 Link Here
30
30
31
struct cpu_stat {
31
struct cpu_stat {
32
  unsigned int user, nice, system, idle, iowait, irq, softirq;
32
  unsigned int user, nice, system, idle, iowait, irq, softirq;
33
  int cpu_avg_samples;
33
};
34
};
34
35
35
enum {
36
enum {
Lines 71-76 Link Here
71
  float cpu_usage;
72
  float cpu_usage;
72
  struct cpu_stat cpu_summed;
73
  struct cpu_stat cpu_summed;
73
  unsigned int cpu_count;
74
  unsigned int cpu_count;
75
  unsigned int cpu_avg_samples;
76
77
  unsigned int net_rec_avg_samples, net_trans_avg_samples;
74
78
75
  float loadavg[3];
79
  float loadavg[3];
76
80
(-)torsmo-0.18/torsmorc.sample (+8 lines)
Lines 75-80 Link Here
75
# set to yes if you want all text to be in uppercase
75
# set to yes if you want all text to be in uppercase
76
uppercase no
76
uppercase no
77
77
78
# number of cpu samples to average
79
cpu_avg_samples 4
80
81
# number of net samples to average
82
net_rec_avg_samples 4 # receiving
83
net_trans_avg_samples # transmitting
84
85
78
# boinc (seti) dir
86
# boinc (seti) dir
79
# seti_dir /opt/seti
87
# seti_dir /opt/seti
80
88
(-)torsmo-0.18/x11.c (-9 lines)
Lines 64-78 Link Here
64
64
65
    XFree(buf); buf = 0;
65
    XFree(buf); buf = 0;
66
66
67
    /* get workarea */
68
    if (XGetWindowProperty(display, root, ATOM(_NET_WORKAREA), desktop*4, 4,
69
          False, XA_CARDINAL, &type, &format, &nitems, &bytes, &buf) ==
70
        Success && type == XA_CARDINAL) {
71
      workarea[0] = ((long *) buf)[0];
72
      workarea[1] = ((long *) buf)[1];
73
      workarea[2] = ((long *) buf)[2];
74
      workarea[3] = ((long *) buf)[3];
75
    }
76
  }
67
  }
77
68
78
  if (buf) { XFree(buf); buf = 0; }
69
  if (buf) { XFree(buf); buf = 0; }

Return to bug 96601