diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-06 19:12:58 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-06 22:18:45 +0200 |
commit | 59da118f2e19be93a466b5311ac84165928d119b (patch) | |
tree | 857c013718d134034fdb9a24295a505c205753fd /Userland/DevTools/Profiler/main.cpp | |
parent | 814200f8dae9f5ab12872ce024988bb0b06b39d5 (diff) | |
download | serenity-59da118f2e19be93a466b5311ac84165928d119b.zip |
Profiler: Add a statusbar and show the timeline selection info in it :^)
Diffstat (limited to 'Userland/DevTools/Profiler/main.cpp')
-rw-r--r-- | Userland/DevTools/Profiler/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp index b3c8aee35c..b908c9175b 100644 --- a/Userland/DevTools/Profiler/main.cpp +++ b/Userland/DevTools/Profiler/main.cpp @@ -27,6 +27,7 @@ #include <LibGUI/ProcessChooser.h> #include <LibGUI/ScrollableContainerWidget.h> #include <LibGUI/Splitter.h> +#include <LibGUI/Statusbar.h> #include <LibGUI/TabWidget.h> #include <LibGUI/TableView.h> #include <LibGUI/TreeView.h> @@ -140,6 +141,28 @@ int main(int argc, char** argv) individual_sample_view.set_model(move(model)); }; + const u64 start_of_trace = profile->first_timestamp(); + const u64 end_of_trace = start_of_trace + profile->length_in_ms(); + const auto clamp_timestamp = [start_of_trace, end_of_trace](u64 timestamp) -> u64 { + return min(end_of_trace, max(timestamp, start_of_trace)); + }; + + auto& statusbar = main_widget.add<GUI::Statusbar>(); + timeline_view->on_selection_change = [&] { + auto& view = *timeline_view; + StringBuilder builder; + 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())); + u64 normalized_hover_time = clamp_timestamp(view.hover_time()); + builder.appendff("Time: {} ms", normalized_hover_time - start_of_trace); + if (normalized_start_time != normalized_end_time) { + auto start = normalized_start_time - start_of_trace; + auto end = normalized_end_time - start_of_trace; + builder.appendff(", Selection: {} - {} ms", start, end); + } + statusbar.set_text(builder.to_string()); + }; + auto menubar = GUI::Menubar::construct(); auto& file_menu = menubar->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); |