Commit 5a32aaf0 authored by jochen's avatar jochen Committed by Commit bot

Remove foreground tab idle handler

For foreground tabs the blink scheduler handles idle time.

BUG=404850,397026
R=hpayer@chromium.org,sullivan@chromium.org,reveman@chromium.org,ulan@chromium.org,dcheng@chromium.org

Review URL: https://codereview.chromium.org/603083002

Cr-Commit-Position: refs/heads/master@{#297025}
parent e5ac6335
...@@ -106,10 +106,6 @@ namespace { ...@@ -106,10 +106,6 @@ namespace {
const int kPluginsRefreshThresholdInSeconds = 3; const int kPluginsRefreshThresholdInSeconds = 3;
#endif #endif
// When two CPU usage queries arrive within this interval, we sample the CPU
// usage only once and send it as a response for both queries.
static const int64 kCPUUsageSampleIntervalMs = 900;
const uint32 kFilteredMessageClasses[] = { const uint32 kFilteredMessageClasses[] = {
ChildProcessMsgStart, ChildProcessMsgStart,
DesktopNotificationMsgStart, DesktopNotificationMsgStart,
...@@ -331,7 +327,6 @@ RenderMessageFilter::RenderMessageFilter( ...@@ -331,7 +327,6 @@ RenderMessageFilter::RenderMessageFilter(
incognito_(browser_context->IsOffTheRecord()), incognito_(browser_context->IsOffTheRecord()),
dom_storage_context_(dom_storage_context), dom_storage_context_(dom_storage_context),
render_process_id_(render_process_id), render_process_id_(render_process_id),
cpu_usage_(0),
audio_manager_(audio_manager), audio_manager_(audio_manager),
media_internals_(media_internals) { media_internals_(media_internals) {
DCHECK(request_context_.get()); DCHECK(request_context_.get());
...@@ -370,18 +365,6 @@ void RenderMessageFilter::OnChannelClosing() { ...@@ -370,18 +365,6 @@ void RenderMessageFilter::OnChannelClosing() {
#endif #endif
} }
void RenderMessageFilter::OnChannelConnected(int32 peer_id) {
base::ProcessHandle handle = PeerHandle();
#if defined(OS_MACOSX)
process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle,
NULL));
#else
process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle));
#endif
cpu_usage_ = process_metrics_->GetCPUUsage(); // Initialize CPU usage counters
cpu_usage_sample_time_ = base::TimeTicks::Now();
}
bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) { bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(RenderMessageFilter, message) IPC_BEGIN_MESSAGE_MAP(RenderMessageFilter, message)
...@@ -451,7 +434,6 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -451,7 +434,6 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewHostMsg_DidGenerateCacheableMetadata, IPC_MESSAGE_HANDLER(ViewHostMsg_DidGenerateCacheableMetadata,
OnCacheableMetadataAvailable) OnCacheableMetadataAvailable)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_Keygen, OnKeygen) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_Keygen, OnKeygen)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPUUsage, OnGetCPUUsage)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioHardwareConfig, IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioHardwareConfig,
OnGetAudioHardwareConfig) OnGetAudioHardwareConfig)
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -852,16 +834,6 @@ void RenderMessageFilter::OnGenerateRoutingID(int* route_id) { ...@@ -852,16 +834,6 @@ void RenderMessageFilter::OnGenerateRoutingID(int* route_id) {
*route_id = render_widget_helper_->GetNextRoutingID(); *route_id = render_widget_helper_->GetNextRoutingID();
} }
void RenderMessageFilter::OnGetCPUUsage(int* cpu_usage) {
base::TimeTicks now = base::TimeTicks::Now();
int64 since_last_sample_ms = (now - cpu_usage_sample_time_).InMilliseconds();
if (since_last_sample_ms > kCPUUsageSampleIntervalMs) {
cpu_usage_sample_time_ = now;
cpu_usage_ = static_cast<int>(process_metrics_->GetCPUUsage());
}
*cpu_usage = cpu_usage_;
}
void RenderMessageFilter::OnGetAudioHardwareConfig( void RenderMessageFilter::OnGetAudioHardwareConfig(
media::AudioParameters* input_params, media::AudioParameters* input_params,
media::AudioParameters* output_params) { media::AudioParameters* output_params) {
......
...@@ -101,7 +101,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter { ...@@ -101,7 +101,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
// IPC::MessageFilter methods: // IPC::MessageFilter methods:
virtual void OnChannelClosing() OVERRIDE; virtual void OnChannelClosing() OVERRIDE;
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
// BrowserMessageFilter methods: // BrowserMessageFilter methods:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
...@@ -214,8 +213,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter { ...@@ -214,8 +213,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
void OnCheckNotificationPermission(const GURL& source_origin, void OnCheckNotificationPermission(const GURL& source_origin,
int* permission_level); int* permission_level);
void OnGetCPUUsage(int* cpu_usage);
void OnGetAudioHardwareConfig(media::AudioParameters* input_params, void OnGetAudioHardwareConfig(media::AudioParameters* input_params,
media::AudioParameters* output_params); media::AudioParameters* output_params);
...@@ -334,13 +331,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter { ...@@ -334,13 +331,6 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
std::set<OpenChannelToNpapiPluginCallback*> plugin_host_clients_; std::set<OpenChannelToNpapiPluginCallback*> plugin_host_clients_;
// Records the last time we sampled CPU usage of the renderer process.
base::TimeTicks cpu_usage_sample_time_;
// Records the last sampled CPU usage in percents.
int cpu_usage_;
// Used for sampling CPU usage of the renderer process.
scoped_ptr<base::ProcessMetrics> process_metrics_;
media::AudioManager* audio_manager_; media::AudioManager* audio_manager_;
MediaInternals* media_internals_; MediaInternals* media_internals_;
......
...@@ -987,10 +987,6 @@ IPC_SYNC_MESSAGE_CONTROL0_2(ViewHostMsg_GetAudioHardwareConfig, ...@@ -987,10 +987,6 @@ IPC_SYNC_MESSAGE_CONTROL0_2(ViewHostMsg_GetAudioHardwareConfig,
media::AudioParameters /* input parameters */, media::AudioParameters /* input parameters */,
media::AudioParameters /* output parameters */) media::AudioParameters /* output parameters */)
// Asks the browser for CPU usage of the renderer process in percents.
IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_GetCPUUsage,
int /* CPU usage in percents */)
// Asks the browser for the renderer process memory size stats. // Asks the browser for the renderer process memory size stats.
IPC_SYNC_MESSAGE_CONTROL0_2(ViewHostMsg_GetProcessMemorySizes, IPC_SYNC_MESSAGE_CONTROL0_2(ViewHostMsg_GetProcessMemorySizes,
size_t /* private_bytes */, size_t /* private_bytes */,
......
...@@ -173,9 +173,7 @@ namespace content { ...@@ -173,9 +173,7 @@ namespace content {
namespace { namespace {
const int64 kInitialIdleHandlerDelayMs = 1000; const int64 kInitialIdleHandlerDelayMs = 1000;
const int64 kShortIdleHandlerDelayMs = 1000;
const int64 kLongIdleHandlerDelayMs = 30*1000; const int64 kLongIdleHandlerDelayMs = 30*1000;
const int kIdleCPUUsageThresholdInPercents = 3;
// Maximum allocation size allowed for image scaling filters that // Maximum allocation size allowed for image scaling filters that
// require pre-scaling. Skia will fallback to a filter that doesn't // require pre-scaling. Skia will fallback to a filter that doesn't
...@@ -1003,7 +1001,13 @@ void RenderThreadImpl::IdleHandler() { ...@@ -1003,7 +1001,13 @@ void RenderThreadImpl::IdleHandler() {
GetContentClient()->renderer()-> GetContentClient()->renderer()->
RunIdleHandlerWhenWidgetsHidden(); RunIdleHandlerWhenWidgetsHidden();
if (run_in_foreground_tab) { if (run_in_foreground_tab) {
IdleHandlerInForegroundTab(); if (idle_notifications_to_skip_ > 0) {
--idle_notifications_to_skip_;
} else {
base::allocator::ReleaseFreeMemory();
base::DiscardableMemory::ReduceMemoryUsage();
}
ScheduleIdleHandler(kLongIdleHandlerDelayMs);
return; return;
} }
...@@ -1047,42 +1051,6 @@ void RenderThreadImpl::IdleHandler() { ...@@ -1047,42 +1051,6 @@ void RenderThreadImpl::IdleHandler() {
FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
} }
void RenderThreadImpl::IdleHandlerInForegroundTab() {
// Increase the delay in the same way as in IdleHandler,
// but make it periodic by reseting it once it is too big.
int64 new_delay_ms = idle_notification_delay_in_ms_ +
1000000 / (idle_notification_delay_in_ms_ + 2000);
if (new_delay_ms >= kLongIdleHandlerDelayMs)
new_delay_ms = kShortIdleHandlerDelayMs;
if (idle_notifications_to_skip_ > 0) {
idle_notifications_to_skip_--;
} else {
int cpu_usage = 0;
Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
// Idle notification hint roughly specifies the expected duration of the
// idle pause. We set it proportional to the idle timer delay.
int idle_hint = static_cast<int>(new_delay_ms / 10);
if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
base::allocator::ReleaseFreeMemory();
bool finished_idle_work = true;
if (blink::mainThreadIsolate() &&
!blink::mainThreadIsolate()->IdleNotification(idle_hint)) {
finished_idle_work = false;
}
if (!base::DiscardableMemory::ReduceMemoryUsage())
finished_idle_work = false;
// V8 finished collecting garbage and discardable memory system has no
// more idle work left.
if (finished_idle_work)
new_delay_ms = kLongIdleHandlerDelayMs;
}
}
ScheduleIdleHandler(new_delay_ms);
}
int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
return idle_notification_delay_in_ms_; return idle_notification_delay_in_ms_;
} }
......
...@@ -452,8 +452,6 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, ...@@ -452,8 +452,6 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread,
void OnCreateNewSharedWorker( void OnCreateNewSharedWorker(
const WorkerProcessMsg_CreateWorker_Params& params); const WorkerProcessMsg_CreateWorker_Params& params);
void IdleHandlerInForegroundTab();
scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateOffscreenContext3d(); scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateOffscreenContext3d();
// These objects live solely on the render thread. // These objects live solely on the render thread.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment