Index: third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp |
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp |
index b09f4f55ee24bf0025cfcd6e9ed3ff3a3b93b822..6e7016b0da64dd82f61d91cea7c911ba2f14bac2 100644 |
--- a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp |
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp |
@@ -126,6 +126,7 @@ public: |
V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) |
: m_session(session) |
, m_isolate(m_session->debugger()->isolate()) |
+ , m_profiler(nullptr) |
, m_state(state) |
, m_frontend(frontendChannel) |
, m_enabled(false) |
@@ -135,6 +136,10 @@ V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc |
V8ProfilerAgentImpl::~V8ProfilerAgentImpl() |
{ |
+#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
|
+ if (m_profiler) |
+ m_profiler->Dispose(); |
+#endif |
} |
void V8ProfilerAgentImpl::consoleProfile(const String16& title) |
@@ -184,6 +189,10 @@ void V8ProfilerAgentImpl::enable(ErrorString*) |
if (m_enabled) |
return; |
m_enabled = true; |
+#if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 |
+ DCHECK(!m_profiler); |
+ m_profiler = v8::CpuProfiler::New(m_isolate); |
+#endif |
m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); |
m_session->changeInstrumentationCounter(+1); |
} |
@@ -197,6 +206,10 @@ void V8ProfilerAgentImpl::disable(ErrorString* errorString) |
stopProfiling(m_startedProfiles[i - 1].m_id, false); |
m_startedProfiles.clear(); |
stop(nullptr, nullptr); |
+#if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 |
+ m_profiler->Dispose(); |
+ m_profiler = nullptr; |
+#endif |
m_enabled = false; |
m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); |
} |
@@ -208,7 +221,7 @@ void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) |
return; |
} |
m_state->setNumber(ProfilerAgentState::samplingInterval, interval); |
- m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
+ profiler()->SetSamplingInterval(interval); |
} |
void V8ProfilerAgentImpl::restore() |
@@ -221,7 +234,7 @@ void V8ProfilerAgentImpl::restore() |
int interval = 0; |
m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); |
if (interval) |
- m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
+ profiler()->SetSamplingInterval(interval); |
if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, false)) { |
ErrorString error; |
start(&error); |
@@ -270,13 +283,13 @@ String16 V8ProfilerAgentImpl::nextProfileId() |
void V8ProfilerAgentImpl::startProfiling(const String16& title) |
{ |
v8::HandleScope handleScope(m_isolate); |
- m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), true); |
+ profiler()->StartProfiling(toV8String(m_isolate, title), true); |
} |
std::unique_ptr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(const String16& title, bool serialize) |
{ |
v8::HandleScope handleScope(m_isolate); |
- v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8String(m_isolate, title)); |
+ v8::CpuProfile* profile = profiler()->StopProfiling(toV8String(m_isolate, title)); |
if (!profile) |
return nullptr; |
std::unique_ptr<protocol::Profiler::CPUProfile> result; |
@@ -291,4 +304,13 @@ bool V8ProfilerAgentImpl::isRecording() const |
return m_recordingCPUProfile || !m_startedProfiles.empty(); |
} |
+v8::CpuProfiler* V8ProfilerAgentImpl::profiler() |
+{ |
+#if V8_MAJOR_VERSION * 100 + V8_MINOR_VERSION >= 504 |
+ return m_profiler; |
+#else |
+ return m_isolate->GetCpuProfiler(); |
+#endif |
+} |
+ |
} // namespace blink |