summaryrefslogtreecommitdiff
path: root/Userland/DevTools/Profiler/FlameGraphView.h
blob: 00714047c743b0c6a0225f657c27275f8a7e5641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * 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 = default;

    Function<void()> on_hover_change;

    GUI::ModelIndex 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;
    };

    String bar_label(StackBar const&) const;
    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;
};

}