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

96 lines
3.2 KiB
C++
Raw Normal View History

2012-12-19 09:30:18 +00:00
/****************************************************************************
* *
2015-11-10 05:21:49 +00:00
* Project64 - A Nintendo 64 emulator. *
2012-12-19 09:30:18 +00:00
* http://www.pj64-emu.com/ *
* Copyright (C) 2012 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#include "stdafx.h"
#include <stdio.h>
#include <Project64-core/N64System/ProfilingClass.h>
2015-12-06 09:59:58 +00:00
#include <Common/LogClass.h>
enum { MAX_FRAMES = 13 };
2015-12-23 19:51:37 +00:00
CProfiling::CProfiling() :
m_CurrentDisplayCount(MAX_FRAMES),
2016-10-02 21:46:05 +00:00
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()
{
2016-10-02 21:46:05 +00:00
if (m_CurrentTimerType == Timer_None) { return m_CurrentTimerType; }
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%%",
2016-10-04 19:58:11 +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
}