Only start ViEPerformanceMonitor when needed.
Tested by taking the added part in base extended test and running in Standard test with cpu threashold in ViEPeroformanceMonitor manually changed to 0. Review URL: http://webrtc-codereview.appspot.com/240005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@772 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
b5475d0076
commit
c693bac6e7
@ -97,8 +97,6 @@ ViEBaseImpl::~ViEBaseImpl()
|
|||||||
{
|
{
|
||||||
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, _instanceId,
|
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, _instanceId,
|
||||||
"ViEBaseImpl::ViEBaseImpl() Dtor");
|
"ViEBaseImpl::ViEBaseImpl() Dtor");
|
||||||
|
|
||||||
_viePerformanceMonitor.Terminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -119,9 +117,6 @@ int ViEBaseImpl::Init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetInitialized();
|
SetInitialized();
|
||||||
|
|
||||||
_viePerformanceMonitor.Init();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,15 +551,14 @@ int ViEBaseImpl::StopReceive(const int videoChannel)
|
|||||||
|
|
||||||
int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer)
|
int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer)
|
||||||
{
|
{
|
||||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId), "%s",
|
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId),
|
||||||
__FUNCTION__);
|
"%s", __FUNCTION__);
|
||||||
if (_viePerformanceMonitor.ViEBaseObserverRegistered())
|
if (_viePerformanceMonitor.ViEBaseObserverRegistered())
|
||||||
{
|
{
|
||||||
SetLastError(kViEBaseObserverAlreadyRegistered);
|
SetLastError(kViEBaseObserverAlreadyRegistered);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return _viePerformanceMonitor.Init(&observer);
|
||||||
return _viePerformanceMonitor.RegisterViEBaseObserver(&observer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -575,8 +569,8 @@ int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer)
|
|||||||
|
|
||||||
int ViEBaseImpl::DeregisterObserver()
|
int ViEBaseImpl::DeregisterObserver()
|
||||||
{
|
{
|
||||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId), "%s",
|
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId),
|
||||||
__FUNCTION__);
|
"%s", __FUNCTION__);
|
||||||
|
|
||||||
if (!_viePerformanceMonitor.ViEBaseObserverRegistered())
|
if (!_viePerformanceMonitor.ViEBaseObserverRegistered())
|
||||||
{
|
{
|
||||||
@ -585,7 +579,8 @@ int ViEBaseImpl::DeregisterObserver()
|
|||||||
"%s No observer registered.", __FUNCTION__);
|
"%s No observer registered.", __FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return _viePerformanceMonitor.RegisterViEBaseObserver(NULL);
|
_viePerformanceMonitor.Terminate();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -35,17 +35,10 @@ ViEPerformanceMonitor::ViEPerformanceMonitor(int engineId)
|
|||||||
_ptrViEMonitorThread(NULL),
|
_ptrViEMonitorThread(NULL),
|
||||||
_monitorkEvent(*EventWrapper::Create()),
|
_monitorkEvent(*EventWrapper::Create()),
|
||||||
_averageApplicationCPU(kViECpuStartValue),
|
_averageApplicationCPU(kViECpuStartValue),
|
||||||
_averageSystemCPU(kViECpuStartValue), _cpu(NULL), _vieBaseObserver(NULL)
|
_averageSystemCPU(kViECpuStartValue),
|
||||||
|
_cpu(NULL),
|
||||||
|
_vieBaseObserver(NULL)
|
||||||
{
|
{
|
||||||
_cpu = CpuWrapper::CreateCpu();
|
|
||||||
if (_cpu)
|
|
||||||
{
|
|
||||||
_cpu->CpuUsage(); // to initialize
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s: Could not create CpuWrapper", __FUNCTION__);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViEPerformanceMonitor::~ViEPerformanceMonitor()
|
ViEPerformanceMonitor::~ViEPerformanceMonitor()
|
||||||
@ -53,24 +46,31 @@ ViEPerformanceMonitor::~ViEPerformanceMonitor()
|
|||||||
Terminate();
|
Terminate();
|
||||||
delete &_pointerCritsect;
|
delete &_pointerCritsect;
|
||||||
delete &_monitorkEvent;
|
delete &_monitorkEvent;
|
||||||
if (_cpu)
|
|
||||||
{
|
|
||||||
delete _cpu;
|
|
||||||
_cpu = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViEPerformanceMonitor::Init()
|
int ViEPerformanceMonitor::Init(ViEBaseObserver* vieBaseObserver)
|
||||||
{
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
||||||
|
"%s", __FUNCTION__);
|
||||||
|
|
||||||
|
CriticalSectionScoped cs(_pointerCritsect);
|
||||||
|
if (!vieBaseObserver || _vieBaseObserver)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
||||||
|
"%s: Bad input argument or observer already set",
|
||||||
|
__FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_cpu = CpuWrapper::CreateCpu();
|
||||||
if (_cpu == NULL)
|
if (_cpu == NULL)
|
||||||
{
|
{
|
||||||
// Performance monitoring not supported
|
// Performance monitoring not supported
|
||||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo,
|
||||||
"%s: Not supported", __FUNCTION__);
|
ViEId(_engineId), "%s: Not supported", __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CriticalSectionScoped cs(_pointerCritsect);
|
|
||||||
if (_ptrViEMonitorThread == NULL)
|
if (_ptrViEMonitorThread == NULL)
|
||||||
{
|
{
|
||||||
_monitorkEvent.StartTimer(true, kViEMonitorPeriodMs);
|
_monitorkEvent.StartTimer(true, kViEMonitorPeriodMs);
|
||||||
@ -92,74 +92,47 @@ int ViEPerformanceMonitor::Init()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_vieBaseObserver = vieBaseObserver;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViEPerformanceMonitor::Terminate()
|
void ViEPerformanceMonitor::Terminate()
|
||||||
{
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
||||||
|
"%s", __FUNCTION__);
|
||||||
|
|
||||||
|
_pointerCritsect.Enter();
|
||||||
|
if (!_vieBaseObserver)
|
||||||
{
|
{
|
||||||
_pointerCritsect.Enter();
|
|
||||||
_vieBaseObserver = NULL;
|
|
||||||
_pointerCritsect.Leave();
|
_pointerCritsect.Leave();
|
||||||
|
return;
|
||||||
_monitorkEvent.StopTimer();
|
|
||||||
if (_ptrViEMonitorThread)
|
|
||||||
{
|
|
||||||
ThreadWrapper* tmpThread = _ptrViEMonitorThread;
|
|
||||||
_ptrViEMonitorThread = NULL;
|
|
||||||
_monitorkEvent.Set();
|
|
||||||
if (tmpThread->Stop())
|
|
||||||
{
|
|
||||||
delete tmpThread;
|
|
||||||
tmpThread = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
_vieBaseObserver = NULL;
|
||||||
|
_monitorkEvent.StopTimer();
|
||||||
|
if (_ptrViEMonitorThread)
|
||||||
|
{
|
||||||
|
ThreadWrapper* tmpThread = _ptrViEMonitorThread;
|
||||||
|
_ptrViEMonitorThread = NULL;
|
||||||
|
_monitorkEvent.Set();
|
||||||
|
_pointerCritsect.Leave();
|
||||||
|
if (tmpThread->Stop())
|
||||||
|
{
|
||||||
|
_pointerCritsect.Enter();
|
||||||
|
delete tmpThread;
|
||||||
|
tmpThread = NULL;
|
||||||
|
delete _cpu;
|
||||||
|
}
|
||||||
|
_cpu = NULL;
|
||||||
|
}
|
||||||
|
_pointerCritsect.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViEPerformanceMonitor::RegisterViEBaseObserver(
|
|
||||||
ViEBaseObserver* vieBaseObserver)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId), "%s",
|
|
||||||
__FUNCTION__);
|
|
||||||
CriticalSectionScoped cs(_pointerCritsect);
|
|
||||||
if (vieBaseObserver)
|
|
||||||
{
|
|
||||||
if (_vieBaseObserver)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s: Observer already started", __FUNCTION__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_vieBaseObserver = vieBaseObserver;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
_vieBaseObserver = NULL;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
bool ViEPerformanceMonitor::ViEBaseObserverRegistered()
|
bool ViEPerformanceMonitor::ViEBaseObserverRegistered()
|
||||||
{
|
{
|
||||||
CriticalSectionScoped cs(_pointerCritsect);
|
CriticalSectionScoped cs(_pointerCritsect);
|
||||||
return _vieBaseObserver != NULL;
|
return _vieBaseObserver != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViEPerformanceMonitor::GetAverageApplicationCPU(int& applicationCPU)
|
|
||||||
{
|
|
||||||
// Not supported
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ViEPerformanceMonitor::GetAverageSystemCPU(int& systemCPU)
|
|
||||||
{
|
|
||||||
if (_cpu)
|
|
||||||
{
|
|
||||||
return _cpu->CpuUsage();
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ViEPerformanceMonitor::ViEMonitorThreadFunction(void* obj)
|
bool ViEPerformanceMonitor::ViEMonitorThreadFunction(void* obj)
|
||||||
{
|
{
|
||||||
return static_cast<ViEPerformanceMonitor*> (obj)->ViEMonitorProcess();
|
return static_cast<ViEPerformanceMonitor*> (obj)->ViEMonitorProcess();
|
||||||
@ -169,23 +142,20 @@ bool ViEPerformanceMonitor::ViEMonitorProcess()
|
|||||||
{
|
{
|
||||||
// Periodically triggered with time KViEMonitorPeriodMs
|
// Periodically triggered with time KViEMonitorPeriodMs
|
||||||
_monitorkEvent.Wait(kViEMonitorPeriodMs);
|
_monitorkEvent.Wait(kViEMonitorPeriodMs);
|
||||||
|
if (_ptrViEMonitorThread == NULL)
|
||||||
{
|
{
|
||||||
if (_ptrViEMonitorThread == NULL)
|
// Thread removed, exit
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CriticalSectionScoped cs(_pointerCritsect);
|
||||||
|
if (_cpu)
|
||||||
|
{
|
||||||
|
int cpuLoad = _cpu->CpuUsage();
|
||||||
|
if (cpuLoad > 75)
|
||||||
{
|
{
|
||||||
// Thread removed, exit
|
if (_vieBaseObserver)
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_cpu)
|
|
||||||
{
|
|
||||||
int cpuLoad = _cpu->CpuUsage();
|
|
||||||
if (cpuLoad > 75)
|
|
||||||
{
|
{
|
||||||
_pointerCritsect.Enter();
|
_vieBaseObserver->PerformanceAlarm(cpuLoad);
|
||||||
if (_vieBaseObserver)
|
|
||||||
{
|
|
||||||
_vieBaseObserver->PerformanceAlarm(cpuLoad);
|
|
||||||
}
|
|
||||||
_pointerCritsect.Leave();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,15 +33,10 @@ public:
|
|||||||
ViEPerformanceMonitor(int engineId);
|
ViEPerformanceMonitor(int engineId);
|
||||||
~ViEPerformanceMonitor();
|
~ViEPerformanceMonitor();
|
||||||
|
|
||||||
int Init();
|
int Init(ViEBaseObserver* vieBaseObserver);
|
||||||
int Terminate();
|
void Terminate();
|
||||||
int RegisterViEBaseObserver(ViEBaseObserver* vieBaseObserver);
|
|
||||||
bool ViEBaseObserverRegistered();
|
bool ViEBaseObserverRegistered();
|
||||||
|
|
||||||
// ViEBase
|
|
||||||
int GetAverageApplicationCPU(int& applicationCPU);
|
|
||||||
int GetAverageSystemCPU(int& systemCPU);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool ViEMonitorThreadFunction(void* obj);
|
static bool ViEMonitorThreadFunction(void* obj);
|
||||||
bool ViEMonitorProcess();
|
bool ViEMonitorProcess();
|
||||||
|
@ -18,6 +18,17 @@
|
|||||||
#include "engine_configurations.h"
|
#include "engine_configurations.h"
|
||||||
#include "video_capture_factory.h"
|
#include "video_capture_factory.h"
|
||||||
|
|
||||||
|
class BaseObserver : public webrtc::ViEBaseObserver {
|
||||||
|
public:
|
||||||
|
BaseObserver()
|
||||||
|
: cpu_load_(0) {}
|
||||||
|
|
||||||
|
virtual void PerformanceAlarm(const unsigned int cpu_load) {
|
||||||
|
cpu_load_ = cpu_load;
|
||||||
|
}
|
||||||
|
unsigned int cpu_load_;
|
||||||
|
};
|
||||||
|
|
||||||
int ViEAutoTest::ViEBaseStandardTest() {
|
int ViEAutoTest::ViEBaseStandardTest() {
|
||||||
ViETest::Log(" ");
|
ViETest::Log(" ");
|
||||||
ViETest::Log("========================================");
|
ViETest::Log("========================================");
|
||||||
@ -315,6 +326,24 @@ int ViEAutoTest::ViEBaseExtendedTest() {
|
|||||||
ViETest::Log("========================================");
|
ViETest::Log("========================================");
|
||||||
ViETest::Log(" ViEBase Extended Test");
|
ViETest::Log(" ViEBase Extended Test");
|
||||||
|
|
||||||
|
// ***************************************************************
|
||||||
|
// Test BaseObserver
|
||||||
|
// ***************************************************************
|
||||||
|
// TODO(mflodman) Add test for base observer. Cpu load must be over 75%.
|
||||||
|
// BaseObserver base_observer;
|
||||||
|
// error = ptrViEBase->RegisterObserver(base_observer);
|
||||||
|
// numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
|
||||||
|
// __FUNCTION__, __LINE__);
|
||||||
|
//
|
||||||
|
// AutoTestSleep(KAutoTestSleepTimeMs);
|
||||||
|
//
|
||||||
|
// error = ptrViEBase->DeregisterObserver();
|
||||||
|
// numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d",
|
||||||
|
// __FUNCTION__, __LINE__);
|
||||||
|
// numberOfErrors += ViETest::TestError(base_observer.cpu_load_ > 0,
|
||||||
|
// "ERROR: %s at line %d",
|
||||||
|
// __FUNCTION__, __LINE__);
|
||||||
|
|
||||||
ViETest::Log(" ");
|
ViETest::Log(" ");
|
||||||
ViETest::Log(" ViEBase Extended Test PASSED!");
|
ViETest::Log(" ViEBase Extended Test PASSED!");
|
||||||
ViETest::Log("========================================");
|
ViETest::Log("========================================");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user