| Index: chrome/common/profiling.cc
|
| diff --git a/chrome/common/profiling.cc b/chrome/common/profiling.cc
|
| index 1acb43fea13a9d4e0e4bb58ffa0d61710f461cba..e1c91502fa04cf6ea3b60f0262eea6d4feb9a817 100644
|
| --- a/chrome/common/profiling.cc
|
| +++ b/chrome/common/profiling.cc
|
| @@ -16,6 +16,31 @@
|
| #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_NE(static_cast<base::debug::AddDynamicSymbol>(NULL),
|
| + add_dynamic_symbol_func);
|
| + DCHECK_NE(static_cast<base::debug::MoveDynamicSymbol>(NULL),
|
| + move_dynamic_symbol_func);
|
| +
|
| + switch (event->type) {
|
| + case v8::JitCodeEvent::CODE_ADDED:
|
| + 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;
|
| +
|
| + default:
|
| + break;
|
| + }
|
| +}
|
| +
|
| std::string GetProfileName() {
|
| static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}";
|
| CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ());
|
| @@ -103,8 +128,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 +136,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)) {
|
|
|