mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
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.
This commit is contained in:
parent
2c17591224
commit
20c2a38ad0
@ -95,6 +95,7 @@ static struct config {
|
|||||||
char *eval;
|
char *eval;
|
||||||
} config;
|
} config;
|
||||||
|
|
||||||
|
static volatile sig_atomic_t force_cancel_loop = 0;
|
||||||
static void usage();
|
static void usage();
|
||||||
static void slaveMode(void);
|
static void slaveMode(void);
|
||||||
char *redisGitSHA1(void);
|
char *redisGitSHA1(void);
|
||||||
@ -1807,11 +1808,17 @@ unsigned long compute_something_fast(void) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void intrinsicLatencyModeStop(int s) {
|
||||||
|
REDIS_NOTUSED(s);
|
||||||
|
force_cancel_loop = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void intrinsicLatencyMode(void) {
|
static void intrinsicLatencyMode(void) {
|
||||||
long long test_end, run_time, max_latency = 0, runs = 0;
|
long long test_end, run_time, max_latency = 0, runs = 0;
|
||||||
|
|
||||||
run_time = config.intrinsic_latency_duration*1000000;
|
run_time = config.intrinsic_latency_duration*1000000;
|
||||||
test_end = ustime() + run_time;
|
test_end = ustime() + run_time;
|
||||||
|
signal(SIGINT, intrinsicLatencyModeStop);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
long long start, end, latency;
|
long long start, end, latency;
|
||||||
@ -1829,7 +1836,7 @@ static void intrinsicLatencyMode(void) {
|
|||||||
printf("Max latency so far: %lld microseconds.\n", max_latency);
|
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",
|
printf("\n%lld total runs (avg %lld microseconds per run).\n",
|
||||||
runs, run_time/runs);
|
runs, run_time/runs);
|
||||||
printf("Worst run took %.02fx times the average.\n",
|
printf("Worst run took %.02fx times the average.\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user