summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-06-17 10:12:57 -0400
committerantirez <antirez@gmail.com>2014-06-21 15:18:32 +0200
commit65bab61159476168589512da27c238405d37e801 (patch)
tree14dc5bf0ff23240dcf806163275baf2cd7afd118
parent8d75a20ab10ecfcdf40113d50bb0cfdb7bd5f6f1 (diff)
downloadredis-65bab61159476168589512da27c238405d37e801.tar.gz
Add SIGINT handler to cli --intrinsic-latency
If we run a long latency session and want to Ctrl-C out of it, it's nice to still get the summary output at the end.
-rw-r--r--src/redis-cli.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index b8e17d24e..bd3b72144 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -95,6 +95,7 @@ static struct config {
char *eval;
} config;
+static volatile sig_atomic_t force_cancel_loop = 0;
static void usage();
static void slaveMode(void);
char *redisGitSHA1(void);
@@ -1807,11 +1808,17 @@ unsigned long compute_something_fast(void) {
return output;
}
+static void intrinsicLatencyModeStop(int s) {
+ REDIS_NOTUSED(s);
+ force_cancel_loop = 1;
+}
+
static void intrinsicLatencyMode(void) {
long long test_end, run_time, max_latency = 0, runs = 0;
run_time = config.intrinsic_latency_duration*1000000;
test_end = ustime() + run_time;
+ signal(SIGINT, intrinsicLatencyModeStop);
while(1) {
long long start, end, latency;
@@ -1829,7 +1836,7 @@ static void intrinsicLatencyMode(void) {
printf("Max latency so far: %lld microseconds.\n", max_latency);
}
- if (end > test_end) {
+ if (force_cancel_loop || end > test_end) {
printf("\n%lld total runs (avg %lld microseconds per run).\n",
runs, run_time/runs);
printf("Worst run took %.02fx times the average.\n",