... | ... |
@@ -4,14 +4,14 @@ |
4 | 4 |
|
5 | 5 |
CC = gcc |
6 | 6 |
CCOPT = -Wall -g |
7 |
-CLIB = core/libdd2m-core.a |
|
7 |
+CLIB = core/libdd2m-core.a viz/libdd2m-viz.a |
|
8 | 8 |
|
9 | 9 |
all: essai fake-values |
10 | 10 |
|
11 | 11 |
# --------------------------------------------- |
12 | 12 |
|
13 | 13 |
essai: essai.c Makefile $(CLIB) |
14 |
- $(CC) ${CCOPT} $< $(CLIB) -o $@ |
|
14 |
+ $(CC) ${CCOPT} $< $(CLIB) -lncurses -o $@ |
|
15 | 15 |
|
16 | 16 |
fake-values: fake-values.c Makefile $(CLIB) |
17 | 17 |
$(CC) ${CCOPT} $< $(CLIB) -o $@ |
... | ... |
@@ -14,10 +14,10 @@ extern int verbosity; |
14 | 14 |
|
15 | 15 |
/* --------------------------------------------------------------- */ |
16 | 16 |
|
17 |
-int get_loadavg(double *where) |
|
17 |
+int get_loadavg(float *where) |
|
18 | 18 |
{ |
19 | 19 |
FILE *fp; |
20 |
-double loads[3]; |
|
20 |
+float loads[3]; |
|
21 | 21 |
int foo; |
22 | 22 |
|
23 | 23 |
if ( ! (fp=fopen("/proc/loadavg", "r")) ) { |
... | ... |
@@ -25,10 +25,10 @@ if ( ! (fp=fopen("/proc/loadavg", "r")) ) { |
25 | 25 |
return -1; |
26 | 26 |
} |
27 | 27 |
|
28 |
-foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2); |
|
28 |
+foo = fscanf(fp, "%f %f %f", loads, loads+1, loads+2); |
|
29 | 29 |
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo); |
30 | 30 |
|
31 |
-memcpy(where, loads, 3 * sizeof(double)); |
|
31 |
+memcpy(where, loads, 3 * sizeof(float)); |
|
32 | 32 |
|
33 | 33 |
fclose(fp); |
34 | 34 |
|
... | ... |
@@ -18,16 +18,16 @@ Configuration config; |
18 | 18 |
/* ---------------------------------------------------------------- */ |
19 | 19 |
int essai_sysmetrics(int k) |
20 | 20 |
{ |
21 |
-double dvalues3[3]; |
|
21 |
+float fvalues3[3]; |
|
22 | 22 |
int foo; |
23 | 23 |
|
24 |
-foo = get_loadavg(dvalues3); |
|
24 |
+foo = get_loadavg(fvalues3); |
|
25 | 25 |
if (foo) { |
26 | 26 |
fprintf(stderr, "err get load avg %d\n", foo); |
27 | 27 |
return -1; |
28 | 28 |
} |
29 | 29 |
|
30 |
-printf("load avg %f %f %f\n", dvalues3[0], dvalues3[1], dvalues3[2]); |
|
30 |
+printf("load avg %f %f %f\n", fvalues3[0], fvalues3[1], fvalues3[2]); |
|
31 | 31 |
|
32 | 32 |
return 0; |
33 | 33 |
} |
... | ... |
@@ -6,21 +6,44 @@ |
6 | 6 |
#include <unistd.h> |
7 | 7 |
#include <stdlib.h> |
8 | 8 |
#include <string.h> |
9 |
+#include <curses.h> |
|
9 | 10 |
#include <time.h> |
10 | 11 |
|
11 | 12 |
#include "core/utils.h" |
12 | 13 |
#include "core/sysmetrics.h" |
14 |
+#include "viz/curses/ecran.h" |
|
13 | 15 |
|
14 | 16 |
int verbosity; |
15 | 17 |
|
16 | 18 |
/* --------------------------------------------------------------- */ |
19 |
+int affiche_loadavg(int nbloops, int k) |
|
20 |
+{ |
|
21 |
+int idx, foo; |
|
22 |
+float lds[3]; |
|
23 |
+ |
|
24 |
+for (idx=0; idx<nbloops; idx++) { |
|
25 |
+ |
|
26 |
+ foo = get_loadavg(lds); |
|
27 |
+ if (foo) fprintf(stderr, "get loadavg -> %d\n", foo); |
|
28 |
+ |
|
29 |
+ foo = aff7segs_float(stdscr, 4, 9, lds[0]); |
|
30 |
+ foo = aff7segs_float(stdscr, 14, 9, lds[1]); |
|
31 |
+ foo = aff7segs_float(stdscr, 24, 9, lds[2]); |
|
32 |
+ |
|
33 |
+ usleep(200*1000); |
|
34 |
+ } |
|
35 |
+return 0; |
|
36 |
+} |
|
37 |
+/* --------------------------------------------------------------- */ |
|
38 |
+static void finish(int signal) |
|
39 |
+{ |
|
40 |
+endwin(); exit(0); |
|
41 |
+} |
|
17 | 42 |
/* --------------------------------------------------------------- */ |
18 | 43 |
|
19 | 44 |
int main(int argc, char *argv[]) |
20 | 45 |
{ |
21 | 46 |
int opt, foo; |
22 |
-double loads[3]; |
|
23 |
-int il[3]; |
|
24 | 47 |
|
25 | 48 |
while ((opt = getopt(argc, argv, "v")) != -1) { |
26 | 49 |
switch (opt) { |
... | ... |
@@ -29,15 +52,19 @@ while ((opt = getopt(argc, argv, "v")) != -1) { |
29 | 29 |
} |
30 | 30 |
} |
31 | 31 |
|
32 |
-foo = get_loadavg(loads); |
|
33 |
-if (foo) fprintf(stderr, "get loadavg -> %d\n", foo); |
|
34 |
-for (foo=0; foo<3; foo++) { |
|
35 |
- il[foo] = ((int)(loads[foo] * 90.0)) & 0x3ff; |
|
36 |
- if (verbosity) |
|
37 |
- fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]); |
|
38 |
- } |
|
39 | 32 |
|
40 |
-printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]); |
|
33 |
+initscr(); |
|
34 |
+nonl(); cbreak(); noecho(); |
|
35 |
+keypad(stdscr, TRUE); /* acces aux touches 'curseur' */ |
|
36 |
+fond_ecran(" Demonstrator "); |
|
37 |
+ |
|
38 |
+affiche_loadavg(10000, 0); |
|
39 |
+ |
|
40 |
+/* |
|
41 |
+ * plop, on a fini, il faut restaurer la console |
|
42 |
+ */ |
|
43 |
+finish(0); |
|
44 |
+ |
|
41 | 45 |
|
42 | 46 |
return 0; |
43 | 47 |
} |