Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
TraceOverviewTimelineView.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 "TraceOverviewTimelineView.hpp"
19#include "src/ui/views/CommunicationIndicator.hpp"
20#include "src/ui/Constants.hpp"
21#include "src/models/UITrace.hpp"
22
23#include <QGraphicsRectItem>
24#include <QApplication>
25#include <QWheelEvent>
26#include <QRubberBand>
27
28TraceOverviewTimelineView::TraceOverviewTimelineView(Trace *fullTrace, QWidget *parent) : QGraphicsView(parent), fullTrace(fullTrace) {
29 auto scene = new QGraphicsScene(this);
30 this->setAutoFillBackground(false);
31 this->setStyleSheet("background: transparent");
32 this->setScene(scene);
33 this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
34
35 selectionFrom = types::TraceTime(0);
36 selectionTo = fullTrace->getRuntime();
37}
38
39
40void TraceOverviewTimelineView::populateScene(QGraphicsScene *scene) {
41 auto width = scene->width();
42 auto runtime = uiTrace->getRuntime().count();
43 auto begin = 0;
44 auto end = begin + runtime;
45
46 qreal top = 0;
47 auto ROW_HEIGHT = scene->height() / static_cast<qreal>(uiTrace->getSlots().size());
48 for (const auto &item: uiTrace->getSlots()) {
49 // Display slots
50 for (const auto &slot: item.second) {
51 auto startTime = slot->startTime.count();
52 auto endTime = slot->endTime.count();
53
54
55 // Ensures slots starting before `begin` (like main) are considered to start at begin
56 auto effectiveStartTime = qMax(begin, startTime);
57 // Ensures slots ending after `end` (like main) are considered to end at end
58 auto effectiveEndTime = qMin(end, endTime);
59
60 auto slotBeginPos = qMax(0.0,
61 (static_cast<qreal>(effectiveStartTime - begin) / static_cast<qreal>(runtime)) *
62 width);
63 auto slotRuntime = static_cast<qreal>(effectiveEndTime - effectiveStartTime);
64 auto rectWidth = (slotRuntime / static_cast<qreal>(runtime)) * width;
65
66 QRectF rect(slotBeginPos, top, qMax(rectWidth, 5.0), ROW_HEIGHT);
67 auto rectItem = scene->addRect(rect);
68
69 // Determine color based on name
70 QColor rectColor;
71 switch (slot->getKind()) {
72 case ::MPI:
73 rectColor = colors::COLOR_SLOT_MPI;
74 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 2);
75 break;
76 case ::OpenMP:
77 rectColor = colors::COLOR_SLOT_OPEN_MP;
78 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 1);
79 break;
80 case ::None:
81 case ::Plain:
82 rectColor = colors::COLOR_SLOT_PLAIN;
83 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 0);
84 break;
85 }
86
87 rectItem->setBrush(rectColor);
88 }
89
90 top += ROW_HEIGHT;
91 }
92
93 QPen selectionPen(Qt::black);
94 QBrush selectionBrush(QColor(0xFF, 0xFF, 0xFF, 0x7F));
95 selectionRectRight = scene->addRect(width - 1,0, 0, top, selectionPen, selectionBrush);
96 selectionRectRight->setZValue(layers::Z_LAYER_SELECTION);
97 selectionRectLeft = scene->addRect(0,0, 0, top, selectionPen, selectionBrush);
98 selectionRectLeft->setZValue(layers::Z_LAYER_SELECTION);
99
100 setSelectionWindow(selectionFrom, selectionTo);
101}
102
103
104void TraceOverviewTimelineView::resizeEvent(QResizeEvent *event) {
105 uiTrace = UITrace::forResolution(fullTrace, event->size().width());
106
107 this->updateView();
108 QGraphicsView::resizeEvent(event);
109}
110
112 this->scene()->clear();
113
114 auto sceneRect = this->rect();
115 sceneRect.setHeight(size().height() - 2);
116
117 this->scene()->setSceneRect(sceneRect);
118 this->populateScene(this->scene());
119}
120
121void TraceOverviewTimelineView::setSelectionWindow(types::TraceTime from, types::TraceTime to) {
122 selectionFrom = from;
123 selectionTo = to;
124 auto durationR = static_cast<qreal>(uiTrace->getRuntime().count());
125 auto fromR = static_cast<qreal>(from.count());
126 auto toR = static_cast<qreal>(to.count());
127 auto width = this->width();
128
129 auto l = selectionRectLeft->rect();
130 l.setWidth(fromR / durationR * width);
131 selectionRectLeft->setRect(l);
132
133 auto r = selectionRectRight->rect();
134 r.setX(toR / durationR * width);
135 selectionRectRight->setRect(r);
136}
137
138
139
141{
142 rubberBandOrigin = event->pos();
143 rubberBandOrigin.setY(0);
144 if (!rubberBand)
145 rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
146 rubberBand->setGeometry(QRect(rubberBandOrigin, QSize(0, this->height())));
147 rubberBand->show();
148}
149
151{
152 auto nextPoint = event->pos();
153 nextPoint.setY(this->height());
154 rubberBand->setGeometry(QRect(rubberBandOrigin, nextPoint).normalized());
155}
156
158{
159 rubberBand->hide();
160
161 auto from = (rubberBand->geometry().x() * fullTrace->getRuntime()) / this->width();
162 auto to = from + (rubberBand->geometry().width() * fullTrace->getRuntime()) / this->width();
163
164 Q_EMIT windowSelectionChanged(from, to);
165}
void windowSelectionChanged(types::TraceTime from, types::TraceTime to)
Signals a change in the selection.
void mousePressEvent(QMouseEvent *event) override
void updateView()
Updates the view to reflect the current selection of the TraceDataProxy.
void setSelectionWindow(types::TraceTime from, types::TraceTime to)
Set a new selection window. The UI is updated to reflect the changes.
void mouseMoveEvent(QMouseEvent *event) override
TraceOverviewTimelineView(Trace *fullTrace, QWidget *parent=nullptr)
Creates a new instance of the TraceOverviewTimelineView class.
void resizeEvent(QResizeEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
Abstract base class for a trace.
Definition: Trace.hpp:52
virtual otf2::chrono::duration getRuntime() const =0
Returns the runtime of the current trace.
virtual std::map< otf2::definition::location_group *, Range< Slot * >, LocationGroupCmp > getSlots() const =0
Returns a map of slots of the current trace.
static UITrace * forResolution(Trace *trace, otf2::chrono::duration timePerPixel)
Definition: UITrace.cpp:43