Changeset 49615 in webkit


Ignore:
Timestamp:
Oct 15, 2009 2:31:11 AM (15 years ago)
Author:
pfeldman@chromium.org
Message:

2009-10-14 Mikhail Naganov <mnaganov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: Migrate profiles to the injected script-based schema.

https://bugs.webkit.org/show_bug.cgi?id=30328

  • bindings/js/JSInspectorBackendCustom.cpp:
  • bindings/v8/custom/V8CustomBinding.h:
  • inspector/InspectorBackend.cpp: (WebCore::InspectorBackend::getProfileHeaders): (WebCore::InspectorBackend::getProfile):
  • inspector/InspectorBackend.h:
  • inspector/InspectorBackend.idl:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::addProfile): (WebCore::InspectorController::getProfileHeaders): (WebCore::InspectorController::getProfile): (WebCore::InspectorController::createProfileHeader):
  • inspector/InspectorController.h:
  • inspector/InspectorFrontend.cpp: (WebCore::InspectorFrontend::addProfileHeader): (WebCore::InspectorFrontend::didGetProfileHeaders): (WebCore::InspectorFrontend::didGetProfile):
  • inspector/InspectorFrontend.h:
  • inspector/JavaScriptProfileNode.cpp: (WebCore::ProfileNodeClass):
  • inspector/front-end/ProfileView.js: (WebInspector.ProfileView.profileCallback): (WebInspector.ProfileView): (WebInspector.ProfileView.prototype._mouseDownInDataGrid): (WebInspector.ProfileView.prototype._assignParentsInProfile):
  • inspector/front-end/ProfilesPanel.js: (WebInspector.ProfilesPanel.prototype.addProfileHeader):
  • inspector/front-end/inspector.js: (WebInspector.addProfileHeader):
Location:
trunk/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r49614 r49615  
     12009-10-14  Mikhail Naganov  <mnaganov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Migrate profiles to the injected script-based schema.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=30328
     8
     9        * bindings/js/JSInspectorBackendCustom.cpp:
     10        * bindings/v8/custom/V8CustomBinding.h:
     11        * inspector/InspectorBackend.cpp:
     12        (WebCore::InspectorBackend::getProfileHeaders):
     13        (WebCore::InspectorBackend::getProfile):
     14        * inspector/InspectorBackend.h:
     15        * inspector/InspectorBackend.idl:
     16        * inspector/InspectorController.cpp:
     17        (WebCore::InspectorController::addProfile):
     18        (WebCore::InspectorController::getProfileHeaders):
     19        (WebCore::InspectorController::getProfile):
     20        (WebCore::InspectorController::createProfileHeader):
     21        * inspector/InspectorController.h:
     22        * inspector/InspectorFrontend.cpp:
     23        (WebCore::InspectorFrontend::addProfileHeader):
     24        (WebCore::InspectorFrontend::didGetProfileHeaders):
     25        (WebCore::InspectorFrontend::didGetProfile):
     26        * inspector/InspectorFrontend.h:
     27        * inspector/JavaScriptProfileNode.cpp:
     28        (WebCore::ProfileNodeClass):
     29        * inspector/front-end/ProfileView.js:
     30        (WebInspector.ProfileView.profileCallback):
     31        (WebInspector.ProfileView):
     32        (WebInspector.ProfileView.prototype._mouseDownInDataGrid):
     33        (WebInspector.ProfileView.prototype._assignParentsInProfile):
     34        * inspector/front-end/ProfilesPanel.js:
     35        (WebInspector.ProfilesPanel.prototype.addProfileHeader):
     36        * inspector/front-end/inspector.js:
     37        (WebInspector.addProfileHeader):
     38
    1392009-10-14  Pavel Feldman  <pfeldman@chromium.org>
    240
  • trunk/WebCore/bindings/js/JSInspectorBackendCustom.cpp

    r49560 r49615  
    6767#include "JavaScriptCallFrame.h"
    6868#include "JavaScriptDebugServer.h"
    69 #include "JavaScriptProfile.h"
    7069#include "JSJavaScriptCallFrame.h"
    71 #include <profiler/Profile.h>
    72 #include <profiler/Profiler.h>
    7370#endif
    7471
     
    254251}
    255252
    256 JSValue JSInspectorBackend::profiles(JSC::ExecState* exec, const JSC::ArgList&)
    257 {
    258     JSLock lock(SilenceAssertionsOnly);
    259     MarkedArgumentBuffer result;
    260     InspectorController* ic = impl()->inspectorController();
    261     if (!ic)
    262         return jsUndefined();
    263     const Vector<RefPtr<Profile> >& profiles = ic->profiles();
    264 
    265     for (size_t i = 0; i < profiles.size(); ++i)
    266         result.append(toJS(exec, profiles[i].get()));
    267 
    268     return constructArray(exec, result);
    269 }
    270 
    271253#endif
    272254
  • trunk/WebCore/bindings/v8/custom/V8CustomBinding.h

    r49560 r49615  
    462462        DECLARE_CALLBACK(TreeWalkerPreviousSibling);
    463463
    464         DECLARE_CALLBACK(InspectorBackendProfiles);
    465464        DECLARE_CALLBACK(InspectorBackendHighlightDOMNode);
    466465        DECLARE_CALLBACK(InspectorBackendAddResourceSourceToFrame);
  • trunk/WebCore/inspector/InspectorBackend.cpp

    r49565 r49615  
    279279
    280280#if ENABLE(JAVASCRIPT_DEBUGGER)
    281 const ProfilesArray& InspectorBackend::profiles() const
    282 {
    283     if (m_inspectorController)
    284         return m_inspectorController->profiles();
    285     return m_emptyProfiles;
    286 }
    287 
    288281void InspectorBackend::startProfiling()
    289282{
     
    315308        return m_inspectorController->profilerEnabled();
    316309    return false;
     310}
     311
     312void InspectorBackend::getProfileHeaders(long callId)
     313{
     314    if (m_inspectorController)
     315        m_inspectorController->getProfileHeaders(callId);
     316}
     317
     318void InspectorBackend::getProfile(long callId, unsigned uid)
     319{
     320    if (m_inspectorController)
     321        m_inspectorController->getProfile(callId, uid);
    317322}
    318323
  • trunk/WebCore/inspector/InspectorBackend.h

    r49565 r49615  
    101101
    102102#if ENABLE(JAVASCRIPT_DEBUGGER)
    103     const ProfilesArray& profiles() const;
    104 
    105103    void startProfiling();
    106104    void stopProfiling();
     
    109107    void disableProfiler(bool always);
    110108    bool profilerEnabled();
     109
     110    void getProfileHeaders(long callId);
     111    void getProfile(long callId, unsigned uid);
    111112
    112113    void enableDebugger(bool always);
     
    172173    InspectorController* m_inspectorController;
    173174    InspectorClient* m_client;
    174 #if ENABLE(JAVASCRIPT_DEBUGGER)
    175     ProfilesArray m_emptyProfiles;
    176 #endif
    177175};
    178176
  • trunk/WebCore/inspector/InspectorBackend.idl

    r49565 r49615  
    101101        void stopProfiling();
    102102
    103         [Custom] Array profiles();
     103        void getProfileHeaders(in long callId);
     104        void getProfile(in long callId, in unsigned long uid);
    104105#endif
    105106        void dispatchOnInjectedScript(in long callId, in DOMString methodName, in DOMString arguments, in boolean async);
  • trunk/WebCore/inspector/InspectorController.cpp

    r49614 r49615  
    13381338
    13391339    RefPtr<Profile> profile = prpProfile;
    1340     m_profiles.append(profile);
     1340    m_profiles.add(profile->uid(), profile);
    13411341
    13421342    if (m_frontend) {
    13431343        JSLock lock(SilenceAssertionsOnly);
    1344         m_frontend->addProfile(toJS(m_scriptState, profile.get()));
     1344        m_frontend->addProfileHeader(createProfileHeader(*profile));
    13451345    }
    13461346
     
    13701370    message += "#0\" started.";
    13711371    addMessageToConsole(JSMessageSource, LogMessageType, LogMessageLevel, message, lineNumber, sourceURL);
     1372}
     1373
     1374void InspectorController::getProfileHeaders(long callId)
     1375{
     1376    if (!m_frontend)
     1377        return;
     1378    ScriptArray result = m_frontend->newScriptArray();
     1379    ProfilesMap::iterator profilesEnd = m_profiles.end();
     1380    int i = 0;
     1381    for (ProfilesMap::iterator it = m_profiles.begin(); it != profilesEnd; ++it)
     1382        result.set(i++, createProfileHeader(*it->second));
     1383    m_frontend->didGetProfileHeaders(callId, result);
     1384}
     1385
     1386void InspectorController::getProfile(long callId, unsigned uid)
     1387{
     1388    if (!m_frontend)
     1389        return;
     1390    ProfilesMap::iterator it = m_profiles.find(uid);
     1391    if (it != m_profiles.end())
     1392        m_frontend->didGetProfile(callId, toJS(m_scriptState, it->second.get()));
     1393}
     1394
     1395ScriptObject InspectorController::createProfileHeader(const JSC::Profile& profile)
     1396{
     1397    ScriptObject header = m_frontend->newScriptObject();
     1398    header.set("title", profile.title());
     1399    header.set("uid", profile.uid());
     1400    return header;
    13721401}
    13731402
  • trunk/WebCore/inspector/InspectorController.h

    r49565 r49615  
    266266    void addProfileFinishedMessageToConsole(PassRefPtr<JSC::Profile>, unsigned lineNumber, const JSC::UString& sourceURL);
    267267    void addStartProfilingMessageToConsole(const JSC::UString& title, unsigned lineNumber, const JSC::UString& sourceURL);
    268     const ProfilesArray& profiles() const { return m_profiles; }
    269268
    270269    bool isRecordingUserInitiatedProfile() const { return m_recordingUserInitiatedProfile; }
     
    316315
    317316#if ENABLE(JAVASCRIPT_DEBUGGER)
     317    typedef HashMap<unsigned int, RefPtr<JSC::Profile> > ProfilesMap;
     318
    318319    void startUserInitiatedProfilingSoon();
    319320    void toggleRecordButton(bool);
    320321    void enableDebuggerFromFrontend(bool always);
     322    void getProfileHeaders(long callId);
     323    void getProfile(long callId, unsigned uid);
     324    ScriptObject createProfileHeader(const JSC::Profile& profile);
    321325#endif
    322326#if ENABLE(DATABASE)
     
    395399    unsigned m_nextUserInitiatedProfileNumber;
    396400    Timer<InspectorController> m_startProfiling;
    397     ProfilesArray m_profiles;
     401    ProfilesMap m_profiles;
    398402#endif
    399403};
  • trunk/WebCore/inspector/InspectorFrontend.cpp

    r49565 r49615  
    262262}
    263263
    264 void InspectorFrontend::addProfile(const JSC::JSValue& profile)
    265 {
    266     OwnPtr<ScriptFunctionCall> function(newFunctionCall("addProfile"));
     264void InspectorFrontend::addProfileHeader(const ScriptValue& profile)
     265{
     266    OwnPtr<ScriptFunctionCall> function(newFunctionCall("addProfileHeader"));
    267267    function->appendArgument(profile);
    268268    function->call();
     
    273273    OwnPtr<ScriptFunctionCall> function(newFunctionCall("setRecordingProfile"));
    274274    function->appendArgument(isProfiling);
     275    function->call();
     276}
     277
     278void InspectorFrontend::didGetProfileHeaders(int callId, const ScriptArray& headers)
     279{
     280    OwnPtr<ScriptFunctionCall> function(newFunctionCall("didGetProfileHeaders"));
     281    function->appendArgument(callId);
     282    function->appendArgument(headers);
     283    function->call();
     284}
     285
     286void InspectorFrontend::didGetProfile(int callId, const ScriptValue& profile)
     287{
     288    OwnPtr<ScriptFunctionCall> function(newFunctionCall("didGetProfile"));
     289    function->appendArgument(callId);
     290    function->appendArgument(profile);
    275291    function->call();
    276292}
  • trunk/WebCore/inspector/InspectorFrontend.h

    r49565 r49615  
    9090        void parsedScriptSource(const JSC::SourceCode&);
    9191        void failedToParseScriptSource(const JSC::SourceCode&, int errorLine, const JSC::UString& errorMessage);
    92         void addProfile(const JSC::JSValue& profile);
     92        void addProfileHeader(const ScriptValue& profile);
    9393        void setRecordingProfile(bool isProfiling);
     94        void didGetProfileHeaders(int callId, const ScriptArray& headers);
     95        void didGetProfile(int callId, const ScriptValue& profile);
    9496        void pausedScript(const ScriptValue& callFrames);
    9597        void resumedScript();
  • trunk/WebCore/inspector/JavaScriptProfileNode.cpp

    r49560 r49615  
    105105}
    106106
    107 static JSValueRef getTotalPercent(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    108 {
    109     JSC::JSLock lock(SilenceAssertionsOnly);
    110 
    111     if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
    112         return JSValueMakeUndefined(ctx);
    113 
    114     ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    115     return JSValueMakeNumber(ctx, profileNode->totalPercent());
    116 }
    117 
    118 static JSValueRef getSelfPercent(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    119 {
    120     JSC::JSLock lock(SilenceAssertionsOnly);
    121 
    122     if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
    123         return JSValueMakeUndefined(ctx);
    124 
    125     ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    126     return JSValueMakeNumber(ctx, profileNode->selfPercent());
    127 }
    128 
    129107static JSValueRef getNumberOfCalls(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    130108{
     
    185163}
    186164
    187 static JSValueRef getParent(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    188 {
    189     JSC::JSLock lock(SilenceAssertionsOnly);
    190 
    191     if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
    192         return JSValueMakeUndefined(ctx);
    193 
    194     ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    195     ExecState* exec = toJS(ctx);
    196     return toRef(exec, toJS(exec, profileNode->parent()));
    197 }
    198 
    199 static JSValueRef getHead(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    200 {
    201     JSC::JSLock lock(SilenceAssertionsOnly);
    202 
    203     if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
    204         return JSValueMakeUndefined(ctx);
    205 
    206     ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
    207     ExecState* exec = toJS(ctx);
    208     return toRef(exec, toJS(exec, profileNode->head()));
    209 }
    210 
    211165static JSValueRef getVisible(JSContextRef ctx, JSObjectRef thisObject, JSStringRef, JSValueRef*)
    212166{
     
    246200        { "totalTime", getTotalTime, 0, kJSPropertyAttributeNone },
    247201        { "selfTime", getSelfTime, 0, kJSPropertyAttributeNone },
    248         { "totalPercent", getTotalPercent, 0, kJSPropertyAttributeNone },
    249         { "selfPercent", getSelfPercent, 0, kJSPropertyAttributeNone },
    250202        { "numberOfCalls", getNumberOfCalls, 0, kJSPropertyAttributeNone },
    251203        { "children", getChildren, 0, kJSPropertyAttributeNone },
    252         { "parent", getParent, 0, kJSPropertyAttributeNone },
    253         { "head", getHead, 0, kJSClassAttributeNone },
    254204        { "visible", getVisible, 0, kJSPropertyAttributeNone },
    255205        { "callUID", getCallUID, 0, kJSPropertyAttributeNone },
  • trunk/WebCore/inspector/front-end/ProfileView.js

    r49560 r49615  
    7979    this.profile = profile;
    8080
    81     this.profileDataGridTree = this.bottomUpProfileDataGridTree;
    82     this.profileDataGridTree.sort(WebInspector.ProfileDataGridTree.propertyComparator("selfTime", false));
    83 
    84     this.refresh();
    85 
    86     this._updatePercentButton();
     81    var self = this;
     82    function profileCallback(profile)
     83    {
     84        self.profile = profile;
     85        self._assignParentsInProfile();
     86     
     87        self.profileDataGridTree = self.bottomUpProfileDataGridTree;
     88        self.profileDataGridTree.sort(WebInspector.ProfileDataGridTree.propertyComparator("selfTime", false));
     89     
     90        self.refresh();
     91     
     92        self._updatePercentButton();
     93    }
     94
     95    var callId = WebInspector.Callback.wrap(profileCallback);
     96    InspectorController.getProfile(callId, this.profile.uid);
    8797}
    8898
     
    534544        event.preventDefault();
    535545        event.stopPropagation();
     546    },
     547
     548    _assignParentsInProfile: function()
     549    {
     550        var head = this.profile.head;
     551        head.parent = null;
     552        head.head = null;
     553        var nodesToTraverse = [ { parent: head, children: head.children } ];
     554        while (nodesToTraverse.length > 0) {
     555            var pair = nodesToTraverse.shift();
     556            var parent = pair.parent;
     557            var children = pair.children;
     558            var length = children.length;
     559            for (var i = 0; i < length; ++i) {
     560                children[i].head = head;
     561                children[i].parent = parent;
     562                if (children[i].children.length > 0)
     563                    nodesToTraverse.push({ parent: children[i], children: children[i].children });
     564            }
     565        }
    536566    }
    537567}
  • trunk/WebCore/inspector/front-end/ProfilesPanel.js

    r49560 r49615  
    162162    },
    163163
    164     addProfile: function(profile)
     164    addProfileHeader: function(profile)
    165165    {
    166166        this._profiles.push(profile);
     
    402402            return;
    403403
    404         var profiles = InspectorController.profiles();
    405         var profilesLength = profiles.length;
    406         for (var i = 0; i < profilesLength; ++i) {
    407             var profile = profiles[i];
    408             this.addProfile(profile);
    409         }
    410 
    411         if (cpuProfiles.children[0])
    412             cpuProfiles.children[0].select();
     404        function populateCallback(profileHeaders) {
     405            profileHeaders.sort(function(a, b) { return a.uid - b.uid; });
     406            var profileHeadersLength = profileHeaders.length;
     407            for (var i = 0; i < profileHeadersLength; ++i)
     408                WebInspector.addProfileHeader(profileHeaders[i]);
     409            if (cpuProfiles.children[0])
     410                cpuProfiles.children[0].select();
     411        }
     412
     413        var callId = WebInspector.Callback.wrap(populateCallback);
     414        InspectorController.getProfileHeaders(callId);
    413415
    414416        delete this._shouldPopulateProfiles;
     
    536538
    537539WebInspector.ProfileGroupSidebarTreeElement.prototype.__proto__ = WebInspector.SidebarTreeElement.prototype;
     540
     541WebInspector.didGetProfileHeaders = WebInspector.Callback.processCallback;
     542WebInspector.didGetProfile = WebInspector.Callback.processCallback;
  • trunk/WebCore/inspector/front-end/inspector.js

    r49560 r49615  
    12631263}
    12641264
    1265 WebInspector.addProfile = function(profile)
    1266 {
    1267     this.panels.profiles.addProfile(profile);
     1265WebInspector.addProfileHeader = function(profile)
     1266{
     1267    this.panels.profiles.addProfileHeader(profile);
    12681268}
    12691269
Note: See TracChangeset for help on using the changeset viewer.