Index: chrome/common/profiling.cc |
diff --git a/chrome/common/profiling.cc b/chrome/common/profiling.cc |
index 1acb43fea13a9d4e0e4bb58ffa0d61710f461cba..1eb5829dc96bb31306e8e4e28f165106bb3461e9 100644 |
--- a/chrome/common/profiling.cc |
+++ b/chrome/common/profiling.cc |
@@ -16,6 +16,25 @@ |
#include "v8/include/v8.h" |
namespace { |
+ |
+base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL; |
+base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL; |
+ |
+void JitCodeEventHandler(const v8::JitCodeEvent* event) { |
+ DCHECK(add_dynamic_symbol_func != NULL && move_dynamic_symbol_func != NULL); |
jar (doing other things)
2013/06/22 00:38:14
nit: probably better is a pair of DCHECK_NE()
Sigurður Ásgeirsson
2013/06/27 17:42:35
Done.
|
+ |
+ switch (event->type) { |
+ case v8::JitCodeEvent::CODE_ADDED: |
jar (doing other things)
2013/06/22 00:38:14
nit: indent 2 to the "case" and then 2 more (below
Sigurður Ásgeirsson
2013/06/27 17:42:35
Done.
|
+ add_dynamic_symbol_func(event->code_start, event->code_len, |
+ event->name.str, event->name.len); |
+ break; |
+ |
+ case v8::JitCodeEvent::CODE_MOVED: |
+ move_dynamic_symbol_func(event->code_start, event->new_code_start); |
+ break; |
+ } |
+} |
+ |
std::string GetProfileName() { |
static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; |
CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); |
@@ -103,8 +122,7 @@ void Profiling::ProcessStarted() { |
std::string process_type = |
command_line.GetSwitchValueASCII(switches::kProcessType); |
- // Establish the V8 return address resolution hook if we're |
- // an instrumented binary. |
+ // Establish the V8 profiling hooks if we're an instrumented binary. |
if (base::debug::IsBinaryInstrumented()) { |
base::debug::ReturnAddressLocationResolver resolve_func = |
base::debug::GetProfilerReturnAddrResolutionFunc(); |
@@ -112,6 +130,25 @@ void Profiling::ProcessStarted() { |
if (resolve_func != NULL) { |
v8::V8::SetReturnAddressLocationResolver(resolve_func); |
} |
+ |
+ // Set up the JIT code entry handler and the symbol callbacks if the |
+ // profiler supplies them. |
+ // TODO(siggi): Maybe add a switch or an environment variable to turn off |
+ // V8 profiling? |
+ base::debug::DynamicFunctionEntryHook entry_hook_func = |
+ base::debug::GetProfilerDynamicFunctionEntryHookFunc(); |
+ add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc(); |
+ move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc(); |
+ |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ if (isolate != NULL && |
+ entry_hook_func != NULL && |
+ add_dynamic_symbol_func != NULL && |
+ move_dynamic_symbol_func != NULL) { |
+ v8::V8::SetFunctionEntryHook(isolate, entry_hook_func); |
+ v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, |
+ &JitCodeEventHandler); |
+ } |
} |
if (command_line.HasSwitch(switches::kProfilingAtStart)) { |