Browse code

adding core/sysmetrics.[ch]

tth authored on 28/01/2019 15:57:45
Showing 5 changed files
... ...
@@ -6,7 +6,7 @@
6 6
 
7 7
 
8 8
 COPT = -Wall -fpic -g -DDEBUG_LEVEL=0
9
-OBJS = lut1024f.o parseconf.o utils.o
9
+OBJS = lut1024f.o parseconf.o utils.o sysmetrics.o
10 10
 DEPS = Makefile
11 11
 ALIB = libdd2m-core.a
12 12
 # ---------------------------------------------------
... ...
@@ -15,13 +15,16 @@ ${ALIB}:	${OBJS}
15 15
 	ar r $@ $?
16 16
 
17 17
 lut1024f.o:	lut1024f.c lut1024.h ${DEPS}
18
-	gcc -Wall -c $<
18
+	gcc $(COPT) -c $<
19 19
 
20 20
 parseconf.o:	parseconf.c config.h  ${DEPS}
21
-	gcc -Wall -c $<
21
+	gcc $(COPT) -c $<
22 22
 
23 23
 utils.o:	utils.c utils.h  ${DEPS}
24
-	gcc -Wall -c $<
24
+	gcc $(COPT) -c $<
25
+
26
+sysmetrics.o:	sysmetrics.c  ${DEPS}
27
+	gcc $(COPT) -c $<
25 28
 
26 29
 # ---------------------------------------------------
27 30
 
28 31
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+/*
1
+ *		core/sysmetrics.c
2
+ */
3
+
4
+#include  <stdio.h>
5
+#include  <unistd.h>
6
+#include  <stdlib.h>
7
+#include    <string.h>
8
+#include  <time.h>
9
+
10
+#include  "sysmetrics.h"
11
+
12
+extern int	verbosity;
13
+
14
+/* --------------------------------------------------------------- */
15
+
16
+int get_loadavg(double *where)
17
+{
18
+FILE		*fp;
19
+double		loads[3];
20
+int		foo;
21
+
22
+if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
23
+	perror("read loadavg");
24
+	return -1;
25
+	}
26
+
27
+foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2);
28
+if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
29
+
30
+memcpy(where, loads, 3 * sizeof(double));
31
+
32
+fclose(fp);
33
+
34
+return 0;	
35
+}
36
+
37
+/* --------------------------------------------------------------- */
0 38
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+
1
+
2
+int get_loadavg(double *where);
3
+
... ...
@@ -8,12 +8,29 @@
8 8
 
9 9
 #include	"lut1024.h"
10 10
 #include	"config.h"
11
+#include  	"sysmetrics.h"
11 12
 
12 13
 int verbosity;
13 14
 
14 15
 Configuration		config;
15 16
 
16 17
 
18
+/* ---------------------------------------------------------------- */
19
+int essai_sysmetrics(int k)
20
+{
21
+double		dvalues3[3];
22
+int		foo;
23
+
24
+foo = get_loadavg(dvalues3);
25
+if (foo) {
26
+	fprintf(stderr, "err get load avg %d\n", foo);
27
+	return -1;
28
+	}
29
+
30
+printf("load avg %f %f %f\n", dvalues3[0], dvalues3[1], dvalues3[2]);
31
+
32
+return 0;
33
+}
17 34
 /* ---------------------------------------------------------------- */
18 35
 
19 36
 int main (int argc, char *argv[])
... ...
@@ -21,14 +38,12 @@ int main (int argc, char *argv[])
21 21
 int		foo, opt;
22 22
 char		*conffile = "dd2-monitor.conf";
23 23
 
24
-
25 24
 fprintf(stderr, "+\n+   DD2 MONITOR\n+\n");
26 25
 
27 26
 /* set some default values */
28 27
 verbosity	= 0;
29 28
 
30 29
 
31
-
32 30
 while ((opt = getopt(argc, argv, "v")) != -1) {
33 31
 	switch (opt) {
34 32
 		case 'v':	verbosity++;		break;
... ...
@@ -46,6 +61,7 @@ foo = parse_config(conffile, 0);
46 46
 fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
47 47
 show_config("foo");
48 48
 
49
+essai_sysmetrics(0);
49 50
 /*
50 51
 foo = load_lut1024f("foo.lut1024f", NULL, 1);
51 52
 fprintf(stderr, "chargement de la lut --> %d\n\n", foo);
... ...
@@ -9,32 +9,11 @@
9 9
 #include  <time.h>
10 10
 
11 11
 #include  "core/utils.h"
12
+#include  "core/sysmetrics.h"
12 13
 
13 14
 int	verbosity;
14 15
 
15 16
 /* --------------------------------------------------------------- */
16
-
17
-int get_loadavg(double *where)
18
-{
19
-FILE		*fp;
20
-double		loads[3];
21
-int		foo;
22
-
23
-if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
24
-	perror("read loadavg");
25
-	return -1;
26
-	}
27
-
28
-foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2);
29
-if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
30
-
31
-memcpy(where, loads, 3 * sizeof(double));
32
-
33
-fclose(fp);
34
-
35
-return 0;	
36
-}
37
-
38 17
 /* --------------------------------------------------------------- */
39 18
 
40 19
 int main(int argc, char *argv[])
... ...
@@ -54,7 +33,8 @@ foo = get_loadavg(loads);
54 54
 if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
55 55
 for (foo=0; foo<3; foo++) {
56 56
 	il[foo] = ((int)(loads[foo] * 90.0)) & 0x3ff;
57
-	fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
57
+	if (verbosity)
58
+		fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
58 59
 	}
59 60
 
60 61
 printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]);