Index: chrome/renderer/chrome_render_process_observer.cc |
diff --git a/chrome/renderer/chrome_render_process_observer.cc b/chrome/renderer/chrome_render_process_observer.cc |
index 15657296ed8e23414ed2e66c4247e40ce9177157..388c1053bdf08c79356e616fc087ba651d9cd703 100644 |
--- a/chrome/renderer/chrome_render_process_observer.cc |
+++ b/chrome/renderer/chrome_render_process_observer.cc |
@@ -34,6 +34,7 @@ |
#include "content/public/renderer/render_thread.h" |
#include "content/public/renderer/render_view.h" |
#include "content/public/renderer/render_view_visitor.h" |
+#include "content/public/renderer/v8_heap_statistics_collector.h" |
#include "crypto/nss_util.h" |
#include "net/base/net_errors.h" |
#include "net/base/net_module.h" |
@@ -145,102 +146,6 @@ DWORD WINAPI GetFontDataPatch(HDC hdc, |
} |
#endif // OS_WIN |
-static const int kWaitForWorkersStatsTimeoutMS = 20; |
- |
-class HeapStatisticsCollector { |
- public: |
- HeapStatisticsCollector() : round_id_(0) {} |
- |
- void InitiateCollection(); |
- static HeapStatisticsCollector* Instance(); |
- |
- private: |
- void CollectOnWorkerThread(scoped_refptr<base::TaskRunner> master, |
- int round_id); |
- void ReceiveStats(int round_id, size_t total_size, size_t used_size); |
- void SendStatsToBrowser(int round_id); |
- |
- size_t total_bytes_; |
- size_t used_bytes_; |
- int workers_to_go_; |
- int round_id_; |
-}; |
- |
-HeapStatisticsCollector* HeapStatisticsCollector::Instance() { |
- CR_DEFINE_STATIC_LOCAL(HeapStatisticsCollector, instance, ()); |
- return &instance; |
-} |
- |
-void HeapStatisticsCollector::InitiateCollection() { |
- v8::HeapStatistics heap_stats; |
- v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_stats); |
- total_bytes_ = heap_stats.total_heap_size(); |
- used_bytes_ = heap_stats.used_heap_size(); |
- base::Closure collect = base::Bind( |
- &HeapStatisticsCollector::CollectOnWorkerThread, |
- base::Unretained(this), |
- base::MessageLoopProxy::current(), |
- round_id_); |
- workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect); |
- if (workers_to_go_) { |
- // The guard task to send out partial stats |
- // in case some workers are not responsive. |
- base::MessageLoopProxy::current()->PostDelayedTask( |
- FROM_HERE, |
- base::Bind(&HeapStatisticsCollector::SendStatsToBrowser, |
- base::Unretained(this), |
- round_id_), |
- base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS)); |
- } else { |
- // No worker threads so just send out the main thread data right away. |
- SendStatsToBrowser(round_id_); |
- } |
-} |
- |
-void HeapStatisticsCollector::CollectOnWorkerThread( |
- scoped_refptr<base::TaskRunner> master, |
- int round_id) { |
- |
- size_t total_bytes = 0; |
- size_t used_bytes = 0; |
- v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
- if (isolate) { |
- v8::HeapStatistics heap_stats; |
- isolate->GetHeapStatistics(&heap_stats); |
- total_bytes = heap_stats.total_heap_size(); |
- used_bytes = heap_stats.used_heap_size(); |
- } |
- master->PostTask( |
- FROM_HERE, |
- base::Bind(&HeapStatisticsCollector::ReceiveStats, |
- base::Unretained(this), |
- round_id, |
- total_bytes, |
- used_bytes)); |
-} |
- |
-void HeapStatisticsCollector::ReceiveStats(int round_id, |
- size_t total_bytes, |
- size_t used_bytes) { |
- if (round_id != round_id_) |
- return; |
- total_bytes_ += total_bytes; |
- used_bytes_ += used_bytes; |
- if (!--workers_to_go_) |
- SendStatsToBrowser(round_id); |
-} |
- |
-void HeapStatisticsCollector::SendStatsToBrowser(int round_id) { |
- if (round_id != round_id_) |
- return; |
- // TODO(alph): Do caching heap stats and use the cache if we haven't got |
- // reply from a worker. |
- // Currently a busy worker stats are not counted. |
- RenderThread::Get()->Send(new ChromeViewHostMsg_V8HeapStats( |
- total_bytes_, used_bytes_)); |
- ++round_id_; |
-} |
- |
} // namespace |
bool ChromeRenderProcessObserver::is_incognito_process_ = false; |
@@ -399,8 +304,19 @@ void ChromeRenderProcessObserver::OnSetFieldTrialGroup( |
chrome_variations::SetChildProcessLoggingVariationList(); |
} |
+namespace { |
+ |
+void OnV8HeapStatsCollected( |
+ const content::V8HeapStatisticsCollector::Statistics& stats) { |
+ RenderThread::Get()->Send(new ChromeViewHostMsg_V8HeapStats( |
+ stats.total_bytes, stats.used_bytes)); |
+} |
+ |
+} // namespace |
+ |
void ChromeRenderProcessObserver::OnGetV8HeapStats() { |
- HeapStatisticsCollector::Instance()->InitiateCollection(); |
+ content::V8HeapStatisticsCollector::Instance()->InitiateCollection( |
+ base::Bind(OnV8HeapStatsCollected)); |
} |
void ChromeRenderProcessObserver::ExecutePendingClearCache() { |