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,
|
||||
"ViEBaseImpl::ViEBaseImpl() Dtor");
|
||||
|
||||
_viePerformanceMonitor.Terminate();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -119,9 +117,6 @@ int ViEBaseImpl::Init()
|
||||
}
|
||||
|
||||
SetInitialized();
|
||||
|
||||
_viePerformanceMonitor.Init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -556,15 +551,14 @@ int ViEBaseImpl::StopReceive(const int videoChannel)
|
||||
|
||||
int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer)
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId), "%s",
|
||||
__FUNCTION__);
|
||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId),
|
||||
"%s", __FUNCTION__);
|
||||
if (_viePerformanceMonitor.ViEBaseObserverRegistered())
|
||||
{
|
||||
SetLastError(kViEBaseObserverAlreadyRegistered);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return _viePerformanceMonitor.RegisterViEBaseObserver(&observer);
|
||||
return _viePerformanceMonitor.Init(&observer);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -575,8 +569,8 @@ int ViEBaseImpl::RegisterObserver(ViEBaseObserver& observer)
|
||||
|
||||
int ViEBaseImpl::DeregisterObserver()
|
||||
{
|
||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId), "%s",
|
||||
__FUNCTION__);
|
||||
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(_instanceId),
|
||||
"%s", __FUNCTION__);
|
||||
|
||||
if (!_viePerformanceMonitor.ViEBaseObserverRegistered())
|
||||
{
|
||||
@ -585,7 +579,8 @@ int ViEBaseImpl::DeregisterObserver()
|
||||
"%s No observer registered.", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
return _viePerformanceMonitor.RegisterViEBaseObserver(NULL);
|
||||
_viePerformanceMonitor.Terminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -35,17 +35,10 @@ ViEPerformanceMonitor::ViEPerformanceMonitor(int engineId)
|
||||
_ptrViEMonitorThread(NULL),
|
||||
_monitorkEvent(*EventWrapper::Create()),
|
||||
_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()
|
||||
@ -53,24 +46,31 @@ ViEPerformanceMonitor::~ViEPerformanceMonitor()
|
||||
Terminate();
|
||||
delete &_pointerCritsect;
|
||||
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)
|
||||
{
|
||||
// Performance monitoring not supported
|
||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
||||
"%s: Not supported", __FUNCTION__);
|
||||
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo,
|
||||
ViEId(_engineId), "%s: Not supported", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CriticalSectionScoped cs(_pointerCritsect);
|
||||
if (_ptrViEMonitorThread == NULL)
|
||||
{
|
||||
_monitorkEvent.StartTimer(true, kViEMonitorPeriodMs);
|
||||
@ -92,74 +92,47 @@ int ViEPerformanceMonitor::Init()
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
_vieBaseObserver = vieBaseObserver;
|
||||
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();
|
||||
|
||||
_monitorkEvent.StopTimer();
|
||||
if (_ptrViEMonitorThread)
|
||||
{
|
||||
ThreadWrapper* tmpThread = _ptrViEMonitorThread;
|
||||
_ptrViEMonitorThread = NULL;
|
||||
_monitorkEvent.Set();
|
||||
if (tmpThread->Stop())
|
||||
{
|
||||
delete tmpThread;
|
||||
tmpThread = NULL;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
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()
|
||||
{
|
||||
CriticalSectionScoped cs(_pointerCritsect);
|
||||
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)
|
||||
{
|
||||
return static_cast<ViEPerformanceMonitor*> (obj)->ViEMonitorProcess();
|
||||
@ -169,23 +142,20 @@ bool ViEPerformanceMonitor::ViEMonitorProcess()
|
||||
{
|
||||
// Periodically triggered with time 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
|
||||
return false;
|
||||
}
|
||||
if (_cpu)
|
||||
{
|
||||
int cpuLoad = _cpu->CpuUsage();
|
||||
if (cpuLoad > 75)
|
||||
if (_vieBaseObserver)
|
||||
{
|
||||
_pointerCritsect.Enter();
|
||||
if (_vieBaseObserver)
|
||||
{
|
||||
_vieBaseObserver->PerformanceAlarm(cpuLoad);
|
||||
}
|
||||
_pointerCritsect.Leave();
|
||||
_vieBaseObserver->PerformanceAlarm(cpuLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,15 +33,10 @@ public:
|
||||
ViEPerformanceMonitor(int engineId);
|
||||
~ViEPerformanceMonitor();
|
||||
|
||||
int Init();
|
||||
int Terminate();
|
||||
int RegisterViEBaseObserver(ViEBaseObserver* vieBaseObserver);
|
||||
int Init(ViEBaseObserver* vieBaseObserver);
|
||||
void Terminate();
|
||||
bool ViEBaseObserverRegistered();
|
||||
|
||||
// ViEBase
|
||||
int GetAverageApplicationCPU(int& applicationCPU);
|
||||
int GetAverageSystemCPU(int& systemCPU);
|
||||
|
||||
protected:
|
||||
static bool ViEMonitorThreadFunction(void* obj);
|
||||
bool ViEMonitorProcess();
|
||||
|
@ -18,6 +18,17 @@
|
||||
#include "engine_configurations.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() {
|
||||
ViETest::Log(" ");
|
||||
ViETest::Log("========================================");
|
||||
@ -315,6 +326,24 @@ int ViEAutoTest::ViEBaseExtendedTest() {
|
||||
ViETest::Log("========================================");
|
||||
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(" ViEBase Extended Test PASSED!");
|
||||
ViETest::Log("========================================");
|
||||
|
Loading…
Reference in New Issue
Block a user