From 7c8067fc5ae46719deb08ee6bb7756d7c4d40e0c Mon Sep 17 00:00:00 2001 From: phyto Date: Thu, 17 Jan 2019 18:37:30 +0100 Subject: [PATCH 1/2] nettoyer le brotch --- Makefile | 13 ++++++------- essai.c | 33 +++++++++++++++++++++++++++------ fake-values.c | 2 +- funcs.c | 40 ---------------------------------------- funcs.h | 13 ------------- 5 files changed, 34 insertions(+), 67 deletions(-) delete mode 100644 funcs.c delete mode 100644 funcs.h diff --git a/Makefile b/Makefile index 0fe9533..c3b8d06 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,12 @@ CCOPT = -Wall -g all: essai fake-values -essai: essai.c funcs.o Makefile - gcc ${CCOPT} $< funcs.o -o $@ +# --------------------------------------------- +essai: essai.c Makefile + gcc ${CCOPT} $< core/utils.o -o $@ -funcs.o: funcs.c funcs.h Makefile - gcc ${CCOPT} -c $< - -fake-values: fake-values.c funcs.o Makefile - gcc ${CCOPT} $< funcs.o -o $@ +fake-values: fake-values.c Makefile + gcc ${CCOPT} $< core/utils.o -o $@ +# --------------------------------------------- diff --git a/essai.c b/essai.c index 0ad7c09..da02dec 100644 --- a/essai.c +++ b/essai.c @@ -5,24 +5,45 @@ #include #include #include +#include -#include "funcs.h" +#include "core/utils.h" -int verbosity; +int verbosity; + +/* --------------------------------------------------------------- */ + +int get_loadavg(double *where) +{ +FILE *fp; +double loads[3]; +int foo; + +if ( ! (fp=fopen("/proc/loadavg", "r")) ) { + perror("read loadavg"); + return -1; + } + +foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2); +if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo); + +memcpy(where, loads, 3 * sizeof(double)); + +fclose(fp); + +return 0; +} /* --------------------------------------------------------------- */ int main(int argc, char *argv[]) { int opt, foo; -int type = 0; double loads[3]; -while ((opt = getopt(argc, argv, "vst:")) != -1) { +while ((opt = getopt(argc, argv, "v")) != -1) { switch (opt) { case 'v': verbosity++; break; - case 's': srand(getpid()); break; - case 't': type = atoi(optarg); break; default: break; } } diff --git a/fake-values.c b/fake-values.c index 292e8f3..b536d79 100644 --- a/fake-values.c +++ b/fake-values.c @@ -6,7 +6,7 @@ #include #include -#include "funcs.h" +#include "core/utils.h" int verbosity; diff --git a/funcs.c b/funcs.c deleted file mode 100644 index 1b1f199..0000000 --- a/funcs.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * funcs.c - */ - -#include -#include -#include -#include -#include -#include - -#include "funcs.h" - -extern int verbosity; - - -/* --------------------------------------------------------------- */ - -int get_loadavg(double *where) -{ -FILE *fp; -double loads[3]; -int foo; - -if ( ! (fp=fopen("/proc/loadavg", "r")) ) { - perror("read loadavg"); - return -1; - } - -foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2); -if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo); - -memcpy(where, loads, 3 * sizeof(double)); - -fclose(fp); - -return 0; -} - -/* --------------------------------------------------------------- */ diff --git a/funcs.h b/funcs.h deleted file mode 100644 index 057594b..0000000 --- a/funcs.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * funcs.c - */ - -/* return an in random value in [0.999] */ -int random1000(int mode); - -/* get the 'timeofday' as a double float */ -double dtime(void); - -/* only usable on standard Linux ! */ -int get_loadavg(double where[]); - From 22fdf52ccbf473ead7ed24712ac65c9519a83888 Mon Sep 17 00:00:00 2001 From: phyto Date: Fri, 18 Jan 2019 15:39:07 +0100 Subject: [PATCH 2/2] makinf a foo.dat fake file --- .gitignore | 1 + essai.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c41f84f..36e3eae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ a.out *.o fake-values essai +foo.dat serial/t core/t diff --git a/essai.c b/essai.c index da02dec..33ab9fa 100644 --- a/essai.c +++ b/essai.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "core/utils.h" @@ -40,6 +41,7 @@ int main(int argc, char *argv[]) { int opt, foo; double loads[3]; +int il[3]; while ((opt = getopt(argc, argv, "v")) != -1) { switch (opt) { @@ -50,8 +52,12 @@ while ((opt = getopt(argc, argv, "v")) != -1) { foo = get_loadavg(loads); if (foo) fprintf(stderr, "get loadavg -> %d\n", foo); +for (foo=0; foo<3; foo++) { + il[foo] = ((int)(loads[foo] * 900.0)) & 0x3ff; + fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]); + } -printf("%f %f %f %f\n", dtime(), loads[0], loads[1], loads[2]); +printf("T %ld %d %d %d %d\n", time(NULL), getpid()%1024, il[0], il[1], il[2]); return 0; }