2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "DVDPerformanceCounter.h"
22 #include "DVDMessageQueue.h"
23 #include "utils/TimeUtils.h"
25 #include "dvd_config.h"
27 #ifdef DVDDEBUG_WITH_PERFORMANCE_COUNTER
31 HRESULT __stdcall DVDPerformanceCounterAudioQueue(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
33 numerator->QuadPart = 0LL;
34 //g_dvdPerformanceCounter.Lock();
35 if (g_dvdPerformanceCounter.m_pAudioQueue)
37 int iSize = g_dvdPerformanceCounter.m_pAudioQueue->GetDataSize();
38 int iMaxSize = g_dvdPerformanceCounter.m_pAudioQueue->GetMaxDataSize();
41 int iPercent = (iSize * 100) / iMaxSize;
42 if (iPercent > 100) iPercent = 100;
43 numerator->QuadPart = iPercent;
46 //g_dvdPerformanceCounter.Unlock();
50 HRESULT __stdcall DVDPerformanceCounterVideoQueue(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
52 numerator->QuadPart = 0LL;
53 //g_dvdPerformanceCounter.Lock();
54 if (g_dvdPerformanceCounter.m_pVideoQueue)
56 int iSize = g_dvdPerformanceCounter.m_pVideoQueue->GetDataSize();
57 int iMaxSize = g_dvdPerformanceCounter.m_pVideoQueue->GetMaxDataSize();
60 int iPercent = (iSize * 100) / iMaxSize;
61 if (iPercent > 100) iPercent = 100;
62 numerator->QuadPart = iPercent;
65 //g_dvdPerformanceCounter.Unlock();
69 inline int64_t get_thread_cpu_usage(ProcessPerformance* p)
73 ULARGE_INTEGER old_time_thread;
74 ULARGE_INTEGER old_time_system;
76 old_time_thread.QuadPart = p->timer_thread.QuadPart;
77 old_time_system.QuadPart = p->timer_system.QuadPart;
79 p->timer_thread.QuadPart = p->thread->GetAbsoluteUsage();
80 p->timer_system.QuadPart = CurrentHostCounter();
82 int64_t threadTime = (p->timer_thread.QuadPart - old_time_thread.QuadPart);
83 int64_t systemTime = (p->timer_system.QuadPart - old_time_system.QuadPart);
85 if (systemTime > 0 && threadTime > 0) return ((threadTime * 100) / systemTime);
90 HRESULT __stdcall DVDPerformanceCounterVideoDecodePerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
92 //g_dvdPerformanceCounter.Lock();
93 numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_videoDecodePerformance);
94 //g_dvdPerformanceCounter.Unlock();
98 HRESULT __stdcall DVDPerformanceCounterAudioDecodePerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
100 //g_dvdPerformanceCounter.Lock();
101 numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_audioDecodePerformance);
102 //g_dvdPerformanceCounter.Unlock();
106 HRESULT __stdcall DVDPerformanceCounterMainPerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
108 //g_dvdPerformanceCounter.Lock();
109 numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_mainPerformance);
110 //g_dvdPerformanceCounter.Unlock();
114 CDVDPerformanceCounter g_dvdPerformanceCounter;
116 CDVDPerformanceCounter::CDVDPerformanceCounter()
118 m_pAudioQueue = NULL;
119 m_pVideoQueue = NULL;
121 memset(&m_videoDecodePerformance, 0, sizeof(m_videoDecodePerformance)); // video decoding
122 memset(&m_audioDecodePerformance, 0, sizeof(m_audioDecodePerformance)); // audio decoding + output to audio device
123 memset(&m_mainPerformance, 0, sizeof(m_mainPerformance)); // reading files, demuxing, decoding of subtitles + menu overlays
128 CDVDPerformanceCounter::~CDVDPerformanceCounter()
133 bool CDVDPerformanceCounter::Initialize()
135 CSingleLock lock(m_critSection);
137 #ifdef DVDDEBUG_WITH_PERFORMANCE_COUNTER
139 DmRegisterPerformanceCounter("DVDAudioQueue", DMCOUNT_SYNC, DVDPerformanceCounterAudioQueue);
140 DmRegisterPerformanceCounter("DVDVideoQueue", DMCOUNT_SYNC, DVDPerformanceCounterVideoQueue);
141 DmRegisterPerformanceCounter("DVDVideoDecodePerformance", DMCOUNT_SYNC, DVDPerformanceCounterVideoDecodePerformance);
142 DmRegisterPerformanceCounter("DVDAudioDecodePerformance", DMCOUNT_SYNC, DVDPerformanceCounterAudioDecodePerformance);
143 DmRegisterPerformanceCounter("DVDMainPerformance", DMCOUNT_SYNC, DVDPerformanceCounterMainPerformance);
150 void CDVDPerformanceCounter::DeInitialize()