Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
SubTrace.cpp
1/*
2 * Marvelous OTF2 Traces Interactive Visualizer (MOTIV)
3 * Copyright (C) 2023 Florian Gallrein, Björn Gehrke
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "SubTrace.hpp"
19#include "Range.hpp"
20
21#include <utility>
22
23
24SubTrace::SubTrace(std::map<otf2::definition::location_group *, Range<Slot *>, LocationGroupCmp> &slots,
25 const Range<Communication *> &communications,
26 const Range<CollectiveCommunicationEvent *> &collectiveCommunications,
27 const otf2::chrono::duration &runtime,
28 const otf2::chrono::duration &startTime) :
29 slots_(std::move(slots)),
30 communications_(communications),
31 collectiveCommunications_(collectiveCommunications),
32 runtime_(runtime),
33 startTime_(startTime) {}
34
36 : slots_(),
37 communications_(),
38 collectiveCommunications_(),
39 runtime_(),
40 startTime_() {};
41
42std::map<otf2::definition::location_group *, Range<Slot *>, LocationGroupCmp> SubTrace::getSlots() const {
43 return slots_;
44}
45
46otf2::chrono::duration SubTrace::getRuntime() const {
47 return runtime_;
48}
49
51 return communications_;
52}
53
56}
57
58otf2::chrono::duration SubTrace::getStartTime() const {
59 return startTime_;
60}
61
62
63template<typename T>
64using TimeAccessor = std::function<otf2::chrono::duration(T const &)>;
65
66
67namespace accessors {
68 const TimeAccessor<Slot *> slotStart = &Slot::startTime;
69 const TimeAccessor<Slot *> slotEnd = &Slot::endTime;
70
71 const TimeAccessor<CommunicationEvent *> communicationEventStart = &CommunicationEvent::getStartTime;
72 const TimeAccessor<CommunicationEvent *> communicationEventEnd = &CommunicationEvent::getEndTime;
73
74 const TimeAccessor<Communication *> communicationStart = [](
75 const Communication *e) { return e->getStartEvent()->getStartTime(); };
76 const TimeAccessor<Communication *> communicationEnd = [](const Communication *e) { return e->getEndEvent()->getEndTime(); };
77};
78
79template<typename T>
80static Range<T> subRange(Range<T> r, otf2::chrono::duration from, otf2::chrono::duration to, TimeAccessor<T> getStart,
81 TimeAccessor<T> getEnd) {
82 std::vector<T> newVec;
83 std::copy_if(r.begin(), r.end(), std::back_inserter(newVec), [from, to, getStart, getEnd](T x) {
84 return getStart(x) < to && getEnd(x) > from;
85 });
86
87 Range<T> newRange(newVec);
88
89 return newRange;
90}
91
92
93Trace *SubTrace::subtrace(otf2::chrono::duration from, otf2::chrono::duration to) {
94 std::map<otf2::definition::location_group *, Range<Slot *>, LocationGroupCmp> newSlots;
95 for (const auto &item: getSlots()) {
96 Range<Slot *> slots = subRange(item.second, from, to, accessors::slotStart, accessors::slotEnd);
97 std::sort(slots.begin(), slots.end(), [](const Slot* lhs, const Slot* rhs) {return lhs->startTime < rhs->startTime;});
98 newSlots.insert({item.first, slots});
99 }
100 auto newCommunications = subRange(getCommunications(), from, to, accessors::communicationStart,
101 accessors::communicationEnd);
102 auto newCollectiveCommunications = subRange<CollectiveCommunicationEvent *>(getCollectiveCommunications(),
103 from,
104 to,
105 accessors::communicationEventStart,
106 accessors::communicationEventEnd);
107
108 auto trace = new SubTrace(newSlots, newCommunications, newCollectiveCommunications, to - from, from);
109
110 return trace;
111}
112
113types::TraceTime SubTrace::getEndTime() const {
114 return startTime_ + runtime_;
115}
116
117types::TraceTime SubTrace::getDuration() const {
118 return runtime_;
119}
120
otf2::chrono::duration getEndTime() const override=0
otf2::chrono::duration getStartTime() const override=0
Class representing any (successful or unsuccessful) communication.
A custom range implementation around std::vector<T>s.
Definition: Range.hpp:37
It end() const
Definition: Range.hpp:121
It begin() const
Definition: Range.hpp:114
A Slot represents a visual slot to be rendered in the UI. It contains the information of a location.
Definition: Slot.hpp:37
types::TraceTime endTime
End time of the slot relative to the trace start time.
Definition: Slot.hpp:60
otf2::chrono::duration startTime
Start time of the slot relative to the trace start time.
Definition: Slot.hpp:55
std::map< otf2::definition::location_group *, Range< Slot * >, LocationGroupCmp > slots_
Definition: SubTrace.hpp:76
Trace * subtrace(otf2::chrono::duration from, otf2::chrono::duration to) override
Creates a subtrace of the current trace.
Definition: SubTrace.cpp:93
Range< CollectiveCommunicationEvent * > collectiveCommunications_
Definition: SubTrace.hpp:86
types::TraceTime getEndTime() const override
Returns the end time of the current object.
Definition: SubTrace.cpp:113
otf2::chrono::duration startTime_
Definition: SubTrace.hpp:96
otf2::chrono::duration getStartTime() const override
Returns the start time of the current object.
Definition: SubTrace.cpp:58
Range< Communication * > getCommunications() override
Returns communication objects of the current trace.
Definition: SubTrace.cpp:50
std::map< otf2::definition::location_group *, Range< Slot * >, LocationGroupCmp > getSlots() const override
Returns a map of slots of the current trace.
Definition: SubTrace.cpp:42
otf2::chrono::duration runtime_
Definition: SubTrace.hpp:91
Range< CollectiveCommunicationEvent * > getCollectiveCommunications() override
Returns communication objects of the current trace.
Definition: SubTrace.cpp:54
SubTrace()
Definition: SubTrace.cpp:35
types::TraceTime getDuration() const override
Returns the duration of the current object.
Definition: SubTrace.cpp:117
Range< Communication * > communications_
Definition: SubTrace.hpp:81
otf2::chrono::duration getRuntime() const override
Returns the runtime of the current trace.
Definition: SubTrace.cpp:46
Abstract base class for a trace.
Definition: Trace.hpp:52
A comparator for otf2::definition::location_group objects.
Definition: Trace.hpp:34