mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
Profiler: Add TimelineView widget and make the timeline cursor global
There's no longer a cursor in each process timeline, instead the parent widget keeps track of it (along with the selection) and it all moves in sync.
This commit is contained in:
parent
84c4c2d884
commit
abc3ad01b2
6 changed files with 103 additions and 28 deletions
|
@ -8,6 +8,7 @@ set(SOURCES
|
||||||
ProfileModel.cpp
|
ProfileModel.cpp
|
||||||
ProfileTimelineWidget.cpp
|
ProfileTimelineWidget.cpp
|
||||||
SamplesModel.cpp
|
SamplesModel.cpp
|
||||||
|
TimelineView.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(Profiler ICON app-profiler)
|
serenity_app(Profiler ICON app-profiler)
|
||||||
|
|
|
@ -6,14 +6,16 @@
|
||||||
|
|
||||||
#include "ProfileTimelineWidget.h"
|
#include "ProfileTimelineWidget.h"
|
||||||
#include "Profile.h"
|
#include "Profile.h"
|
||||||
|
#include "TimelineView.h"
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
namespace Profiler {
|
namespace Profiler {
|
||||||
|
|
||||||
ProfileTimelineWidget::ProfileTimelineWidget(Profile& profile, Process const& process)
|
ProfileTimelineWidget::ProfileTimelineWidget(TimelineView& view, Profile& profile, Process const& process)
|
||||||
: m_profile(profile)
|
: m_view(view)
|
||||||
|
, m_profile(profile)
|
||||||
, m_process(process)
|
, m_process(process)
|
||||||
{
|
{
|
||||||
set_fill_with_background_color(true);
|
set_fill_with_background_color(true);
|
||||||
|
@ -21,7 +23,6 @@ ProfileTimelineWidget::ProfileTimelineWidget(Profile& profile, Process const& pr
|
||||||
set_fixed_height(40);
|
set_fixed_height(40);
|
||||||
set_fixed_width(m_profile.length_in_ms() / 10);
|
set_fixed_width(m_profile.length_in_ms() / 10);
|
||||||
set_frame_thickness(1);
|
set_frame_thickness(1);
|
||||||
m_hover_time = m_profile.first_timestamp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileTimelineWidget::~ProfileTimelineWidget()
|
ProfileTimelineWidget::~ProfileTimelineWidget()
|
||||||
|
@ -64,9 +65,9 @@ void ProfileTimelineWidget::paint_event(GUI::PaintEvent& event)
|
||||||
painter.draw_line({ x + i, frame_thickness() + column_height }, { x + i, height() - frame_thickness() * 2 }, color);
|
painter.draw_line({ x + i, frame_thickness() + column_height }, { x + i, height() - frame_thickness() * 2 }, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 normalized_start_time = clamp_timestamp(min(m_select_start_time, m_select_end_time));
|
u64 normalized_start_time = clamp_timestamp(min(m_view.select_start_time(), m_view.select_end_time()));
|
||||||
u64 normalized_end_time = clamp_timestamp(max(m_select_start_time, m_select_end_time));
|
u64 normalized_end_time = clamp_timestamp(max(m_view.select_start_time(), m_view.select_end_time()));
|
||||||
u64 normalized_hover_time = clamp_timestamp(m_hover_time);
|
u64 normalized_hover_time = clamp_timestamp(m_view.hover_time());
|
||||||
|
|
||||||
int select_start_x = (int)((float)(normalized_start_time - start_of_trace) * column_width);
|
int select_start_x = (int)((float)(normalized_start_time - start_of_trace) * column_width);
|
||||||
int select_end_x = (int)((float)(normalized_end_time - start_of_trace) * column_width);
|
int select_end_x = (int)((float)(normalized_end_time - start_of_trace) * column_width);
|
||||||
|
@ -108,20 +109,20 @@ void ProfileTimelineWidget::mousedown_event(GUI::MouseEvent& event)
|
||||||
if (event.button() != GUI::MouseButton::Left)
|
if (event.button() != GUI::MouseButton::Left)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_selecting = true;
|
m_view.set_selecting({}, true);
|
||||||
m_select_start_time = timestamp_at_x(event.x());
|
m_view.set_select_start_time({}, timestamp_at_x(event.x()));
|
||||||
m_select_end_time = m_select_start_time;
|
m_view.set_select_end_time({}, m_view.select_start_time());
|
||||||
m_profile.set_timestamp_filter_range(m_select_start_time, m_select_end_time);
|
m_profile.set_timestamp_filter_range(m_view.select_start_time(), m_view.select_end_time());
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileTimelineWidget::mousemove_event(GUI::MouseEvent& event)
|
void ProfileTimelineWidget::mousemove_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
m_hover_time = timestamp_at_x(event.x());
|
m_view.set_hover_time({}, timestamp_at_x(event.x()));
|
||||||
|
|
||||||
if (m_selecting) {
|
if (m_view.is_selecting()) {
|
||||||
m_select_end_time = m_hover_time;
|
m_view.set_select_end_time({}, m_view.hover_time());
|
||||||
m_profile.set_timestamp_filter_range(m_select_start_time, m_select_end_time);
|
m_profile.set_timestamp_filter_range(m_view.select_start_time(), m_view.select_end_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -132,8 +133,8 @@ void ProfileTimelineWidget::mouseup_event(GUI::MouseEvent& event)
|
||||||
if (event.button() != GUI::MouseButton::Left)
|
if (event.button() != GUI::MouseButton::Left)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_selecting = false;
|
m_view.set_selecting({}, false);
|
||||||
if (m_select_start_time == m_select_end_time)
|
if (m_view.select_start_time() == m_view.select_end_time())
|
||||||
m_profile.clear_timestamp_filter_range();
|
m_profile.clear_timestamp_filter_range();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Profiler {
|
||||||
|
|
||||||
class Process;
|
class Process;
|
||||||
class Profile;
|
class Profile;
|
||||||
|
class TimelineView;
|
||||||
|
|
||||||
class ProfileTimelineWidget final : public GUI::Frame {
|
class ProfileTimelineWidget final : public GUI::Frame {
|
||||||
C_OBJECT(ProfileTimelineWidget)
|
C_OBJECT(ProfileTimelineWidget)
|
||||||
|
@ -24,17 +25,13 @@ private:
|
||||||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||||
virtual void mouseup_event(GUI::MouseEvent&) override;
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
||||||
|
|
||||||
explicit ProfileTimelineWidget(Profile&, Process const&);
|
explicit ProfileTimelineWidget(TimelineView&, Profile&, Process const&);
|
||||||
|
|
||||||
u64 timestamp_at_x(int x) const;
|
u64 timestamp_at_x(int x) const;
|
||||||
|
|
||||||
|
TimelineView& m_view;
|
||||||
Profile& m_profile;
|
Profile& m_profile;
|
||||||
Process const& m_process;
|
Process const& m_process;
|
||||||
|
|
||||||
bool m_selecting { false };
|
|
||||||
u64 m_select_start_time { 0 };
|
|
||||||
u64 m_select_end_time { 0 };
|
|
||||||
u64 m_hover_time { 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
22
Userland/DevTools/Profiler/TimelineView.cpp
Normal file
22
Userland/DevTools/Profiler/TimelineView.cpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TimelineView.h"
|
||||||
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
|
||||||
|
namespace Profiler {
|
||||||
|
|
||||||
|
TimelineView::TimelineView()
|
||||||
|
{
|
||||||
|
set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
set_shrink_to_fit(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TimelineView::~TimelineView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
56
Userland/DevTools/Profiler/TimelineView.h
Normal file
56
Userland/DevTools/Profiler/TimelineView.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
|
namespace Profiler {
|
||||||
|
|
||||||
|
class ProfileTimelineWidget;
|
||||||
|
|
||||||
|
class TimelineView final : public GUI::Widget {
|
||||||
|
C_OBJECT(TimelineView);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~TimelineView() override;
|
||||||
|
|
||||||
|
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; }
|
||||||
|
u64 hover_time() const { return m_hover_time; }
|
||||||
|
|
||||||
|
void set_selecting(Badge<ProfileTimelineWidget>, bool value)
|
||||||
|
{
|
||||||
|
m_selecting = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
void set_select_start_time(Badge<ProfileTimelineWidget>, u64 value)
|
||||||
|
{
|
||||||
|
m_select_start_time = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
void set_select_end_time(Badge<ProfileTimelineWidget>, u64 value)
|
||||||
|
{
|
||||||
|
m_select_end_time = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
void set_hover_time(Badge<ProfileTimelineWidget>, u64 value)
|
||||||
|
{
|
||||||
|
m_hover_time = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TimelineView();
|
||||||
|
|
||||||
|
bool m_selecting { false };
|
||||||
|
u64 m_select_start_time { 0 };
|
||||||
|
u64 m_select_end_time { 0 };
|
||||||
|
u64 m_hover_time { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
#include "ProcessPickerWidget.h"
|
#include "ProcessPickerWidget.h"
|
||||||
#include "Profile.h"
|
#include "Profile.h"
|
||||||
#include "ProfileTimelineWidget.h"
|
#include "ProfileTimelineWidget.h"
|
||||||
|
#include "TimelineView.h"
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
|
@ -89,10 +90,7 @@ int main(int argc, char** argv)
|
||||||
main_widget.set_fill_with_background_color(true);
|
main_widget.set_fill_with_background_color(true);
|
||||||
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
|
||||||
auto timelines_widget = GUI::Widget::construct();
|
auto timeline_view = TimelineView::construct();
|
||||||
timelines_widget->set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
timelines_widget->set_shrink_to_fit(true);
|
|
||||||
|
|
||||||
for (auto& process : profile->processes()) {
|
for (auto& process : profile->processes()) {
|
||||||
size_t event_count = 0;
|
size_t event_count = 0;
|
||||||
for (auto& event : profile->events()) {
|
for (auto& event : profile->events()) {
|
||||||
|
@ -101,11 +99,11 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
if (!event_count)
|
if (!event_count)
|
||||||
continue;
|
continue;
|
||||||
timelines_widget->add<ProfileTimelineWidget>(*profile, process);
|
timeline_view->add<ProfileTimelineWidget>(*timeline_view, *profile, process);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& scrollable_container = main_widget.add<GUI::ScrollableContainerWidget>();
|
auto& scrollable_container = main_widget.add<GUI::ScrollableContainerWidget>();
|
||||||
scrollable_container.set_widget(timelines_widget.ptr());
|
scrollable_container.set_widget(timeline_view.ptr());
|
||||||
|
|
||||||
main_widget.add<ProcessPickerWidget>(*profile);
|
main_widget.add<ProcessPickerWidget>(*profile);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue