Commit dcd9e625 authored by Alastair Robertson's avatar Alastair Robertson

Simplify code to generate histogram labels

parent c203e541
......@@ -176,54 +176,19 @@ int BPFtrace::print_quantize(std::vector<uint64_t> values)
if (max_index == -1)
return 0;
std::cout << std::setw(16) << std::left << "[0, 1]"
<< std::setw(8) << std::right << values.at(0)
<< " |" << std::endl;
for (int i = 1; i <= max_index; i++)
for (int i = 0; i <= max_index; i++)
{
int power1 = i, power2;
char suffix1 = '\0', suffix2 = '\0';
if (power1 >= 30)
{
suffix1 = 'G';
power1 -= 30;
}
else if (power1 >= 20)
{
suffix1 = 'M';
if (power1 == 29)
suffix2 = 'G';
power1 -= 20;
}
else if (power1 >= 10)
{
suffix1 = 'k';
if (power1 == 19)
suffix2 = 'M';
power1 -= 10;
}
if (!suffix2)
std::ostringstream header;
if (i == 0)
{
suffix2 = suffix1;
power2 = power1;
header << "[0, 1]";
}
else
{
power2 = power1 - 10;
header << "[" << quantize_index_label(i);
header << ", " << quantize_index_label(i+1) << ")";
}
int start = 1<<power1;
int end = (1<<(power2+1));
std::ostringstream header;
header << "[" << start;
if (suffix1)
header << suffix1;
header << ", " << end;
if (suffix2)
header << suffix2;
header << ")";
int max_width = 52;
int bar_width = values.at(i)/(float)max_value*max_width;
std::string bar(bar_width, '@');
......@@ -237,4 +202,35 @@ int BPFtrace::print_quantize(std::vector<uint64_t> values)
return 0;
}
std::string BPFtrace::quantize_index_label(int power)
{
char suffix = '\0';
if (power >= 40)
{
suffix = 'T';
power -= 40;
}
else if (power >= 30)
{
suffix = 'G';
power -= 30;
}
else if (power >= 20)
{
suffix = 'M';
power -= 20;
}
else if (power >= 10)
{
suffix = 'k';
power -= 10;
}
std::ostringstream label;
label << (1<<power);
if (suffix)
label << suffix;
return label.str();
}
} // namespace bpftrace
......@@ -26,6 +26,7 @@ private:
int print_map(Map &map);
int print_map_quantize(Map &map);
int print_quantize(std::vector<uint64_t> values);
std::string quantize_index_label(int power);
};
} // namespace bpftrace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment