mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
Profiler: Make processes selectable in the timeline view
This commit is contained in:
parent
7b9cabb5a3
commit
43b3fd748a
3 changed files with 49 additions and 5 deletions
|
@ -6,19 +6,24 @@
|
||||||
|
|
||||||
#include "TimelineHeader.h"
|
#include "TimelineHeader.h"
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
|
#include "Profile.h"
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <LibGUI/FileIconProvider.h>
|
#include <LibGUI/FileIconProvider.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
#include <LibGfx/Font.h>
|
||||||
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
namespace Profiler {
|
namespace Profiler {
|
||||||
|
|
||||||
TimelineHeader::TimelineHeader(Process const& process)
|
TimelineHeader::TimelineHeader(Profile& profile, Process const& process)
|
||||||
: m_process(process)
|
: m_profile(profile)
|
||||||
|
, m_process(process)
|
||||||
{
|
{
|
||||||
set_frame_shape(Gfx::FrameShape::Panel);
|
set_frame_shape(Gfx::FrameShape::Panel);
|
||||||
set_frame_shadow(Gfx::FrameShadow::Raised);
|
set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||||
set_fixed_size(200, 40);
|
set_fixed_size(200, 40);
|
||||||
|
update_selection();
|
||||||
|
|
||||||
m_icon = GUI::FileIconProvider::icon_for_executable(m_process.executable).bitmap_for_size(32);
|
m_icon = GUI::FileIconProvider::icon_for_executable(m_process.executable).bitmap_for_size(32);
|
||||||
m_text = String::formatted("{} ({})", LexicalPath(m_process.executable).basename(), m_process.pid);
|
m_text = String::formatted("{} ({})", LexicalPath(m_process.executable).basename(), m_process.pid);
|
||||||
|
@ -34,6 +39,8 @@ void TimelineHeader::paint_event(GUI::PaintEvent& event)
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
|
painter.fill_rect(frame_inner_rect(), m_selected ? palette().selection() : palette().button());
|
||||||
|
|
||||||
Gfx::IntRect icon_rect { frame_thickness() + 2, 0, 32, 32 };
|
Gfx::IntRect icon_rect { frame_thickness() + 2, 0, 32, 32 };
|
||||||
icon_rect.center_vertically_within(frame_inner_rect());
|
icon_rect.center_vertically_within(frame_inner_rect());
|
||||||
|
|
||||||
|
@ -48,7 +55,23 @@ void TimelineHeader::paint_event(GUI::PaintEvent& event)
|
||||||
};
|
};
|
||||||
text_rect.center_vertically_within(frame_inner_rect());
|
text_rect.center_vertically_within(frame_inner_rect());
|
||||||
|
|
||||||
painter.draw_text(text_rect, m_text, Gfx::TextAlignment::CenterLeft);
|
auto& font = m_selected ? painter.font().bold_variant() : painter.font();
|
||||||
|
auto color = m_selected ? palette().selection_text() : palette().button_text();
|
||||||
|
painter.draw_text(text_rect, m_text, font, Gfx::TextAlignment::CenterLeft, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimelineHeader::update_selection()
|
||||||
|
{
|
||||||
|
m_selected = m_profile.has_process_filter() && m_profile.process_filter_contains(m_process.pid, m_process.start_valid);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimelineHeader::mousedown_event(GUI::MouseEvent& event)
|
||||||
|
{
|
||||||
|
if (event.button() != GUI::MouseButton::Left)
|
||||||
|
return;
|
||||||
|
m_selected = !m_selected;
|
||||||
|
on_selection_change(m_selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
namespace Profiler {
|
namespace Profiler {
|
||||||
|
|
||||||
|
class Profile;
|
||||||
class Process;
|
class Process;
|
||||||
|
|
||||||
class TimelineHeader final : public GUI::Frame {
|
class TimelineHeader final : public GUI::Frame {
|
||||||
|
@ -18,14 +19,21 @@ class TimelineHeader final : public GUI::Frame {
|
||||||
public:
|
public:
|
||||||
virtual ~TimelineHeader();
|
virtual ~TimelineHeader();
|
||||||
|
|
||||||
|
Function<void(bool)> on_selection_change;
|
||||||
|
|
||||||
|
void update_selection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimelineHeader(Process const&);
|
TimelineHeader(Profile& profile, Process const&);
|
||||||
|
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
|
|
||||||
|
Profile& m_profile;
|
||||||
Process const& m_process;
|
Process const& m_process;
|
||||||
RefPtr<Gfx::Bitmap> m_icon;
|
RefPtr<Gfx::Bitmap> m_icon;
|
||||||
String m_text;
|
String m_text;
|
||||||
|
bool m_selected;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,20 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
if (!event_count)
|
if (!event_count)
|
||||||
continue;
|
continue;
|
||||||
timeline_header_container->add<TimelineHeader>(process);
|
auto& timeline_header = timeline_header_container->add<TimelineHeader>(*profile, process);
|
||||||
|
timeline_header.set_shrink_to_fit(true);
|
||||||
|
timeline_header.on_selection_change = [&](bool selected) {
|
||||||
|
if (selected) {
|
||||||
|
auto end_valid = process.end_valid == 0 ? profile->last_timestamp() : process.end_valid;
|
||||||
|
profile->set_process_filter(process.pid, process.start_valid, end_valid);
|
||||||
|
} else
|
||||||
|
profile->clear_process_filter();
|
||||||
|
|
||||||
|
timeline_header_container->for_each_child_widget([](auto& other_timeline_header) {
|
||||||
|
static_cast<TimelineHeader&>(other_timeline_header).update_selection();
|
||||||
|
return IterationDecision::Continue;
|
||||||
|
});
|
||||||
|
};
|
||||||
timeline_view->add<TimelineTrack>(*timeline_view, *profile, process);
|
timeline_view->add<TimelineTrack>(*timeline_view, *profile, process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue