Profiler: Round sample percentages to a constant number of digits

This constant is currently 3 but can be changed easily or integrated
into a user setting. Note that the results are not ideal because during
pretty-printing we're not using any nice rounding rules, so many
percentage values will actually appear as 0.399999 even though they were
rounded to three digits.
This commit is contained in:
kleines Filmröllchen 2022-04-26 22:56:57 +02:00 committed by Linus Groh
parent d9decfbbf3
commit 6368ef41f8
Notes: sideshowbarker 2024-07-17 11:12:20 +09:00
2 changed files with 11 additions and 2 deletions

View File

@ -111,14 +111,19 @@ GUI::Variant ProfileModel::data(GUI::ModelIndex const& index, GUI::ModelRole rol
return {};
}
if (role == GUI::ModelRole::Display) {
auto round_percentages = [this](auto percentage) {
return roundf(static_cast<float>(percentage) / static_cast<float>(m_profile.filtered_event_indices().size())
* percent_digits_rounding_constant)
* 100.0f / percent_digits_rounding_constant;
};
if (index.column() == Column::SampleCount) {
if (m_profile.show_percentages())
return ((float)node->event_count() / (float)m_profile.filtered_event_indices().size()) * 100.0f;
return round_percentages(node->event_count());
return node->event_count();
}
if (index.column() == Column::SelfCount) {
if (m_profile.show_percentages())
return ((float)node->self_count() / (float)m_profile.filtered_event_indices().size()) * 100.0f;
return round_percentages(node->self_count());
return node->self_count();
}
if (index.column() == Column::ObjectName)

View File

@ -13,6 +13,10 @@ namespace Profiler {
class Profile;
// Number of digits after the decimal point for sample percentages.
static constexpr int const number_of_percent_digits = 3;
static constexpr float const percent_digits_rounding_constant = AK::pow(10, number_of_percent_digits);
class ProfileModel final : public GUI::Model {
public:
static NonnullRefPtr<ProfileModel> create(Profile& profile)