mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-15 02:29:51 +01:00
Make Frame Profiling a normal option and add simple % frame stats.
Might need tweaking.:]
This commit is contained in:
1 parent
1de91d79da
commit
ebf16e2a5a
11 files changed
+227
-188
No files matched your search
+177
-122
@@ -18,10 +18,13 @@
|
||||
#include <algorithm>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "Core/Config.h"
|
||||
#include "Core/HLE/sceDisplay.h"
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "ui/ui_context.h"
|
||||
#include "ui/view.h"
|
||||
#include "profiler/profiler.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
static const uint32_t nice_colors[] = {
|
||||
0xFF8040,
|
||||
@@ -52,144 +55,196 @@ enum ProfileCatStatus {
|
||||
};
|
||||
|
||||
void DrawProfile(UIContext &ui) {
|
||||
#ifdef USE_PROFILER
|
||||
PROFILE_THIS_SCOPE("timing");
|
||||
int numCategories = Profiler_GetNumCategories();
|
||||
int historyLength = Profiler_GetHistoryLength();
|
||||
if (g_Config.bShowFrameProfiler) {
|
||||
PROFILE_THIS_SCOPE("timing");
|
||||
int numCategories = Profiler_GetNumCategories();
|
||||
int historyLength = Profiler_GetHistoryLength();
|
||||
|
||||
ui.SetFontStyle(ui.theme->uiFont);
|
||||
ui.SetFontStyle(ui.theme->uiFont);
|
||||
|
||||
static float lastMaxVal = 1.0f / 60.0f;
|
||||
float legendMinVal = lastMaxVal * (1.0f / 120.0f);
|
||||
static float lastMaxVal = 1.0f / 60.0f;
|
||||
float legendMinVal = lastMaxVal * (1.0f / 120.0f);
|
||||
|
||||
std::vector<float> history(historyLength);
|
||||
std::vector<ProfileCatStatus> catStatus(numCategories);
|
||||
std::vector<float> history(historyLength);
|
||||
std::vector<ProfileCatStatus> catStatus(numCategories);
|
||||
|
||||
float rowH = 30.0f;
|
||||
float legendHeight = 0.0f;
|
||||
float legendWidth = 80.0f;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
if (!strcmp(name, "timing")) {
|
||||
catStatus[i] = PROFILE_CAT_IGNORE;
|
||||
continue;
|
||||
float rowH = 30.0f;
|
||||
float legendHeight = 0.0f;
|
||||
float legendWidth = 80.0f;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
if (!strcmp(name, "timing")) {
|
||||
catStatus[i] = PROFILE_CAT_IGNORE;
|
||||
continue;
|
||||
}
|
||||
|
||||
Profiler_GetHistory(i, &history[0], historyLength);
|
||||
catStatus[i] = PROFILE_CAT_NOLEGEND;
|
||||
for (int j = 0; j < historyLength; ++j) {
|
||||
if (history[j] > legendMinVal) {
|
||||
catStatus[i] = PROFILE_CAT_VISIBLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// So they don't move horizontally, we always measure.
|
||||
float w = 0.0f, h = 0.0f;
|
||||
ui.MeasureText(ui.GetFontStyle(), 1.0f, 1.0f, name, &w, &h);
|
||||
if (w * 1.5f > legendWidth) {
|
||||
legendWidth = w * 1.5f;
|
||||
}
|
||||
legendHeight += rowH;
|
||||
}
|
||||
legendWidth += 20.0f;
|
||||
|
||||
Profiler_GetHistory(i, &history[0], historyLength);
|
||||
catStatus[i] = PROFILE_CAT_NOLEGEND;
|
||||
for (int j = 0; j < historyLength; ++j) {
|
||||
if (history[j] > legendMinVal) {
|
||||
catStatus[i] = PROFILE_CAT_VISIBLE;
|
||||
break;
|
||||
float legendStartY = legendHeight > ui.GetBounds().centerY() ? ui.GetBounds().y2() - legendHeight : ui.GetBounds().centerY();
|
||||
float legendStartX = ui.GetBounds().x2() - std::min(legendWidth, 200.0f);
|
||||
|
||||
const uint32_t opacity = 140 << 24;
|
||||
|
||||
int legendNum = 0;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
uint32_t color = nice_colors[i % ARRAY_SIZE(nice_colors)];
|
||||
|
||||
if (catStatus[i] == PROFILE_CAT_VISIBLE) {
|
||||
float y = legendStartY + legendNum++ * rowH;
|
||||
ui.FillRect(UI::Drawable(opacity | color), Bounds(legendStartX, y, rowH - 2, rowH - 2));
|
||||
ui.DrawTextShadow(name, legendStartX + rowH + 2, y, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
}
|
||||
}
|
||||
|
||||
// So they don't move horizontally, we always measure.
|
||||
float w = 0.0f, h = 0.0f;
|
||||
ui.MeasureText(ui.GetFontStyle(), 1.0f, 1.0f, name, &w, &h);
|
||||
if (w > legendWidth) {
|
||||
legendWidth = w;
|
||||
float graphWidth = ui.GetBounds().x2() - legendWidth - 20.0f;
|
||||
float graphHeight = ui.GetBounds().h * 0.8f;
|
||||
|
||||
float dx = graphWidth / historyLength;
|
||||
|
||||
/*
|
||||
ui.Flush();
|
||||
|
||||
ui.BeginNoTex();
|
||||
*/
|
||||
|
||||
bool area = true;
|
||||
float minVal = 0.0f;
|
||||
float maxVal = lastMaxVal; // TODO - adjust to frame length
|
||||
if (maxVal < 0.001f)
|
||||
maxVal = 0.001f;
|
||||
if (maxVal > 1.0f / 15.0f)
|
||||
maxVal = 1.0f / 15.0f;
|
||||
|
||||
float scale = (graphHeight) / (maxVal - minVal);
|
||||
|
||||
float y_60th = ui.GetBounds().y2() - 10 - (1.0f / 60.0f) * scale;
|
||||
float y_1ms = ui.GetBounds().y2() - 10 - (1.0f / 1000.0f) * scale;
|
||||
|
||||
ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_60th, graphWidth, 2));
|
||||
ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_1ms, graphWidth, 2));
|
||||
ui.DrawTextShadow("1/60s", 5, y_60th, 0x80FFFF00);
|
||||
ui.DrawTextShadow("1ms", 5, y_1ms, 0x80FFFF00);
|
||||
|
||||
std::vector<float> total;
|
||||
total.resize(historyLength);
|
||||
|
||||
maxVal = 0.0f;
|
||||
float maxTotal = 0.0f;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
if (catStatus[i] == PROFILE_CAT_IGNORE) {
|
||||
continue;
|
||||
}
|
||||
Profiler_GetHistory(i, &history[0], historyLength);
|
||||
|
||||
float x = 10;
|
||||
uint32_t col = nice_colors[i % ARRAY_SIZE(nice_colors)];
|
||||
if (area)
|
||||
col = opacity | (col & 0xFFFFFF);
|
||||
UI::Drawable color(col);
|
||||
UI::Drawable outline((opacity >> 1) | 0xFFFFFF);
|
||||
|
||||
float bottom = ui.GetBounds().y2();
|
||||
if (area) {
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
float val = history[n];
|
||||
float valY1 = bottom - 10 - (val + total[n]) * scale;
|
||||
float valY2 = bottom - 10 - total[n] * scale;
|
||||
ui.FillRect(outline, Bounds(x, valY2, dx, 1.0f));
|
||||
ui.FillRect(color, Bounds(x, valY1, dx, valY2 - valY1));
|
||||
x += dx;
|
||||
total[n] += val;
|
||||
}
|
||||
} else {
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
float val = history[n];
|
||||
if (val > maxVal)
|
||||
maxVal = val;
|
||||
float valY = bottom - 10 - history[n] * scale;
|
||||
ui.FillRect(color, Bounds(x, valY, dx, 5));
|
||||
x += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
legendHeight += rowH;
|
||||
}
|
||||
legendWidth += 20.0f;
|
||||
|
||||
float legendStartY = legendHeight > ui.GetBounds().centerY() ? ui.GetBounds().y2() - legendHeight : ui.GetBounds().centerY();
|
||||
float legendStartX = ui.GetBounds().x2() - std::min(legendWidth, 200.0f);
|
||||
|
||||
const uint32_t opacity = 140 << 24;
|
||||
|
||||
int legendNum = 0;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
uint32_t color = nice_colors[i % ARRAY_SIZE(nice_colors)];
|
||||
|
||||
if (catStatus[i] == PROFILE_CAT_VISIBLE) {
|
||||
float y = legendStartY + legendNum++ * rowH;
|
||||
ui.FillRect(UI::Drawable(opacity | color), Bounds(legendStartX, y, rowH - 2, rowH - 2));
|
||||
ui.DrawTextShadow(name, legendStartX + rowH + 2, y, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
if (total[n] > maxTotal)
|
||||
maxTotal = total[n];
|
||||
}
|
||||
}
|
||||
|
||||
float graphWidth = ui.GetBounds().x2() - legendWidth - 20.0f;
|
||||
float graphHeight = ui.GetBounds().h * 0.8f;
|
||||
|
||||
float dx = graphWidth / historyLength;
|
||||
|
||||
/*
|
||||
ui.Flush();
|
||||
|
||||
ui.BeginNoTex();
|
||||
*/
|
||||
|
||||
bool area = true;
|
||||
float minVal = 0.0f;
|
||||
float maxVal = lastMaxVal; // TODO - adjust to frame length
|
||||
if (maxVal < 0.001f)
|
||||
maxVal = 0.001f;
|
||||
if (maxVal > 1.0f / 15.0f)
|
||||
maxVal = 1.0f / 15.0f;
|
||||
|
||||
float scale = (graphHeight) / (maxVal - minVal);
|
||||
|
||||
float y_60th = ui.GetBounds().y2() - 10 - (1.0f / 60.0f) * scale;
|
||||
float y_1ms = ui.GetBounds().y2() - 10 - (1.0f / 1000.0f) * scale;
|
||||
|
||||
ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_60th, graphWidth, 2));
|
||||
ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_1ms, graphWidth, 2));
|
||||
ui.DrawTextShadow("1/60s", 5, y_60th, 0x80FFFF00);
|
||||
ui.DrawTextShadow("1ms", 5, y_1ms, 0x80FFFF00);
|
||||
|
||||
std::vector<float> total;
|
||||
total.resize(historyLength);
|
||||
|
||||
maxVal = 0.0f;
|
||||
float maxTotal = 0.0f;
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
if (catStatus[i] == PROFILE_CAT_IGNORE) {
|
||||
continue;
|
||||
}
|
||||
Profiler_GetHistory(i, &history[0], historyLength);
|
||||
|
||||
float x = 10;
|
||||
uint32_t col = nice_colors[i % ARRAY_SIZE(nice_colors)];
|
||||
if (area)
|
||||
col = opacity | (col & 0xFFFFFF);
|
||||
UI::Drawable color(col);
|
||||
UI::Drawable outline((opacity >> 1) | 0xFFFFFF);
|
||||
|
||||
float bottom = ui.GetBounds().y2();
|
||||
if (area) {
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
float val = history[n];
|
||||
float valY1 = bottom - 10 - (val + total[n]) * scale;
|
||||
float valY2 = bottom - 10 - total[n] * scale;
|
||||
ui.FillRect(outline, Bounds(x, valY2, dx, 1.0f));
|
||||
ui.FillRect(color, Bounds(x, valY1, dx, valY2 - valY1));
|
||||
x += dx;
|
||||
total[n] += val;
|
||||
maxVal = maxTotal;
|
||||
}
|
||||
|
||||
lastMaxVal = lastMaxVal * 0.95f + maxVal * 0.05f;
|
||||
}
|
||||
if (g_Config.bSimpleFrameStats) {
|
||||
PROFILE_THIS_SCOPE("timing");
|
||||
int numCategories = Profiler_GetNumCategories();
|
||||
int historyLength = Profiler_GetHistoryLength();
|
||||
|
||||
ui.SetFontStyle(ui.theme->uiFont);
|
||||
|
||||
static float lastMaxVal = 1.0f / 60.0f;
|
||||
float legendMinVal = lastMaxVal * (1.0f / 120.0f);
|
||||
|
||||
std::vector<float> history(historyLength);
|
||||
std::vector<ProfileCatStatus> catStatus(numCategories);
|
||||
|
||||
float rowH = 30.0f;
|
||||
float legendHeight = 0.0f;
|
||||
float legendWidth = 80.0f;
|
||||
/* for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
if (!strcmp(name, "timing")) {
|
||||
catStatus[i] = PROFILE_CAT_IGNORE;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
float val = history[n];
|
||||
if (val > maxVal)
|
||||
maxVal = val;
|
||||
float valY = bottom - 10 - history[n] * scale;
|
||||
ui.FillRect(color, Bounds(x, valY, dx, 5));
|
||||
x += dx;
|
||||
}*/
|
||||
|
||||
float legendStartY = 40.0f;
|
||||
float legendStartX = 5.0f;
|
||||
|
||||
int legendNum = 0;
|
||||
float total = 0;
|
||||
|
||||
for (int i = 0; i < numCategories; i++) {
|
||||
const char *name = Profiler_GetCategoryName(i);
|
||||
Profiler_GetHistory(i, &history[0], 30);
|
||||
float val = 0;
|
||||
for (int n = 0; n < 30; n++) {
|
||||
val += history[n];
|
||||
}
|
||||
val /= 30;
|
||||
float vps, fps, actual_fps;
|
||||
__DisplayGetFPS(&vps, &fps, &actual_fps);
|
||||
val *= 1000.0f; // Value in ms ("%.2f ms")
|
||||
val = (100.0f * val) / (1.0f / fps * 1000.0f); // Value in % ("%.1f%%")
|
||||
total += val;
|
||||
if (catStatus[i] == PROFILE_CAT_VISIBLE) {
|
||||
float y = legendStartY + legendNum++ * rowH;
|
||||
ui.DrawTextShadow(name, legendStartX, y, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
ui.DrawTextShadow(StringFromFormat("%.1f%%", val).c_str(), legendStartX + 128, y, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
}
|
||||
}
|
||||
ui.DrawTextShadow("Total:", legendStartX, legendStartY + legendNum * rowH, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
ui.DrawTextShadow(StringFromFormat("%.1f%%", total).c_str(), legendStartX + 128, legendStartY + legendNum * rowH, 0xFFFFFFFF, ALIGN_VBASELINE);
|
||||
}
|
||||
|
||||
for (int n = 0; n < historyLength; n++) {
|
||||
if (total[n] > maxTotal)
|
||||
maxTotal = total[n];
|
||||
}
|
||||
|
||||
if (area) {
|
||||
maxVal = maxTotal;
|
||||
}
|
||||
|
||||
lastMaxVal = lastMaxVal * 0.95f + maxVal * 0.05f;
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user