diff options
Diffstat (limited to 'src/citra_qt/debugger/profiler.cpp')
| -rw-r--r-- | src/citra_qt/debugger/profiler.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/citra_qt/debugger/profiler.cpp b/src/citra_qt/debugger/profiler.cpp new file mode 100644 index 000000000..ae0568b6a --- /dev/null +++ b/src/citra_qt/debugger/profiler.cpp | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "profiler.h" | ||
| 6 | |||
| 7 | #include "common/profiler_reporting.h" | ||
| 8 | |||
| 9 | using namespace Common::Profiling; | ||
| 10 | |||
| 11 | static QVariant GetDataForColumn(int col, const AggregatedDuration& duration) | ||
| 12 | { | ||
| 13 | static auto duration_to_float = [](Duration dur) -> float { | ||
| 14 | using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>; | ||
| 15 | return std::chrono::duration_cast<FloatMs>(dur).count(); | ||
| 16 | }; | ||
| 17 | |||
| 18 | switch (col) { | ||
| 19 | case 1: return duration_to_float(duration.avg); | ||
| 20 | case 2: return duration_to_float(duration.min); | ||
| 21 | case 3: return duration_to_float(duration.max); | ||
| 22 | default: return QVariant(); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | static const TimingCategoryInfo* GetCategoryInfo(int id) | ||
| 27 | { | ||
| 28 | const auto& categories = GetProfilingManager().GetTimingCategoriesInfo(); | ||
| 29 | if (id >= categories.size()) { | ||
| 30 | return nullptr; | ||
| 31 | } else { | ||
| 32 | return &categories[id]; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | ProfilerModel::ProfilerModel(QObject* parent) : QAbstractItemModel(parent) | ||
| 37 | { | ||
| 38 | updateProfilingInfo(); | ||
| 39 | const auto& categories = GetProfilingManager().GetTimingCategoriesInfo(); | ||
| 40 | results.time_per_category.resize(categories.size()); | ||
| 41 | } | ||
| 42 | |||
| 43 | QVariant ProfilerModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
| 44 | { | ||
| 45 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | ||
| 46 | switch (section) { | ||
| 47 | case 0: return tr("Category"); | ||
| 48 | case 1: return tr("Avg"); | ||
| 49 | case 2: return tr("Min"); | ||
| 50 | case 3: return tr("Max"); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | return QVariant(); | ||
| 55 | } | ||
| 56 | |||
| 57 | QModelIndex ProfilerModel::index(int row, int column, const QModelIndex& parent) const | ||
| 58 | { | ||
| 59 | return createIndex(row, column); | ||
| 60 | } | ||
| 61 | |||
| 62 | QModelIndex ProfilerModel::parent(const QModelIndex& child) const | ||
| 63 | { | ||
| 64 | return QModelIndex(); | ||
| 65 | } | ||
| 66 | |||
| 67 | int ProfilerModel::columnCount(const QModelIndex& parent) const | ||
| 68 | { | ||
| 69 | return 4; | ||
| 70 | } | ||
| 71 | |||
| 72 | int ProfilerModel::rowCount(const QModelIndex& parent) const | ||
| 73 | { | ||
| 74 | if (parent.isValid()) { | ||
| 75 | return 0; | ||
| 76 | } else { | ||
| 77 | return results.time_per_category.size() + 2; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | QVariant ProfilerModel::data(const QModelIndex& index, int role) const | ||
| 82 | { | ||
| 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 | } else { | ||
| 97 | if (index.column() == 0) { | ||
| 98 | const TimingCategoryInfo* info = GetCategoryInfo(index.row() - 2); | ||
| 99 | return info != nullptr ? QString(info->name) : QVariant(); | ||
| 100 | } else { | ||
| 101 | if (index.row() - 2 < results.time_per_category.size()) { | ||
| 102 | return GetDataForColumn(index.column(), results.time_per_category[index.row() - 2]); | ||
| 103 | } else { | ||
| 104 | return QVariant(); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | return QVariant(); | ||
| 111 | } | ||
| 112 | |||
| 113 | void ProfilerModel::updateProfilingInfo() | ||
| 114 | { | ||
| 115 | results = GetTimingResultsAggregator()->GetAggregatedResults(); | ||
| 116 | emit dataChanged(createIndex(0, 1), createIndex(rowCount() - 1, 3)); | ||
| 117 | } | ||
| 118 | |||
| 119 | ProfilerWidget::ProfilerWidget(QWidget* parent) : QDockWidget(parent) | ||
| 120 | { | ||
| 121 | ui.setupUi(this); | ||
| 122 | |||
| 123 | model = new ProfilerModel(this); | ||
| 124 | ui.treeView->setModel(model); | ||
| 125 | |||
| 126 | connect(this, SIGNAL(visibilityChanged(bool)), SLOT(setProfilingInfoUpdateEnabled(bool))); | ||
| 127 | connect(&update_timer, SIGNAL(timeout()), model, SLOT(updateProfilingInfo())); | ||
| 128 | } | ||
| 129 | |||
| 130 | void ProfilerWidget::setProfilingInfoUpdateEnabled(bool enable) | ||
| 131 | { | ||
| 132 | if (enable) { | ||
| 133 | update_timer.start(100); | ||
| 134 | model->updateProfilingInfo(); | ||
| 135 | } else { | ||
| 136 | update_timer.stop(); | ||
| 137 | } | ||
| 138 | } | ||