HistogramStat: Handle divide by zero situation

Summary:
The num() might return cur_num as 0 and we are making sure that
cur_num will not be 0 down the path. The mult variable is being set to
100.0/cur_num which makes program crash when cur_num is 0.
Closes https://github.com/facebook/rocksdb/pull/3105

Differential Revision: D6222594

Pulled By: ajkr

fbshipit-source-id: 986154709897ff4dbbeb0e8aa81eb8c0b2a2db76
main
Prashant D 7 years ago committed by Facebook Github Bot
parent 25fbd9a996
commit 3c208e7616
  1. 1
      monitoring/histogram.cc

@ -202,6 +202,7 @@ std::string HistogramStat::ToString() const {
Percentile(99.99)); Percentile(99.99));
r.append(buf); r.append(buf);
r.append("------------------------------------------------------\n"); r.append("------------------------------------------------------\n");
if (cur_num == 0) return r; // all buckets are empty
const double mult = 100.0 / cur_num; const double mult = 100.0 / cur_num;
uint64_t cumulative_sum = 0; uint64_t cumulative_sum = 0;
for (unsigned int b = 0; b < num_buckets_; b++) { for (unsigned int b = 0; b < num_buckets_; b++) {

Loading…
Cancel
Save