Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/renderer/chrome_render_process_observer.cc

Issue 196103006: Add V8 heap statistics in a time-line manner in tracing. (Closed) Base URL: /home/dmikurube/repos/chromium@work-sai-json
Patch Set: rebased Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/chrome_render_process_observer.h" 5 #include "chrome/renderer/chrome_render_process_observer.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/allocator/allocator_extension.h" 10 #include "base/allocator/allocator_extension.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "chrome/common/variations/variations_util.h" 29 #include "chrome/common/variations/variations_util.h"
30 #include "chrome/renderer/content_settings_observer.h" 30 #include "chrome/renderer/content_settings_observer.h"
31 #include "chrome/renderer/extensions/extension_localization_peer.h" 31 #include "chrome/renderer/extensions/extension_localization_peer.h"
32 #include "chrome/renderer/security_filter_peer.h" 32 #include "chrome/renderer/security_filter_peer.h"
33 #include "content/public/child/resource_dispatcher_delegate.h" 33 #include "content/public/child/resource_dispatcher_delegate.h"
34 #include "content/public/renderer/render_thread.h" 34 #include "content/public/renderer/render_thread.h"
35 #include "content/public/renderer/render_view.h" 35 #include "content/public/renderer/render_view.h"
36 #include "content/public/renderer/render_view_visitor.h" 36 #include "content/public/renderer/render_view_visitor.h"
37 #include "content/public/renderer/v8_heap_statistics_collector.h"
37 #include "crypto/nss_util.h" 38 #include "crypto/nss_util.h"
38 #include "net/base/net_errors.h" 39 #include "net/base/net_errors.h"
39 #include "net/base/net_module.h" 40 #include "net/base/net_module.h"
40 #include "third_party/WebKit/public/web/WebCache.h" 41 #include "third_party/WebKit/public/web/WebCache.h"
41 #include "third_party/WebKit/public/web/WebDocument.h" 42 #include "third_party/WebKit/public/web/WebDocument.h"
42 #include "third_party/WebKit/public/web/WebFrame.h" 43 #include "third_party/WebKit/public/web/WebFrame.h"
43 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 44 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
44 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
45 #include "third_party/WebKit/public/web/WebView.h" 46 #include "third_party/WebKit/public/web/WebView.h"
46 47
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 std::vector<char> font_data; 139 std::vector<char> font_data;
139 RenderThread::Get()->PreCacheFont(logfont); 140 RenderThread::Get()->PreCacheFont(logfont);
140 rv = GetFontData(hdc, table, offset, buffer, length); 141 rv = GetFontData(hdc, table, offset, buffer, length);
141 RenderThread::Get()->ReleaseCachedFonts(); 142 RenderThread::Get()->ReleaseCachedFonts();
142 } 143 }
143 } 144 }
144 return rv; 145 return rv;
145 } 146 }
146 #endif // OS_WIN 147 #endif // OS_WIN
147 148
148 static const int kWaitForWorkersStatsTimeoutMS = 20;
149
150 class HeapStatisticsCollector {
151 public:
152 HeapStatisticsCollector() : round_id_(0) {}
153
154 void InitiateCollection();
155 static HeapStatisticsCollector* Instance();
156
157 private:
158 void CollectOnWorkerThread(scoped_refptr<base::TaskRunner> master,
159 int round_id);
160 void ReceiveStats(int round_id, size_t total_size, size_t used_size);
161 void SendStatsToBrowser(int round_id);
162
163 size_t total_bytes_;
164 size_t used_bytes_;
165 int workers_to_go_;
166 int round_id_;
167 };
168
169 HeapStatisticsCollector* HeapStatisticsCollector::Instance() {
170 CR_DEFINE_STATIC_LOCAL(HeapStatisticsCollector, instance, ());
171 return &instance;
172 }
173
174 void HeapStatisticsCollector::InitiateCollection() {
175 v8::HeapStatistics heap_stats;
176 v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_stats);
177 total_bytes_ = heap_stats.total_heap_size();
178 used_bytes_ = heap_stats.used_heap_size();
179 base::Closure collect = base::Bind(
180 &HeapStatisticsCollector::CollectOnWorkerThread,
181 base::Unretained(this),
182 base::MessageLoopProxy::current(),
183 round_id_);
184 workers_to_go_ = RenderThread::Get()->PostTaskToAllWebWorkers(collect);
185 if (workers_to_go_) {
186 // The guard task to send out partial stats
187 // in case some workers are not responsive.
188 base::MessageLoopProxy::current()->PostDelayedTask(
189 FROM_HERE,
190 base::Bind(&HeapStatisticsCollector::SendStatsToBrowser,
191 base::Unretained(this),
192 round_id_),
193 base::TimeDelta::FromMilliseconds(kWaitForWorkersStatsTimeoutMS));
194 } else {
195 // No worker threads so just send out the main thread data right away.
196 SendStatsToBrowser(round_id_);
197 }
198 }
199
200 void HeapStatisticsCollector::CollectOnWorkerThread(
201 scoped_refptr<base::TaskRunner> master,
202 int round_id) {
203
204 size_t total_bytes = 0;
205 size_t used_bytes = 0;
206 v8::Isolate* isolate = v8::Isolate::GetCurrent();
207 if (isolate) {
208 v8::HeapStatistics heap_stats;
209 isolate->GetHeapStatistics(&heap_stats);
210 total_bytes = heap_stats.total_heap_size();
211 used_bytes = heap_stats.used_heap_size();
212 }
213 master->PostTask(
214 FROM_HERE,
215 base::Bind(&HeapStatisticsCollector::ReceiveStats,
216 base::Unretained(this),
217 round_id,
218 total_bytes,
219 used_bytes));
220 }
221
222 void HeapStatisticsCollector::ReceiveStats(int round_id,
223 size_t total_bytes,
224 size_t used_bytes) {
225 if (round_id != round_id_)
226 return;
227 total_bytes_ += total_bytes;
228 used_bytes_ += used_bytes;
229 if (!--workers_to_go_)
230 SendStatsToBrowser(round_id);
231 }
232
233 void HeapStatisticsCollector::SendStatsToBrowser(int round_id) {
234 if (round_id != round_id_)
235 return;
236 // TODO(alph): Do caching heap stats and use the cache if we haven't got
237 // reply from a worker.
238 // Currently a busy worker stats are not counted.
239 RenderThread::Get()->Send(new ChromeViewHostMsg_V8HeapStats(
240 total_bytes_, used_bytes_));
241 ++round_id_;
242 }
243
244 } // namespace 149 } // namespace
245 150
246 bool ChromeRenderProcessObserver::is_incognito_process_ = false; 151 bool ChromeRenderProcessObserver::is_incognito_process_ = false;
247 152
248 ChromeRenderProcessObserver::ChromeRenderProcessObserver( 153 ChromeRenderProcessObserver::ChromeRenderProcessObserver(
249 ChromeContentRendererClient* client) 154 ChromeContentRendererClient* client)
250 : client_(client), 155 : client_(client),
251 clear_cache_pending_(false), 156 clear_cache_pending_(false),
252 webkit_initialized_(false), 157 webkit_initialized_(false),
253 pending_cache_min_dead_capacity_(0), 158 pending_cache_min_dead_capacity_(0),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 base::FieldTrial* trial = 297 base::FieldTrial* trial =
393 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); 298 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name);
394 // TODO(mef): Remove this check after the investigation of 359406 is complete. 299 // TODO(mef): Remove this check after the investigation of 359406 is complete.
395 CHECK(trial) << field_trial_name << ":" << group_name; 300 CHECK(trial) << field_trial_name << ":" << group_name;
396 // Ensure the trial is marked as "used" by calling group() on it. This is 301 // Ensure the trial is marked as "used" by calling group() on it. This is
397 // needed to ensure the trial is properly reported in renderer crash reports. 302 // needed to ensure the trial is properly reported in renderer crash reports.
398 trial->group(); 303 trial->group();
399 chrome_variations::SetChildProcessLoggingVariationList(); 304 chrome_variations::SetChildProcessLoggingVariationList();
400 } 305 }
401 306
307 namespace {
308
309 void OnV8HeapStatsCollected(
310 const content::V8HeapStatisticsCollector::Statistics& stats) {
311 RenderThread::Get()->Send(new ChromeViewHostMsg_V8HeapStats(
312 stats.total_bytes, stats.used_bytes));
313 }
314
315 } // namespace
316
402 void ChromeRenderProcessObserver::OnGetV8HeapStats() { 317 void ChromeRenderProcessObserver::OnGetV8HeapStats() {
403 HeapStatisticsCollector::Instance()->InitiateCollection(); 318 content::V8HeapStatisticsCollector::Instance()->InitiateCollection(
319 base::Bind(OnV8HeapStatsCollected));
404 } 320 }
405 321
406 void ChromeRenderProcessObserver::ExecutePendingClearCache() { 322 void ChromeRenderProcessObserver::ExecutePendingClearCache() {
407 if (clear_cache_pending_ && webkit_initialized_) { 323 if (clear_cache_pending_ && webkit_initialized_) {
408 clear_cache_pending_ = false; 324 clear_cache_pending_ = false;
409 WebCache::clear(); 325 WebCache::clear();
410 } 326 }
411 } 327 }
412 328
413 const RendererContentSettingRules* 329 const RendererContentSettingRules*
414 ChromeRenderProcessObserver::content_setting_rules() const { 330 ChromeRenderProcessObserver::content_setting_rules() const {
415 return &content_setting_rules_; 331 return &content_setting_rules_;
416 } 332 }
OLDNEW
« no previous file with comments | « no previous file | content/content_renderer.gypi » ('j') | content/public/renderer/v8_heap_statistics_collector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698