1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +00:00

Profiler: Add a statusbar and show the timeline selection info in it :^)

This commit is contained in:
Andreas Kling 2021-05-06 19:12:58 +02:00
parent 814200f8da
commit 59da118f2e
3 changed files with 48 additions and 21 deletions

View file

@ -75,26 +75,14 @@ void TimelineTrack::paint_event(GUI::PaintEvent& event)
painter.fill_rect({ select_start_x, frame_thickness(), select_end_x - select_start_x, height() - frame_thickness() * 2 }, Color(0, 0, 0, 60));
painter.fill_rect({ select_hover_x, frame_thickness(), 1, height() - frame_thickness() * 2 }, Color::NamedColor::Black);
{
StringBuilder timeline_desc_builder;
timeline_desc_builder.appendff("{} ({}), ", m_process.executable, m_process.pid);
timeline_desc_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;
timeline_desc_builder.appendff(", Selection: {} - {} ms", start, end);
}
const auto text = timeline_desc_builder.build();
Gfx::IntRect rect {
frame_thickness() + 3,
frame_thickness() + 3,
font().width(text),
font().glyph_height()
};
painter.draw_text(rect, text, font());
}
auto text = String::formatted("{} ({})", m_process.executable, m_process.pid);
Gfx::IntRect text_rect {
frame_thickness() + 3,
frame_thickness() + 3,
font().width(text),
font().glyph_height()
};
painter.draw_text(text_rect, text, font());
}
u64 TimelineTrack::timestamp_at_x(int x) const

View file

@ -18,6 +18,8 @@ class TimelineView final : public GUI::Widget {
public:
virtual ~TimelineView() override;
Function<void()> on_selection_change;
bool is_selecting() const { return m_selecting; }
u64 select_start_time() const { return m_select_start_time; }
u64 select_end_time() const { return m_select_end_time; }
@ -25,23 +27,37 @@ public:
void set_selecting(Badge<TimelineTrack>, bool value)
{
if (m_selecting == value)
return;
m_selecting = value;
update();
}
void set_select_start_time(Badge<TimelineTrack>, u64 value)
{
if (m_select_start_time == value)
return;
m_select_start_time = value;
update();
if (on_selection_change)
on_selection_change();
}
void set_select_end_time(Badge<TimelineTrack>, u64 value)
{
if (m_select_end_time == value)
return;
m_select_end_time = value;
update();
if (on_selection_change)
on_selection_change();
}
void set_hover_time(Badge<TimelineTrack>, u64 value)
{
if (m_hover_time == value)
return;
m_hover_time = value;
update();
if (on_selection_change)
on_selection_change();
}
private:

View file

@ -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(); }));