mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +00:00
Profiler: Add a flamegraph view for the stack
The flamegraph makes it easier to quickly spot expensive functions, based on the width of their bar.
This commit is contained in:
parent
4fe380f6da
commit
0d98bba167
4 changed files with 312 additions and 10 deletions
60
Userland/DevTools/Profiler/FlameGraphView.h
Normal file
60
Userland/DevTools/Profiler/FlameGraphView.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Nicholas Hollett <niax@niax.co.uk>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Profile.h"
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGfx/Color.h>
|
||||
|
||||
namespace Profiler {
|
||||
|
||||
class FlameGraphView final : public GUI::Widget
|
||||
, GUI::ModelClient {
|
||||
C_OBJECT(FlameGraphView);
|
||||
|
||||
public:
|
||||
virtual ~FlameGraphView() override;
|
||||
|
||||
Function<void()> on_hover_change;
|
||||
|
||||
GUI::ModelIndex const hovered_index() const;
|
||||
|
||||
protected:
|
||||
virtual void model_did_update(unsigned flags) override;
|
||||
|
||||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||
|
||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
|
||||
private:
|
||||
explicit FlameGraphView(GUI::Model&, int text_column, int width_column);
|
||||
|
||||
struct StackBar {
|
||||
GUI::ModelIndex const index;
|
||||
Gfx::IntRect rect;
|
||||
bool selected;
|
||||
};
|
||||
|
||||
void layout_bars();
|
||||
void layout_children(GUI::ModelIndex& parent, int depth, int left, int right, Vector<GUI::ModelIndex>& selected);
|
||||
|
||||
GUI::Model& m_model;
|
||||
int m_text_column { -1 };
|
||||
int m_width_column { -1 };
|
||||
Vector<Gfx::Color> m_colors;
|
||||
Vector<StackBar> m_bars;
|
||||
StackBar* m_hovered_bar {};
|
||||
Vector<GUI::ModelIndex> m_selected_indexes;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue