1 // ****************************************************************************
2 // vfdload.c (C) 1992-2003 Christophe de Dinechin (ddd)
4 // ****************************************************************************
8 // Display the current load using a bar graph
17 // ****************************************************************************
18 // This document is confidential.
19 // Do not redistribute without written permission
20 // ****************************************************************************
22 // * Revision : $Revision$
24 // ****************************************************************************
26 #define VFDCLIENT "vfdload"
27 #define VFDOPTIONS "vfdload.tbl"
28 #define VFDCONFIG "load"
29 long refresh_rate
= 100000;
31 #include "vfdclient.h"
34 // ----------------------------------------------------------------------------
35 // Information about system load
36 // ----------------------------------------------------------------------------
38 unsigned long user
, sys
, nice
, idle
, total
;
42 int main(int argc
, char *argv
[])
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
50 float load1
, load2
, load3
;
53 load_t cur
, prev
, diff
;
54 int user
[256], sys
[256];
58 vfd_options(argc
, argv
);
59 vfd
= vfd_open(server
, port
);
62 cf
= vfd_configure(vfd
, cfg
);
63 x
= cf
.x
; y
= cf
.y
; w
= cf
.w
; h
= cf
.h
;
68 FILE *f
= fopen ("/proc/stat", "r");
69 fscanf(f
, "cpu %lu %lu %lu %lu",
70 &cur
.user
, &cur
.nice
, &cur
.sys
, &cur
.idle
);
72 cur
.total
= cur
.user
+ cur
.nice
+ cur
.sys
+ cur
.idle
;
74 diff
.user
= cur
.user
- prev
.user
;
75 diff
.sys
= cur
.sys
- prev
.sys
;
76 diff
.nice
= cur
.nice
- prev
.nice
;
77 diff
.idle
= cur
.idle
- prev
.idle
;
78 diff
.total
= cur
.total
- prev
.total
;
85 user
[index
] = (h
-2) * (diff
.user
+ diff
.nice
) / diff
.total
;
86 sys
[index
] = (h
- 2) * diff
.sys
/ diff
.total
;
89 vfd_rectangle(vfd
, x
, y
, w
, h
);
90 for (i
= 0; i
< w
; i
++)
92 int user_h
= user
[(index
-i
) & 255];
93 int sys_h
= sys
[(index
- i
) & 255];
94 vfd_fill_rectangle(vfd
,
95 x
+ w
- 1 - i
, by
- user_h
,
97 vfd_fill_rectangle(vfd
,
103 index
= (index
+ 1) & 255;
104 usleep(refresh_rate
);