X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fdebug.c;h=cfb6a81977a5e65d68eaee3ec4effb9b37caa701;hb=60b4792d65ba4b2a45733894f6a57e6581ddc487;hp=7cdd4fd50d67ed2325763c6e18aa8b37c88071a5;hpb=e26a903ddf80011e3b72a780d7392a8333c996af;p=bluesky.git diff --git a/bluesky/debug.c b/bluesky/debug.c index 7cdd4fd..cfb6a81 100644 --- a/bluesky/debug.c +++ b/bluesky/debug.c @@ -35,6 +35,17 @@ static void inode_dump(gpointer key, gpointer value, gpointer user_data) inode->change_count, inode->change_commit); } +static void cloudlog_dump(gpointer key, gpointer value, gpointer user_data) +{ + BlueSkyCloudLog *log = (BlueSkyCloudLog *)value; + + for (int i = 0; i < sizeof(BlueSkyCloudID); i++) { + g_print("%02x", (uint8_t)(log->id.bytes[i])); + } + g_print(": ty=%d inode=%"PRIu64" locs=%x\n", + log->type, log->inum, log->location_flags); +} + /* Dump a summary of filesystem state as it is cached in memory. */ void bluesky_debug_dump(BlueSkyFS *fs) { @@ -58,4 +69,39 @@ void bluesky_debug_dump(BlueSkyFS *fs) g_print("\n"); g_hash_table_foreach(fs->inodes, inode_dump, fs); + + g_print("\nLog Objects:\n"); + g_hash_table_foreach(fs->locations, cloudlog_dump, fs); + g_print("\n"); +} + +/* 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); }