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

Side by Side Diff: chrome/common/profiling.cc

Issue 15914002: Implement glue for V8 JIT code profiling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix clang compile problem. Created 7 years, 5 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 | « base/debug/profiler.cc ('k') | no next file » | 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 "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.h" 12 #include "base/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 "v8/include/v8.h" 16 #include "v8/include/v8.h"
17 17
18 namespace { 18 namespace {
19
20 base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL;
21 base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL;
22
23 void JitCodeEventHandler(const v8::JitCodeEvent* event) {
24 DCHECK_NE(static_cast<base::debug::AddDynamicSymbol>(NULL),
25 add_dynamic_symbol_func);
26 DCHECK_NE(static_cast<base::debug::MoveDynamicSymbol>(NULL),
27 move_dynamic_symbol_func);
28
29 switch (event->type) {
30 case v8::JitCodeEvent::CODE_ADDED:
31 add_dynamic_symbol_func(event->code_start, event->code_len,
32 event->name.str, event->name.len);
33 break;
34
35 case v8::JitCodeEvent::CODE_MOVED:
36 move_dynamic_symbol_func(event->code_start, event->new_code_start);
37 break;
38
39 default:
40 break;
41 }
42 }
43
19 std::string GetProfileName() { 44 std::string GetProfileName() {
20 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; 45 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}";
21 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); 46 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ());
22 47
23 if (profile_name.empty()) { 48 if (profile_name.empty()) {
24 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 49 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
25 if (command_line.HasSwitch(switches::kProfilingFile)) 50 if (command_line.HasSwitch(switches::kProfilingFile))
26 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); 51 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile);
27 else 52 else
28 profile_name = std::string(kDefaultProfileName); 53 profile_name = std::string(kDefaultProfileName);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 g_flush_thread_control = LAZY_INSTANCE_INITIALIZER; 121 g_flush_thread_control = LAZY_INSTANCE_INITIALIZER;
97 122
98 } // namespace 123 } // namespace
99 124
100 // static 125 // static
101 void Profiling::ProcessStarted() { 126 void Profiling::ProcessStarted() {
102 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 127 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
103 std::string process_type = 128 std::string process_type =
104 command_line.GetSwitchValueASCII(switches::kProcessType); 129 command_line.GetSwitchValueASCII(switches::kProcessType);
105 130
106 // Establish the V8 return address resolution hook if we're 131 // Establish the V8 profiling hooks if we're an instrumented binary.
107 // an instrumented binary.
108 if (base::debug::IsBinaryInstrumented()) { 132 if (base::debug::IsBinaryInstrumented()) {
109 base::debug::ReturnAddressLocationResolver resolve_func = 133 base::debug::ReturnAddressLocationResolver resolve_func =
110 base::debug::GetProfilerReturnAddrResolutionFunc(); 134 base::debug::GetProfilerReturnAddrResolutionFunc();
111 135
112 if (resolve_func != NULL) { 136 if (resolve_func != NULL) {
113 v8::V8::SetReturnAddressLocationResolver(resolve_func); 137 v8::V8::SetReturnAddressLocationResolver(resolve_func);
114 } 138 }
139
140 // Set up the JIT code entry handler and the symbol callbacks if the
141 // profiler supplies them.
142 // TODO(siggi): Maybe add a switch or an environment variable to turn off
143 // V8 profiling?
144 base::debug::DynamicFunctionEntryHook entry_hook_func =
145 base::debug::GetProfilerDynamicFunctionEntryHookFunc();
146 add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc();
147 move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc();
148
149 v8::Isolate* isolate = v8::Isolate::GetCurrent();
150 if (isolate != NULL &&
151 entry_hook_func != NULL &&
152 add_dynamic_symbol_func != NULL &&
153 move_dynamic_symbol_func != NULL) {
154 v8::V8::SetFunctionEntryHook(isolate, entry_hook_func);
155 v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault,
156 &JitCodeEventHandler);
157 }
115 } 158 }
116 159
117 if (command_line.HasSwitch(switches::kProfilingAtStart)) { 160 if (command_line.HasSwitch(switches::kProfilingAtStart)) {
118 std::string process_type_to_start = 161 std::string process_type_to_start =
119 command_line.GetSwitchValueASCII(switches::kProfilingAtStart); 162 command_line.GetSwitchValueASCII(switches::kProfilingAtStart);
120 if (process_type == process_type_to_start) 163 if (process_type == process_type_to_start)
121 Start(); 164 Start();
122 } 165 }
123 } 166 }
124 167
(...skipping 20 matching lines...) Expand all
145 return base::debug::BeingProfiled(); 188 return base::debug::BeingProfiled();
146 } 189 }
147 190
148 // static 191 // static
149 void Profiling::Toggle() { 192 void Profiling::Toggle() {
150 if (BeingProfiled()) 193 if (BeingProfiled())
151 Stop(); 194 Stop();
152 else 195 else
153 Start(); 196 Start();
154 } 197 }
OLDNEW
« no previous file with comments | « base/debug/profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698