1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2009 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
15 #include "bluesky-private.h"
17 /* Debugging support for BlueSky. */
19 static void inode_dump(gpointer key, gpointer value, gpointer user_data)
21 BlueSkyInode *inode = (BlueSkyInode *)value;
23 g_print("Inode %"PRIu64":\n", inode->inum);
25 gboolean locked = TRUE;
26 if (g_mutex_trylock(inode->lock)) {
28 g_mutex_unlock(inode->lock);
30 g_print(" Locked: %c Refcount: %d\n",
31 locked ? 'T' : 'F', inode->refcount);
33 g_print(" Type: %d Mode: %o\n", inode->type, inode->mode);
34 g_print(" change_count = %"PRIu64", change_commit = %"PRIu64", "
35 "change_cloud = %"PRIu64"\n",
36 inode->change_count, inode->change_commit, inode->change_cloud);
39 static void cloudlog_dump(gpointer key, gpointer value, gpointer user_data)
41 BlueSkyCloudLog *log = (BlueSkyCloudLog *)value;
43 for (int i = 0; i < sizeof(BlueSkyCloudID); i++) {
44 g_print("%02x", (uint8_t)(log->id.bytes[i]));
46 g_print(": refs=%d ty=%d inode=%"PRIu64" locs=%x log@(%d,%d) cloud@(%d,%d,%d)\n",
48 log->type, log->inum, log->location_flags,
49 log->log_seq, log->log_offset, log->location.directory,
50 log->location.sequence, log->location.offset);
53 /* Dump a summary of filesystem state as it is cached in memory. */
54 void bluesky_debug_dump(BlueSkyFS *fs)
56 g_print("*** DEBUG DUMP FOR FILESYSTEM %s ***\n", fs->name);
57 g_print("Cached blocks: %d\tDirty blocks: %d\n",
58 g_atomic_int_get(&fs->cache_total),
59 g_atomic_int_get(&fs->cache_dirty));
60 g_print("Cached inodes: %u\tNext inode: %"PRIu64"\n",
61 g_hash_table_size(fs->inodes), fs->next_inum);
64 g_print("Unsynced inode list:");
65 for (item = fs->unlogged_list.next; item != NULL; item = item->next) {
66 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
69 g_print("Dirty inode LRU list:");
70 for (item = fs->dirty_list.next; item != NULL; item = item->next) {
71 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
74 g_print("Accessed inode LRU list:");
75 for (item = fs->accessed_list.next; item != NULL; item = item->next) {
76 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
80 g_hash_table_foreach(fs->inodes, inode_dump, fs);
82 g_print("\nLog Objects:\n");
83 g_hash_table_foreach(fs->locations, cloudlog_dump, fs);
87 /* Statistics counters: for operation counts, bytes transferred, etc. */
88 static GStaticMutex stats_lock = G_STATIC_MUTEX_INIT;
89 static GList *stats_list = NULL;
91 struct bluesky_stats *bluesky_stats_new(const char *name)
93 struct bluesky_stats *stats = g_new0(struct bluesky_stats, 1);
95 g_static_mutex_lock(&stats_lock);
96 stats_list = g_list_append(stats_list, stats);
97 g_static_mutex_unlock(&stats_lock);
101 void bluesky_stats_add(struct bluesky_stats *stats, int64_t value)
103 __sync_fetch_and_add(&stats->count, (int64_t)1);
104 __sync_fetch_and_add(&stats->sum, value);
107 void bluesky_stats_dump_all()
109 g_static_mutex_lock(&stats_lock);
110 for (GList *item = stats_list; item != NULL; item = item->next) {
111 struct bluesky_stats *stats = (struct bluesky_stats *)item->data;
112 g_print("%s: count=%"PRIi64" sum=%"PRIi64"\n",
113 stats->name, stats->count, stats->sum);
115 g_static_mutex_unlock(&stats_lock);