project64/Source/Project64-core/N64System/Profiling.cpp

94 lines
2.5 KiB
C++
Raw Normal View History

#include "stdafx.h"
2022-10-10 00:22:17 +00:00
#include <stdio.h>
2021-04-14 05:34:15 +00:00
#include <Common/Log.h>
2022-10-10 00:22:17 +00:00
#include <Project64-core/N64System/Profiling.h>
2022-10-10 00:22:17 +00:00
enum
{
MAX_FRAMES = 13
};
2015-12-23 19:51:37 +00:00
CProfiling::CProfiling() :
2022-10-10 00:22:17 +00:00
m_CurrentDisplayCount(MAX_FRAMES),
m_CurrentTimerType(Timer_None)
{
2016-10-02 21:46:05 +00:00
memset(m_Timers, 0, sizeof(m_Timers));
}
2016-10-02 21:46:05 +00:00
void CProfiling::RecordTime(PROFILE_TIMERS timer, uint32_t TimeTaken)
{
2016-10-02 21:46:05 +00:00
m_Timers[timer] += TimeTaken;
}
2016-10-04 19:58:11 +00:00
uint64_t CProfiling::NonCPUTime(void)
{
uint64_t TotalTime = 0;
for (int i = 0; i < Timer_Max; i++)
{
if (i == Timer_R4300)
{
continue;
}
TotalTime += m_Timers[i];
}
return TotalTime;
}
2016-10-02 21:46:05 +00:00
PROFILE_TIMERS CProfiling::StartTimer(PROFILE_TIMERS TimerType)
{
2016-10-02 21:46:05 +00:00
PROFILE_TIMERS PreviousType = StopTimer();
m_CurrentTimerType = TimerType;
m_StartTime.SetToNow();
return PreviousType;
}
2016-10-02 21:46:05 +00:00
PROFILE_TIMERS CProfiling::StopTimer()
{
2022-10-10 00:22:17 +00:00
if (m_CurrentTimerType == Timer_None)
{
return m_CurrentTimerType;
}
2016-10-02 21:46:05 +00:00
HighResTimeStamp EndTime;
EndTime.SetToNow();
uint64_t TimeTaken = EndTime.GetMicroSeconds() - m_StartTime.GetMicroSeconds();
m_Timers[m_CurrentTimerType] += TimeTaken;
PROFILE_TIMERS CurrentTimerType = m_CurrentTimerType;
m_CurrentTimerType = Timer_None;
return CurrentTimerType;
}
2016-10-02 21:46:05 +00:00
void CProfiling::ShowCPU_Usage()
{
2016-10-04 19:58:11 +00:00
PROFILE_TIMERS PreviousType = StopTimer();
2016-10-02 21:46:05 +00:00
uint64_t TotalTime = m_Timers[Timer_R4300] + m_Timers[Timer_RSP_Dlist] + m_Timers[Timer_RSP_Alist] + m_Timers[Timer_Idel];
2016-10-02 21:46:05 +00:00
if (m_CurrentDisplayCount > 0)
2015-12-23 19:51:37 +00:00
{
2016-10-02 21:46:05 +00:00
m_CurrentDisplayCount -= 1;
return;
}
2015-12-23 19:51:37 +00:00
2016-10-02 21:46:05 +00:00
uint32_t R4300 = (uint32_t)(m_Timers[Timer_R4300] * 10000 / TotalTime);
uint32_t RSP_Dlist = (uint32_t)(m_Timers[Timer_RSP_Dlist] * 10000 / TotalTime);
uint32_t RSP_Alist = (uint32_t)(m_Timers[Timer_RSP_Alist] * 10000 / TotalTime);
uint32_t Idel = (uint32_t)(m_Timers[Timer_Idel] * 10000 / TotalTime);
2015-12-23 19:51:37 +00:00
2016-10-02 21:46:05 +00:00
m_CurrentDisplayCount = MAX_FRAMES;
g_Notify->DisplayMessage(0, stdstr_f("r4300i: %d.%02d%% GFX: %d.%02d%% Alist: %d.%02d%% Idle: %d.%02d%%",
2022-10-10 00:22:17 +00:00
R4300 / 100, R4300 % 100, RSP_Dlist / 100, RSP_Dlist % 100, RSP_Alist / 100, RSP_Alist % 100, Idel / 100, Idel % 100)
.c_str());
2015-12-23 19:51:37 +00:00
2016-10-02 21:46:05 +00:00
ResetTimers();
2016-10-04 19:58:11 +00:00
if (PreviousType != Timer_None)
{
StartTimer(PreviousType);
}
2016-10-02 21:46:05 +00:00
}
2015-12-23 19:51:37 +00:00
2016-10-02 21:46:05 +00:00
void CProfiling::ResetTimers()
{
memset(m_Timers, 0, sizeof(m_Timers));
2015-12-23 19:51:37 +00:00
}