From 657f719760d327bde9282fe92036bd886ed296bc Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 7 Feb 2015 20:15:40 +0100 Subject: redis-cli --latency-dist now uses a color palette. Still not happy with the result but low grays are hard to see in certain monitors with a non perfect gamma. --- src/redis-cli.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index bf2d1d44a..d683a3fba 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1086,6 +1086,15 @@ static void latencyMode(void) { #define LATENCY_DIST_MAX_GRAY 255 #define LATENCY_DIST_GRAYS (LATENCY_DIST_MAX_GRAY-LATENCY_DIST_MIN_GRAY+1) +/* Gray palette. Currently not used. + * int spectrum_palette_size = 24; +* int spectrum_palette[] = {0, 233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}; +*/ + +/* Color palette from https://github.com/draios/sysdig */ +int spectrum_palette[] = {0, 22, 28, 64, 34, 2, 76, 46, 118, 154, 191, 227, 226, 11, 220, 209, 208, 202, 197, 9, 1}; +int spectrum_palette_size = 21; + /* Structure to store samples distribution. */ struct distsamples { long long max; /* Max latency to fit into this interval (usec). */ @@ -1107,20 +1116,17 @@ struct distsamples { void showLatencyDistSamples(struct distsamples *samples, long long tot) { int j; - /* We convert samples into a number between 0 and DIST_GRAYS, + /* We convert samples into a index inside the palette * proportional to the percentage a given bucket represents. * This way intensity of the different parts of the spectrum * don't change relative to the number of requests, which avoids to * pollute the visualization with non-latency related info. */ printf("\033[38;5;0m"); /* Set foreground color to black. */ for (j = 0; ; j++) { - float color = (float) samples[j].count / tot * LATENCY_DIST_GRAYS; - color = ceil(color) + (LATENCY_DIST_MIN_GRAY-1); - if (color == LATENCY_DIST_MIN_GRAY-1) { - printf("\033[48;5;0m "); - } else { - printf("\033[48;5;%dm%c", (int)color, samples[j].character); - } + int coloridx = + ceil((float) samples[j].count / tot * (spectrum_palette_size-1)); + int color = spectrum_palette[coloridx]; + printf("\033[48;5;%dm%c", (int)color, samples[j].character); samples[j].count = 0; if (samples[j].max == 0) break; /* Last sample. */ } -- cgit v1.2.1