Index: third_party/WebKit/Source/core/inspector/v8/V8ProfilerAgentImpl.cpp |
diff --git a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp b/third_party/WebKit/Source/core/inspector/v8/V8ProfilerAgentImpl.cpp |
similarity index 63% |
copy from third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp |
copy to third_party/WebKit/Source/core/inspector/v8/V8ProfilerAgentImpl.cpp |
index 254e269d41400b059de275e2b51d222c89e43376..2c544edca939bc1d5b3db6440de7348cbb3b4ee3 100644 |
--- a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp |
+++ b/third_party/WebKit/Source/core/inspector/v8/V8ProfilerAgentImpl.cpp |
@@ -1,42 +1,13 @@ |
-/* |
- * Copyright (C) 2010 Apple Inc. All rights reserved. |
- * Copyright (C) 2010 Google Inc. All rights reserved. |
- * |
- * Redistribution and use in source and binary forms, with or without |
- * modification, are permitted provided that the following conditions |
- * are met: |
- * |
- * 1. Redistributions of source code must retain the above copyright |
- * notice, this list of conditions and the following disclaimer. |
- * 2. Redistributions in binary form must reproduce the above copyright |
- * notice, this list of conditions and the following disclaimer in the |
- * documentation and/or other materials provided with the distribution. |
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
- * its contributors may be used to endorse or promote products derived |
- * from this software without specific prior written permission. |
- * |
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- */ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
#include "config.h" |
-#include "core/inspector/InspectorProfilerAgent.h" |
+#include "core/inspector/v8/V8ProfilerAgentImpl.h" |
#include "bindings/core/v8/ScriptCallStackFactory.h" |
#include "bindings/core/v8/V8Binding.h" |
-#include "core/frame/UseCounter.h" |
-#include "core/inspector/InjectedScript.h" |
-#include "core/inspector/InjectedScriptHost.h" |
#include "core/inspector/InspectorState.h" |
-#include "core/inspector/InstrumentingAgents.h" |
#include "core/inspector/ScriptCallStack.h" |
#include <v8-profiler.h> |
@@ -45,7 +16,6 @@ namespace blink { |
namespace ProfilerAgentState { |
static const char samplingInterval[] = "samplingInterval"; |
static const char userInitiatedProfiling[] = "userInitiatedProfiling"; |
-static const char profilerEnabled[] = "profilerEnabled"; |
static const char nextProfileId[] = "nextProfileId"; |
} |
@@ -141,7 +111,7 @@ PassRefPtr<TypeBuilder::Debugger::Location> currentDebugLocation() |
} // namespace |
-class InspectorProfilerAgent::ProfileDescriptor { |
+class V8ProfilerAgentImpl::ProfileDescriptor { |
public: |
ProfileDescriptor(const String& id, const String& title) |
: m_id(id) |
@@ -150,37 +120,36 @@ public: |
String m_title; |
}; |
-PassOwnPtrWillBeRawPtr<InspectorProfilerAgent> InspectorProfilerAgent::create(v8::Isolate* isolate, InjectedScriptManager* injectedScriptManager, Client* client) |
+PassOwnPtr<V8ProfilerAgent> V8ProfilerAgent::create(v8::Isolate* isolate) |
{ |
- return adoptPtrWillBeNoop(new InspectorProfilerAgent(isolate, injectedScriptManager, client)); |
+ return adoptPtrWillBeNoop(new V8ProfilerAgentImpl(isolate)); |
} |
-InspectorProfilerAgent::InspectorProfilerAgent(v8::Isolate* isolate, InjectedScriptManager* injectedScriptManager, Client* client) |
- : InspectorBaseAgent<InspectorProfilerAgent, InspectorFrontend::Profiler>("Profiler") |
- , m_isolate(isolate) |
- , m_injectedScriptManager(injectedScriptManager) |
+V8ProfilerAgentImpl::V8ProfilerAgentImpl(v8::Isolate* isolate) |
+ : m_isolate(isolate) |
+ , m_state(nullptr) |
+ , m_frontend(nullptr) |
+ , m_enabled(false) |
, m_recordingCPUProfile(false) |
- , m_client(client) |
{ |
} |
-InspectorProfilerAgent::~InspectorProfilerAgent() |
+V8ProfilerAgentImpl::~V8ProfilerAgentImpl() |
{ |
} |
-void InspectorProfilerAgent::consoleProfile(ExecutionContext* context, const String& title) |
+void V8ProfilerAgentImpl::consoleProfile(const String& title) |
{ |
- UseCounter::count(context, UseCounter::DevToolsConsoleProfile); |
- ASSERT(frontend() && enabled()); |
+ ASSERT(m_frontend && m_enabled); |
String id = nextProfileId(); |
m_startedProfiles.append(ProfileDescriptor(id, title)); |
startProfiling(id); |
- frontend()->consoleProfileStarted(id, currentDebugLocation(), title.isNull() ? 0 : &title); |
+ m_frontend->consoleProfileStarted(id, currentDebugLocation(), title.isNull() ? 0 : &title); |
} |
-void InspectorProfilerAgent::consoleProfileEnd(const String& title) |
+void V8ProfilerAgentImpl::consoleProfileEnd(const String& title) |
{ |
- ASSERT(frontend() && enabled()); |
+ ASSERT(m_frontend && m_enabled); |
String id; |
String resolvedTitle; |
// Take last started profile if no title was passed. |
@@ -206,36 +175,24 @@ void InspectorProfilerAgent::consoleProfileEnd(const String& title) |
if (!profile) |
return; |
RefPtr<TypeBuilder::Debugger::Location> location = currentDebugLocation(); |
- frontend()->consoleProfileFinished(id, location, profile, resolvedTitle.isNull() ? 0 : &resolvedTitle); |
+ m_frontend->consoleProfileFinished(id, location, profile, resolvedTitle.isNull() ? 0 : &resolvedTitle); |
} |
-void InspectorProfilerAgent::enable(ErrorString*) |
+void V8ProfilerAgentImpl::enable(ErrorString*) |
{ |
- m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); |
- doEnable(); |
+ m_enabled = true; |
} |
-void InspectorProfilerAgent::doEnable() |
-{ |
- m_instrumentingAgents->setInspectorProfilerAgent(this); |
-} |
- |
-void InspectorProfilerAgent::disable(ErrorString*) |
+void V8ProfilerAgentImpl::disable(ErrorString*) |
{ |
for (Vector<ProfileDescriptor>::reverse_iterator it = m_startedProfiles.rbegin(); it != m_startedProfiles.rend(); ++it) |
stopProfiling(it->m_id, false); |
m_startedProfiles.clear(); |
stop(0, 0); |
- m_instrumentingAgents->setInspectorProfilerAgent(nullptr); |
- m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); |
-} |
- |
-bool InspectorProfilerAgent::enabled() |
-{ |
- return m_state->getBoolean(ProfilerAgentState::profilerEnabled); |
+ m_enabled = false; |
} |
-void InspectorProfilerAgent::setSamplingInterval(ErrorString* error, int interval) |
+void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) |
{ |
if (m_recordingCPUProfile) { |
*error = "Cannot change sampling interval when profiling."; |
@@ -245,10 +202,17 @@ void InspectorProfilerAgent::setSamplingInterval(ErrorString* error, int interva |
m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
} |
-void InspectorProfilerAgent::restore() |
+void V8ProfilerAgentImpl::clearFrontend() |
{ |
- if (m_state->getBoolean(ProfilerAgentState::profilerEnabled)) |
- doEnable(); |
+ ErrorString error; |
+ disable(&error); |
+ ASSERT(m_frontend); |
+ m_frontend = nullptr; |
+} |
+ |
+void V8ProfilerAgentImpl::restore() |
+{ |
+ m_enabled = true; |
if (long interval = m_state->getLong(ProfilerAgentState::samplingInterval, 0)) |
m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
if (m_state->getBoolean(ProfilerAgentState::userInitiatedProfiling)) { |
@@ -257,28 +221,26 @@ void InspectorProfilerAgent::restore() |
} |
} |
-void InspectorProfilerAgent::start(ErrorString* error) |
+void V8ProfilerAgentImpl::start(ErrorString* error) |
{ |
if (m_recordingCPUProfile) |
return; |
- if (!enabled()) { |
+ if (!m_enabled) { |
*error = "Profiler is not enabled"; |
return; |
} |
m_recordingCPUProfile = true; |
- if (m_client) |
- m_client->profilingStarted(); |
m_frontendInitiatedProfileId = nextProfileId(); |
startProfiling(m_frontendInitiatedProfileId); |
m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true); |
} |
-void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder::Profiler::CPUProfile>& profile) |
+void V8ProfilerAgentImpl::stop(ErrorString* errorString, RefPtr<TypeBuilder::Profiler::CPUProfile>& profile) |
{ |
stop(errorString, &profile); |
} |
-void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder::Profiler::CPUProfile>* profile) |
+void V8ProfilerAgentImpl::stop(ErrorString* errorString, RefPtr<TypeBuilder::Profiler::CPUProfile>* profile) |
{ |
if (!m_recordingCPUProfile) { |
if (errorString) |
@@ -286,8 +248,6 @@ void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder:: |
return; |
} |
m_recordingCPUProfile = false; |
- if (m_client) |
- m_client->profilingStopped(); |
RefPtr<TypeBuilder::Profiler::CPUProfile> cpuProfile = stopProfiling(m_frontendInitiatedProfileId, !!profile); |
if (profile) { |
*profile = cpuProfile; |
@@ -298,20 +258,20 @@ void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder:: |
m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false); |
} |
-String InspectorProfilerAgent::nextProfileId() |
+String V8ProfilerAgentImpl::nextProfileId() |
{ |
long nextId = m_state->getLong(ProfilerAgentState::nextProfileId, 1); |
m_state->setLong(ProfilerAgentState::nextProfileId, nextId + 1); |
return String::number(nextId); |
} |
-void InspectorProfilerAgent::startProfiling(const String& title) |
+void V8ProfilerAgentImpl::startProfiling(const String& title) |
{ |
v8::HandleScope handleScope(m_isolate); |
m_isolate->GetCpuProfiler()->StartProfiling(v8String(m_isolate, title), true); |
} |
-PassRefPtr<TypeBuilder::Profiler::CPUProfile> InspectorProfilerAgent::stopProfiling(const String& title, bool serialize) |
+PassRefPtr<TypeBuilder::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(const String& title, bool serialize) |
{ |
v8::HandleScope handleScope(m_isolate); |
v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(v8String(m_isolate, title)); |
@@ -324,49 +284,23 @@ PassRefPtr<TypeBuilder::Profiler::CPUProfile> InspectorProfilerAgent::stopProfil |
return result.release(); |
} |
-bool InspectorProfilerAgent::isRecording() const |
+bool V8ProfilerAgentImpl::isRecording() const |
{ |
return m_recordingCPUProfile || !m_startedProfiles.isEmpty(); |
} |
-void InspectorProfilerAgent::idleFinished() |
+void V8ProfilerAgentImpl::idleFinished() |
{ |
if (!isRecording()) |
return; |
m_isolate->GetCpuProfiler()->SetIdle(false); |
} |
-void InspectorProfilerAgent::idleStarted() |
+void V8ProfilerAgentImpl::idleStarted() |
{ |
if (!isRecording()) |
return; |
m_isolate->GetCpuProfiler()->SetIdle(true); |
} |
-void InspectorProfilerAgent::willProcessTask() |
-{ |
- idleFinished(); |
-} |
- |
-void InspectorProfilerAgent::didProcessTask() |
-{ |
- idleStarted(); |
-} |
- |
-void InspectorProfilerAgent::willEnterNestedRunLoop() |
-{ |
- idleStarted(); |
-} |
- |
-void InspectorProfilerAgent::didLeaveNestedRunLoop() |
-{ |
- idleFinished(); |
-} |
- |
-DEFINE_TRACE(InspectorProfilerAgent) |
-{ |
- visitor->trace(m_injectedScriptManager); |
- InspectorBaseAgent::trace(visitor); |
-} |
- |
} // namespace blink |