Commit 3c0db900 authored by Matheus Marchini's avatar Matheus Marchini

truncate zero range on hist

Fixes: https://github.com/iovisor/bpftrace/issues/51
parent 2562ff60
...@@ -929,14 +929,18 @@ int BPFtrace::print_map_stats(IMap &map) ...@@ -929,14 +929,18 @@ int BPFtrace::print_map_stats(IMap &map)
int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) const int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) const
{ {
int min_index = -1;
int max_index = -1; int max_index = -1;
int max_value = 0; int max_value = 0;
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
{ {
int v = values.at(i); int v = values.at(i);
if (v != 0) if (v > 0) {
if (min_index == -1)
min_index = i;
max_index = i; max_index = i;
}
if (v > max_value) if (v > max_value)
max_value = v; max_value = v;
} }
...@@ -944,7 +948,7 @@ int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) cons ...@@ -944,7 +948,7 @@ int BPFtrace::print_hist(const std::vector<uint64_t> &values, uint32_t div) cons
if (max_index == -1) if (max_index == -1)
return 0; return 0;
for (int i = 0; i <= max_index; i++) for (int i = min_index; i <= max_index; i++)
{ {
std::ostringstream header; std::ostringstream header;
if (i == 0) if (i == 0)
......
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