OLD | NEW |
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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/statistics_recorder.h" | 15 #include "base/metrics/statistics_recorder.h" |
16 #include "base/metrics/stats_counters.h" | 16 #include "base/metrics/stats_counters.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/pending_task.h" | 18 #include "base/pending_task.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
21 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/timer/hi_res_timer_manager.h" | 23 #include "base/timer/hi_res_timer_manager.h" |
24 #include "content/child/child_process.h" | 24 #include "content/child/child_process.h" |
25 #include "content/child/content_child_helpers.h" | |
26 #include "content/common/content_constants_internal.h" | 25 #include "content/common/content_constants_internal.h" |
27 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/main_function_params.h" | 27 #include "content/public/common/main_function_params.h" |
29 #include "content/public/renderer/content_renderer_client.h" | 28 #include "content/public/renderer/content_renderer_client.h" |
30 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" | 29 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
31 #include "content/renderer/pepper/pepper_plugin_registry.h" | 30 #include "content/renderer/pepper/pepper_plugin_registry.h" |
32 #include "content/renderer/render_process_impl.h" | 31 #include "content/renderer/render_process_impl.h" |
33 #include "content/renderer/render_thread_impl.h" | 32 #include "content/renderer/render_thread_impl.h" |
34 #include "content/renderer/renderer_main_platform_delegate.h" | 33 #include "content/renderer/renderer_main_platform_delegate.h" |
35 #include "ui/base/ui_base_switches.h" | 34 #include "ui/base/ui_base_switches.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 if (!begin_process_message_.is_null()) | 87 if (!begin_process_message_.is_null()) |
89 process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_); | 88 process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_); |
90 } | 89 } |
91 | 90 |
92 private: | 91 private: |
93 base::TimeTicks begin_process_message_; | 92 base::TimeTicks begin_process_message_; |
94 base::HistogramBase* const process_times_; | 93 base::HistogramBase* const process_times_; |
95 DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver); | 94 DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver); |
96 }; | 95 }; |
97 | 96 |
98 // For measuring memory usage after each task. Behind a command line flag. | |
99 class MemoryObserver : public base::MessageLoop::TaskObserver { | |
100 public: | |
101 MemoryObserver() {} | |
102 virtual ~MemoryObserver() {} | |
103 | |
104 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | |
105 } | |
106 | |
107 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | |
108 HISTOGRAM_MEMORY_KB("Memory.RendererUsed", GetMemoryUsageKB()); | |
109 } | |
110 private: | |
111 DISALLOW_COPY_AND_ASSIGN(MemoryObserver); | |
112 }; | |
113 | |
114 } // namespace | 97 } // namespace |
115 | 98 |
116 // mainline routine for running as the Renderer process | 99 // mainline routine for running as the Renderer process |
117 int RendererMain(const MainFunctionParams& parameters) { | 100 int RendererMain(const MainFunctionParams& parameters) { |
118 TRACE_EVENT_BEGIN_ETW("RendererMain", 0, ""); | 101 TRACE_EVENT_BEGIN_ETW("RendererMain", 0, ""); |
119 base::debug::TraceLog::GetInstance()->SetProcessName("Renderer"); | 102 base::debug::TraceLog::GetInstance()->SetProcessName("Renderer"); |
120 base::debug::TraceLog::GetInstance()->SetProcessSortIndex( | 103 base::debug::TraceLog::GetInstance()->SetProcessSortIndex( |
121 kTraceEventRendererProcessSortIndex); | 104 kTraceEventRendererProcessSortIndex); |
122 | 105 |
123 const CommandLine& parsed_command_line = parameters.command_line; | 106 const CommandLine& parsed_command_line = parameters.command_line; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // needs to be backed by a Foundation-level loop to process NSTimers. See | 146 // needs to be backed by a Foundation-level loop to process NSTimers. See |
164 // http://crbug.com/306348#c24 for details. | 147 // http://crbug.com/306348#c24 for details. |
165 scoped_ptr<base::MessagePump> pump(new base::MessagePumpNSRunLoop()); | 148 scoped_ptr<base::MessagePump> pump(new base::MessagePumpNSRunLoop()); |
166 base::MessageLoop main_message_loop(pump.Pass()); | 149 base::MessageLoop main_message_loop(pump.Pass()); |
167 #else | 150 #else |
168 // The main message loop of the renderer services doesn't have IO or UI tasks. | 151 // The main message loop of the renderer services doesn't have IO or UI tasks. |
169 base::MessageLoop main_message_loop; | 152 base::MessageLoop main_message_loop; |
170 #endif | 153 #endif |
171 main_message_loop.AddTaskObserver(&task_observer); | 154 main_message_loop.AddTaskObserver(&task_observer); |
172 | 155 |
173 scoped_ptr<MemoryObserver> memory_observer; | |
174 if (parsed_command_line.HasSwitch(switches::kMemoryMetrics)) { | |
175 memory_observer.reset(new MemoryObserver()); | |
176 main_message_loop.AddTaskObserver(memory_observer.get()); | |
177 } | |
178 | |
179 base::PlatformThread::SetName("CrRendererMain"); | 156 base::PlatformThread::SetName("CrRendererMain"); |
180 | 157 |
181 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox); | 158 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox); |
182 | 159 |
183 // Initialize histogram statistics gathering system. | 160 // Initialize histogram statistics gathering system. |
184 base::StatisticsRecorder::Initialize(); | 161 base::StatisticsRecorder::Initialize(); |
185 | 162 |
186 // Initialize statistical testing infrastructure. We set the entropy provider | 163 // Initialize statistical testing infrastructure. We set the entropy provider |
187 // to NULL to disallow the renderer process from creating its own one-time | 164 // to NULL to disallow the renderer process from creating its own one-time |
188 // randomized trials; they should be created in the browser process. | 165 // randomized trials; they should be created in the browser process. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 base::MessageLoop::current()->Run(); | 227 base::MessageLoop::current()->Run(); |
251 TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0); | 228 TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0); |
252 } | 229 } |
253 } | 230 } |
254 platform.PlatformUninitialize(); | 231 platform.PlatformUninitialize(); |
255 TRACE_EVENT_END_ETW("RendererMain", 0, ""); | 232 TRACE_EVENT_END_ETW("RendererMain", 0, ""); |
256 return 0; | 233 return 0; |
257 } | 234 } |
258 | 235 |
259 } // namespace content | 236 } // namespace content |
OLD | NEW |