Skip to content

Commit 657f719

Browse files
committed
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.
1 parent ff13fa7 commit 657f719

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/redis-cli.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,15 @@ static void latencyMode(void) {
10861086
#define LATENCY_DIST_MAX_GRAY 255
10871087
#define LATENCY_DIST_GRAYS (LATENCY_DIST_MAX_GRAY-LATENCY_DIST_MIN_GRAY+1)
10881088

1089+
/* Gray palette. Currently not used.
1090+
* int spectrum_palette_size = 24;
1091+
* 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};
1092+
*/
1093+
1094+
/* Color palette from https://github.com/draios/sysdig */
1095+
int spectrum_palette[] = {0, 22, 28, 64, 34, 2, 76, 46, 118, 154, 191, 227, 226, 11, 220, 209, 208, 202, 197, 9, 1};
1096+
int spectrum_palette_size = 21;
1097+
10891098
/* Structure to store samples distribution. */
10901099
struct distsamples {
10911100
long long max; /* Max latency to fit into this interval (usec). */
@@ -1107,20 +1116,17 @@ struct distsamples {
11071116
void showLatencyDistSamples(struct distsamples *samples, long long tot) {
11081117
int j;
11091118

1110-
/* We convert samples into a number between 0 and DIST_GRAYS,
1119+
/* We convert samples into a index inside the palette
11111120
* proportional to the percentage a given bucket represents.
11121121
* This way intensity of the different parts of the spectrum
11131122
* don't change relative to the number of requests, which avoids to
11141123
* pollute the visualization with non-latency related info. */
11151124
printf("\033[38;5;0m"); /* Set foreground color to black. */
11161125
for (j = 0; ; j++) {
1117-
float color = (float) samples[j].count / tot * LATENCY_DIST_GRAYS;
1118-
color = ceil(color) + (LATENCY_DIST_MIN_GRAY-1);
1119-
if (color == LATENCY_DIST_MIN_GRAY-1) {
1120-
printf("\033[48;5;0m ");
1121-
} else {
1122-
printf("\033[48;5;%dm%c", (int)color, samples[j].character);
1123-
}
1126+
int coloridx =
1127+
ceil((float) samples[j].count / tot * (spectrum_palette_size-1));
1128+
int color = spectrum_palette[coloridx];
1129+
printf("\033[48;5;%dm%c", (int)color, samples[j].character);
11241130
samples[j].count = 0;
11251131
if (samples[j].max == 0) break; /* Last sample. */
11261132
}

0 commit comments

Comments
 (0)