diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 22:59:39 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 22:59:39 +0000 |
commit | 65fa1399cab981a3b8ddf96e3cbaa9a64b3efdd2 (patch) | |
tree | 8f4c747c4cdc26cf52721c0978477a1cc9686a53 /chrome | |
parent | 9bc32f394aad3058a016b05a0bd96a561f5be386 (diff) | |
download | chromium_src-65fa1399cab981a3b8ddf96e3cbaa9a64b3efdd2.zip chromium_src-65fa1399cab981a3b8ddf96e3cbaa9a64b3efdd2.tar.gz chromium_src-65fa1399cab981a3b8ddf96e3cbaa9a64b3efdd2.tar.bz2 |
Add a ticks counter that tells you how idle is a render process
It gives you a timedelta since the last time it was known that the renderer was active
- so far receiving a message from the renderer seems a simple heuristic.
- The goal is to use it to prioritize the use of hot renderers or do something to cold ones.
BUG=none
TEST=test included
Review URL: http://codereview.chromium.org/267018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28469 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 930c0b3..922f382 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -181,3 +181,17 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterWindowClose) { alert->AcceptWindow(); } +// Test that get_process_idle_time() returns reasonable values when compared +// with time deltas measured locally. +IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { + base::TimeTicks start = base::TimeTicks::Now(); + ui_test_utils::NavigateToURL(browser(), + ui_test_utils::GetTestUrl(L".", L"title1.html")); + RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); + for (; !it.IsAtEnd(); it.Advance()) { + base::TimeDelta renderer_td = + it.GetCurrentValue()->get_child_process_idle_time(); + base::TimeDelta browser_td = base::TimeTicks::Now() - start; + EXPECT_TRUE(browser_td >= renderer_td); + } +} diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index d699592..35df945 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -781,6 +781,7 @@ bool BrowserRenderProcessHost::Send(IPC::Message* msg) { } void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { + mark_child_process_activity_time(); if (msg.routing_id() == MSG_ROUTING_CONTROL) { // dispatch control messages bool msg_is_ok = true; @@ -860,6 +861,7 @@ void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { CHECK(peer_pid == process_.pid()) << peer_pid << " " << process_.pid(); #endif } + mark_child_process_activity_time(); } #if defined(IPC_MESSAGE_LOG_ENABLED) diff --git a/chrome/browser/renderer_host/render_process_host.cc b/chrome/browser/renderer_host/render_process_host.cc index 6cefab0..5f9363e 100644 --- a/chrome/browser/renderer_host/render_process_host.cc +++ b/chrome/browser/renderer_host/render_process_host.cc @@ -85,6 +85,8 @@ RenderProcessHost::RenderProcessHost(Profile* profile) ignore_input_events_(false) { all_hosts.AddWithID(this, id()); all_hosts.set_check_on_null_data(true); + // Initialize |child_process_activity_time_| to a reasonable value. + mark_child_process_activity_time(); } RenderProcessHost::~RenderProcessHost() { diff --git a/chrome/browser/renderer_host/render_process_host.h b/chrome/browser/renderer_host/render_process_host.h index f266e53..4014b63 100644 --- a/chrome/browser/renderer_host/render_process_host.h +++ b/chrome/browser/renderer_host/render_process_host.h @@ -11,6 +11,7 @@ #include "base/id_map.h" #include "base/process.h" #include "base/scoped_ptr.h" +#include "base/time.h" #include "chrome/common/transport_dib.h" #include "chrome/common/visitedlink_common.h" #include "ipc/ipc_sync_channel.h" @@ -108,6 +109,20 @@ class RenderProcessHost : public IPC::Channel::Sender, return ignore_input_events_; } + // Returns how long the child has been idle. The definition of idle + // depends on when a derived class calls mark_child_process_activity_time(). + // This is a rough indicator and its resolution should not be better than + // 10 milliseconds. + base::TimeDelta get_child_process_idle_time() const { + return base::TimeTicks::Now() - child_process_activity_time_; + } + + // Call this function when it is evident that the child process is actively + // performing some operation, for example if we just received an IPC message. + void mark_child_process_activity_time() { + child_process_activity_time_ = base::TimeTicks::Now(); + } + // Try to shutdown the associated render process as fast as possible, but // only if |count| matches the number of render widgets that this process // controls. @@ -263,6 +278,9 @@ class RenderProcessHost : public IPC::Channel::Sender, // See getter above. static bool run_renderer_in_process_; + // Records the last time we regarded the child process active. + base::TimeTicks child_process_activity_time_; + DISALLOW_COPY_AND_ASSIGN(RenderProcessHost); }; |