MCPcopy Create free account
hub / github.com/F-Stack/f-stack / showLatencyDistSamples

Function showLatencyDistSamples

app/redis-6.2.6/src/redis-cli.c:6934–6953  ·  view source on GitHub ↗

Helper function for latencyDistMode(). Performs the spectrum visualization * of the collected samples targeting an xterm 256 terminal. * * Takes an array of distsamples structures, ordered from smaller to bigger * 'max' value. Last sample max must be 0, to mean that it olds all the * samples greater than the previous one, and is also the stop sentinel. * * "tot' is the total number of sampl

Source from the content-addressed store, hash-verified

6932 *
6933 * As a side effect the function sets all the buckets count to 0. */
6934void showLatencyDistSamples(struct distsamples *samples, long long tot) {
6935 int j;
6936
6937 /* We convert samples into an index inside the palette
6938 * proportional to the percentage a given bucket represents.
6939 * This way intensity of the different parts of the spectrum
6940 * don't change relative to the number of requests, which avoids to
6941 * pollute the visualization with non-latency related info. */
6942 printf("\033[38;5;0m"); /* Set foreground color to black. */
6943 for (j = 0; ; j++) {
6944 int coloridx =
6945 ceil((double) samples[j].count / tot * (spectrum_palette_size-1));
6946 int color = spectrum_palette[coloridx];
6947 printf("\033[48;5;%dm%c", (int)color, samples[j].character);
6948 samples[j].count = 0;
6949 if (samples[j].max == 0) break; /* Last sample. */
6950 }
6951 printf("\033[0m\n");
6952 fflush(stdout);
6953}
6954
6955/* Show the legend: different buckets values and colors meaning, so
6956 * that the spectrum is more easily readable. */

Callers 1

latencyDistModeFunction · 0.85

Calls 1

printfFunction · 0.50

Tested by

no test coverage detected