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

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: Ready for review. Created 7 years, 6 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
« base/debug/profiler.cc ('K') | « 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(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.
25
26 switch (event->type) {
27 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.
28 add_dynamic_symbol_func(event->code_start, event->code_len,
29 event->name.str, event->name.len);
30 break;
31
32 case v8::JitCodeEvent::CODE_MOVED:
33 move_dynamic_symbol_func(event->code_start, event->new_code_start);
34 break;
35 }
36 }
37
19 std::string GetProfileName() { 38 std::string GetProfileName() {
20 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; 39 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}";
21 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); 40 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ());
22 41
23 if (profile_name.empty()) { 42 if (profile_name.empty()) {
24 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 43 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
25 if (command_line.HasSwitch(switches::kProfilingFile)) 44 if (command_line.HasSwitch(switches::kProfilingFile))
26 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); 45 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile);
27 else 46 else
28 profile_name = std::string(kDefaultProfileName); 47 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; 115 g_flush_thread_control = LAZY_INSTANCE_INITIALIZER;
97 116
98 } // namespace 117 } // namespace
99 118
100 // static 119 // static
101 void Profiling::ProcessStarted() { 120 void Profiling::ProcessStarted() {
102 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 121 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
103 std::string process_type = 122 std::string process_type =
104 command_line.GetSwitchValueASCII(switches::kProcessType); 123 command_line.GetSwitchValueASCII(switches::kProcessType);
105 124
106 // Establish the V8 return address resolution hook if we're 125 // Establish the V8 profiling hooks if we're an instrumented binary.
107 // an instrumented binary.
108 if (base::debug::IsBinaryInstrumented()) { 126 if (base::debug::IsBinaryInstrumented()) {
109 base::debug::ReturnAddressLocationResolver resolve_func = 127 base::debug::ReturnAddressLocationResolver resolve_func =
110 base::debug::GetProfilerReturnAddrResolutionFunc(); 128 base::debug::GetProfilerReturnAddrResolutionFunc();
111 129
112 if (resolve_func != NULL) { 130 if (resolve_func != NULL) {
113 v8::V8::SetReturnAddressLocationResolver(resolve_func); 131 v8::V8::SetReturnAddressLocationResolver(resolve_func);
114 } 132 }
133
134 // Set up the JIT code entry handler and the symbol callbacks if the
135 // profiler supplies them.
136 // TODO(siggi): Maybe add a switch or an environment variable to turn off
137 // V8 profiling?
138 base::debug::DynamicFunctionEntryHook entry_hook_func =
139 base::debug::GetProfilerDynamicFunctionEntryHookFunc();
140 add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc();
141 move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc();
142
143 v8::Isolate* isolate = v8::Isolate::GetCurrent();
144 if (isolate != NULL &&
145 entry_hook_func != NULL &&
146 add_dynamic_symbol_func != NULL &&
147 move_dynamic_symbol_func != NULL) {
148 v8::V8::SetFunctionEntryHook(isolate, entry_hook_func);
149 v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault,
150 &JitCodeEventHandler);
151 }
115 } 152 }
116 153
117 if (command_line.HasSwitch(switches::kProfilingAtStart)) { 154 if (command_line.HasSwitch(switches::kProfilingAtStart)) {
118 std::string process_type_to_start = 155 std::string process_type_to_start =
119 command_line.GetSwitchValueASCII(switches::kProfilingAtStart); 156 command_line.GetSwitchValueASCII(switches::kProfilingAtStart);
120 if (process_type == process_type_to_start) 157 if (process_type == process_type_to_start)
121 Start(); 158 Start();
122 } 159 }
123 } 160 }
124 161
(...skipping 20 matching lines...) Expand all
145 return base::debug::BeingProfiled(); 182 return base::debug::BeingProfiled();
146 } 183 }
147 184
148 // static 185 // static
149 void Profiling::Toggle() { 186 void Profiling::Toggle() {
150 if (BeingProfiled()) 187 if (BeingProfiled())
151 Stop(); 188 Stop();
152 else 189 else
153 Start(); 190 Start();
154 } 191 }
OLDNEW
« base/debug/profiler.cc ('K') | « base/debug/profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698