mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 17:05:07 +00:00
ProfileViewer: Add a timeline widget for a visual view of the profile
Userspace stack frames are in blue, kernel stack frames in red :^)
This commit is contained in:
parent
46a57c7f59
commit
a3e7c99ffe
6 changed files with 121 additions and 16 deletions
53
DevTools/ProfileViewer/ProfileTimelineWidget.cpp
Normal file
53
DevTools/ProfileViewer/ProfileTimelineWidget.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "ProfileTimelineWidget.h"
|
||||
#include "Profile.h"
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
||||
ProfileTimelineWidget::ProfileTimelineWidget(Profile& profile, GWidget* parent)
|
||||
: GFrame(parent)
|
||||
, m_profile(profile)
|
||||
{
|
||||
set_frame_thickness(2);
|
||||
set_frame_shadow(FrameShadow::Sunken);
|
||||
set_frame_shape(FrameShape::Container);
|
||||
set_background_color(Color::White);
|
||||
set_fill_with_background_color(true);
|
||||
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
set_preferred_size(0, 80);
|
||||
}
|
||||
|
||||
ProfileTimelineWidget::~ProfileTimelineWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfileTimelineWidget::paint_event(GPaintEvent& event)
|
||||
{
|
||||
GFrame::paint_event(event);
|
||||
|
||||
GPainter painter(*this);
|
||||
painter.add_clip_rect(event.rect());
|
||||
|
||||
float column_width = (float)frame_inner_rect().width() / (float)m_profile.length_in_ms();
|
||||
|
||||
m_profile.for_each_sample([&](const JsonObject& sample) {
|
||||
u64 t = sample.get("timestamp").to_number<u64>() - m_profile.first_timestamp();
|
||||
int x = (int)((float)t * column_width);
|
||||
int cw = max(1, (int)column_width);
|
||||
|
||||
bool in_kernel = sample.get("frames").as_array().at(1).as_object().get("address").to_number<u32>() < (8 * MB);
|
||||
Color color = in_kernel ? Color::from_rgb(0xc25e5a) : Color::from_rgb(0x5a65c2);
|
||||
for (int i = 0; i < cw; ++i)
|
||||
painter.draw_line({ x + i, frame_thickness() }, { x + i, height() - frame_thickness() * 2 }, color);
|
||||
});
|
||||
}
|
||||
|
||||
void ProfileTimelineWidget::mousedown_event(GMouseEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void ProfileTimelineWidget::mousemove_event(GMouseEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void ProfileTimelineWidget::mouseup_event(GMouseEvent&)
|
||||
{
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue