aboutsummaryrefslogtreecommitdiff
path: root/profiling/server/include/timelineDecoder/TimelineDecoder.hpp
blob: 9776ec91f9a0a4da70aa08606de22f1eb0f17b04 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once

#include "ITimelineDecoder.hpp"

#include <mutex>
#include <utility>
#include <vector>

namespace arm
{

namespace pipe
{

class TimelineDecoder : public ITimelineDecoder
{

public:

    struct Model
    {
        std::vector<Entity> m_Entities;
        std::vector<EventClass> m_EventClasses;
        std::vector<Event> m_Events;
        std::vector<Label> m_Labels;
        std::vector<Relationship> m_Relationships;
    };

    using OnNewEntityCallback       =  void (*)(Model &, const Entity);
    using OnNewEventClassCallback   =  void (*)(Model &, const EventClass);
    using OnNewEventCallback        =  void (*)(Model &, const Event);
    using OnNewLabelCallback        =  void (*)(Model &, const Label);
    using OnNewRelationshipCallback =  void (*)(Model &, const Relationship);

    virtual TimelineStatus CreateEntity(const Entity &) override;
    virtual TimelineStatus CreateEventClass(const EventClass &) override;
    virtual TimelineStatus CreateEvent(const Event &) override;
    virtual TimelineStatus CreateLabel(const Label &) override;
    virtual TimelineStatus CreateRelationship(const Relationship &) override;

    template<class F>
    decltype(auto) ApplyToModel(F&& f){
        std::lock_guard<std::mutex> lock(m_ModelMutex);
        return f(m_Model);
    }

    TimelineStatus SetEntityCallback(const OnNewEntityCallback);
    TimelineStatus SetEventClassCallback(const OnNewEventClassCallback);
    TimelineStatus SetEventCallback(const OnNewEventCallback);
    TimelineStatus SetLabelCallback(const OnNewLabelCallback);
    TimelineStatus SetRelationshipCallback(const OnNewRelationshipCallback);

    void SetDefaultCallbacks();

    void print();

private:
    Model m_Model;
    std::mutex m_ModelMutex;

    OnNewEntityCallback m_OnNewEntityCallback;
    OnNewEventClassCallback m_OnNewEventClassCallback;
    OnNewEventCallback m_OnNewEventCallback;
    OnNewLabelCallback m_OnNewLabelCallback;
    OnNewRelationshipCallback m_OnNewRelationshipCallback;

    void printLabels();
    void printEntities();
    void printEventClasses();
    void printRelationships();
    void printEvents();
};

} // namespace pipe
} // namespace arm