summaryrefslogtreecommitdiffstats
path: root/xlators/debug
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/debug')
-rw-r--r--xlators/debug/io-stats/src/io-stats.c105
1 files changed, 84 insertions, 21 deletions
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
index 65aeee52b..fa0dd395c 100644
--- a/xlators/debug/io-stats/src/io-stats.c
+++ b/xlators/debug/io-stats/src/io-stats.c
@@ -917,9 +917,19 @@ ios_dump_args_init (struct ios_dump_args *args, ios_dump_type_t type,
return ret;
}
+static void
+ios_global_stats_clear (struct ios_global_stats *stats, struct timeval *now)
+{
+ GF_ASSERT (stats);
+ GF_ASSERT (now);
+
+ memset (stats, 0, sizeof (*stats));
+ stats->started_at = *now;
+}
+
int
io_stats_dump (xlator_t *this, struct ios_dump_args *args,
- gf1_cli_stats_op op)
+ gf1_cli_stats_op op, gf_boolean_t is_peek)
{
struct ios_conf *conf = NULL;
struct ios_global_stats cumulative = {0, };
@@ -937,29 +947,31 @@ io_stats_dump (xlator_t *this, struct ios_dump_args *args,
gettimeofday (&now, NULL);
LOCK (&conf->lock);
{
- if (op == GF_CLI_STATS_INFO ||
- op == GF_CLI_STATS_INFO_CUMULATIVE)
+ if (op == GF_CLI_INFO_ALL ||
+ op == GF_CLI_INFO_CUMULATIVE)
cumulative = conf->cumulative;
- if (op == GF_CLI_STATS_INFO ||
- op == GF_CLI_STATS_INFO_INCREMENTAL) {
+ if (op == GF_CLI_INFO_ALL ||
+ op == GF_CLI_INFO_INCREMENTAL) {
incremental = conf->incremental;
+ increment = conf->increment;
- increment = conf->increment++;
+ if (!is_peek) {
+ increment = conf->increment++;
- memset (&conf->incremental, 0,
- sizeof (conf->incremental));
- conf->incremental.started_at = now;
+ ios_global_stats_clear (&conf->incremental,
+ &now);
+ }
}
}
UNLOCK (&conf->lock);
- if (op == GF_CLI_STATS_INFO ||
- op == GF_CLI_STATS_INFO_CUMULATIVE)
+ if (op == GF_CLI_INFO_ALL ||
+ op == GF_CLI_INFO_CUMULATIVE)
io_stats_dump_global (this, &cumulative, &now, -1, args);
- if (op == GF_CLI_STATS_INFO ||
- op == GF_CLI_STATS_INFO_INCREMENTAL)
+ if (op == GF_CLI_INFO_ALL ||
+ op == GF_CLI_INFO_INCREMENTAL)
io_stats_dump_global (this, &incremental, &now, increment, args);
return 0;
@@ -2218,10 +2230,10 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
gf_log (this->name, GF_LOG_ERROR, "failed to open %s "
"for writing", filename);
return -1;
- }
+ }
(void) ios_dump_args_init (&args, IOS_DUMP_TYPE_FILE,
logfp);
- io_stats_dump (this, &args, GF_CLI_STATS_INFO);
+ io_stats_dump (this, &args, GF_CLI_INFO_ALL, _gf_false);
fclose (logfp);
}
return 0;
@@ -2625,6 +2637,29 @@ ios_destroy_top_stats (struct ios_conf *conf)
return;
}
+static int
+io_stats_clear (struct ios_conf *conf)
+{
+ struct timeval now;
+ int ret = -1;
+
+ GF_ASSERT (conf);
+
+ if (!gettimeofday (&now, NULL))
+ {
+ LOCK (&conf->lock);
+ {
+ ios_global_stats_clear (&conf->cumulative, &now);
+ ios_global_stats_clear (&conf->incremental, &now);
+ conf->increment = 0;
+ }
+ UNLOCK (&conf->lock);
+ ret = 0;
+ }
+
+ return ret;
+}
+
int
reconfigure (xlator_t *this, dict_t *options)
{
@@ -2791,6 +2826,7 @@ notify (xlator_t *this, int32_t event, void *data, ...)
int32_t list_cnt = 0;
double throughput = 0;
double time = 0;
+ gf_boolean_t is_peek = _gf_false;
va_list ap;
dict = data;
@@ -2851,13 +2887,40 @@ notify (xlator_t *this, int32_t event, void *data, ...)
}
} else {
ret = dict_get_int32 (dict, "info-op", &op);
- if (ret || op < GF_CLI_STATS_INFO ||
- GF_CLI_STATS_INFO_CUMULATIVE < op)
- op = GF_CLI_STATS_INFO;
+ if (ret || op < GF_CLI_INFO_ALL ||
+ GF_CLI_INFO_CLEAR < op)
+ op = GF_CLI_INFO_ALL;
+
+ ret = dict_set_int32 (output, "info-op", op);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set info-op in dict");
+ goto out;
+ }
+
+ if (GF_CLI_INFO_CLEAR == op) {
+ ret = io_stats_clear (this->private);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to clear info stats");
- (void) ios_dump_args_init (&args, IOS_DUMP_TYPE_DICT,
- output);
- ret = io_stats_dump (this, &args, op);
+ ret = dict_set_int32 (output, "stats-cleared",
+ ret ? 0 : 1);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set stats-cleared"
+ " in dict");
+ }
+ else {
+ ret = dict_get_str_boolean (dict, "peek",
+ _gf_false);
+ if (-1 != ret)
+ is_peek = ret;
+
+ (void) ios_dump_args_init (&args,
+ IOS_DUMP_TYPE_DICT, output);
+ ret = io_stats_dump (this, &args, op, is_peek);
+ }
}
break;
default: