#include #include #include #include #include #include int main(int argc, char **argv) { time_t tick; struct timeval tv[2]; int prev = 0; int fwd = 0; int back = 0; int max = 0; for (;;) { gettimeofday(tv, 0); if (prev) { if (tv[0].tv_sec < tv[1].tv_sec || (tv[0].tv_sec == tv[1].tv_sec && tv[0].tv_usec < tv[1].tv_usec)) { unsigned long long delta = ((tv[1].tv_sec - tv[0].tv_sec) * 1000000 + (tv[1].tv_usec - tv[0].tv_usec)); if (delta > max) { max = delta; } ++back; } else { if (tv[0].tv_sec - tv[1].tv_sec > 1) { unsigned long long delta = ((tv[0].tv_sec - tv[1].tv_sec) * 1000000 + (tv[0].tv_usec - tv[1].tv_usec)); printf("got a huge step forward, delta=%lldus\n", delta); } ++fwd; } } if (tick != tv[0].tv_sec && tv[0].tv_sec == tv[1].tv_sec + 1) { tick = tv[0].tv_sec; printf("%.24s: fwd:%d/%d:back max %07u\n", ctime(&tv[0].tv_sec), fwd, back, max); fwd = back = 0; max = 0; } prev = 1; tv[1] = tv[0]; } }