Commit 1fc0c1f7 authored by williangaspar's avatar williangaspar

lhist human readable fixes: https://github.com/iovisor/bpftrace/issues/2

parent e35d318c
......@@ -891,7 +891,7 @@ int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) cons
return 0;
}
int BPFtrace::print_lhist(const std::vector<uint64_t> &values, int min, int max, int step) const
int BPFtrace::print_lhist(const std::vector<uint64_t> &values, int min, int max, int step) const
{
int max_index = -1;
int max_value = 0;
......@@ -910,7 +910,7 @@ int BPFtrace::print_lhist(const std::vector<uint64_t> &values, int min, int max,
return 0;
std::ostringstream lt;
lt << "(...," << min << "]";
lt << "(...," << lhist_index_label(min) << "]";
std::ostringstream gt;
// trim empty values
......@@ -937,12 +937,12 @@ int BPFtrace::print_lhist(const std::vector<uint64_t> &values, int min, int max,
int bar_width = values.at(i)/(float)max_value*max_width;
std::ostringstream header;
if (i == 0) {
header << "(...," << min << "]";
header << "(...," << lhist_index_label(min) << "]";
} else if (i == (buckets + 1)) {
header << "[" << max << ",...)";
header << "[" << lhist_index_label(max) << ",...)";
} else {
header << "[" << (i - 1) * step + min;
header << ", " << i * step + min << ")";
header << "[" << lhist_index_label((i - 1) * step + min);
header << ", " << lhist_index_label(i * step + min) << ")";
}
std::string bar(bar_width, '@');
......@@ -987,6 +987,32 @@ std::string BPFtrace::hist_index_label(int power)
return label.str();
}
std::string BPFtrace::lhist_index_label(int number)
{
int kilo = 1024;
int mega = 1048576;
std::ostringstream label;
if (number < kilo)
{
label << number;
}
else if (number % mega == 0)
{
label << number / mega << 'm';
}
else if (number % kilo == 0)
{
label << number / kilo << 'k';
}
else {
label << number;
}
return label.str();
}
uint64_t BPFtrace::reduce_value(const std::vector<uint8_t> &value, int ncpus)
{
uint64_t sum = 0;
......
......@@ -82,6 +82,7 @@ private:
static uint64_t min_value(const std::vector<uint8_t> &value, int ncpus);
static uint64_t max_value(const std::vector<uint8_t> &value, int ncpus);
static std::string hist_index_label(int power);
static std::string lhist_index_label(int number);
std::vector<uint8_t> find_empty_key(IMap &map, size_t size) const;
};
......
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