Exemple #1
0
int main(int argc, char **argv)
{
    long long tnow, tlast;
    struct timespec t1, dtmin, dtminp, dtmax;
    int print_interval = 50000;
    int print_countdown = 1;
    int clock_id = CLOCK_MONOTONIC;
    dtmin.tv_sec = INT_MAX;
    dtmin.tv_nsec = 0;
    dtminp.tv_sec = INT_MAX;
    dtminp.tv_nsec = 0;
    dtmax.tv_sec = 0;
    dtmax.tv_nsec = 0;
    tlast = 0;

    if(argc == 2) {
        clock_id = atoi(argv[1]);
        printf("using clock %d\n", clock_id);
    }
    clock_gettime(clock_id, &t1);
    
    for(;;) {
        struct timespec t, dt;
        clock_gettime(clock_id, &t);
        dt = ts_sub(t, t1);
        t1 = t;
        dtmin = ts_min(dtmin, dt);
        if(dt.tv_sec > 0 || dt.tv_nsec > 0)
            dtminp = ts_min(dtminp, dt);
        if(print_countdown != print_interval)
            dtmax = ts_max(dtmax, dt);
        if(--print_countdown == 0) {
            fprintf(stderr,"%09ld.%09ld, dt %ld.%09ld, min %ld.%09ld, minp %ld.%09ld, max %ld.%09ld\n",
                    t.tv_sec, t.tv_nsec, dt.tv_sec, dt.tv_nsec,
                    dtmin.tv_sec, dtmin.tv_nsec, dtminp.tv_sec, dtminp.tv_nsec,
                    dtmax.tv_sec, dtmax.tv_nsec);
            print_countdown = print_interval;
        }
    }
    for(;;) {
        tnow = nanotime();
        if(tnow < tlast) {
#if 0
            fprintf(stderr,"time went backwards: %lld -> %lld\n",
                    tlast, tnow);
            exit(1);
#endif
            fprintf(stderr,"%lld ROLLBACK\n", tnow);
        } else {
            fprintf(stderr,"%lld\n", tnow);
        }
        tlast = tnow;
    }

    return 0;
}
Exemple #2
0
static unsigned long ts_dos2unix(unsigned long ts)
{
 unsigned int y, m, d, hh, mm, ss;

 if(ts==0)
  return(0);
 y=ts_year(ts);
 m=ts_month(ts);
 d=ts_day(ts);
 hh=ts_hour(ts);
 mm=ts_min(ts);
 ss=ts_sec(ts);
 /* TODO: These assertions must be replaced by run-time check for incorrect timestamps
    like 31/15/2063 or 00/00/1980, since month array is 1...12 only. */
 #ifdef DEBUG
  debug_assert(m>=1&&m<=12);
  debug_assert(d>=1&&d<=31);
 #endif
 return(mk_unixtime(y, m, d, hh, mm, ss));
}