|
Lines 16-89
Link Here
|
| 16 |
#include <sys/time.h> |
16 |
#include <sys/time.h> |
| 17 |
#include <time.h> |
17 |
#include <time.h> |
| 18 |
#include <liblogthread.h> |
18 |
#include <liblogthread.h> |
|
|
19 |
#include "disk_util.h" |
| 19 |
|
20 |
|
| 20 |
inline void _diff_tv(struct timeval *dest, struct timeval *start, struct timeval *end); |
|
|
| 21 |
inline int get_time(struct timeval *tv, int use_uptime); |
| 22 |
|
21 |
|
| 23 |
inline void |
|
|
| 24 |
_diff_tv(struct timeval *dest, struct timeval *start, struct timeval *end) |
| 25 |
{ |
| 26 |
dest->tv_sec = end->tv_sec - start->tv_sec; |
| 27 |
dest->tv_usec = end->tv_usec - start->tv_usec; |
| 28 |
|
| 29 |
if (dest->tv_usec < 0) { |
| 30 |
dest->tv_usec += 1000000; |
| 31 |
dest->tv_sec--; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* |
| 38 |
* Grab the uptime from /proc/uptime. |
| 39 |
* |
| 40 |
* @param tv Timeval struct to store time in. The sec |
| 41 |
* field contains seconds, the usec field |
| 42 |
* contains the hundredths-of-seconds (converted |
| 43 |
* to micro-seconds) |
| 44 |
* @return -1 on failure, 0 on success. |
| 45 |
*/ |
| 46 |
static inline int |
| 47 |
getuptime(struct timeval *tv) |
| 48 |
{ |
| 49 |
FILE *fp; |
| 50 |
struct timeval junk; |
| 51 |
int rv; |
| 52 |
|
| 53 |
fp = fopen("/proc/uptime","r"); |
| 54 |
if (!fp) |
| 55 |
return -1; |
| 56 |
|
| 57 |
#if defined(__sparc__) |
| 58 |
rv = fscanf(fp,"%ld.%d %ld.%d\n", &tv->tv_sec, &tv->tv_usec, |
| 59 |
&junk.tv_sec, &junk.tv_usec); |
| 60 |
#else |
| 61 |
rv = fscanf(fp,"%ld.%ld %ld.%ld\n", &tv->tv_sec, &tv->tv_usec, |
| 62 |
&junk.tv_sec, &junk.tv_usec); |
| 63 |
#endif |
| 64 |
fclose(fp); |
| 65 |
|
| 66 |
if (rv != 4) { |
| 67 |
return -1; |
| 68 |
} |
| 69 |
|
| 70 |
tv->tv_usec *= 10000; |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
inline int |
| 77 |
get_time(struct timeval *tv, int use_uptime) |
| 78 |
{ |
| 79 |
if (use_uptime) { |
| 80 |
return getuptime(tv); |
| 81 |
} else { |
| 82 |
return gettimeofday(tv, NULL); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/** |
22 |
/** |
| 88 |
Update write times and calculate a new average time |
23 |
Update write times and calculate a new average time |
| 89 |
*/ |
24 |
*/ |