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

Side by Side Diff: components/web_cache/browser/web_cache_manager.cc

Issue 1283793004: [tracing] Add WebCache memory usage in Blink to chrome://tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unregister. Created 5 years, 4 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 "components/web_cache/browser/web_cache_manager.h" 5 #include "components/web_cache/browser/web_cache_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/format_macros.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
13 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 #include "base/prefs/pref_registry_simple.h" 15 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/stringprintf.h"
17 #include "base/sys_info.h" 19 #include "base/sys_info.h"
18 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "base/trace_event/memory_allocator_dump.h"
23 #include "base/trace_event/memory_dump_manager.h"
24 #include "base/trace_event/process_memory_dump.h"
20 #include "components/web_cache/common/web_cache_messages.h" 25 #include "components/web_cache/common/web_cache_messages.h"
26 #include "content/common/child_process_host_impl.h"
21 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
24 30
25 using base::Time; 31 using base::Time;
26 using base::TimeDelta; 32 using base::TimeDelta;
27 using blink::WebCache; 33 using blink::WebCache;
28 34
29 namespace web_cache { 35 namespace web_cache {
30 36
(...skipping 28 matching lines...) Expand all
59 return Singleton<WebCacheManager>::get(); 65 return Singleton<WebCacheManager>::get();
60 } 66 }
61 67
62 WebCacheManager::WebCacheManager() 68 WebCacheManager::WebCacheManager()
63 : global_size_limit_(GetDefaultGlobalSizeLimit()), 69 : global_size_limit_(GetDefaultGlobalSizeLimit()),
64 weak_factory_(this) { 70 weak_factory_(this) {
65 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 71 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
66 content::NotificationService::AllBrowserContextsAndSources()); 72 content::NotificationService::AllBrowserContextsAndSources());
67 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 73 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
68 content::NotificationService::AllBrowserContextsAndSources()); 74 content::NotificationService::AllBrowserContextsAndSources());
75 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
76 this);
69 } 77 }
70 78
71 WebCacheManager::~WebCacheManager() { 79 WebCacheManager::~WebCacheManager() {
80 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
81 this);
72 } 82 }
73 83
74 void WebCacheManager::Add(int renderer_id) { 84 void WebCacheManager::Add(int renderer_id) {
75 DCHECK(inactive_renderers_.count(renderer_id) == 0); 85 DCHECK(inactive_renderers_.count(renderer_id) == 0);
76 86
77 // It is tempting to make the following DCHECK here, but it fails when a new 87 // It is tempting to make the following DCHECK here, but it fails when a new
78 // tab is created as we observe activity from that tab because the 88 // tab is created as we observe activity from that tab because the
79 // RenderProcessHost is recreated and adds itself. 89 // RenderProcessHost is recreated and adds itself.
80 // 90 //
81 // DCHECK(active_renderers_.count(renderer_id) == 0); 91 // DCHECK(active_renderers_.count(renderer_id) == 0);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 content::Source<content::RenderProcessHost>(source).ptr(); 180 content::Source<content::RenderProcessHost>(source).ptr();
171 Remove(process->GetID()); 181 Remove(process->GetID());
172 break; 182 break;
173 } 183 }
174 default: 184 default:
175 NOTREACHED(); 185 NOTREACHED();
176 break; 186 break;
177 } 187 }
178 } 188 }
179 189
190 bool WebCacheManager::OnMemoryDump(
191 const base::trace_event::MemoryDumpArgs& args,
192 base::trace_event::ProcessMemoryDump* pmd) {
193 std::set<int>::const_iterator active_renderers_iter =
194 active_renderers_.begin();
195 while (active_renderers_iter != active_renderers_.end()) {
196 DumpUsageStats(*active_renderers_iter, pmd);
197 ++active_renderers_iter;
198 }
199
200 std::set<int>::const_iterator inactive_renderers_iter =
201 inactive_renderers_.begin();
202 while (inactive_renderers_iter != inactive_renderers_.end()) {
203 DumpUsageStats(*inactive_renderers_iter, pmd);
204 ++inactive_renderers_iter;
205 }
206
207 return true;
208 }
209
210 void WebCacheManager::DumpUsageStats(
211 int renderer_id,
212 base::trace_event::ProcessMemoryDump* pmd) {
213 StatsMap::iterator stats = stats_.find(renderer_id);
214 if (stats == stats_.end())
215 return;
216 uint64 child_tracing_id =
217 content::ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
ssid 2015/08/11 17:40:01 This causes a DEPS addition to component which is
218 renderer_id);
219 std::string dump_name = base::StringPrintf(
220 "web_cache/renderer_%lu", static_cast<unsigned long>(child_tracing_id));
221 base::trace_event::MemoryAllocatorDump* allocator_dump =
222 pmd->CreateAllocatorDump(dump_name);
223 allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
224 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
225 stats->second.liveSize + stats->second.deadSize);
226
227 allocator_dump->AddScalar("live_size",
228 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
229 stats->second.liveSize);
230 allocator_dump->AddScalar("dead_size",
231 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
232 stats->second.deadSize);
233
234 auto shared_guid = base::trace_event::MemoryAllocatorDumpGuid(
235 base::StringPrintf("web-cache-x-process/%" PRIx64, child_tracing_id));
236 pmd->CreateSharedGlobalAllocatorDump(shared_guid);
237 pmd->AddOwnershipEdge(allocator_dump->guid(), shared_guid);
238 }
239
180 // static 240 // static
181 size_t WebCacheManager::GetDefaultGlobalSizeLimit() { 241 size_t WebCacheManager::GetDefaultGlobalSizeLimit() {
182 return GetDefaultCacheSize(); 242 return GetDefaultCacheSize();
183 } 243 }
184 244
185 void WebCacheManager::GatherStats(const std::set<int>& renderers, 245 void WebCacheManager::GatherStats(const std::set<int>& renderers,
186 WebCache::UsageStats* stats) { 246 WebCache::UsageStats* stats) {
187 DCHECK(stats); 247 DCHECK(stats);
188 248
189 memset(stats, 0, sizeof(WebCache::UsageStats)); 249 memset(stats, 0, sizeof(WebCache::UsageStats));
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 inactive_renderers_.insert(*iter); 494 inactive_renderers_.insert(*iter);
435 active_renderers_.erase(*iter); 495 active_renderers_.erase(*iter);
436 iter = active_renderers_.begin(); 496 iter = active_renderers_.begin();
437 continue; 497 continue;
438 } 498 }
439 ++iter; 499 ++iter;
440 } 500 }
441 } 501 }
442 502
443 } // namespace web_cache 503 } // namespace web_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698