From 348aaaad42163d6829112c9b18026c16b09e1914 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Fri, 2 Apr 2010 12:20:21 -0700 Subject: [PATCH] Add general statistics-gathering infrastructure. --- bluesky/bluesky.h | 10 ++++++++++ bluesky/debug.c | 31 +++++++++++++++++++++++++++++++ bluesky/store.c | 12 ++++++++++++ nfs3/nfsd.c | 9 +++++++++ nfs3/rpc.c | 1 + 5 files changed, 63 insertions(+) diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index 714ec55..ff2bf23 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -41,6 +41,16 @@ extern BlueSkyOptions bluesky_options; * limit */ extern int bluesky_max_threads; +/* A general-purpose counter for gathering run-time statistics. */ +struct bluesky_stats { + const char *name; + int64_t count; + int64_t sum; +}; +struct bluesky_stats *bluesky_stats_new(const char *name); +void bluesky_stats_add(struct bluesky_stats *stats, int64_t value); +void bluesky_stats_dump_all(); + /* BlueSky status and error codes. Various frontends should translate these to * the appropriate error code for whatever protocol they implement. */ typedef enum { diff --git a/bluesky/debug.c b/bluesky/debug.c index 7cdd4fd..b409c74 100644 --- a/bluesky/debug.c +++ b/bluesky/debug.c @@ -59,3 +59,34 @@ void bluesky_debug_dump(BlueSkyFS *fs) g_hash_table_foreach(fs->inodes, inode_dump, fs); } + +/* Statistics counters: for operation counts, bytes transferred, etc. */ +static GStaticMutex stats_lock = G_STATIC_MUTEX_INIT; +static GList *stats_list = NULL; + +struct bluesky_stats *bluesky_stats_new(const char *name) +{ + struct bluesky_stats *stats = g_new0(struct bluesky_stats, 1); + stats->name = name; + g_static_mutex_lock(&stats_lock); + stats_list = g_list_append(stats_list, stats); + g_static_mutex_unlock(&stats_lock); + return stats; +} + +void bluesky_stats_add(struct bluesky_stats *stats, int64_t value) +{ + __sync_fetch_and_add(&stats->count, (int64_t)1); + __sync_fetch_and_add(&stats->sum, value); +} + +void bluesky_stats_dump_all() +{ + g_static_mutex_lock(&stats_lock); + for (GList *item = stats_list; item != NULL; item = item->next) { + struct bluesky_stats *stats = (struct bluesky_stats *)item->data; + g_print("%s: count=%"PRIi64" sum=%"PRIi64"\n", + stats->name, stats->count, stats->sum); + } + g_static_mutex_unlock(&stats_lock); +} diff --git a/bluesky/store.c b/bluesky/store.c index ae6bdb6..2043806 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -24,6 +24,8 @@ struct _BlueSkyStore { GMutex *lock; GCond *cond_idle; int pending; /* Count of operations not yet complete. */ + + struct bluesky_stats *stats_get, *stats_put; }; GHashTable *store_implementations; @@ -71,6 +73,10 @@ BlueSkyStore *bluesky_store_new(const gchar *type) store->lock = g_mutex_new(); store->cond_idle = g_cond_new(); store->pending = 0; + store->stats_get = bluesky_stats_new(g_strdup_printf("Store[%s]: GETS", + type)); + store->stats_put = bluesky_stats_new(g_strdup_printf("Store[%s]: PUTS", + type)); g_free(scheme); return store; } @@ -224,6 +230,12 @@ void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async) "[%p] complete: elapsed = %"PRIi64" ns, latency = %"PRIi64" ns", async, elapsed, latency); } + + if (async->op == STORE_OP_GET) { + bluesky_stats_add(async->store->stats_get, 1); + } else if (async->op == STORE_OP_PUT) { + bluesky_stats_add(async->store->stats_put, 1); + } } void bluesky_store_async_submit(BlueSkyStoreAsync *async) diff --git a/nfs3/nfsd.c b/nfs3/nfsd.c index b2e1071..fc1f955 100644 --- a/nfs3/nfsd.c +++ b/nfs3/nfsd.c @@ -26,11 +26,20 @@ void register_rpc(); BlueSkyFS *fs; BlueSkyStore *store; +static void shutdown_handler(int num) +{ + g_print("SIGINT caught, shutting down...\n"); + g_print("Proxy statistics:\n"); + bluesky_stats_dump_all(); + exit(1); +} + int main(int argc, char *argv[]) { int i; signal(SIGPIPE, SIG_IGN); + signal(SIGINT, shutdown_handler); bluesky_init(); g_set_prgname("nfsd"); diff --git a/nfs3/rpc.c b/nfs3/rpc.c index 2342b79..dbe0a64 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -508,6 +508,7 @@ static gboolean async_flushd(gpointer data) if (fs_dump_requested) { bluesky_debug_dump(fs); + bluesky_stats_dump_all(); fs_dump_requested = 0; } -- 2.20.1