From 67b26a733bef488b767d10a12eb3779fca02c27e Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 30 Jan 2019 19:14:40 +0100 Subject: [PATCH] making a perfmeter --- Makefile | 4 ++-- core/sysmetrics.c | 8 ++++---- core/sysmetrics.h | 2 +- core/t.c | 6 +++--- essai.c | 47 +++++++++++++++++++++++++++++++++++++---------- 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index d43301d..8f8bf2d 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,14 @@ CC = gcc CCOPT = -Wall -g -CLIB = core/libdd2m-core.a +CLIB = core/libdd2m-core.a viz/libdd2m-viz.a all: essai fake-values # --------------------------------------------- essai: essai.c Makefile $(CLIB) - $(CC) ${CCOPT} $< $(CLIB) -o $@ + $(CC) ${CCOPT} $< $(CLIB) -lncurses -o $@ fake-values: fake-values.c Makefile $(CLIB) $(CC) ${CCOPT} $< $(CLIB) -o $@ diff --git a/core/sysmetrics.c b/core/sysmetrics.c index 2e536f8..032da13 100644 --- a/core/sysmetrics.c +++ b/core/sysmetrics.c @@ -14,10 +14,10 @@ extern int verbosity; /* --------------------------------------------------------------- */ -int get_loadavg(double *where) +int get_loadavg(float *where) { FILE *fp; -double loads[3]; +float loads[3]; int foo; if ( ! (fp=fopen("/proc/loadavg", "r")) ) { @@ -25,10 +25,10 @@ if ( ! (fp=fopen("/proc/loadavg", "r")) ) { return -1; } -foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2); +foo = fscanf(fp, "%f %f %f", loads, loads+1, loads+2); if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo); -memcpy(where, loads, 3 * sizeof(double)); +memcpy(where, loads, 3 * sizeof(float)); fclose(fp); diff --git a/core/sysmetrics.h b/core/sysmetrics.h index f27b60c..bb99b15 100644 --- a/core/sysmetrics.h +++ b/core/sysmetrics.h @@ -1,4 +1,4 @@ -int get_loadavg(double *where); +int get_loadavg(float *where); diff --git a/core/t.c b/core/t.c index 873a529..5fbeda1 100644 --- a/core/t.c +++ b/core/t.c @@ -18,16 +18,16 @@ Configuration config; /* ---------------------------------------------------------------- */ int essai_sysmetrics(int k) { -double dvalues3[3]; +float fvalues3[3]; int foo; -foo = get_loadavg(dvalues3); +foo = get_loadavg(fvalues3); if (foo) { fprintf(stderr, "err get load avg %d\n", foo); return -1; } -printf("load avg %f %f %f\n", dvalues3[0], dvalues3[1], dvalues3[2]); +printf("load avg %f %f %f\n", fvalues3[0], fvalues3[1], fvalues3[2]); return 0; } diff --git a/essai.c b/essai.c index 01565c7..2697382 100644 --- a/essai.c +++ b/essai.c @@ -6,21 +6,44 @@ #include #include #include +#include #include #include "core/utils.h" #include "core/sysmetrics.h" +#include "viz/curses/ecran.h" int verbosity; /* --------------------------------------------------------------- */ +int affiche_loadavg(int nbloops, int k) +{ +int idx, foo; +float lds[3]; + +for (idx=0; idx %d\n", foo); + + foo = aff7segs_float(stdscr, 4, 9, lds[0]); + foo = aff7segs_float(stdscr, 14, 9, lds[1]); + foo = aff7segs_float(stdscr, 24, 9, lds[2]); + + usleep(200*1000); + } +return 0; +} +/* --------------------------------------------------------------- */ +static void finish(int signal) +{ +endwin(); exit(0); +} /* --------------------------------------------------------------- */ int main(int argc, char *argv[]) { int opt, foo; -double loads[3]; -int il[3]; while ((opt = getopt(argc, argv, "v")) != -1) { switch (opt) { @@ -29,15 +52,19 @@ 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] * 90.0)) & 0x3ff; - if (verbosity) - fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]); - } -printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]); +initscr(); +nonl(); cbreak(); noecho(); +keypad(stdscr, TRUE); /* acces aux touches 'curseur' */ +fond_ecran(" Demonstrator "); + +affiche_loadavg(10000, 0); + +/* + * plop, on a fini, il faut restaurer la console + */ +finish(0); + return 0; }