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.cpp111
1 files changed, 2 insertions, 109 deletions
diff --git a/src/citra_qt/debugger/profiler.cpp b/src/citra_qt/debugger/profiler.cpp
index cee10403d..f060bbe08 100644
--- a/src/citra_qt/debugger/profiler.cpp
+++ b/src/citra_qt/debugger/profiler.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <QAction>
6#include <QLayout>
5#include <QMouseEvent> 7#include <QMouseEvent>
6#include <QPainter> 8#include <QPainter>
7#include <QString> 9#include <QString>
@@ -9,121 +11,12 @@
9#include "citra_qt/util/util.h" 11#include "citra_qt/util/util.h"
10#include "common/common_types.h" 12#include "common/common_types.h"
11#include "common/microprofile.h" 13#include "common/microprofile.h"
12#include "common/profiler_reporting.h"
13 14
14// Include the implementation of the UI in this file. This isn't in microprofile.cpp because the 15// Include the implementation of the UI in this file. This isn't in microprofile.cpp because the
15// non-Qt frontends don't need it (and don't implement the UI drawing hooks either). 16// non-Qt frontends don't need it (and don't implement the UI drawing hooks either).
16#if MICROPROFILE_ENABLED 17#if MICROPROFILE_ENABLED
17#define MICROPROFILEUI_IMPL 1 18#define MICROPROFILEUI_IMPL 1
18#include "common/microprofileui.h" 19#include "common/microprofileui.h"
19#endif
20
21using namespace Common::Profiling;
22
23static QVariant GetDataForColumn(int col, const AggregatedDuration& duration) {
24 static auto duration_to_float = [](Duration dur) -> float {
25 using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>;
26 return std::chrono::duration_cast<FloatMs>(dur).count();
27 };
28
29 switch (col) {
30 case 1:
31 return duration_to_float(duration.avg);
32 case 2:
33 return duration_to_float(duration.min);
34 case 3:
35 return duration_to_float(duration.max);
36 default:
37 return QVariant();
38 }
39}
40
41ProfilerModel::ProfilerModel(QObject* parent) : QAbstractItemModel(parent) {
42 updateProfilingInfo();
43}
44
45QVariant ProfilerModel::headerData(int section, Qt::Orientation orientation, int role) const {
46 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
47 switch (section) {
48 case 0:
49 return tr("Category");
50 case 1:
51 return tr("Avg");
52 case 2:
53 return tr("Min");
54 case 3:
55 return tr("Max");
56 }
57 }
58
59 return QVariant();
60}
61
62QModelIndex ProfilerModel::index(int row, int column, const QModelIndex& parent) const {
63 return createIndex(row, column);
64}
65
66QModelIndex ProfilerModel::parent(const QModelIndex& child) const {
67 return QModelIndex();
68}
69
70int ProfilerModel::columnCount(const QModelIndex& parent) const {
71 return 4;
72}
73
74int ProfilerModel::rowCount(const QModelIndex& parent) const {
75 if (parent.isValid()) {
76 return 0;
77 } else {
78 return 2;
79 }
80}
81
82QVariant ProfilerModel::data(const QModelIndex& index, int role) const {
83 if (role == Qt::DisplayRole) {
84 if (index.row() == 0) {
85 if (index.column() == 0) {
86 return tr("Frame");
87 } else {
88 return GetDataForColumn(index.column(), results.frame_time);
89 }
90 } else if (index.row() == 1) {
91 if (index.column() == 0) {
92 return tr("Frame (with swapping)");
93 } else {
94 return GetDataForColumn(index.column(), results.interframe_time);
95 }
96 }
97 }
98
99 return QVariant();
100}
101
102void ProfilerModel::updateProfilingInfo() {
103 results = GetTimingResultsAggregator()->GetAggregatedResults();
104 emit dataChanged(createIndex(0, 1), createIndex(rowCount() - 1, 3));
105}
106
107ProfilerWidget::ProfilerWidget(QWidget* parent) : QDockWidget(parent) {
108 ui.setupUi(this);
109
110 model = new ProfilerModel(this);
111 ui.treeView->setModel(model);
112
113 connect(this, SIGNAL(visibilityChanged(bool)), SLOT(setProfilingInfoUpdateEnabled(bool)));
114 connect(&update_timer, SIGNAL(timeout()), model, SLOT(updateProfilingInfo()));
115}
116
117void ProfilerWidget::setProfilingInfoUpdateEnabled(bool enable) {
118 if (enable) {
119 update_timer.start(100);
120 model->updateProfilingInfo();
121 } else {
122 update_timer.stop();
123 }
124}
125
126#if MICROPROFILE_ENABLED
127 20
128class MicroProfileWidget : public QWidget { 21class MicroProfileWidget : public QWidget {
129public: 22public: