Commit 44a3c6b6 authored by alph's avatar alph Committed by Commit bot

DevTools: Switch V8ProfilerAgent to use v8::CpuProfiler::New API.

The old v8::Isolate::GetCpuProfiler API is going to be deprecated soon.

Review-Url: https://codereview.chromium.org/2127423003
Cr-Commit-Position: refs/heads/master@{#407245}
parent a668d781
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include <vector> #include <vector>
#define ENSURE_V8_VERSION(major, minor) \
(V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= (major) * 1000 + (minor))
namespace blink { namespace blink {
namespace ProfilerAgentState { namespace ProfilerAgentState {
...@@ -128,6 +131,7 @@ public: ...@@ -128,6 +131,7 @@ public:
V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state)
: m_session(session) : m_session(session)
, m_isolate(m_session->debugger()->isolate()) , m_isolate(m_session->debugger()->isolate())
, m_profiler(nullptr)
, m_state(state) , m_state(state)
, m_frontend(frontendChannel) , m_frontend(frontendChannel)
, m_enabled(false) , m_enabled(false)
...@@ -137,6 +141,10 @@ V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc ...@@ -137,6 +141,10 @@ V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc
V8ProfilerAgentImpl::~V8ProfilerAgentImpl() V8ProfilerAgentImpl::~V8ProfilerAgentImpl()
{ {
#if ENSURE_V8_VERSION(5, 4)
if (m_profiler)
m_profiler->Dispose();
#endif
} }
void V8ProfilerAgentImpl::consoleProfile(const String16& title) void V8ProfilerAgentImpl::consoleProfile(const String16& title)
...@@ -186,6 +194,10 @@ void V8ProfilerAgentImpl::enable(ErrorString*) ...@@ -186,6 +194,10 @@ void V8ProfilerAgentImpl::enable(ErrorString*)
if (m_enabled) if (m_enabled)
return; return;
m_enabled = true; m_enabled = true;
#if ENSURE_V8_VERSION(5, 4)
DCHECK(!m_profiler);
m_profiler = v8::CpuProfiler::New(m_isolate);
#endif
m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); m_state->setBoolean(ProfilerAgentState::profilerEnabled, true);
} }
...@@ -197,6 +209,10 @@ void V8ProfilerAgentImpl::disable(ErrorString* errorString) ...@@ -197,6 +209,10 @@ void V8ProfilerAgentImpl::disable(ErrorString* errorString)
stopProfiling(m_startedProfiles[i - 1].m_id, false); stopProfiling(m_startedProfiles[i - 1].m_id, false);
m_startedProfiles.clear(); m_startedProfiles.clear();
stop(nullptr, nullptr); stop(nullptr, nullptr);
#if ENSURE_V8_VERSION(5, 4)
m_profiler->Dispose();
m_profiler = nullptr;
#endif
m_enabled = false; m_enabled = false;
m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); m_state->setBoolean(ProfilerAgentState::profilerEnabled, false);
} }
...@@ -208,7 +224,7 @@ void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) ...@@ -208,7 +224,7 @@ void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval)
return; return;
} }
m_state->setInteger(ProfilerAgentState::samplingInterval, interval); m_state->setInteger(ProfilerAgentState::samplingInterval, interval);
m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); profiler()->SetSamplingInterval(interval);
} }
void V8ProfilerAgentImpl::restore() void V8ProfilerAgentImpl::restore()
...@@ -217,10 +233,14 @@ void V8ProfilerAgentImpl::restore() ...@@ -217,10 +233,14 @@ void V8ProfilerAgentImpl::restore()
if (!m_state->booleanProperty(ProfilerAgentState::profilerEnabled, false)) if (!m_state->booleanProperty(ProfilerAgentState::profilerEnabled, false))
return; return;
m_enabled = true; m_enabled = true;
#if ENSURE_V8_VERSION(5, 4)
DCHECK(!m_profiler);
m_profiler = v8::CpuProfiler::New(m_isolate);
#endif
int interval = 0; int interval = 0;
m_state->getInteger(ProfilerAgentState::samplingInterval, &interval); m_state->getInteger(ProfilerAgentState::samplingInterval, &interval);
if (interval) if (interval)
m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); profiler()->SetSamplingInterval(interval);
if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, false)) { if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, false)) {
ErrorString error; ErrorString error;
start(&error); start(&error);
...@@ -269,13 +289,13 @@ String16 V8ProfilerAgentImpl::nextProfileId() ...@@ -269,13 +289,13 @@ String16 V8ProfilerAgentImpl::nextProfileId()
void V8ProfilerAgentImpl::startProfiling(const String16& title) void V8ProfilerAgentImpl::startProfiling(const String16& title)
{ {
v8::HandleScope handleScope(m_isolate); 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) std::unique_ptr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(const String16& title, bool serialize)
{ {
v8::HandleScope handleScope(m_isolate); 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) if (!profile)
return nullptr; return nullptr;
std::unique_ptr<protocol::Profiler::CPUProfile> result; std::unique_ptr<protocol::Profiler::CPUProfile> result;
...@@ -290,4 +310,13 @@ bool V8ProfilerAgentImpl::isRecording() const ...@@ -290,4 +310,13 @@ bool V8ProfilerAgentImpl::isRecording() const
return m_recordingCPUProfile || !m_startedProfiles.empty(); return m_recordingCPUProfile || !m_startedProfiles.empty();
} }
v8::CpuProfiler* V8ProfilerAgentImpl::profiler()
{
#if ENSURE_V8_VERSION(5, 4)
return m_profiler;
#else
return m_isolate->GetCpuProfiler();
#endif
}
} // namespace blink } // namespace blink
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <vector> #include <vector>
namespace v8 { namespace v8 {
class CpuProfiler;
class Isolate; class Isolate;
} }
...@@ -39,6 +40,7 @@ public: ...@@ -39,6 +40,7 @@ public:
private: private:
String16 nextProfileId(); String16 nextProfileId();
v8::CpuProfiler* profiler();
void startProfiling(const String16& title); void startProfiling(const String16& title);
std::unique_ptr<protocol::Profiler::CPUProfile> stopProfiling(const String16& title, bool serialize); std::unique_ptr<protocol::Profiler::CPUProfile> stopProfiling(const String16& title, bool serialize);
...@@ -47,6 +49,7 @@ private: ...@@ -47,6 +49,7 @@ private:
V8InspectorSessionImpl* m_session; V8InspectorSessionImpl* m_session;
v8::Isolate* m_isolate; v8::Isolate* m_isolate;
v8::CpuProfiler* m_profiler;
protocol::DictionaryValue* m_state; protocol::DictionaryValue* m_state;
protocol::Profiler::Frontend m_frontend; protocol::Profiler::Frontend m_frontend;
bool m_enabled; bool m_enabled;
...@@ -58,5 +61,4 @@ private: ...@@ -58,5 +61,4 @@ private:
} // namespace blink } // namespace blink
#endif // !defined(V8ProfilerAgentImpl_h) #endif // !defined(V8ProfilerAgentImpl_h)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment