summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.c17
-rw-r--r--utils/utils.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 05f0059ec..b0707b7f2 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -236,6 +236,23 @@ char *strcasestr(const char *haystack, const char *needle)
return NULL;
}
+/**
+ * Returns a number of centiseconds, that increases in real time, for the
+ * purposes of measuring how long something takes in wall-clock terms. It uses
+ * gettimeofday() for this. Should the call to gettimeofday() fail, it returns
+ * zero.
+ *
+ * \return number of centiseconds that increases monotonically
+ */
+unsigned int wallclock(void)
+{
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == -1)
+ return 0;
+
+ return ((tv.tv_sec * 100) + (tv.tv_usec / 10000));
+}
#ifdef __FreeBSD__
diff --git a/utils/utils.h b/utils/utils.h
index cfc7d8edc..67173d242 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -56,6 +56,7 @@ void unicode_transliterate(unsigned int c, char **r);
char *human_friendly_bytesize(unsigned long bytesize);
const char *rfc1123_date(time_t t);
char *strcasestr(const char *haystack, const char *needle);
+unsigned int wallclock(void);
#ifdef __FreeBSD__
/* FreeBSD lacks strndup */
char *strndup(const char *s, size_t n);