Skip to content

gui: change HistogramView bucket sizes#9564

Merged
maliberty merged 4 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:gui_histogram
Mar 2, 2026
Merged

gui: change HistogramView bucket sizes#9564
maliberty merged 4 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:gui_histogram

Conversation

@openroad-ci
Copy link
Collaborator

Closes #9387

Implements suggested changes in the charts histogram.

Signed-off-by: LucasYuki <lucasyuki@yahoo.com.br>
Signed-off-by: LucasYuki <lucasyuki@yahoo.com.br>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors the histogram bucket size calculation to use a standard algorithm for generating "nice" intervals, which improves code clarity and the visual quality of the histogram. However, I've identified two critical edge-case scenarios that could lead to application crashes. My review includes suggestions to address these issues by handling cases where the data range is zero, which would otherwise cause mathematical errors, and by ensuring the histogram is always configured with at least one bin to prevent errors in downstream processing.

const float bin_min = std::floor(min_slack / bin_interval) * bin_interval;
const float bin_max = std::ceil(max_slack / bin_interval) * bin_interval;

const int bins = (bin_max - bin_min) / bin_interval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

If min_slack and max_slack are equal, bin_min can equal bin_max. This results in bins being 0 due to integer truncation. Passing 0 for the number of bins to utl::Histogram will cause a crash later when getMaxBinCount() is called on an empty bins vector. You should ensure there's at least one bin. Using std::round is also safer for floating-point-to-integer conversion.

Suggested change
const int bins = (bin_max - bin_min) / bin_interval;
const int bins = std::max(1, static_cast<int>(std::round((bin_max - bin_min) / bin_interval)));

Comment on lines 730 to 749
{
if (exact_interval < 10) {
return std::ceil(exact_interval);
}

float snap_interval = 0;
const int digits = computeNumberOfDigits(exact_interval);

while (snap_interval < exact_interval) {
snap_interval += 5 * std::pow(10, digits - 2);
int exp = std::floor(std::log10(exact_interval));
precision_count_ = std::max(-exp, 0);

double mag = std::pow(10.0, exp);
double residual = exact_interval / mag;

double nice_coeff;
if (residual < 1.5) {
nice_coeff = 1.0;
} else if (residual < 3.0) {
nice_coeff = 2.0;
} else if (residual < 7.0) {
nice_coeff = 5.0;
} else {
nice_coeff = 10.0;
}

return snap_interval;
return nice_coeff * mag;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

If exact_interval is zero or negative (which can happen if max_slack equals min_slack), calling std::log10 will result in an error (-inf or NaN). This propagates through the calculations and can lead to a crash. Please add a guard to handle this edge case.

{
  if (exact_interval <= 0.0f) {
    return 1.0f;
  }
  int exp = std::floor(std::log10(exact_interval));
  precision_count_ = std::max(-exp, 0);

  double mag = std::pow(10.0, exp);
  double residual = exact_interval / mag;

  double nice_coeff;
  if (residual < 1.5) {
    nice_coeff = 1.0;
  } else if (residual < 3.0) {
    nice_coeff = 2.0;
  } else if (residual < 7.0) {
    nice_coeff = 5.0;
  } else {
    nice_coeff = 10.0;
  }

  return nice_coeff * mag;
}

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: LucasYuki <lucasyuki@yahoo.com.br>
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

clang-tidy review says "All clean, LGTM! 👍"

@LucasYuki LucasYuki requested a review from maliberty March 2, 2026 14:41
@maliberty maliberty merged commit 9e92f64 into The-OpenROAD-Project:master Mar 2, 2026
13 checks passed
@maliberty maliberty deleted the gui_histogram branch March 2, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use nicer ranges for bucket count and sizes

3 participants