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

Side by Side Diff: content/renderer/renderer_main.cc

Issue 11829032: Add a histogram for renderer memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar build fixes Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/public/common/content_switches.cc ('k') | webkit/glue/webkit_glue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/debug/debugger.h" 7 #include "base/debug/debugger.h"
8 #include "base/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/hi_res_timer_manager.h" 10 #include "base/hi_res_timer_manager.h"
(...skipping 12 matching lines...) Expand all
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "content/common/pepper_plugin_registry.h" 24 #include "content/common/pepper_plugin_registry.h"
25 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
26 #include "content/public/common/main_function_params.h" 26 #include "content/public/common/main_function_params.h"
27 #include "content/public/renderer/content_renderer_client.h" 27 #include "content/public/renderer/content_renderer_client.h"
28 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" 28 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
29 #include "content/renderer/render_process_impl.h" 29 #include "content/renderer/render_process_impl.h"
30 #include "content/renderer/render_thread_impl.h" 30 #include "content/renderer/render_thread_impl.h"
31 #include "content/renderer/renderer_main_platform_delegate.h" 31 #include "content/renderer/renderer_main_platform_delegate.h"
32 #include "ui/base/ui_base_switches.h" 32 #include "ui/base/ui_base_switches.h"
33 #include "webkit/glue/webkit_glue.h"
33 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" 34 #include "webkit/plugins/ppapi/ppapi_interface_factory.h"
34 35
35 #if defined(OS_MACOSX) 36 #if defined(OS_MACOSX)
36 #include <Carbon/Carbon.h> 37 #include <Carbon/Carbon.h>
37 #include <signal.h> 38 #include <signal.h>
38 #include <unistd.h> 39 #include <unistd.h>
39 40
40 #include "base/mac/mac_util.h" 41 #include "base/mac/mac_util.h"
41 #include "base/mac/scoped_nsautorelease_pool.h" 42 #include "base/mac/scoped_nsautorelease_pool.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (!begin_process_message_.is_null()) 78 if (!begin_process_message_.is_null())
78 process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_); 79 process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_);
79 } 80 }
80 81
81 private: 82 private:
82 base::TimeTicks begin_process_message_; 83 base::TimeTicks begin_process_message_;
83 base::Histogram* const process_times_; 84 base::Histogram* const process_times_;
84 DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver); 85 DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver);
85 }; 86 };
86 87
88 // For measuring memory usage after each task. Behind a command line flag.
89 class MemoryObserver : public MessageLoop::TaskObserver {
90 public:
91 MemoryObserver() {}
92
93 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE {}
94
95 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE {
96 HISTOGRAM_MEMORY_KB("Memory.RendererUsed", webkit_glue::MemoryUsageKB());
97 }
98 private:
99 DISALLOW_COPY_AND_ASSIGN(MemoryObserver);
100 };
101
87 // mainline routine for running as the Renderer process 102 // mainline routine for running as the Renderer process
88 int RendererMain(const MainFunctionParams& parameters) { 103 int RendererMain(const MainFunctionParams& parameters) {
89 TRACE_EVENT_BEGIN_ETW("RendererMain", 0, ""); 104 TRACE_EVENT_BEGIN_ETW("RendererMain", 0, "");
90 105
91 const CommandLine& parsed_command_line = parameters.command_line; 106 const CommandLine& parsed_command_line = parameters.command_line;
92 107
93 #if defined(OS_MACOSX) 108 #if defined(OS_MACOSX)
94 base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool; 109 base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool;
95 #endif // OS_MACOSX 110 #endif // OS_MACOSX
96 111
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // now; see http://crbug.com/13890 for info) we need to have a UI loop. 143 // now; see http://crbug.com/13890 for info) we need to have a UI loop.
129 MessageLoop main_message_loop(MessageLoop::TYPE_UI); 144 MessageLoop main_message_loop(MessageLoop::TYPE_UI);
130 #else 145 #else
131 // The main message loop of the renderer services doesn't have IO or UI tasks, 146 // The main message loop of the renderer services doesn't have IO or UI tasks,
132 // unless in-process-plugins is used. 147 // unless in-process-plugins is used.
133 MessageLoop main_message_loop(RenderProcessImpl::InProcessPlugins() ? 148 MessageLoop main_message_loop(RenderProcessImpl::InProcessPlugins() ?
134 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT); 149 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT);
135 #endif 150 #endif
136 main_message_loop.AddTaskObserver(&task_observer); 151 main_message_loop.AddTaskObserver(&task_observer);
137 152
153 scoped_ptr<MemoryObserver> memory_observer;
154 if (parsed_command_line.HasSwitch(switches::kMemoryMetrics)) {
155 memory_observer.reset(new MemoryObserver());
156 main_message_loop.AddTaskObserver(memory_observer.get());
157 }
158
138 base::PlatformThread::SetName("CrRendererMain"); 159 base::PlatformThread::SetName("CrRendererMain");
139 160
140 base::SystemMonitor system_monitor; 161 base::SystemMonitor system_monitor;
141 HighResolutionTimerManager hi_res_timer_manager; 162 HighResolutionTimerManager hi_res_timer_manager;
142 163
143 platform.PlatformInitialize(); 164 platform.PlatformInitialize();
144 165
145 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox); 166 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox);
146 platform.InitSandboxTests(no_sandbox); 167 platform.InitSandboxTests(no_sandbox);
147 168
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 MessageLoop::current()->Run(); 223 MessageLoop::current()->Run();
203 TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0); 224 TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0);
204 } 225 }
205 } 226 }
206 platform.PlatformUninitialize(); 227 platform.PlatformUninitialize();
207 TRACE_EVENT_END_ETW("RendererMain", 0, ""); 228 TRACE_EVENT_END_ETW("RendererMain", 0, "");
208 return 0; 229 return 0;
209 } 230 }
210 231
211 } // namespace content 232 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/content_switches.cc ('k') | webkit/glue/webkit_glue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698