Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/v8_inspector/V8ProfilerAgentImpl.h" | 5 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
| 6 | 6 |
| 7 #include "platform/v8_inspector/Atomics.h" | 7 #include "platform/v8_inspector/Atomics.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 10 #include "platform/v8_inspector/V8StackTraceImpl.h" | 10 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 ProfileDescriptor(const String16& id, const String16& title) | 119 ProfileDescriptor(const String16& id, const String16& title) |
| 120 : m_id(id) | 120 : m_id(id) |
| 121 , m_title(title) { } | 121 , m_title(title) { } |
| 122 String16 m_id; | 122 String16 m_id; |
| 123 String16 m_title; | 123 String16 m_title; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc ol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) | 126 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc ol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) |
| 127 : m_session(session) | 127 : m_session(session) |
| 128 , m_isolate(m_session->debugger()->isolate()) | 128 , m_isolate(m_session->debugger()->isolate()) |
| 129 , m_profiler(nullptr) | |
| 129 , m_state(state) | 130 , m_state(state) |
| 130 , m_frontend(frontendChannel) | 131 , m_frontend(frontendChannel) |
| 131 , m_enabled(false) | 132 , m_enabled(false) |
| 132 , m_recordingCPUProfile(false) | 133 , m_recordingCPUProfile(false) |
| 133 { | 134 { |
| 134 } | 135 } |
| 135 | 136 |
| 136 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() | 137 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() |
| 137 { | 138 { |
| 139 #if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 | |
|
pfeldman
2016/07/08 19:10:08
I'd rather that we hold off deprecation before v8
alph
2016/07/08 19:22:10
It landed today. What's wrong with deprecation?
Th
| |
| 140 if (m_profiler) | |
| 141 m_profiler->Dispose(); | |
| 142 #endif | |
| 138 } | 143 } |
| 139 | 144 |
| 140 void V8ProfilerAgentImpl::consoleProfile(const String16& title) | 145 void V8ProfilerAgentImpl::consoleProfile(const String16& title) |
| 141 { | 146 { |
| 142 if (!m_enabled) | 147 if (!m_enabled) |
| 143 return; | 148 return; |
| 144 String16 id = nextProfileId(); | 149 String16 id = nextProfileId(); |
| 145 m_startedProfiles.push_back(ProfileDescriptor(id, title)); | 150 m_startedProfiles.push_back(ProfileDescriptor(id, title)); |
| 146 startProfiling(id); | 151 startProfiling(id); |
| 147 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->debugge r()), title); | 152 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->debugge r()), title); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 177 return; | 182 return; |
| 178 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio n(m_session->debugger()); | 183 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio n(m_session->debugger()); |
| 179 m_frontend.consoleProfileFinished(id, std::move(location), std::move(profile ), resolvedTitle); | 184 m_frontend.consoleProfileFinished(id, std::move(location), std::move(profile ), resolvedTitle); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void V8ProfilerAgentImpl::enable(ErrorString*) | 187 void V8ProfilerAgentImpl::enable(ErrorString*) |
| 183 { | 188 { |
| 184 if (m_enabled) | 189 if (m_enabled) |
| 185 return; | 190 return; |
| 186 m_enabled = true; | 191 m_enabled = true; |
| 192 #if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 | |
| 193 DCHECK(!m_profiler); | |
| 194 m_profiler = v8::CpuProfiler::New(m_isolate); | |
| 195 #endif | |
| 187 m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); | 196 m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); |
| 188 m_session->changeInstrumentationCounter(+1); | 197 m_session->changeInstrumentationCounter(+1); |
| 189 } | 198 } |
| 190 | 199 |
| 191 void V8ProfilerAgentImpl::disable(ErrorString* errorString) | 200 void V8ProfilerAgentImpl::disable(ErrorString* errorString) |
| 192 { | 201 { |
| 193 if (!m_enabled) | 202 if (!m_enabled) |
| 194 return; | 203 return; |
| 195 m_session->changeInstrumentationCounter(-1); | 204 m_session->changeInstrumentationCounter(-1); |
| 196 for (size_t i = m_startedProfiles.size(); i > 0; --i) | 205 for (size_t i = m_startedProfiles.size(); i > 0; --i) |
| 197 stopProfiling(m_startedProfiles[i - 1].m_id, false); | 206 stopProfiling(m_startedProfiles[i - 1].m_id, false); |
| 198 m_startedProfiles.clear(); | 207 m_startedProfiles.clear(); |
| 199 stop(nullptr, nullptr); | 208 stop(nullptr, nullptr); |
| 209 #if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 | |
| 210 m_profiler->Dispose(); | |
| 211 m_profiler = nullptr; | |
| 212 #endif | |
| 200 m_enabled = false; | 213 m_enabled = false; |
| 201 m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); | 214 m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); |
| 202 } | 215 } |
| 203 | 216 |
| 204 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) | 217 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) |
| 205 { | 218 { |
| 206 if (m_recordingCPUProfile) { | 219 if (m_recordingCPUProfile) { |
| 207 *error = "Cannot change sampling interval when profiling."; | 220 *error = "Cannot change sampling interval when profiling."; |
| 208 return; | 221 return; |
| 209 } | 222 } |
| 210 m_state->setNumber(ProfilerAgentState::samplingInterval, interval); | 223 m_state->setNumber(ProfilerAgentState::samplingInterval, interval); |
| 211 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); | 224 profiler()->SetSamplingInterval(interval); |
| 212 } | 225 } |
| 213 | 226 |
| 214 void V8ProfilerAgentImpl::restore() | 227 void V8ProfilerAgentImpl::restore() |
| 215 { | 228 { |
| 216 DCHECK(!m_enabled); | 229 DCHECK(!m_enabled); |
| 217 if (!m_state->booleanProperty(ProfilerAgentState::profilerEnabled, false)) | 230 if (!m_state->booleanProperty(ProfilerAgentState::profilerEnabled, false)) |
| 218 return; | 231 return; |
| 219 m_enabled = true; | 232 m_enabled = true; |
| 220 m_session->changeInstrumentationCounter(+1); | 233 m_session->changeInstrumentationCounter(+1); |
| 221 int interval = 0; | 234 int interval = 0; |
| 222 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); | 235 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); |
| 223 if (interval) | 236 if (interval) |
| 224 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); | 237 profiler()->SetSamplingInterval(interval); |
| 225 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal se)) { | 238 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal se)) { |
| 226 ErrorString error; | 239 ErrorString error; |
| 227 start(&error); | 240 start(&error); |
| 228 } | 241 } |
| 229 } | 242 } |
| 230 | 243 |
| 231 void V8ProfilerAgentImpl::start(ErrorString* error) | 244 void V8ProfilerAgentImpl::start(ErrorString* error) |
| 232 { | 245 { |
| 233 if (m_recordingCPUProfile) | 246 if (m_recordingCPUProfile) |
| 234 return; | 247 return; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 263 } | 276 } |
| 264 | 277 |
| 265 String16 V8ProfilerAgentImpl::nextProfileId() | 278 String16 V8ProfilerAgentImpl::nextProfileId() |
| 266 { | 279 { |
| 267 return String16::number(atomicIncrement(&s_lastProfileId)); | 280 return String16::number(atomicIncrement(&s_lastProfileId)); |
| 268 } | 281 } |
| 269 | 282 |
| 270 void V8ProfilerAgentImpl::startProfiling(const String16& title) | 283 void V8ProfilerAgentImpl::startProfiling(const String16& title) |
| 271 { | 284 { |
| 272 v8::HandleScope handleScope(m_isolate); | 285 v8::HandleScope handleScope(m_isolate); |
| 273 m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), tr ue); | 286 profiler()->StartProfiling(toV8String(m_isolate, title), true); |
| 274 } | 287 } |
| 275 | 288 |
| 276 std::unique_ptr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfili ng(const String16& title, bool serialize) | 289 std::unique_ptr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfili ng(const String16& title, bool serialize) |
| 277 { | 290 { |
| 278 v8::HandleScope handleScope(m_isolate); | 291 v8::HandleScope handleScope(m_isolate); |
| 279 v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8Str ing(m_isolate, title)); | 292 v8::CpuProfile* profile = profiler()->StopProfiling(toV8String(m_isolate, ti tle)); |
| 280 if (!profile) | 293 if (!profile) |
| 281 return nullptr; | 294 return nullptr; |
| 282 std::unique_ptr<protocol::Profiler::CPUProfile> result; | 295 std::unique_ptr<protocol::Profiler::CPUProfile> result; |
| 283 if (serialize) | 296 if (serialize) |
| 284 result = createCPUProfile(m_isolate, profile); | 297 result = createCPUProfile(m_isolate, profile); |
| 285 profile->Delete(); | 298 profile->Delete(); |
| 286 return result; | 299 return result; |
| 287 } | 300 } |
| 288 | 301 |
| 289 bool V8ProfilerAgentImpl::isRecording() const | 302 bool V8ProfilerAgentImpl::isRecording() const |
| 290 { | 303 { |
| 291 return m_recordingCPUProfile || !m_startedProfiles.empty(); | 304 return m_recordingCPUProfile || !m_startedProfiles.empty(); |
| 292 } | 305 } |
| 293 | 306 |
| 307 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() | |
| 308 { | |
| 309 #if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 | |
| 310 return m_profiler; | |
| 311 #else | |
| 312 return m_isolate->GetCpuProfiler(); | |
| 313 #endif | |
| 314 } | |
| 315 | |
| 294 } // namespace blink | 316 } // namespace blink |
| OLD | NEW |