summaryrefslogtreecommitdiff
path: root/Userland/DevTools/Profiler/main.cpp
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-04-26 21:39:50 +0200
committerLinus Groh <mail@linusgroh.de>2022-05-07 20:21:51 +0200
commitd9decfbbf3046a2244f64e21f992c27f98531150 (patch)
treeb8096b63f9ce0da8ac735a5b64832483e90cd95f /Userland/DevTools/Profiler/main.cpp
parent19a4b820c470d3124afe00471d4fe091d92a00dd (diff)
downloadserenity-d9decfbbf3046a2244f64e21f992c27f98531150.zip
Profiler: Show percentages with three decimal points
This is great when the percentages are very low.
Diffstat (limited to 'Userland/DevTools/Profiler/main.cpp')
-rw-r--r--Userland/DevTools/Profiler/main.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp
index 3fd79f0b75..53aca5e915 100644
--- a/Userland/DevTools/Profiler/main.cpp
+++ b/Userland/DevTools/Profiler/main.cpp
@@ -222,6 +222,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return min(end_of_trace, max(timestamp, start_of_trace));
};
+ auto const format_sample_count = [&profile](auto sample_count) {
+ if (profile->show_percentages())
+ return String::formatted("{:.3f}%", sample_count.as_float_or(0.0));
+ return String::formatted("{} Samples", sample_count.to_i32());
+ };
+
auto statusbar = TRY(main_widget->try_add<GUI::Statusbar>());
auto statusbar_update = [&] {
auto& view = *timeline_view;
@@ -230,11 +236,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto flamegraph_hovered_index = flamegraph_view->hovered_index();
if (flamegraph_hovered_index.is_valid()) {
auto stack = profile->model().data(flamegraph_hovered_index.sibling_at_column(ProfileModel::Column::StackFrame)).to_string();
- auto sample_count = profile->model().data(flamegraph_hovered_index.sibling_at_column(ProfileModel::Column::SampleCount)).to_i32();
- auto self_count = profile->model().data(flamegraph_hovered_index.sibling_at_column(ProfileModel::Column::SelfCount)).to_i32();
+ auto sample_count = profile->model().data(flamegraph_hovered_index.sibling_at_column(ProfileModel::Column::SampleCount));
+ auto self_count = profile->model().data(flamegraph_hovered_index.sibling_at_column(ProfileModel::Column::SelfCount));
builder.appendff("{}, ", stack);
- builder.appendff("Samples: {}{}, ", sample_count, profile->show_percentages() ? "%" : " Samples");
- builder.appendff("Self: {}{}", self_count, profile->show_percentages() ? "%" : " Samples");
+ builder.appendff("Samples: {}, ", format_sample_count(sample_count));
+ builder.appendff("Self: {}", format_sample_count(self_count));
} else {
u64 normalized_start_time = clamp_timestamp(min(view.select_start_time(), view.select_end_time()));
u64 normalized_end_time = clamp_timestamp(max(view.select_start_time(), view.select_end_time()));