From: Michael Vrable Date: Tue, 27 Oct 2009 19:29:28 +0000 (-0700) Subject: Add high-resolution timekeeping functions (primarily for benchmarking). X-Git-Url: http://git.vrable.net/?a=commitdiff_plain;h=54641cabe724241dc1a04b769e92a33ac99d640a;p=bluesky.git Add high-resolution timekeeping functions (primarily for benchmarking). --- diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index f37a537..e141dd3 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -104,6 +104,10 @@ typedef struct { /* Timestamp, measured in microseconds since the Unix epoch. */ typedef int64_t bluesky_time; +/* High-resolution timer, measured in nanoseconds. */ +typedef int64_t bluesky_time_hires; +bluesky_time_hires bluesky_now_hires(); + /* In-memory representation of an inode within a Blue Sky server. This * corresponds roughly with information that is committed to persistent * storage. Locking/refcounting rules: diff --git a/bluesky/file.c b/bluesky/file.c index 5f7d9cd..14de372 100644 --- a/bluesky/file.c +++ b/bluesky/file.c @@ -87,6 +87,7 @@ void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size) void bluesky_file_write(BlueSkyInode *inode, uint64_t offset, const char *data, gint len) { + g_print("Start write: %ld\n", bluesky_now_hires()); g_return_if_fail(inode->type == BLUESKY_REGULAR); g_return_if_fail(offset < inode->size); g_return_if_fail(len <= inode->size - offset); @@ -112,6 +113,7 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset, bluesky_inode_update_ctime(inode, 1); bluesky_inode_flush(inode->fs, inode); + g_print("End write: %ld\n", bluesky_now_hires()); } void bluesky_file_read(BlueSkyInode *inode, uint64_t offset, diff --git a/bluesky/util.c b/bluesky/util.c index 85f6a70..6a36169 100644 --- a/bluesky/util.c +++ b/bluesky/util.c @@ -15,6 +15,17 @@ /* Miscellaneous useful functions that don't really fit anywhere else. */ +bluesky_time_hires bluesky_now_hires() +{ + struct timespec time; + + if (clock_gettime(CLOCK_REALTIME, &time) != 0) { + perror("clock_gettime"); + return 0; + } + + return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec; +} /* Convert a UTF-8 string to lowercase. This can be used to implement * case-insensitive lookups and comparisons, by normalizing all values to