| 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 "chrome/common/profiling.h" | 5 #include "chrome/common/profiling.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/profiler.h" | 10 #include "base/debug/profiler.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "gin/public/debug.h" |
| 16 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL; | 21 base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL; |
| 21 base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL; | 22 base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL; |
| 22 | 23 |
| 23 void JitCodeEventHandler(const v8::JitCodeEvent* event) { | 24 void JitCodeEventHandler(const v8::JitCodeEvent* event) { |
| 24 DCHECK_NE(static_cast<base::debug::AddDynamicSymbol>(NULL), | 25 DCHECK_NE(static_cast<base::debug::AddDynamicSymbol>(NULL), |
| 25 add_dynamic_symbol_func); | 26 add_dynamic_symbol_func); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 140 |
| 140 // Set up the JIT code entry handler and the symbol callbacks if the | 141 // Set up the JIT code entry handler and the symbol callbacks if the |
| 141 // profiler supplies them. | 142 // profiler supplies them. |
| 142 // TODO(siggi): Maybe add a switch or an environment variable to turn off | 143 // TODO(siggi): Maybe add a switch or an environment variable to turn off |
| 143 // V8 profiling? | 144 // V8 profiling? |
| 144 base::debug::DynamicFunctionEntryHook entry_hook_func = | 145 base::debug::DynamicFunctionEntryHook entry_hook_func = |
| 145 base::debug::GetProfilerDynamicFunctionEntryHookFunc(); | 146 base::debug::GetProfilerDynamicFunctionEntryHookFunc(); |
| 146 add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc(); | 147 add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc(); |
| 147 move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc(); | 148 move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc(); |
| 148 | 149 |
| 149 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 150 if (entry_hook_func != NULL && |
| 150 if (isolate != NULL && | |
| 151 entry_hook_func != NULL && | |
| 152 add_dynamic_symbol_func != NULL && | 151 add_dynamic_symbol_func != NULL && |
| 153 move_dynamic_symbol_func != NULL) { | 152 move_dynamic_symbol_func != NULL) { |
| 154 v8::V8::SetFunctionEntryHook(isolate, entry_hook_func); | 153 gin::Debug::SetFunctionEntryHook(entry_hook_func); |
| 155 v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, | 154 gin::Debug::SetJitCodeEventHandler(&JitCodeEventHandler); |
| 156 &JitCodeEventHandler); | |
| 157 } | 155 } |
| 158 } | 156 } |
| 159 | 157 |
| 160 if (command_line.HasSwitch(switches::kProfilingAtStart)) { | 158 if (command_line.HasSwitch(switches::kProfilingAtStart)) { |
| 161 std::string process_type_to_start = | 159 std::string process_type_to_start = |
| 162 command_line.GetSwitchValueASCII(switches::kProfilingAtStart); | 160 command_line.GetSwitchValueASCII(switches::kProfilingAtStart); |
| 163 if (process_type == process_type_to_start) | 161 if (process_type == process_type_to_start) |
| 164 Start(); | 162 Start(); |
| 165 } | 163 } |
| 166 } | 164 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 188 return base::debug::BeingProfiled(); | 186 return base::debug::BeingProfiled(); |
| 189 } | 187 } |
| 190 | 188 |
| 191 // static | 189 // static |
| 192 void Profiling::Toggle() { | 190 void Profiling::Toggle() { |
| 193 if (BeingProfiled()) | 191 if (BeingProfiled()) |
| 194 Stop(); | 192 Stop(); |
| 195 else | 193 else |
| 196 Start(); | 194 Start(); |
| 197 } | 195 } |
| OLD | NEW |