Use fixed precision for string histogram buckets. (#1563)
`absl::StrCat/StrAppend` convert numeric values to strings with inconsistent decimal precision, which can lead to ugly formatting of the histogram. This can be fixed by using `StrAppendFormat` with `%f`, which uses 6 decimals (printf default and as it was when we had `std::to_string`).master
parent
c999c3012b
commit
897762675c
|
@ -21,6 +21,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "cartographer/common/port.h"
|
#include "cartographer/common/port.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
@ -59,8 +60,8 @@ std::string Histogram::ToString(const int buckets) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
total_count += count;
|
total_count += count;
|
||||||
absl::StrAppend(&result, "\n[", lower_bound, ", ", upper_bound,
|
absl::StrAppendFormat(&result, "\n[%f, %f%c", lower_bound, upper_bound,
|
||||||
i + 1 == buckets ? "]" : ")");
|
i + 1 == buckets ? ']' : ')');
|
||||||
constexpr int kMaxBarChars = 20;
|
constexpr int kMaxBarChars = 20;
|
||||||
const int bar =
|
const int bar =
|
||||||
(count * kMaxBarChars + values_.size() / 2) / values_.size();
|
(count * kMaxBarChars + values_.size() / 2) / values_.size();
|
||||||
|
|
Loading…
Reference in New Issue