Commit c603af63 authored by yurys@chromium.org's avatar yurys@chromium.org

2010-08-04 Yury Semikhatsky <yurys@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: serialize CPU profiles to InspectorValues instead of
        using JS wrappers.
        https://bugs.webkit.org/show_bug.cgi?id=43475

        * Android.jscbindings.mk:
        * CMakeLists.txt:
        * GNUmakefile.am:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/ScriptProfile.h:
        * bindings/js/ScriptProfiler.cpp:
        (WebCore::ScriptProfiler::stop):
        * bindings/scripts/CodeGeneratorJS.pm:
        * bindings/v8/ScriptProfile.cpp:
        (WebCore::buildInspectorObjectFor):
        (WebCore::ScriptProfile::buildInspectorObjectForHead):
        * bindings/v8/ScriptProfile.h:
        * inspector/Inspector.idl:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::addProfile):
        (WebCore::InspectorController::addProfileFinishedMessageToConsole):
        (WebCore::InspectorController::getProfileHeaders):
        (WebCore::InspectorController::getProfile):
        (WebCore::InspectorController::createProfileHeader):
        * inspector/InspectorController.h:
        * inspector/InspectorFrontend.cpp:
        * inspector/InspectorFrontend.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64642 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1ec05034
......@@ -170,6 +170,7 @@ LOCAL_SRC_FILES += \
bindings/js/ScriptEventListener.cpp \
bindings/js/ScriptFunctionCall.cpp \
bindings/js/ScriptObject.cpp \
bindings/js/ScriptProfile.cpp \
bindings/js/ScriptState.cpp \
bindings/js/ScriptValue.cpp \
bindings/js/SerializedScriptValue.cpp \
......
......@@ -684,6 +684,7 @@ SET(WebCore_SOURCES
bindings/js/ScriptFunctionCall.cpp
bindings/js/ScriptGCEvent.cpp
bindings/js/ScriptObject.cpp
bindings/js/ScriptProfile.cpp
bindings/js/ScriptProfiler.cpp
bindings/js/ScriptState.cpp
bindings/js/ScriptValue.cpp
......
2010-08-04 Yury Semikhatsky <yurys@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: serialize CPU profiles to InspectorValues instead of
using JS wrappers.
https://bugs.webkit.org/show_bug.cgi?id=43475
* Android.jscbindings.mk:
* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ScriptProfile.h:
* bindings/js/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::stop):
* bindings/scripts/CodeGeneratorJS.pm:
* bindings/v8/ScriptProfile.cpp:
(WebCore::buildInspectorObjectFor):
(WebCore::ScriptProfile::buildInspectorObjectForHead):
* bindings/v8/ScriptProfile.h:
* inspector/Inspector.idl:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::addProfile):
(WebCore::InspectorController::addProfileFinishedMessageToConsole):
(WebCore::InspectorController::getProfileHeaders):
(WebCore::InspectorController::getProfile):
(WebCore::InspectorController::createProfileHeader):
* inspector/InspectorController.h:
* inspector/InspectorFrontend.cpp:
* inspector/InspectorFrontend.h:
2010-08-04 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Simon Hausmann.
......@@ -776,6 +776,7 @@ webcore_sources += \
WebCore/bindings/js/ScriptInstance.h \
WebCore/bindings/js/ScriptObject.cpp \
WebCore/bindings/js/ScriptObject.h \
WebCore/bindings/js/ScriptProfile.cpp \
WebCore/bindings/js/ScriptProfile.h \
WebCore/bindings/js/ScriptProfileNode.h \
WebCore/bindings/js/ScriptProfiler.cpp \
......
......@@ -378,6 +378,7 @@ SOURCES += \
bindings/js/ScriptFunctionCall.cpp \
bindings/js/ScriptGCEvent.cpp \
bindings/js/ScriptObject.cpp \
bindings/js/ScriptProfile.cpp \
bindings/js/ScriptState.cpp \
bindings/js/ScriptValue.cpp \
bindings/js/ScheduledAction.cpp \
......
......@@ -48247,6 +48247,10 @@
RelativePath="..\bindings\js\ScriptObject.h"
>
</File>
<File
RelativePath="..\bindings\js\ScriptProfile.cpp"
>
</File>
<File
RelativePath="..\bindings\js\ScriptSourceCode.h"
>
......@@ -5187,6 +5187,7 @@
ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED501DC50B249F2900AE18D9 /* EditorMac.mm */; };
EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE3A4FF0C7A430600956A37 /* ColorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
EDEC98030AED7E170059137F /* WebCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = EDEC98020AED7E170059137F /* WebCorePrefix.h */; };
F33F0282120947F200E5743A /* ScriptProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F33F0281120947F200E5743A /* ScriptProfile.cpp */; };
F344C7141125B82C00F26EEE /* InspectorFrontendClient.h in Headers */ = {isa = PBXBuildFile; fileRef = F344C7121125B82C00F26EEE /* InspectorFrontendClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
F344C75311294D9D00F26EEE /* InspectorFrontendClientLocal.h in Headers */ = {isa = PBXBuildFile; fileRef = F344C75211294D9D00F26EEE /* InspectorFrontendClientLocal.h */; settings = {ATTRIBUTES = (Private, ); }; };
F344C75811294FF600F26EEE /* InspectorFrontendClientLocal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F344C75711294FF600F26EEE /* InspectorFrontendClientLocal.cpp */; };
......@@ -10920,6 +10921,7 @@
ED501DC50B249F2900AE18D9 /* EditorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = EditorMac.mm; path = mac/EditorMac.mm; sourceTree = "<group>"; };
EDE3A4FF0C7A430600956A37 /* ColorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorMac.h; sourceTree = "<group>"; };
EDEC98020AED7E170059137F /* WebCorePrefix.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCorePrefix.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
F33F0281120947F200E5743A /* ScriptProfile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptProfile.cpp; sourceTree = "<group>"; };
F344C7121125B82C00F26EEE /* InspectorFrontendClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendClient.h; sourceTree = "<group>"; };
F344C75211294D9D00F26EEE /* InspectorFrontendClientLocal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendClientLocal.h; sourceTree = "<group>"; };
F344C75711294FF600F26EEE /* InspectorFrontendClientLocal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorFrontendClientLocal.cpp; sourceTree = "<group>"; };
......@@ -15822,6 +15824,7 @@
934CC1160EDCAC7300A658F2 /* ScriptInstance.h */,
41F066E30F64BCF600A07EAC /* ScriptObject.cpp */,
41F066E20F64BCF600A07EAC /* ScriptObject.h */,
F33F0281120947F200E5743A /* ScriptProfile.cpp */,
9F72304C11184B4100AD0126 /* ScriptProfile.h */,
9FA37EE31172FC8000C4CD55 /* ScriptProfileNode.h */,
9F72304D11184B4100AD0126 /* ScriptProfiler.cpp */,
......@@ -21917,6 +21920,7 @@
41002CCE0F66EDEF009E660D /* ScriptFunctionCall.cpp in Sources */,
4FD8D0F2119C718B002FA825 /* ScriptGCEvent.cpp in Sources */,
41F066E50F64BCF600A07EAC /* ScriptObject.cpp in Sources */,
F33F0282120947F200E5743A /* ScriptProfile.cpp in Sources */,
9F72305011184B4100AD0126 /* ScriptProfiler.cpp in Sources */,
4127D5370F8AAB1D00E424F5 /* ScriptState.cpp in Sources */,
934CC0E10ED39D6F00A658F2 /* ScriptValue.cpp in Sources */,
/*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR
* 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.
*/
#include "config.h"
#include "ScriptProfile.h"
#if ENABLE(JAVASCRIPT_DEBUGGER)
#include "InspectorValues.h"
#include "JSDOMBinding.h"
#include <profiler/Profile.h>
#include <profiler/ProfileNode.h>
namespace WebCore {
PassRefPtr<ScriptProfile> ScriptProfile::create(PassRefPtr<JSC::Profile> profile)
{
if (!profile)
return 0;
return adoptRef(new ScriptProfile(profile));
}
ScriptProfile::ScriptProfile(PassRefPtr<JSC::Profile> profile)
: m_profile(profile)
{
}
ScriptProfile::~ScriptProfile()
{
}
String ScriptProfile::title() const
{
return ustringToString(m_profile->title());
}
unsigned int ScriptProfile::uid() const
{
return m_profile->uid();
}
ScriptProfileNode* ScriptProfile::head() const
{
return m_profile->head();
}
static PassRefPtr<InspectorObject> buildInspectorObjectFor(const JSC::ProfileNode* node)
{
RefPtr<InspectorObject> result = InspectorObject::create();
result->setString("functionName", ustringToString(node->functionName()));
result->setString("url", ustringToString(node->url()));
result->setNumber("lineNumber", node->lineNumber());
result->setNumber("totalTime", node->totalTime());
result->setNumber("selfTime", node->selfTime());
result->setNumber("numberOfCalls", node->numberOfCalls());
result->setBool("visible", node->visible());
result->setNumber("callUID", node->callIdentifier().hash());
RefPtr<InspectorArray> childrenArray = InspectorArray::create();
typedef Vector<RefPtr<JSC::ProfileNode> > ProfileNodesList;
const ProfileNodesList& children = node->children();
ProfileNodesList::const_iterator end = children.end();
for (ProfileNodesList::const_iterator iter = children.begin(); iter != end; ++iter)
childrenArray->push(buildInspectorObjectFor(iter->get()));
result->set("children", childrenArray);
return result;
}
PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const
{
return buildInspectorObjectFor(m_profile->head());
}
} // namespace WebCore
#endif // ENABLE(JAVASCRIPT_DEBUGGER)
......@@ -28,11 +28,37 @@
#define ScriptProfile_h
#if ENABLE(JAVASCRIPT_DEBUGGER)
#include <profiler/Profile.h>
#include "ScriptProfileNode.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace JSC {
class Profile;
}
namespace WebCore {
typedef JSC::Profile ScriptProfile;
class InspectorObject;
class String;
class ScriptProfile : public RefCounted<ScriptProfile> {
public:
static PassRefPtr<ScriptProfile> create(PassRefPtr<JSC::Profile> profile);
virtual ~ScriptProfile();
String title() const;
unsigned int uid() const;
ScriptProfileNode* head() const;
PassRefPtr<InspectorObject> buildInspectorObjectForHead() const;
private:
ScriptProfile(PassRefPtr<JSC::Profile> profile);
RefPtr<JSC::Profile> m_profile;
};
} // namespace WebCore
......
......@@ -42,7 +42,8 @@ void ScriptProfiler::start(ScriptState* state, const String& title)
PassRefPtr<ScriptProfile> ScriptProfiler::stop(ScriptState* state, const String& title)
{
return JSC::Profiler::profiler()->stopProfiling(state, stringToUString(title));
RefPtr<JSC::Profile> profile = JSC::Profiler::profiler()->stopProfiling(state, stringToUString(title));
return ScriptProfile::create(profile);
}
} // namespace WebCore
......
......@@ -299,7 +299,7 @@ sub AddIncludesForSVGAnimatedType
sub IsScriptProfileType
{
my $type = shift;
return 1 if ($type eq "ScriptProfile" or $type eq "ScriptProfileNode");
return 1 if ($type eq "ScriptProfileNode");
return 0;
}
......
......@@ -29,12 +29,13 @@
*/
#include "config.h"
#include "ScriptProfile.h"
#include "InspectorValues.h"
#include "V8Binding.h"
#include <v8-profiler.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
......@@ -54,4 +55,32 @@ PassRefPtr<ScriptProfileNode> ScriptProfile::head() const
return ScriptProfileNode::create(m_profile->GetTopDownRoot());
}
static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::CpuProfileNode* node)
{
v8::HandleScope handleScope;
RefPtr<InspectorObject> result = InspectorObject::create();
result->setString("functionName", toWebCoreString(node->GetFunctionName()));
result->setString("url", toWebCoreString(node->GetScriptResourceName()));
result->setNumber("lineNumber", node->GetLineNumber());
result->setNumber("totalTime", node->GetTotalTime());
result->setNumber("selfTime", node->GetSelfTime());
result->setNumber("numberOfCalls", 0);
result->setBool("visible", true);
result->setNumber("callUID", node->GetCallUid());
RefPtr<InspectorArray> children = InspectorArray::create();
const int childrenCount = node->GetChildrenCount();
for (int i = 0; i < childrenCount; i++) {
const v8::CpuProfileNode* child = node->GetChild(i);
children->push(buildInspectorObjectFor(child));
}
result->set("children", children);
return result;
}
PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const
{
return buildInspectorObjectFor(m_profile->GetTopDownRoot());
}
} // namespace WebCore
......@@ -40,6 +40,8 @@ class CpuProfile;
namespace WebCore {
class InspectorObject;
class ScriptProfile : public RefCounted<ScriptProfile> {
public:
static PassRefPtr<ScriptProfile> create(const v8::CpuProfile* profile)
......@@ -52,12 +54,13 @@ public:
unsigned int uid() const;
PassRefPtr<ScriptProfileNode> head() const;
protected:
PassRefPtr<InspectorObject> buildInspectorObjectForHead() const;
private:
ScriptProfile(const v8::CpuProfile* profile)
: m_profile(profile)
{}
private:
const v8::CpuProfile* m_profile;
};
......
......@@ -49,6 +49,7 @@ module core {
#if defined(ENABLE_JAVASCRIPT_DEBUGGER) && ENABLE_JAVASCRIPT_DEBUGGER
[notify] void pausedScript(out Value callFrames);
[notify] void resumedScript();
[notify] void addProfileHeader(out Object header);
#endif
[handler=Controller] void storeLastActivePanel(in String panelName);
......@@ -97,8 +98,8 @@ module core {
[handler=Controller] void startProfiling();
[handler=Controller] void stopProfiling();
[handler=Controller] void getProfileHeaders(in long callId);
[handler=Controller] void getProfile(in long callId, in unsigned long uid);
[handler=Controller] void getProfileHeaders(in long callId, out Array headers);
[handler=Controller] void getProfile(in long callId, in unsigned long uid, out Object profile);
[handler=Controller] void removeProfile(in unsigned long uid);
[handler=Controller] void clearProfiles();
......
......@@ -108,14 +108,6 @@
#if ENABLE(JAVASCRIPT_DEBUGGER)
#include "ScriptDebugServer.h"
#if USE(JSC)
#include <runtime/JSLock.h>
#include <runtime/UString.h>
#include "JSScriptProfile.h"
#else
#include "ScriptScope.h"
#include "V8ScriptProfile.h"
#endif
#endif
using namespace std;
......@@ -1498,11 +1490,8 @@ void InspectorController::addProfile(PassRefPtr<ScriptProfile> prpProfile, unsig
RefPtr<ScriptProfile> profile = prpProfile;
m_profiles.add(profile->uid(), profile);
if (m_frontend) {
#if USE(JSC)
JSC::JSLock lock(JSC::SilenceAssertionsOnly);
#endif
m_frontend->addProfileHeader(createProfileHeader(*profile));
if (m_remoteFrontend) {
m_remoteFrontend->addProfileHeader(createProfileHeader(*profile));
}
addProfileFinishedMessageToConsole(profile, lineNumber, sourceURL);
......@@ -1512,11 +1501,7 @@ void InspectorController::addProfileFinishedMessageToConsole(PassRefPtr<ScriptPr
{
RefPtr<ScriptProfile> profile = prpProfile;
#if USE(JSC)
String title = ustringToString(profile->title());
#else
String title = profile->title();
#endif
String message = String::format("Profile \"webkit-profile://%s/%s#%d\" finished.", CPUProfileType, encodeWithURLEscapeSequences(title).utf8().data(), profile->uid());
addMessageToConsole(JSMessageSource, LogMessageType, LogMessageLevel, message, lineNumber, sourceURL);
}
......@@ -1548,14 +1533,13 @@ void InspectorController::clearProfiles()
void InspectorController::getProfileHeaders(long callId)
{
if (!m_frontend)
if (!m_remoteFrontend)
return;
ScriptArray result = m_frontend->newScriptArray();
RefPtr<InspectorArray> result = InspectorArray::create();
ProfilesMap::iterator profilesEnd = m_profiles.end();
int i = 0;
for (ProfilesMap::iterator it = m_profiles.begin(); it != profilesEnd; ++it)
result.set(i++, createProfileHeader(*it->second));
m_frontend->didGetProfileHeaders(callId, result);
result->push(createProfileHeader(*it->second));
m_remoteFrontend->didGetProfileHeaders(callId, result);
}
void InspectorController::getProfile(long callId, unsigned uid)
......@@ -1564,27 +1548,18 @@ void InspectorController::getProfile(long callId, unsigned uid)
return;
ProfilesMap::iterator it = m_profiles.find(uid);
if (it != m_profiles.end()) {
#if USE(JSC)
m_frontend->didGetProfile(callId, toJS(m_frontend->scriptState(), it->second.get()));
#else
ScriptScope scope(m_frontend->scriptState());
m_frontend->didGetProfile(callId, toV8(it->second.get()));
#endif
RefPtr<InspectorObject> profileObject = createProfileHeader(*it->second);
profileObject->set("head", it->second->buildInspectorObjectForHead());
m_remoteFrontend->didGetProfile(callId, profileObject);
}
}
ScriptObject InspectorController::createProfileHeader(const ScriptProfile& profile)
PassRefPtr<InspectorObject> InspectorController::createProfileHeader(const ScriptProfile& profile)
{
#if USE(JSC)
String title = ustringToString(profile.title());
#else
String title = profile.title();
#endif
ScriptObject header = m_frontend->newScriptObject();
header.set("title", title);
header.set("uid", profile.uid());
header.set("typeId", String(CPUProfileType));
RefPtr<InspectorObject> header = InspectorObject::create();
header->setString("title", profile.title());
header->setNumber("uid", profile.uid());
header->setString("typeId", String(CPUProfileType));
return header;
}
......
......@@ -318,7 +318,7 @@ private:
void enableDebuggerFromFrontend(bool always);
void getProfileHeaders(long callId);
void getProfile(long callId, unsigned uid);
ScriptObject createProfileHeader(const ScriptProfile& profile);
PassRefPtr<InspectorObject> createProfileHeader(const ScriptProfile& profile);
#endif
#if ENABLE(DATABASE)
void selectDatabase(Database* database);
......
......@@ -310,14 +310,6 @@ void InspectorFrontend::profilerWasDisabled()
callSimpleFunction("profilerWasDisabled");
}
void InspectorFrontend::addProfileHeader(const ScriptValue& profile)
{
ScriptFunctionCall function(m_webInspector, "dispatch");
function.appendArgument("addProfileHeader");
function.appendArgument(profile);
function.call();
}
void InspectorFrontend::setRecordingProfile(bool isProfiling)
{
ScriptFunctionCall function(m_webInspector, "dispatch");
......@@ -326,15 +318,6 @@ void InspectorFrontend::setRecordingProfile(bool isProfiling)
function.call();
}
void InspectorFrontend::didGetProfileHeaders(long callId, const ScriptArray& headers)
{
ScriptFunctionCall function(m_webInspector, "dispatch");
function.appendArgument("didGetProfileHeaders");
function.appendArgument(callId);
function.appendArgument(headers);
function.call();
}
void InspectorFrontend::didGetProfile(long callId, const ScriptValue& profile)
{
ScriptFunctionCall function(m_webInspector, "dispatch");
......
......@@ -102,9 +102,7 @@ namespace WebCore {
void profilerWasEnabled();
void profilerWasDisabled();
void addProfileHeader(const ScriptValue& profile);
void setRecordingProfile(bool isProfiling);
void didGetProfileHeaders(long callId, const ScriptArray& headers);
void didGetProfile(long callId, const ScriptValue& profile);
#endif
......
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