Debugger: Performance Tracker - Allow controlling display mode/speed with left/right click buttons
This commit is contained in:
parent
9ceb522874
commit
ffc81903f9
4 changed files with 65 additions and 26 deletions
|
@ -8,6 +8,8 @@ The original scripts can be found on his blog here: http://upsilandre.over-blog.
|
||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
#include "PPU.h"
|
#include "PPU.h"
|
||||||
#include "DebugHud.h"
|
#include "DebugHud.h"
|
||||||
|
#include "IKeyManager.h"
|
||||||
|
#include "KeyManager.h"
|
||||||
|
|
||||||
enum Colors
|
enum Colors
|
||||||
{
|
{
|
||||||
|
@ -40,12 +42,34 @@ PerfTrackerMode PerformanceTracker::GetMode()
|
||||||
return _mode;
|
return _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PerformanceTracker::ProcessMouseInput()
|
||||||
|
{
|
||||||
|
bool leftButtonPressed = KeyManager::IsMouseButtonPressed(MouseButton::LeftButton);
|
||||||
|
bool rightButtonPressed = KeyManager::IsMouseButtonPressed(MouseButton::RightButton);
|
||||||
|
if(_leftButtonPressed && leftButtonPressed != _leftButtonPressed) {
|
||||||
|
//Left button was clicked
|
||||||
|
_mode = (PerfTrackerMode)((_mode + 1) % 4);
|
||||||
|
if(_mode == PerfTrackerMode::Disabled) {
|
||||||
|
_mode = PerfTrackerMode::Fullscreen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(_rightButtonPressed && rightButtonPressed != _rightButtonPressed) {
|
||||||
|
//Right button was clicked
|
||||||
|
_updateSpeed = _updateSpeed == PerfTrackerSpeed::Fast ? PerfTrackerSpeed::Normal : PerfTrackerSpeed::Fast;
|
||||||
|
}
|
||||||
|
|
||||||
|
_leftButtonPressed = leftButtonPressed;
|
||||||
|
_rightButtonPressed = rightButtonPressed;
|
||||||
|
}
|
||||||
|
|
||||||
void PerformanceTracker::ProcessEndOfFrame()
|
void PerformanceTracker::ProcessEndOfFrame()
|
||||||
{
|
{
|
||||||
if(_mode == PerfTrackerMode::Disabled) {
|
if(_mode == PerfTrackerMode::Disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProcessMouseInput();
|
||||||
|
|
||||||
_data.frameCount++;
|
_data.frameCount++;
|
||||||
_data.frameProcessed = false;
|
_data.frameProcessed = false;
|
||||||
|
|
||||||
|
@ -144,8 +168,6 @@ void PerformanceTracker::ProcessCpuExec(AddressTypeInfo & addressInfo)
|
||||||
|
|
||||||
//Store the current frame's CPU usage as a data point for the chart (each lag frame counts as +100% CPU)
|
//Store the current frame's CPU usage as a data point for the chart (each lag frame counts as +100% CPU)
|
||||||
int finalCpu = _data.partialCpu + (lag * 100);
|
int finalCpu = _data.partialCpu + (lag * 100);
|
||||||
_data.cpuChartDataPoints[_data.cpuChartPos] = finalCpu;
|
|
||||||
_data.cpuChartPos = (_data.cpuChartPos + 1) % 256;
|
|
||||||
|
|
||||||
//Update the average CPU statistic
|
//Update the average CPU statistic
|
||||||
_data.totalCpu += finalCpu;
|
_data.totalCpu += finalCpu;
|
||||||
|
@ -161,19 +183,25 @@ void PerformanceTracker::ProcessCpuExec(AddressTypeInfo & addressInfo)
|
||||||
|
|
||||||
_data.gameFrame++;
|
_data.gameFrame++;
|
||||||
|
|
||||||
//Update the onscreen display for the CPU %
|
_data.updateTimer++;
|
||||||
_data.updateCpu = finalCpu;
|
if(_updateSpeed == PerfTrackerSpeed::Fast || _data.updateTimer == 8) {
|
||||||
|
_data.updateTimer = 0;
|
||||||
|
_data.cpuChartDataPoints[_data.cpuChartPos] = finalCpu;
|
||||||
|
_data.cpuChartPos = (_data.cpuChartPos + 1) % 256;
|
||||||
|
|
||||||
//Calculate the average FPS for the last 20 frames (and add it as a data point for the chart)
|
//Update the onscreen display for the CPU %
|
||||||
_data.fps = 0;
|
_data.updateCpu = finalCpu;
|
||||||
int i = _data.isLagFramePos < 20 ? (60 - (20 - _data.isLagFramePos)) : (_data.isLagFramePos - 20);
|
|
||||||
do {
|
|
||||||
_data.fps += _data.isLagFrame[i] ? 0 : 1;
|
|
||||||
i = (i + 1) % 60;
|
|
||||||
} while(i != _data.isLagFramePos);
|
|
||||||
_data.fps *= 3;
|
|
||||||
|
|
||||||
_data.fpsChartDataPoints[_data.fpsChartPos] = _data.fps;
|
//Calculate the average FPS for the last 60 frames (and add it as a data point for the chart)
|
||||||
_data.fpsChartPos = (_data.fpsChartPos + 1) % 256;
|
_data.fps = 0;
|
||||||
|
int i = _data.isLagFramePos;
|
||||||
|
do {
|
||||||
|
_data.fps += _data.isLagFrame[i] ? 0 : 1;
|
||||||
|
i = (i + 1) % 60;
|
||||||
|
} while(i != _data.isLagFramePos);
|
||||||
|
|
||||||
|
_data.fpsChartDataPoints[_data.fpsChartPos] = _data.fps;
|
||||||
|
_data.fpsChartPos = (_data.fpsChartPos + 1) % 256;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
struct PerfTrackerData
|
struct PerfTrackerData
|
||||||
{
|
{
|
||||||
|
int updateTimer = 0;
|
||||||
int frameCount = 0;
|
int frameCount = 0;
|
||||||
int prevFrameCount = 0;
|
int prevFrameCount = 0;
|
||||||
bool frameProcessed = false;
|
bool frameProcessed = false;
|
||||||
|
@ -23,6 +24,12 @@ struct PerfTrackerData
|
||||||
int cpuChartDataPoints[256] = {};
|
int cpuChartDataPoints[256] = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum PerfTrackerSpeed
|
||||||
|
{
|
||||||
|
Normal = 0,
|
||||||
|
Fast = 1
|
||||||
|
};
|
||||||
|
|
||||||
class PerformanceTracker
|
class PerformanceTracker
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -32,8 +39,12 @@ private:
|
||||||
int32_t _address = -1;
|
int32_t _address = -1;
|
||||||
AddressType _type = AddressType::InternalRam;
|
AddressType _type = AddressType::InternalRam;
|
||||||
PerfTrackerMode _mode = PerfTrackerMode::Disabled;
|
PerfTrackerMode _mode = PerfTrackerMode::Disabled;
|
||||||
|
PerfTrackerSpeed _updateSpeed = PerfTrackerSpeed::Normal;
|
||||||
bool _needReset = false;
|
bool _needReset = false;
|
||||||
|
bool _leftButtonPressed = false;
|
||||||
|
bool _rightButtonPressed = false;
|
||||||
|
|
||||||
|
void ProcessMouseInput();
|
||||||
void DrawChart(int *dataPoints, int startPos, int color, int scale, int maxValue);
|
void DrawChart(int *dataPoints, int startPos, int color, int scale, int maxValue);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -498,6 +498,16 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
} else {
|
} else {
|
||||||
items[nameof(mnuEditSourceFile)].Visible = false;
|
items[nameof(mnuEditSourceFile)].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddressTypeInfo addressInfo = Viewer.GetAddressInfo(Viewer.CodeViewer.SelectedLine);
|
||||||
|
if(addressInfo.Address >= 0) {
|
||||||
|
int relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
|
||||||
|
items[nameof(mnuPerfTracker)].Text = "Performance Tracker ($" + relAddress.ToString("X4") + ")";
|
||||||
|
items[nameof(mnuPerfTracker)].Enabled = true;
|
||||||
|
} else {
|
||||||
|
items[nameof(mnuPerfTracker)].Text = "Performance Tracker";
|
||||||
|
items[nameof(mnuPerfTracker)].Enabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool UpdateContextMenu(Point mouseLocation)
|
private bool UpdateContextMenu(Point mouseLocation)
|
||||||
|
@ -508,16 +518,6 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
|
|
||||||
mnuSwitchView.Text = IsSourceView ? "Switch to Disassembly View" : "Switch to Source View";
|
mnuSwitchView.Text = IsSourceView ? "Switch to Disassembly View" : "Switch to Source View";
|
||||||
|
|
||||||
AddressTypeInfo addressInfo = Viewer.GetAddressInfo(Viewer.CodeViewer.SelectedLine);
|
|
||||||
if(addressInfo.Address >= 0) {
|
|
||||||
int relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
|
|
||||||
mnuPerfTracker.Text = "Performance Tracker ($" + relAddress.ToString("X4") + ")";
|
|
||||||
mnuPerfTracker.Enabled = true;
|
|
||||||
} else {
|
|
||||||
mnuPerfTracker.Text = "Performance Tracker";
|
|
||||||
mnuPerfTracker.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation);
|
string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation);
|
||||||
Ld65DbgImporter.SymbolInfo symbol = null;
|
Ld65DbgImporter.SymbolInfo symbol = null;
|
||||||
CodeLabel codeLabel = null;
|
CodeLabel codeLabel = null;
|
||||||
|
|
|
@ -1353,8 +1353,8 @@ namespace Mesen.GUI.Forms
|
||||||
|
|
||||||
private void ctrlRenderer_DoubleClick(object sender, EventArgs e)
|
private void ctrlRenderer_DoubleClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if(!CursorManager.NeedMouseIcon && !CursorManager.AllowMouseCapture && !DebugWindowManager.ScriptWindowOpened) {
|
if(!CursorManager.NeedMouseIcon && !CursorManager.AllowMouseCapture && !DebugWindowManager.HasOpenedWindow) {
|
||||||
//Disable double clicking (used to switch to fullscreen mode) when using a mouse-controlled device
|
//Disable double clicking (used to switch to fullscreen mode) when using a mouse-controlled device (or when debugger is opened)
|
||||||
ToggleFullscreen();
|
ToggleFullscreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue