/[pcsx2_0.9.7]/trunk/pcsx2/gui/CpuUsageProvider.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/CpuUsageProvider.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 2441 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17
18 #include "CpuUsageProvider.h"
19 #include "System.h"
20
21 #ifndef __LINUX__
22 #include "SysThreads.h"
23 #endif
24
25 #include "GS.h"
26
27 void AllThreeThreads::LoadWithCurrentTimes()
28 {
29 ee = GetCoreThread().GetCpuTime();
30 gs = GetMTGS().GetCpuTime();
31 ui = GetThreadCpuTime();
32 update = GetCPUTicks();
33 }
34
35 AllThreeThreads AllThreeThreads::operator-( const AllThreeThreads& right ) const
36 {
37 AllThreeThreads retval;
38
39 retval.ee = ee - right.ee;
40 retval.gs = gs - right.gs;
41 retval.ui = ui - right.ui;
42 retval.update = update - right.update;
43
44 return retval;
45 }
46
47 DefaultCpuUsageProvider::DefaultCpuUsageProvider()
48 {
49 m_pct_ee = 0;
50 m_pct_gs = 0;
51 m_pct_ui = 0;
52 m_writepos = 0;
53
54 Reset();
55 }
56
57 void DefaultCpuUsageProvider::Reset()
58 {
59 for( uint i=0; i<QueueDepth; ++i )
60 m_queue[i].LoadWithCurrentTimes();
61 }
62
63 bool DefaultCpuUsageProvider::IsImplemented() const
64 {
65 return GetThreadTicksPerSecond() != 0;
66 }
67
68 void DefaultCpuUsageProvider::UpdateStats()
69 {
70 // Measure deltas between the first and last positions in the ring buffer:
71
72 AllThreeThreads& newone( m_queue[m_writepos] );
73 newone.LoadWithCurrentTimes();
74 m_writepos = (m_writepos+1) % QueueDepth;
75 const AllThreeThreads deltas( newone - m_queue[m_writepos] );
76
77 // get the real time passed, scaled to the Thread's tick frequency.
78 u64 timepass = (deltas.update * GetThreadTicksPerSecond()) / GetTickFrequency();
79
80 m_pct_ee = (deltas.ee * 100) / timepass;
81 m_pct_gs = (deltas.gs * 100) / timepass;
82 m_pct_ui = (deltas.ui * 100) / timepass;
83 }
84
85 int DefaultCpuUsageProvider::GetEEcorePct() const
86 {
87 return m_pct_ee;
88 }
89
90 int DefaultCpuUsageProvider::GetGsPct() const
91 {
92 return m_pct_gs;
93 }
94
95 int DefaultCpuUsageProvider::GetGuiPct() const
96 {
97 return m_pct_ui;
98 }

  ViewVC Help
Powered by ViewVC 1.1.22