X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fclock.c;h=c4958137eda8d5a9e9ead89239f2202b2a6cfa47;hb=HEAD;hp=8f6d6699bd4ac2cfc88cfc3f581cbf7cd8d43447;hpb=310f09c0f55a2fb6f3f3746d6ded20099792b773;p=debian%2Famanda diff --git a/common-src/clock.c b/common-src/clock.c index 8f6d669..c495813 100644 --- a/common-src/clock.c +++ b/common-src/clock.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -25,7 +26,7 @@ * University of Maryland at College Park */ /* - * $Id: clock.c,v 1.7.2.1 2007/02/06 12:44:03 martinea Exp $ + * $Id: clock.c,v 1.7 2006/07/27 18:12:10 martinea Exp $ * * timing functions */ @@ -34,10 +35,6 @@ #include "clock.h" /* local functions */ -static struct timeval timesub(struct timeval end, struct timeval start); -static struct timeval timeadd(struct timeval a, struct timeval b); - -times_t times_zero; times_t start_time; static int clock_running = 0; @@ -50,25 +47,18 @@ clock_is_running(void) void startclock(void) { - amanda_timezone dontcare; - clock_running = 1; - amanda_gettimeofday(&start_time.r, &dontcare); + + g_get_current_time(&start_time); } times_t stopclock(void) { - times_t diff; - struct timeval end_time; - amanda_timezone dontcare; + GTimeVal diff; + + diff = curclock(); - if(!clock_running) { - fprintf(stderr,"stopclock botch\n"); - exit(1); - } - amanda_gettimeofday(&end_time, &dontcare); - diff.r = timesub(end_time,start_time.r); clock_running = 0; return diff; } @@ -76,56 +66,15 @@ stopclock(void) times_t curclock(void) { - times_t diff; - struct timeval end_time; - amanda_timezone dontcare; + GTimeVal end_time; if(!clock_running) { - fprintf(stderr,"curclock botch\n"); + g_fprintf(stderr,_("curclock botch\n")); exit(1); } - amanda_gettimeofday(&end_time, &dontcare); - diff.r = timesub(end_time,start_time.r); - return diff; -} -times_t -timesadd( - times_t a, - times_t b) -{ - times_t sum; - - sum.r = timeadd(a.r,b.r); - return sum; -} - -times_t -timessub( - times_t a, - times_t b) -{ - times_t dif; - - dif.r = timesub(a.r,b.r); - return dif; -} - -char * -times_str( - times_t t) -{ - static char str[10][NUM_STR_SIZE+10]; - static size_t n = 0; - char *s; - - /* tv_sec/tv_usec are longs on some systems */ - snprintf(str[n], SIZEOF(str[n]), "rtime %lu.%03lu", - (unsigned long)t.r.tv_sec, - (unsigned long)t.r.tv_usec / 1000); - s = str[n++]; - n %= am_countof(str); - return s; + g_get_current_time(&end_time); + return timesub(end_time,start_time); } char * @@ -137,20 +86,16 @@ walltime_str( char *s; /* tv_sec/tv_usec are longs on some systems */ - snprintf(str[n], SIZEOF(str[n]), "%lu.%03lu", - (unsigned long)t.r.tv_sec, - (unsigned long)t.r.tv_usec/1000); + g_snprintf(str[n], SIZEOF(str[n]), "%lu.%03lu", + (unsigned long)t.tv_sec, + (unsigned long)t.tv_usec/1000); s = str[n++]; n %= am_countof(str); return s; } -static struct timeval -timesub( - struct timeval end, - struct timeval start) -{ - struct timeval diff; +GTimeVal timesub(GTimeVal end, GTimeVal start) { + GTimeVal diff; if(end.tv_usec < start.tv_usec) { /* borrow 1 sec */ if (end.tv_sec > 0) @@ -167,12 +112,8 @@ timesub( return diff; } -static struct timeval -timeadd( - struct timeval a, - struct timeval b) -{ - struct timeval sum; +GTimeVal timeadd(GTimeVal a, GTimeVal b) { + GTimeVal sum; sum.tv_sec = a.tv_sec + b.tv_sec; sum.tv_usec = a.tv_usec + b.tv_usec; @@ -183,3 +124,15 @@ timeadd( } return sum; } + +double g_timeval_to_double(GTimeVal v) { + return v.tv_sec + ((double)v.tv_usec) / G_USEC_PER_SEC; +} + +void amanda_gettimeofday(struct timeval * timeval_time) { + GTimeVal gtimeval_time; + + g_get_current_time(>imeval_time); + timeval_time->tv_sec = gtimeval_time.tv_sec; + timeval_time->tv_usec = gtimeval_time.tv_usec; +}