summaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/profiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/debugger/profiler.cpp')
-rw-r--r--src/citra_qt/debugger/profiler.cpp72
1 files changed, 33 insertions, 39 deletions
diff --git a/src/citra_qt/debugger/profiler.cpp b/src/citra_qt/debugger/profiler.cpp
index 17898f54b..cee10403d 100644
--- a/src/citra_qt/debugger/profiler.cpp
+++ b/src/citra_qt/debugger/profiler.cpp
@@ -5,10 +5,8 @@
5#include <QMouseEvent> 5#include <QMouseEvent>
6#include <QPainter> 6#include <QPainter>
7#include <QString> 7#include <QString>
8
9#include "citra_qt/debugger/profiler.h" 8#include "citra_qt/debugger/profiler.h"
10#include "citra_qt/util/util.h" 9#include "citra_qt/util/util.h"
11
12#include "common/common_types.h" 10#include "common/common_types.h"
13#include "common/microprofile.h" 11#include "common/microprofile.h"
14#include "common/profiler_reporting.h" 12#include "common/profiler_reporting.h"
@@ -22,57 +20,58 @@
22 20
23using namespace Common::Profiling; 21using namespace Common::Profiling;
24 22
25static QVariant GetDataForColumn(int col, const AggregatedDuration& duration) 23static QVariant GetDataForColumn(int col, const AggregatedDuration& duration) {
26{
27 static auto duration_to_float = [](Duration dur) -> float { 24 static auto duration_to_float = [](Duration dur) -> float {
28 using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>; 25 using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>;
29 return std::chrono::duration_cast<FloatMs>(dur).count(); 26 return std::chrono::duration_cast<FloatMs>(dur).count();
30 }; 27 };
31 28
32 switch (col) { 29 switch (col) {
33 case 1: return duration_to_float(duration.avg); 30 case 1:
34 case 2: return duration_to_float(duration.min); 31 return duration_to_float(duration.avg);
35 case 3: return duration_to_float(duration.max); 32 case 2:
36 default: return QVariant(); 33 return duration_to_float(duration.min);
34 case 3:
35 return duration_to_float(duration.max);
36 default:
37 return QVariant();
37 } 38 }
38} 39}
39 40
40ProfilerModel::ProfilerModel(QObject* parent) : QAbstractItemModel(parent) 41ProfilerModel::ProfilerModel(QObject* parent) : QAbstractItemModel(parent) {
41{
42 updateProfilingInfo(); 42 updateProfilingInfo();
43} 43}
44 44
45QVariant ProfilerModel::headerData(int section, Qt::Orientation orientation, int role) const 45QVariant ProfilerModel::headerData(int section, Qt::Orientation orientation, int role) const {
46{
47 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { 46 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
48 switch (section) { 47 switch (section) {
49 case 0: return tr("Category"); 48 case 0:
50 case 1: return tr("Avg"); 49 return tr("Category");
51 case 2: return tr("Min"); 50 case 1:
52 case 3: return tr("Max"); 51 return tr("Avg");
52 case 2:
53 return tr("Min");
54 case 3:
55 return tr("Max");
53 } 56 }
54 } 57 }
55 58
56 return QVariant(); 59 return QVariant();
57} 60}
58 61
59QModelIndex ProfilerModel::index(int row, int column, const QModelIndex& parent) const 62QModelIndex ProfilerModel::index(int row, int column, const QModelIndex& parent) const {
60{
61 return createIndex(row, column); 63 return createIndex(row, column);
62} 64}
63 65
64QModelIndex ProfilerModel::parent(const QModelIndex& child) const 66QModelIndex ProfilerModel::parent(const QModelIndex& child) const {
65{
66 return QModelIndex(); 67 return QModelIndex();
67} 68}
68 69
69int ProfilerModel::columnCount(const QModelIndex& parent) const 70int ProfilerModel::columnCount(const QModelIndex& parent) const {
70{
71 return 4; 71 return 4;
72} 72}
73 73
74int ProfilerModel::rowCount(const QModelIndex& parent) const 74int ProfilerModel::rowCount(const QModelIndex& parent) const {
75{
76 if (parent.isValid()) { 75 if (parent.isValid()) {
77 return 0; 76 return 0;
78 } else { 77 } else {
@@ -80,8 +79,7 @@ int ProfilerModel::rowCount(const QModelIndex& parent) const
80 } 79 }
81} 80}
82 81
83QVariant ProfilerModel::data(const QModelIndex& index, int role) const 82QVariant ProfilerModel::data(const QModelIndex& index, int role) const {
84{
85 if (role == Qt::DisplayRole) { 83 if (role == Qt::DisplayRole) {
86 if (index.row() == 0) { 84 if (index.row() == 0) {
87 if (index.column() == 0) { 85 if (index.column() == 0) {
@@ -101,14 +99,12 @@ QVariant ProfilerModel::data(const QModelIndex& index, int role) const
101 return QVariant(); 99 return QVariant();
102} 100}
103 101
104void ProfilerModel::updateProfilingInfo() 102void ProfilerModel::updateProfilingInfo() {
105{
106 results = GetTimingResultsAggregator()->GetAggregatedResults(); 103 results = GetTimingResultsAggregator()->GetAggregatedResults();
107 emit dataChanged(createIndex(0, 1), createIndex(rowCount() - 1, 3)); 104 emit dataChanged(createIndex(0, 1), createIndex(rowCount() - 1, 3));
108} 105}
109 106
110ProfilerWidget::ProfilerWidget(QWidget* parent) : QDockWidget(parent) 107ProfilerWidget::ProfilerWidget(QWidget* parent) : QDockWidget(parent) {
111{
112 ui.setupUi(this); 108 ui.setupUi(this);
113 109
114 model = new ProfilerModel(this); 110 model = new ProfilerModel(this);
@@ -118,8 +114,7 @@ ProfilerWidget::ProfilerWidget(QWidget* parent) : QDockWidget(parent)
118 connect(&update_timer, SIGNAL(timeout()), model, SLOT(updateProfilingInfo())); 114 connect(&update_timer, SIGNAL(timeout()), model, SLOT(updateProfilingInfo()));
119} 115}
120 116
121void ProfilerWidget::setProfilingInfoUpdateEnabled(bool enable) 117void ProfilerWidget::setProfilingInfoUpdateEnabled(bool enable) {
122{
123 if (enable) { 118 if (enable) {
124 update_timer.start(100); 119 update_timer.start(100);
125 model->updateProfilingInfo(); 120 model->updateProfilingInfo();
@@ -157,9 +152,7 @@ private:
157 152
158#endif 153#endif
159 154
160MicroProfileDialog::MicroProfileDialog(QWidget* parent) 155MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {
161 : QWidget(parent, Qt::Dialog)
162{
163 setObjectName("MicroProfile"); 156 setObjectName("MicroProfile");
164 setWindowTitle(tr("MicroProfile")); 157 setWindowTitle(tr("MicroProfile"));
165 resize(1000, 600); 158 resize(1000, 600);
@@ -175,7 +168,8 @@ MicroProfileDialog::MicroProfileDialog(QWidget* parent)
175 layout->addWidget(widget); 168 layout->addWidget(widget);
176 setLayout(layout); 169 setLayout(layout);
177 170
178 // Configure focus so that widget is focusable and the dialog automatically forwards focus to it. 171 // Configure focus so that widget is focusable and the dialog automatically forwards focus to
172 // it.
179 setFocusProxy(widget); 173 setFocusProxy(widget);
180 widget->setFocusPolicy(Qt::StrongFocus); 174 widget->setFocusPolicy(Qt::StrongFocus);
181 widget->setFocus(); 175 widget->setFocus();
@@ -207,7 +201,6 @@ void MicroProfileDialog::hideEvent(QHideEvent* ev) {
207 QWidget::hideEvent(ev); 201 QWidget::hideEvent(ev);
208} 202}
209 203
210
211#if MICROPROFILE_ENABLED 204#if MICROPROFILE_ENABLED
212 205
213/// There's no way to pass a user pointer to MicroProfile, so this variable is used to make the 206/// There's no way to pass a user pointer to MicroProfile, so this variable is used to make the
@@ -308,7 +301,8 @@ void MicroProfileDrawText(int x, int y, u32 hex_color, const char* text, u32 tex
308 } 301 }
309} 302}
310 303
311void MicroProfileDrawBox(int left, int top, int right, int bottom, u32 hex_color, MicroProfileBoxType type) { 304void MicroProfileDrawBox(int left, int top, int right, int bottom, u32 hex_color,
305 MicroProfileBoxType type) {
312 QColor color = QColor::fromRgba(hex_color); 306 QColor color = QColor::fromRgba(hex_color);
313 QBrush brush = color; 307 QBrush brush = color;
314 if (type == MicroProfileBoxTypeBar) { 308 if (type == MicroProfileBoxTypeBar) {
@@ -326,7 +320,7 @@ void MicroProfileDrawLine2D(u32 vertices_length, float* vertices, u32 hex_color)
326 static std::vector<QPointF> point_buf; 320 static std::vector<QPointF> point_buf;
327 321
328 for (u32 i = 0; i < vertices_length; ++i) { 322 for (u32 i = 0; i < vertices_length; ++i) {
329 point_buf.emplace_back(vertices[i*2 + 0], vertices[i*2 + 1]); 323 point_buf.emplace_back(vertices[i * 2 + 0], vertices[i * 2 + 1]);
330 } 324 }
331 325
332 // hex_color does not include an alpha, so it must be assumed to be 255 326 // hex_color does not include an alpha, so it must be assumed to be 255