Browse Source

adding core/sysmetrics.[ch]

tth 1 year ago
parent
commit
65e9d58486
5 changed files with 70 additions and 29 deletions
  1. 7
    4
      core/Makefile
  2. 38
    0
      core/sysmetrics.c
  3. 4
    0
      core/sysmetrics.h
  4. 18
    2
      core/t.c
  5. 3
    23
      essai.c

+ 7
- 4
core/Makefile View File

@@ -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
 

+ 38
- 0
core/sysmetrics.c View File

@@ -0,0 +1,38 @@
1
+/*
2
+ *		core/sysmetrics.c
3
+ */
4
+
5
+#include  <stdio.h>
6
+#include  <unistd.h>
7
+#include  <stdlib.h>
8
+#include    <string.h>
9
+#include  <time.h>
10
+
11
+#include  "sysmetrics.h"
12
+
13
+extern int	verbosity;
14
+
15
+/* --------------------------------------------------------------- */
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
+/* --------------------------------------------------------------- */

+ 4
- 0
core/sysmetrics.h View File

@@ -0,0 +1,4 @@
1
+
2
+
3
+int get_loadavg(double *where);
4
+

+ 18
- 2
core/t.c View File

@@ -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 38
 int		foo, opt;
22 39
 char		*conffile = "dd2-monitor.conf";
23 40
 
24
-
25 41
 fprintf(stderr, "+\n+   DD2 MONITOR\n+\n");
26 42
 
27 43
 /* set some default values */
28 44
 verbosity	= 0;
29 45
 
30 46
 
31
-
32 47
 while ((opt = getopt(argc, argv, "v")) != -1) {
33 48
 	switch (opt) {
34 49
 		case 'v':	verbosity++;		break;
@@ -46,6 +61,7 @@ foo = parse_config(conffile, 0);
46 61
 fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
47 62
 show_config("foo");
48 63
 
64
+essai_sysmetrics(0);
49 65
 /*
50 66
 foo = load_lut1024f("foo.lut1024f", NULL, 1);
51 67
 fprintf(stderr, "chargement de la lut --> %d\n\n", foo);

+ 3
- 23
essai.c View File

@@ -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 33
 if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
55 34
 for (foo=0; foo<3; foo++) {
56 35
 	il[foo] = ((int)(loads[foo] * 90.0)) & 0x3ff;
57
-	fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
36
+	if (verbosity)
37
+		fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
58 38
 	}
59 39
 
60 40
 printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]);

Loading…
Cancel
Save