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
| 6022 | * |
| 6023 | * As a side effect the function sets all the buckets count to 0. */ |
| 6024 | void showLatencyDistSamples(struct distsamples *samples, long long tot) { |
| 6025 | int j; |
| 6026 | |
| 6027 | /* We convert samples into an index inside the palette |
| 6028 | * proportional to the percentage a given bucket represents. |
| 6029 | * This way intensity of the different parts of the spectrum |
| 6030 | * don't change relative to the number of requests, which avoids to |
| 6031 | * pollute the visualization with non-latency related info. */ |
| 6032 | printf("\033[38;5;0m"); /* Set foreground color to black. */ |
| 6033 | for (j = 0; ; j++) { |
| 6034 | int coloridx = |
| 6035 | ceil((double) samples[j].count / tot * (spectrum_palette_size-1)); |
| 6036 | int color = spectrum_palette[coloridx]; |
| 6037 | printf("\033[48;5;%dm%c", (int)color, samples[j].character); |
| 6038 | samples[j].count = 0; |
| 6039 | if (samples[j].max == 0) break; /* Last sample. */ |
| 6040 | } |
| 6041 | printf("\033[0m\n"); |
| 6042 | fflush(stdout); |
| 6043 | } |
| 6044 | |
| 6045 | /* Show the legend: different buckets values and colors meaning, so |
| 6046 | * that the spectrum is more easily readable. */ |