diff options
author | Kaushik BV <kaushikbv@gluster.com> | 2010-08-30 01:33:14 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-08-30 00:50:38 -0700 |
commit | a2dd1e8702eb8dc7234d8262e34182adf1f0573c (patch) | |
tree | 741f25d9318560a883cf402c23a108bc1b755681 /libglusterfs/src/statedump.c | |
parent | fb3cb751f18a931d2a61d168fa13bf8ec3b45e1a (diff) |
Provides the ability to filter the output of state dump
Signed-off-by: Kaushik BV <kaushikbv@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 828 (glusterdump filled up the /)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=828
Diffstat (limited to 'libglusterfs/src/statedump.c')
-rw-r--r-- | libglusterfs/src/statedump.c | 236 |
1 files changed, 210 insertions, 26 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 08adf3403..05f1a777f 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -28,10 +28,18 @@ #include <malloc.h> #endif /* MALLOC_H */ + +#define GF_PROC_DUMP_IS_OPTION_ENABLED(opt) \ + (dump_options.dump_##opt == _gf_true) + +#define GF_PROC_DUMP_IS_XL_OPTION_ENABLED(opt)\ + (dump_options.xl_options.dump_##opt == _gf_true) + extern xlator_t global_xlator; static pthread_mutex_t gf_proc_dump_mutex; static int gf_dump_fd = -1; +static gf_dump_options_t dump_options; static void @@ -85,7 +93,7 @@ gf_proc_dump_add_section (char *key, ...) va_list ap; int ret; - assert(key); + GF_ASSERT(key); memset (buf, 0, sizeof(buf)); snprintf (buf, GF_DUMP_MAX_BUF_LEN, "\n["); @@ -110,6 +118,8 @@ gf_proc_dump_write (char *key, char *value,...) va_list ap; int ret; + GF_ASSERT (key); + offset = strlen (key); memset (buf, 0, GF_DUMP_MAX_BUF_LEN); @@ -141,26 +151,26 @@ gf_proc_dump_xlator_mem_info (xlator_t *xl) if (!xl->mem_acct.rec) return; - gf_proc_dump_add_section("%s.%s - Memory usage", xl->type,xl->name); - gf_proc_dump_write("num_types", "%d", xl->mem_acct.num_types); + gf_proc_dump_add_section ("%s.%s - Memory usage", xl->type,xl->name); + gf_proc_dump_write ("num_types", "%d", xl->mem_acct.num_types); for (i = 0; i < xl->mem_acct.num_types; i++) { if (!(memcmp (&xl->mem_acct.rec[i], &rec, - sizeof(struct mem_acct)))) + sizeof (struct mem_acct)))) continue; - gf_proc_dump_add_section("%s.%s - usage-type %d", xl->type, + gf_proc_dump_add_section ("%s.%s - usage-type %d", xl->type, xl->name,i); - gf_proc_dump_build_key(prefix, "memusage", "%s.%s.type.%d", + gf_proc_dump_build_key (prefix, "memusage", "%s.%s.type.%d", xl->type, xl->name, i); - gf_proc_dump_build_key(key, prefix, "size"); - gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].size); - gf_proc_dump_build_key(key, prefix, "num_allocs"); - gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].num_allocs); - gf_proc_dump_build_key(key, prefix, "max_size"); - gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].max_size); - gf_proc_dump_build_key(key, prefix, "max_num_allocs"); - gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].max_num_allocs); + gf_proc_dump_build_key (key, prefix, "size"); + gf_proc_dump_write (key, "%u", xl->mem_acct.rec[i].size); + gf_proc_dump_build_key (key, prefix, "num_allocs"); + gf_proc_dump_write (key, "%u", xl->mem_acct.rec[i].num_allocs); + gf_proc_dump_build_key (key, prefix, "max_size"); + gf_proc_dump_write (key, "%u", xl->mem_acct.rec[i].max_size); + gf_proc_dump_build_key (key, prefix, "max_num_allocs"); + gf_proc_dump_write (key, "%u", xl->mem_acct.rec[i].max_num_allocs); } return; @@ -199,31 +209,190 @@ void gf_proc_dump_latency_info (xlator_t *xl); void gf_proc_dump_xlator_info (xlator_t *this_xl) { - + glusterfs_ctx_t *ctx = NULL; + xlator_t *fuse_xlator, *this_xlator; + if (!this_xl) return; + + ctx = glusterfs_ctx_get (); + if (!ctx) + return; + + if (ctx->master){ + + gf_log ("", GF_LOG_DEBUG, "Dumping Proc for fuse Xlator"); + fuse_xlator = (xlator_t *) ctx->master; + + if (!fuse_xlator->dumpops) + return; + + if (fuse_xlator->dumpops->priv && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (priv)) + fuse_xlator->dumpops->priv (fuse_xlator); + + if (fuse_xlator->dumpops->inode && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode)) { + + if (!ctx->active) + return; + this_xlator = (xlator_t *) ctx->active->top; + + if (this_xlator && this_xlator->itable) + inode_table_dump (this_xlator->itable, + "xlator.mount.fuse.itable"); + else + return; + } + + if (fuse_xlator->dumpops->fd && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (fd)) + fuse_xlator->dumpops->fd (fuse_xlator); + } + while (this_xl) { + + if (ctx->measure_latency) + gf_proc_dump_latency_info (this_xl); - gf_proc_dump_latency_info (this_xl); - gf_proc_dump_xlator_mem_info(this_xl); + gf_proc_dump_xlator_mem_info(this_xl); if (!this_xl->dumpops) { this_xl = this_xl->next; continue; } - if (this_xl->dumpops->priv) - this_xl->dumpops->priv (this_xl); - if (this_xl->dumpops->inode) + + if (this_xl->dumpops->priv && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (priv)) + this_xl->dumpops->priv (this_xl); + + if (this_xl->dumpops->inode && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode)) this_xl->dumpops->inode (this_xl); - if (this_xl->dumpops->fd) + + + if (this_xl->dumpops->fd && + GF_PROC_DUMP_IS_XL_OPTION_ENABLED (fd)) this_xl->dumpops->fd (this_xl); + this_xl = this_xl->next; } return; } +static int +gf_proc_dump_parse_set_option (char *key, char *value) +{ + gf_boolean_t *opt_key = NULL; + gf_boolean_t opt_value = _gf_false; + + + if (!strncasecmp (key, "mem", 3)) { + opt_key = &dump_options.dump_mem; + } else if (!strncasecmp (key, "iobuf", 5)) { + opt_key = &dump_options.dump_iobuf; + } else if (!strncasecmp (key, "callpool", 8)) { + opt_key = &dump_options.dump_callpool; + } else if (!strncasecmp (key, "priv", 4)) { + opt_key = &dump_options.xl_options.dump_priv; + } else if (!strncasecmp (key, "fd", 2)) { + opt_key = &dump_options.xl_options.dump_fd; + } else if (!strncasecmp (key, "inode", 5)) { + opt_key = &dump_options.xl_options.dump_inode; + } + + if (!opt_key) { + //None of dump options match the key, return back + gf_log ("", GF_LOG_WARNING, "None of the options matched key" + ": %s", key); + return -1; + } + + opt_value = (strncasecmp (value, "yes", 3) ? + _gf_false: _gf_true); + + GF_PROC_DUMP_SET_OPTION (*opt_key, opt_value); + + return 0; +} + + +static int +gf_proc_dump_enable_all_options () +{ + + GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_true); + + return 0; +} + +static int +gf_proc_dump_disable_all_options () +{ + GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, + _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_false); + + return 0; +} + +static int +gf_proc_dump_options_init () +{ + int ret = -1; + FILE *fp = NULL; + char buf[256]; + char *key = NULL, *value = NULL; + char *saveptr = NULL; + + + fp = fopen (GF_DUMP_OPTIONFILE, "r"); + + if (!fp) { + //ENOENT, return success + (void) gf_proc_dump_enable_all_options (); + return 0; + } + + (void) gf_proc_dump_disable_all_options (); + + ret = fscanf (fp, "%s", buf); + + while (ret != EOF) { + + key = strtok_r (buf, "=", &saveptr); + if (!key) { + ret = fscanf (fp, "%s", buf); + continue; + } + + value = strtok_r (NULL, "=", &saveptr); + + if (!value) { + ret = fscanf (fp, "%s", buf); + continue; + } + + gf_log ("", GF_LOG_DEBUG, "key = %s, value = %s", + key, value); + + gf_proc_dump_parse_set_option (key, value); + + } + + return 0; +} void gf_proc_dump_info (int signum) @@ -231,16 +400,29 @@ gf_proc_dump_info (int signum) int ret = -1; glusterfs_ctx_t *ctx = NULL; + gf_proc_dump_lock (); ret = gf_proc_dump_open (); if (ret < 0) goto out; - gf_proc_dump_mem_info (); - ctx = glusterfs_ctx_get (); + + ret = gf_proc_dump_options_init (); + + if (ret < 0) + goto out; + + if (GF_PROC_DUMP_IS_OPTION_ENABLED (mem)) + gf_proc_dump_mem_info (); + + ctx = glusterfs_ctx_get (); + if (ctx) { - iobuf_stats_dump (ctx->iobuf_pool); - gf_proc_dump_pending_frames (ctx->pool); - gf_proc_dump_xlator_info (ctx->active->first); + if (GF_PROC_DUMP_IS_OPTION_ENABLED (iobuf)) + iobuf_stats_dump (ctx->iobuf_pool); + if (GF_PROC_DUMP_IS_OPTION_ENABLED (callpool)) + gf_proc_dump_pending_frames (ctx->pool); + gf_proc_dump_xlator_info (ctx->active->top); + } gf_proc_dump_close (); @@ -272,3 +454,5 @@ gf_proc_dump_cleanup (void) { pthread_mutex_destroy (&gf_proc_dump_mutex); } + + |