From 2dfad2fb242d059396103ea063b078845b403908 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 26 Jan 2010 13:06:53 +0000 Subject: [PATCH] Improved CPU usage and fps stats. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2523 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/src/Utilities/Windows/WinMisc.cpp | 2 +- common/src/Utilities/Windows/WinThreads.cpp | 10 ++-- pcsx2/gui/App.h | 4 +- pcsx2/gui/AppMain.cpp | 25 +++++---- pcsx2/gui/CpuUsageProvider.cpp | 56 +++++++++++++-------- pcsx2/gui/CpuUsageProvider.h | 19 +++++-- pcsx2/gui/FrameForGS.cpp | 8 +-- 7 files changed, 71 insertions(+), 53 deletions(-) diff --git a/common/src/Utilities/Windows/WinMisc.cpp b/common/src/Utilities/Windows/WinMisc.cpp index 795b0cad7a..a9821f1ca9 100644 --- a/common/src/Utilities/Windows/WinMisc.cpp +++ b/common/src/Utilities/Windows/WinMisc.cpp @@ -20,7 +20,7 @@ #include -static LARGE_INTEGER lfreq; +static __aligned16 LARGE_INTEGER lfreq; void InitCPUTicks() { diff --git a/common/src/Utilities/Windows/WinThreads.cpp b/common/src/Utilities/Windows/WinThreads.cpp index 48b8d4cbc7..a4324475f0 100644 --- a/common/src/Utilities/Windows/WinThreads.cpp +++ b/common/src/Utilities/Windows/WinThreads.cpp @@ -64,7 +64,7 @@ u64 Threading::GetThreadCpuTime() { FileTimeSucks user, kernel; FILETIME dummy; - GetThreadTimes( GetCurrentThread(), &dummy, &dummy, &user.filetime, &kernel.filetime ); + GetThreadTimes( GetCurrentThread(), &dummy, &dummy, &kernel.filetime, &user.filetime ); return user.u64time + kernel.u64time; } @@ -80,10 +80,7 @@ u64 Threading::PersistentThread::GetCpuTime() const FileTimeSucks user, kernel; FILETIME dummy; - // Note: Vista and Win7 need only THREAD_QUERY_LIMITED_INFORMATION (XP and 2k need more), - // however we own our process threads, so shouldn't matter in any case... - - if( GetThreadTimes( (HANDLE)m_native_handle, &dummy, &dummy, &user.filetime, &kernel.filetime ) ) + if( GetThreadTimes( (HANDLE)m_native_handle, &dummy, &dummy, &kernel.filetime, &user.filetime ) ) return user.u64time + kernel.u64time; return 0; // thread prolly doesn't exist anymore. @@ -91,6 +88,9 @@ u64 Threading::PersistentThread::GetCpuTime() const void Threading::PersistentThread::_platform_specific_OnStartInThread() { + // OpenThread Note: Vista and Win7 need only THREAD_QUERY_LIMITED_INFORMATION (XP and 2k need more), + // however we own our process threads, so shouldn't matter in any case... + m_native_id = (uptr)GetCurrentThreadId(); m_native_handle = (uptr)OpenThread( THREAD_QUERY_INFORMATION, false, (DWORD)m_native_id ); diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index d422c03224..b530b7ab35 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -327,7 +327,7 @@ struct pxAppResources ScopedPtr RecentIsoList; pxAppResources(); - ~pxAppResources() throw() { } + virtual ~pxAppResources() throw() { } }; // -------------------------------------------------------------------------------------- @@ -340,8 +340,6 @@ public: protected: u64 m_fpsqueue[FramerateQueueDepth]; - u64 m_fpsqueue_tally; - u64 m_ticks_lastframe; int m_fpsqueue_writepos; uint m_initpause; diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index 9afeaadfe0..3335fd6aa8 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -195,39 +195,38 @@ void Pcsx2App::PadKeyDispatch( const keyEvent& ev ) void FramerateManager::Reset() { - memzero( m_fpsqueue ); + //memzero( m_fpsqueue ); m_initpause = FramerateQueueDepth; - m_fpsqueue_tally = 0; m_fpsqueue_writepos = 0; + + for( int i=0; i 0 ) --m_initpause; + m_fpsqueue[m_fpsqueue_writepos] = GetCPUTicks(); + + // intentionally leave 1 on the counter here, since ultimately we want to divide the + // final result (in GetFramerate() by QueueDepth-1. + if( m_initpause > 1 ) --m_initpause; } double FramerateManager::GetFramerate() const { if( m_initpause > (FramerateQueueDepth/2) ) return 0.0; - u32 ticks_per_frame = m_fpsqueue_tally / (FramerateQueueDepth-m_initpause); + const u64 delta = m_fpsqueue[m_fpsqueue_writepos] - m_fpsqueue[(m_fpsqueue_writepos + 1) % FramerateQueueDepth]; + const u32 ticks_per_frame = (u32)(delta / (FramerateQueueDepth-m_initpause)); return (double)GetTickFrequency() / (double)ticks_per_frame; } diff --git a/pcsx2/gui/CpuUsageProvider.cpp b/pcsx2/gui/CpuUsageProvider.cpp index b1127b694d..a159c1ede4 100644 --- a/pcsx2/gui/CpuUsageProvider.cpp +++ b/pcsx2/gui/CpuUsageProvider.cpp @@ -24,17 +24,35 @@ #include "GS.h" +void AllThreeThreads::LoadWithCurrentTimes() +{ + ee = GetCoreThread().GetCpuTime(); + gs = GetMTGS().GetCpuTime(); + ui = GetThreadCpuTime(); + update = GetCPUTicks(); +} + +AllThreeThreads AllThreeThreads::operator-( const AllThreeThreads& right ) const +{ + AllThreeThreads retval; + + retval.ee = ee - right.ee; + retval.gs = gs - right.gs; + retval.ui = ui - right.ui; + retval.update = update - right.update; + + return retval; +} + DefaultCpuUsageProvider::DefaultCpuUsageProvider() { - m_lasttime_ee = GetCoreThread().GetCpuTime(); - m_lasttime_gs = GetMTGS().GetCpuTime(); - m_lasttime_ui = GetThreadCpuTime(); - - m_lasttime_update = GetCPUTicks(); - m_pct_ee = 0; m_pct_gs = 0; m_pct_ui = 0; + m_writepos = 0; + + for( int i=0; iGetGuiPct(); } }; +struct AllThreeThreads +{ + u64 ee, gs, ui; + u64 update; + + void LoadWithCurrentTimes(); + AllThreeThreads operator-( const AllThreeThreads& right ) const; +}; + class DefaultCpuUsageProvider : public BaseCpuUsageProvider { +public: + static const uint QueueDepth = 4; + protected: - u64 m_lasttime_ee; - u64 m_lasttime_gs; - u64 m_lasttime_ui; - - u64 m_lasttime_update; + AllThreeThreads m_queue[QueueDepth]; + uint m_writepos; u32 m_pct_ee; u32 m_pct_gs; u32 m_pct_ui; diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 7b30d0e238..46b7fc8a19 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -271,14 +271,14 @@ wxStaticText* GSFrame::GetLabel_OutputDisabled() const void GSFrame::CoreThread_OnResumed() { - m_timer_UpdateTitle.Start( 333 ); + m_timer_UpdateTitle.Start( 275 ); } void GSFrame::CoreThread_OnSuspended() { // Could stop the timer outright here, tho no harm in having an occasional // update here or there, just in case some state info changes while emu is suspended. - m_timer_UpdateTitle.Start( 2000 ); + m_timer_UpdateTitle.Start( 333 ); } // overrides base Show behavior. @@ -301,7 +301,7 @@ bool GSFrame::Show( bool shown ) if( wxStaticText* label = GetLabel_OutputDisabled() ) label->Show( EmuConfig.GS.DisableOutput ); - m_timer_UpdateTitle.Start( 333 ); + m_timer_UpdateTitle.Start( 275 ); } else { @@ -350,7 +350,7 @@ void GSFrame::OnUpdateTitle( wxTimerEvent& evt ) if( m_CpuUsage.IsImplemented() ) { m_CpuUsage.UpdateStats(); - cpuUsage = wxsFormat( L" | EE: %d%% | GS: %d%%", m_CpuUsage.GetEEcorePct(), m_CpuUsage.GetGsPct() ); + cpuUsage = wxsFormat( L" | EE: %d%% | GS: %d%% | UI: %d%%", m_CpuUsage.GetEEcorePct(), m_CpuUsage.GetGsPct(), m_CpuUsage.GetGuiPct() ); } SetTitle( wxsFormat( L"%s | Limiter: %s | fps: %2.02f%s",