summaryrefslogtreecommitdiff
path: root/Userland/DevTools/Profiler/TimelineTrack.h
blob: fb74dde0b6c2c9cbce6ff1866cefd1c7ffbc41eb (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
/*
 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "Histogram.h"
#include <LibGUI/Frame.h>

namespace Profiler {

struct Process;
class Profile;
class TimelineView;

class TimelineTrack final : public GUI::Frame {
    C_OBJECT(TimelineTrack);

public:
    virtual ~TimelineTrack() override;

    void set_scale(float);

private:
    float column_width() const;

    template<typename Callback>
    void for_each_signpost(Callback);

    virtual void event(Core::Event&) override;
    virtual void paint_event(GUI::PaintEvent&) override;
    virtual void mousemove_event(GUI::MouseEvent&) override;

    struct HistogramInputs {
        bool operator==(HistogramInputs const&) const = default;
        u64 start { 0 };
        u64 end { 0 };
        size_t columns { 0 };
    };

    void recompute_histograms_if_needed(HistogramInputs const&);

    explicit TimelineTrack(TimelineView const&, Profile const&, Process const&);

    TimelineView const& m_view;
    Profile const& m_profile;
    Process const& m_process;

    HistogramInputs m_cached_histogram_inputs;

    Optional<Histogram<u64>> m_kernel_histogram;
    Optional<Histogram<u64>> m_user_histogram;
    decltype(m_kernel_histogram->at(0)) m_max_value { 0 };
};

}