Commit bb0b8b2d authored by alph's avatar alph Committed by Commit bot

[inspector] Drop V8_VERSION checks.

BUG=chromium:635948

Review-Url: https://codereview.chromium.org/2323273002
Cr-Commit-Position: refs/heads/master@{#39314}
parent 5465c25c
...@@ -23,11 +23,9 @@ namespace HeapProfilerAgentState { ...@@ -23,11 +23,9 @@ namespace HeapProfilerAgentState {
static const char heapProfilerEnabled[] = "heapProfilerEnabled"; static const char heapProfilerEnabled[] = "heapProfilerEnabled";
static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled"; static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled";
static const char allocationTrackingEnabled[] = "allocationTrackingEnabled"; static const char allocationTrackingEnabled[] = "allocationTrackingEnabled";
#if V8_MAJOR_VERSION >= 5
static const char samplingHeapProfilerEnabled[] = "samplingHeapProfilerEnabled"; static const char samplingHeapProfilerEnabled[] = "samplingHeapProfilerEnabled";
static const char samplingHeapProfilerInterval[] = static const char samplingHeapProfilerInterval[] =
"samplingHeapProfilerInterval"; "samplingHeapProfilerInterval";
#endif
} }
class HeapSnapshotProgress final : public v8::ActivityControl { class HeapSnapshotProgress final : public v8::ActivityControl {
...@@ -164,7 +162,6 @@ void V8HeapProfilerAgentImpl::restore() { ...@@ -164,7 +162,6 @@ void V8HeapProfilerAgentImpl::restore() {
HeapProfilerAgentState::heapObjectsTrackingEnabled, false)) HeapProfilerAgentState::heapObjectsTrackingEnabled, false))
startTrackingHeapObjectsInternal(m_state->booleanProperty( startTrackingHeapObjectsInternal(m_state->booleanProperty(
HeapProfilerAgentState::allocationTrackingEnabled, false)); HeapProfilerAgentState::allocationTrackingEnabled, false));
#if V8_MAJOR_VERSION >= 5
if (m_state->booleanProperty( if (m_state->booleanProperty(
HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) { HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) {
ErrorString error; ErrorString error;
...@@ -173,7 +170,6 @@ void V8HeapProfilerAgentImpl::restore() { ...@@ -173,7 +170,6 @@ void V8HeapProfilerAgentImpl::restore() {
DCHECK_GE(samplingInterval, 0); DCHECK_GE(samplingInterval, 0);
startSampling(&error, Maybe<double>(samplingInterval)); startSampling(&error, Maybe<double>(samplingInterval));
} }
#endif
} }
void V8HeapProfilerAgentImpl::collectGarbage(ErrorString*) { void V8HeapProfilerAgentImpl::collectGarbage(ErrorString*) {
...@@ -202,13 +198,11 @@ void V8HeapProfilerAgentImpl::enable(ErrorString*) { ...@@ -202,13 +198,11 @@ void V8HeapProfilerAgentImpl::enable(ErrorString*) {
void V8HeapProfilerAgentImpl::disable(ErrorString* error) { void V8HeapProfilerAgentImpl::disable(ErrorString* error) {
stopTrackingHeapObjectsInternal(); stopTrackingHeapObjectsInternal();
#if V8_MAJOR_VERSION >= 5
if (m_state->booleanProperty( if (m_state->booleanProperty(
HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) { HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) {
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (profiler) profiler->StopSamplingHeapProfiler(); if (profiler) profiler->StopSamplingHeapProfiler();
} }
#endif
m_isolate->GetHeapProfiler()->ClearObjectIds(); m_isolate->GetHeapProfiler()->ClearObjectIds();
m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false);
} }
...@@ -340,7 +334,6 @@ void V8HeapProfilerAgentImpl::stopTrackingHeapObjectsInternal() { ...@@ -340,7 +334,6 @@ void V8HeapProfilerAgentImpl::stopTrackingHeapObjectsInternal() {
void V8HeapProfilerAgentImpl::startSampling( void V8HeapProfilerAgentImpl::startSampling(
ErrorString* errorString, const Maybe<double>& samplingInterval) { ErrorString* errorString, const Maybe<double>& samplingInterval) {
#if V8_MAJOR_VERSION >= 5
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) { if (!profiler) {
*errorString = "Cannot access v8 heap profiler"; *errorString = "Cannot access v8 heap profiler";
...@@ -353,18 +346,11 @@ void V8HeapProfilerAgentImpl::startSampling( ...@@ -353,18 +346,11 @@ void V8HeapProfilerAgentImpl::startSampling(
samplingIntervalValue); samplingIntervalValue);
m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled,
true); true);
#if V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= 5002
profiler->StartSamplingHeapProfiler( profiler->StartSamplingHeapProfiler(
static_cast<uint64_t>(samplingIntervalValue), 128, static_cast<uint64_t>(samplingIntervalValue), 128,
v8::HeapProfiler::kSamplingForceGC); v8::HeapProfiler::kSamplingForceGC);
#else
profiler->StartSamplingHeapProfiler(
static_cast<uint64_t>(samplingIntervalValue), 128);
#endif
#endif
} }
#if V8_MAJOR_VERSION >= 5
namespace { namespace {
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode>
buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) { buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) {
...@@ -392,12 +378,10 @@ buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) { ...@@ -392,12 +378,10 @@ buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) {
return result; return result;
} }
} // namespace } // namespace
#endif
void V8HeapProfilerAgentImpl::stopSampling( void V8HeapProfilerAgentImpl::stopSampling(
ErrorString* errorString, ErrorString* errorString,
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>* profile) { std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>* profile) {
#if V8_MAJOR_VERSION >= 5
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) { if (!profiler) {
*errorString = "Cannot access v8 heap profiler"; *errorString = "Cannot access v8 heap profiler";
...@@ -418,7 +402,6 @@ void V8HeapProfilerAgentImpl::stopSampling( ...@@ -418,7 +402,6 @@ void V8HeapProfilerAgentImpl::stopSampling(
*profile = protocol::HeapProfiler::SamplingHeapProfile::create() *profile = protocol::HeapProfiler::SamplingHeapProfile::create()
.setHead(buildSampingHeapProfileNode(root)) .setHead(buildSampingHeapProfileNode(root))
.build(); .build();
#endif
} }
} // namespace v8_inspector } // namespace v8_inspector
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
#include <vector> #include <vector>
#define ENSURE_V8_VERSION(major, minor) \
(V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= (major)*1000 + (minor))
namespace v8_inspector { namespace v8_inspector {
namespace ProfilerAgentState { namespace ProfilerAgentState {
...@@ -162,9 +159,7 @@ V8ProfilerAgentImpl::V8ProfilerAgentImpl( ...@@ -162,9 +159,7 @@ V8ProfilerAgentImpl::V8ProfilerAgentImpl(
m_recordingCPUProfile(false) {} m_recordingCPUProfile(false) {}
V8ProfilerAgentImpl::~V8ProfilerAgentImpl() { V8ProfilerAgentImpl::~V8ProfilerAgentImpl() {
#if ENSURE_V8_VERSION(5, 4)
if (m_profiler) m_profiler->Dispose(); if (m_profiler) m_profiler->Dispose();
#endif
} }
void V8ProfilerAgentImpl::consoleProfile(const String16& title) { void V8ProfilerAgentImpl::consoleProfile(const String16& title) {
...@@ -209,10 +204,8 @@ void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) { ...@@ -209,10 +204,8 @@ void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) {
void V8ProfilerAgentImpl::enable(ErrorString*) { void V8ProfilerAgentImpl::enable(ErrorString*) {
if (m_enabled) return; if (m_enabled) return;
m_enabled = true; m_enabled = true;
#if ENSURE_V8_VERSION(5, 4)
DCHECK(!m_profiler); DCHECK(!m_profiler);
m_profiler = v8::CpuProfiler::New(m_isolate); m_profiler = v8::CpuProfiler::New(m_isolate);
#endif
m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); m_state->setBoolean(ProfilerAgentState::profilerEnabled, true);
} }
...@@ -222,10 +215,8 @@ void V8ProfilerAgentImpl::disable(ErrorString* errorString) { ...@@ -222,10 +215,8 @@ 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->Dispose();
m_profiler = nullptr; m_profiler = nullptr;
#endif
m_enabled = false; m_enabled = false;
m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); m_state->setBoolean(ProfilerAgentState::profilerEnabled, false);
} }
...@@ -237,7 +228,7 @@ void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, ...@@ -237,7 +228,7 @@ void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error,
return; return;
} }
m_state->setInteger(ProfilerAgentState::samplingInterval, interval); m_state->setInteger(ProfilerAgentState::samplingInterval, interval);
profiler()->SetSamplingInterval(interval); m_profiler->SetSamplingInterval(interval);
} }
void V8ProfilerAgentImpl::restore() { void V8ProfilerAgentImpl::restore() {
...@@ -245,13 +236,11 @@ void V8ProfilerAgentImpl::restore() { ...@@ -245,13 +236,11 @@ 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); DCHECK(!m_profiler);
m_profiler = v8::CpuProfiler::New(m_isolate); 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) profiler()->SetSamplingInterval(interval); if (interval) m_profiler->SetSamplingInterval(interval);
if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling,
false)) { false)) {
ErrorString error; ErrorString error;
...@@ -295,14 +284,14 @@ String16 V8ProfilerAgentImpl::nextProfileId() { ...@@ -295,14 +284,14 @@ 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);
profiler()->StartProfiling(toV8String(m_isolate, title), true); m_profiler->StartProfiling(toV8String(m_isolate, title), true);
} }
std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling( std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling(
const String16& title, bool serialize) { const String16& title, bool serialize) {
v8::HandleScope handleScope(m_isolate); v8::HandleScope handleScope(m_isolate);
v8::CpuProfile* profile = v8::CpuProfile* profile =
profiler()->StopProfiling(toV8String(m_isolate, title)); m_profiler->StopProfiling(toV8String(m_isolate, title));
if (!profile) return nullptr; if (!profile) return nullptr;
std::unique_ptr<protocol::Profiler::Profile> result; std::unique_ptr<protocol::Profiler::Profile> result;
if (serialize) result = createCPUProfile(m_isolate, profile); if (serialize) result = createCPUProfile(m_isolate, profile);
...@@ -314,12 +303,4 @@ bool V8ProfilerAgentImpl::isRecording() const { ...@@ -314,12 +303,4 @@ 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 v8_inspector } // namespace v8_inspector
...@@ -45,7 +45,6 @@ class V8ProfilerAgentImpl : public protocol::Profiler::Backend { ...@@ -45,7 +45,6 @@ class V8ProfilerAgentImpl : public protocol::Profiler::Backend {
private: private:
String16 nextProfileId(); String16 nextProfileId();
v8::CpuProfiler* profiler();
void startProfiling(const String16& title); void startProfiling(const String16& title);
std::unique_ptr<protocol::Profiler::Profile> stopProfiling( std::unique_ptr<protocol::Profiler::Profile> stopProfiling(
......
...@@ -158,9 +158,7 @@ std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( ...@@ -158,9 +158,7 @@ std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture(
v8::HandleScope handleScope(isolate); v8::HandleScope handleScope(isolate);
v8::Local<v8::StackTrace> stackTrace; v8::Local<v8::StackTrace> stackTrace;
if (isolate->InContext()) { if (isolate->InContext()) {
#if V8_MAJOR_VERSION >= 5
isolate->GetCpuProfiler()->CollectSample(); isolate->GetCpuProfiler()->CollectSample();
#endif
stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize,
stackTraceOptions); stackTraceOptions);
} }
......
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