HighPerformanceGraphicsUsageSampler.cpp [plain text]
#include "config.h"
#include "HighPerformanceGraphicsUsageSampler.h"
#include "WebPageProxy.h"
#include "WebProcessPool.h"
#include <WebCore/DiagnosticLoggingKeys.h>
namespace WebKit {
using namespace WebCore;
static const Seconds samplingInterval { 10_min };
HighPerformanceGraphicsUsageSampler::HighPerformanceGraphicsUsageSampler(WebProcessPool& webProcessPool)
: m_webProcessPool(webProcessPool)
, m_timer(RunLoop::main(), this, &HighPerformanceGraphicsUsageSampler::timerFired)
{
m_timer.startRepeating(samplingInterval);
}
void HighPerformanceGraphicsUsageSampler::timerFired()
{
bool isUsingHighPerformanceWebGL = false;
bool isUsingHighPerformanceWebGLInVisibleView = false;
WebPageProxy* firstPage = nullptr;
for (auto& webProcess : m_webProcessPool.processes()) {
for (auto& page : webProcess->pages()) {
if (!firstPage)
firstPage = page;
if (page->isUsingHighPerformanceWebGL()) {
isUsingHighPerformanceWebGL = true;
if (page->isViewVisible()) {
isUsingHighPerformanceWebGLInVisibleView = true;
break;
}
}
}
}
if (!firstPage)
return;
String state = DiagnosticLoggingKeys::inactiveKey();
if (isUsingHighPerformanceWebGLInVisibleView)
state = DiagnosticLoggingKeys::activeInForegroundTabKey();
else if (isUsingHighPerformanceWebGL)
state = DiagnosticLoggingKeys::activeInBackgroundTabOnlyKey();
firstPage->logDiagnosticMessage(DiagnosticLoggingKeys::webGLStateKey(), state, ShouldSample::No);
}
}