diff --git a/include/sigar_private.h b/include/sigar_private.h index 41d0c7df..b77f938f 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -117,6 +117,7 @@ #endif #define SIGAR_MSEC 1000L +#define SIGAR_USEC 1000000L #define SIGAR_NSEC 1000000000L #define SIGAR_SEC2NANO(s) \ diff --git a/include/sigar_util.h b/include/sigar_util.h index c4f82f5c..5e2079cb 100644 --- a/include/sigar_util.h +++ b/include/sigar_util.h @@ -62,6 +62,8 @@ #define PROCP_FS_ROOT "/proc/" #endif +sigar_int64_t sigar_time_now_millis(void); + char *sigar_uitoa(char *buf, unsigned int n, int *len); int sigar_inet_ntoa(sigar_t *sigar, diff --git a/src/sigar_util.c b/src/sigar_util.c index 0916ab97..4cfd545d 100644 --- a/src/sigar_util.c +++ b/src/sigar_util.c @@ -812,3 +812,13 @@ SIGAR_DECLARE(void) sigar_log_impl_file(sigar_t *sigar, void *data, FILE *fp = (FILE*)data; fprintf(fp, "[%s] %s\n", log_levels[level], message); } + +sigar_int64_t sigar_time_now_millis(void) +{ +#ifdef WIN32 +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * SIGAR_USEC) + tv.tv_usec) / SIGAR_MSEC; +#endif +}