X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=common%2Fb.c;h=6fa1963e0f80eea350961080edea76e17ffb7021;hb=8f27a344abbb2caa2306e784c0f1a411dd301081;hp=b82531c0cda3f73dfbd15d3d6eaa71e3260165b3;hpb=9d224cba6a348ca86bea2c6cb32a32d01c8bffbe;p=libc-test diff --git a/common/b.c b/common/b.c index b82531c..6fa1963 100644 --- a/common/b.c +++ b/common/b.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 200809L #include #include #include @@ -9,9 +8,9 @@ #include #include "test.h" -#define T(t) -#define B(t) void t(); -#include "main.h" +#define T(f) +#define B(f) void f(int); +#include "tests.h" #undef B static int verbose = 1; @@ -20,7 +19,7 @@ void error__(const char *n, int l, const char *s, ...) { fprintf(stderr, "use error in tests only\n"); } -int N; +static int N; static unsigned long long start; static unsigned long long dt; //static unsigned long long bytes; @@ -31,7 +30,7 @@ static unsigned long long dt; static unsigned long long tic() { struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { + if (clock_gettime(CLOCK_REALTIME, &ts) < 0) { fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno)); return 0; } @@ -57,6 +56,7 @@ void reset_timer() { static int nextN() { unsigned long long n = dt/N; + unsigned long long i; if (n) n = SEC/2/n; @@ -69,7 +69,14 @@ static int nextN() { n = N+1; if (n > MAXN) n = MAXN; - return n; + + /* round up to a nice number */ + for (i = 1; i < n; i *= 10); + if (i/2 >= n) + i /= 2; + if (i/2 >= n) + i /= 2; + return i; } void vmstats() { @@ -81,7 +88,7 @@ void vmstats() { f = fopen("/proc/self/smaps", "rb"); if (f) while (fgets(buf, sizeof buf, f)) { - if (sscanf(buf, "%*lx-%*lx %*s %*lx %x:%x %*lu %*s", &maj, &min)==2) + if (sscanf(buf, "%*x-%*x %*s %*x %x:%x %*u %*s", &maj, &min)==2) in_heap = (!maj && !min && !strstr(buf, "---p") && (strstr(buf, "[heap]") || !strchr(buf, '['))); if (in_heap) { if (sscanf(buf, "Size: %lu", &l)==1) vm_size += l; @@ -103,7 +110,7 @@ void stats() { fputc('\n', stderr); } -static void run(const char *name, void (*f)()) { +static void run(const char *name, void (*f)(int)) { int p = fork(); if (p) { int s; @@ -113,9 +120,10 @@ static void run(const char *name, void (*f)()) { } fprintf(stderr, "%-32s", name); for (N=1; ; N=nextN()) { + // TODO: fork at each iteration and pass N,dt..? reset_timer(); start_timer(); - f(); + f(N); stop_timer(); // fprintf(stderr, "%10d%12llu next: %d\n", N, dt, nextN()); if (dt >= SEC/2 || N >= MAXN) { @@ -131,6 +139,6 @@ static void run(const char *name, void (*f)()) { int main() { #define B(t) run(#t, t); -#include "main.h" +#include "tests.h" return 0; }