Changeset 116218 in webkit


Ignore:
Timestamp:
May 5, 2012 3:23:21 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: save HeapSnapshot implementation.
https://bugs.webkit.org/show_bug.cgi?id=85595

HeapSnapshot specific implementation for loading was moved
from ProfilesPanel to HeapProfileHeader class.

Reviewed by Yury Semikhatsky.

Source/WebCore:

  • inspector/front-end/HeapSnapshotView.js:

(WebInspector.HeapSnapshotView.prototype.get profileWrapper):
(WebInspector.HeapSnapshotView.prototype.get baseProfileWrapper):
(WebInspector.HeapProfileHeader):
(WebInspector.HeapProfileHeader.prototype.load.setProfileWait):
(WebInspector.HeapProfileHeader.prototype.load.done):
(WebInspector.HeapProfileHeader.prototype.load):
(WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
(WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
(WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
(WebInspector.HeapProfileHeader.prototype.canSave):
(WebInspector.HeapProfileHeader.prototype.save):

  • inspector/front-end/InspectorFrontendAPI.js:

(InspectorFrontendAPI.appendedToURL):

  • inspector/front-end/ProfilesPanel.js:

(WebInspector.ProfilesPanel.prototype._registerProfileType):
(WebInspector.ProfilesPanel.prototype._handleContextMenuEvent):
(WebInspector.ProfilesPanel.prototype.loadHeapSnapshot):
(WebInspector.ProfilesPanel.prototype._addHeapSnapshotChunk):
(WebInspector.ProfilesPanel.prototype._finishHeapSnapshot):
(WebInspector.ProfileSidebarTreeElement.prototype.set searchMatches):
(WebInspector.ProfileSidebarTreeElement.prototype.handleContextMenuEvent):

  • inspector/front-end/inspector.js:

(WebInspector.append):
(WebInspector.appendedToURL):

LayoutTests:

  • inspector/profiler/heap-snapshot-inspect-dom-wrapper.html:
  • inspector/profiler/heap-snapshot-test.js:

(initialize_HeapSnapshotTest):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r116217 r116218  
     12012-05-05  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: save HeapSnapshot implementation.
     4        https://bugs.webkit.org/show_bug.cgi?id=85595
     5
     6        HeapSnapshot specific implementation for loading was moved
     7        from ProfilesPanel to HeapProfileHeader class.
     8
     9        Reviewed by Yury Semikhatsky.
     10
     11        * inspector/profiler/heap-snapshot-inspect-dom-wrapper.html:
     12        * inspector/profiler/heap-snapshot-test.js:
     13        (initialize_HeapSnapshotTest):
     14
    1152012-05-05  Pavel Feldman  <pfeldman@chromium.org>
    216
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-inspect-dom-wrapper.html

    r114271 r116218  
    2828        var panel = WebInspector.panels.profiles;
    2929        var profile = panel._profilesIdMap[panel._makeKey(uid, WebInspector.HeapSnapshotProfileType.TypeId)];
    30         InspectorTest.addSniffer(profile.proxy, "_callLoadCallbacks", step2);
     30        InspectorTest.addSniffer(profile._proxy, "_callLoadCallbacks", step2);
    3131    }
    3232
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js

    r114872 r116218  
    524524    InspectorTest.override(ProfilerAgent, "getProfile", pushGeneratedSnapshot);
    525525    InspectorTest._takeAndOpenSnapshotCallback = callback;
     526    var profileType = WebInspector.panels.profiles.getProfileType(profile.typeId);
     527    profile = profileType.createProfile(profile);
    526528    WebInspector.panels.profiles.addProfileHeader(profile);
    527529    WebInspector.panels.profiles.showProfile(profile);
  • trunk/Source/WebCore/ChangeLog

    r116217 r116218  
     12012-05-05  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: save HeapSnapshot implementation.
     4        https://bugs.webkit.org/show_bug.cgi?id=85595
     5
     6        HeapSnapshot specific implementation for loading was moved
     7        from ProfilesPanel to HeapProfileHeader class.
     8
     9        Reviewed by Yury Semikhatsky.
     10
     11        * inspector/front-end/HeapSnapshotView.js:
     12        (WebInspector.HeapSnapshotView.prototype.get profileWrapper):
     13        (WebInspector.HeapSnapshotView.prototype.get baseProfileWrapper):
     14        (WebInspector.HeapProfileHeader):
     15        (WebInspector.HeapProfileHeader.prototype.load.setProfileWait):
     16        (WebInspector.HeapProfileHeader.prototype.load.done):
     17        (WebInspector.HeapProfileHeader.prototype.load):
     18        (WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
     19        (WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
     20        (WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
     21        (WebInspector.HeapProfileHeader.prototype.canSave):
     22        (WebInspector.HeapProfileHeader.prototype.save):
     23        * inspector/front-end/InspectorFrontendAPI.js:
     24        (InspectorFrontendAPI.appendedToURL):
     25        * inspector/front-end/ProfilesPanel.js:
     26        (WebInspector.ProfilesPanel.prototype._registerProfileType):
     27        (WebInspector.ProfilesPanel.prototype._handleContextMenuEvent):
     28        (WebInspector.ProfilesPanel.prototype.loadHeapSnapshot):
     29        (WebInspector.ProfilesPanel.prototype._addHeapSnapshotChunk):
     30        (WebInspector.ProfilesPanel.prototype._finishHeapSnapshot):
     31        (WebInspector.ProfileSidebarTreeElement.prototype.set searchMatches):
     32        (WebInspector.ProfileSidebarTreeElement.prototype.handleContextMenuEvent):
     33        * inspector/front-end/inspector.js:
     34        (WebInspector.append):
     35        (WebInspector.appendedToURL):
     36
    1372012-05-05  Pavel Feldman  <pfeldman@chromium.org>
    238
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js

    r116210 r116218  
    182182    get profileWrapper()
    183183    {
    184         return this.profile.proxy;
     184        return this.profile._proxy;
    185185    },
    186186
     
    192192    get baseProfileWrapper()
    193193    {
    194         return this.baseProfile.proxy;
     194        return this.baseProfile._proxy;
    195195    },
    196196
     
    771771
    772772WebInspector.HeapSnapshotProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
     773
     774/**
     775 * @constructor
     776 * @extends {WebInspector.ProfileHeader}
     777 * @param {string} profileType
     778 * @param {string} title
     779 * @param {number} uid
     780 * @param {number} maxJSObjectId
     781 */
     782WebInspector.HeapProfileHeader = function(profileType, title, uid, maxJSObjectId)
     783{
     784    WebInspector.ProfileHeader.call(this, profileType, title, uid);
     785    this.maxJSObjectId = maxJSObjectId;
     786    this._loaded = false;
     787    this._totalNumberOfChunks = 0;
     788}
     789
     790WebInspector.HeapProfileHeader.prototype = {
     791    load: function(callback)
     792    {
     793        if (this._loaded) {
     794            callback.call(null);
     795            return;
     796        }
     797
     798        if (!this._proxy) {
     799            function setProfileWait(event) {
     800                this.sidebarElement.wait = event.data;
     801            }
     802            var worker = new WebInspector.HeapSnapshotWorker();
     803            worker.addEventListener("wait", setProfileWait, this);
     804            this._proxy = worker.createObject("WebInspector.HeapSnapshotLoader");
     805        }
     806
     807        if (this._proxy.startLoading(callback)) {
     808            this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
     809            this.sidebarElement.wait = true;
     810            function done()
     811            {
     812                this._loaded = true;
     813            }
     814            ProfilerAgent.getProfile(this.typeId, this.uid, done.bind(this));
     815        }
     816    },
     817
     818    _saveStatusUpdate: function()
     819    {
     820        ++this._savedChunksCount;
     821        if (this._savedChunksCount === this._totalNumberOfChunks) {
     822            this.sidebarElement.subtitle = Number.bytesToString(this._proxy.totalSize);
     823            this.sidebarElement.wait = false;
     824        } else
     825            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", Math.floor(this._savedChunksCount * 100 / this._totalNumberOfChunks));
     826    },
     827
     828    pushJSONChunk: function(chunk)
     829    {
     830        if (this._loaded) {
     831            this.sidebarElement.wait = true;
     832            WebInspector.append(this._fileName, chunk, this._saveStatusUpdate.bind(this));
     833        } else {
     834            ++this._totalNumberOfChunks;
     835            this._proxy.pushJSONChunk(chunk);
     836        }
     837    },
     838
     839    finishHeapSnapshot: function()
     840    {
     841        function parsed(snapshotProxy)
     842        {
     843            this._proxy = snapshotProxy;
     844            this.sidebarElement.subtitle = Number.bytesToString(snapshotProxy.totalSize);
     845            this.sidebarElement.wait = false;
     846            var worker = /** @type {WebInspector.HeapSnapshotWorker} */ snapshotProxy.worker;
     847            worker.startCheckingForLongRunningCalls();
     848        }
     849        if (this._proxy.finishLoading(parsed.bind(this)))
     850            this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
     851    },
     852
     853    canSave: function()
     854    {
     855        return this._loaded && InspectorFrontendHost.canSave() && ("append" in InspectorFrontendHost);
     856    },
     857
     858    save: function()
     859    {
     860        function startWritingSnapshot()
     861        {
     862            this.sidebarElement.wait = true;
     863            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 0\%");
     864            this._savedChunksCount = 0;
     865            ProfilerAgent.getProfile(this.typeId, this.uid);
     866        }
     867        this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".json";
     868        WebInspector.save(this._fileName, "", true, startWritingSnapshot.bind(this));
     869    }
     870}
     871
     872WebInspector.HeapProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;
  • trunk/Source/WebCore/inspector/front-end/InspectorFrontendAPI.js

    r113199 r116218  
    111111    },
    112112
     113    appendedToURL: function(url)
     114    {
     115        WebInspector.appendedToURL(url);
     116    },
     117
    113118    setToolbarColors: function(backgroundColor, color)
    114119    {
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js

    r116210 r116218  
    139139/**
    140140 * @constructor
    141  * @extends {WebInspector.ProfileHeader}
    142  * @param {string} profileType
    143  * @param {string} title
    144  * @param {number} uid
    145  * @param {number} maxJSObjectId
    146  */
    147 WebInspector.HeapProfileHeader = function(profileType, title, uid, maxJSObjectId)
    148 {
    149     WebInspector.ProfileHeader.call(this, profileType, title, uid);
    150     this.maxJSObjectId = maxJSObjectId;
    151 }
    152 
    153 /**
    154  * @constructor
    155141 * @extends {WebInspector.Panel}
    156142 */
     
    337323        profileType.treeElement.hidden = true;
    338324        this.sidebarTree.appendChild(profileType.treeElement);
     325        profileType.treeElement.childrenListElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
     326    },
     327
     328    _handleContextMenuEvent: function(event)
     329    {
     330        var element = event.srcElement;
     331        while (element && !element.treeElement)
     332            element = element.parentElement;
     333        if (!element)
     334            return;
     335        if (element.treeElement.handleContextMenuEvent)
     336            element.treeElement.handleContextMenuEvent(event);
    339337    },
    340338
     
    560558        if (!profile)
    561559            return;
    562 
    563         if (!profile.proxy) {
    564             function setProfileWait(event) {
    565                 profile.sidebarElement.wait = event.data;
    566             }
    567             var worker = new WebInspector.HeapSnapshotWorker();
    568             worker.addEventListener("wait", setProfileWait, this);
    569             profile.proxy = worker.createObject("WebInspector.HeapSnapshotLoader");
    570         }
    571         var proxy = profile.proxy;
    572         if (proxy.startLoading(callback)) {
    573             profile.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
    574             profile.sidebarElement.wait = true;
    575             ProfilerAgent.getProfile(profile.typeId, profile.uid);
    576         }
     560        profile.load(callback);
    577561    },
    578562
     
    584568    {
    585569        var profile = this._profilesIdMap[this._makeKey(uid, WebInspector.HeapSnapshotProfileType.TypeId)];
    586         if (!profile || !profile.proxy)
    587             return;
    588         profile.proxy.pushJSONChunk(chunk);
     570        if (!profile )
     571            return;
     572        profile.pushJSONChunk(chunk);
    589573    },
    590574
     
    595579    {
    596580        var profile = this._profilesIdMap[this._makeKey(uid, WebInspector.HeapSnapshotProfileType.TypeId)];
    597         if (!profile || !profile.proxy)
    598             return;
    599         var proxy = profile.proxy;
    600         function parsed(snapshotProxy)
    601         {
    602             profile.proxy = snapshotProxy;
    603             profile.sidebarElement.subtitle = Number.bytesToString(snapshotProxy.totalSize);
    604             profile.sidebarElement.wait = false;
    605             var worker = /** @type {WebInspector.HeapSnapshotWorker} */ snapshotProxy.worker;
    606             worker.startCheckingForLongRunningCalls();
    607         }
    608         if (proxy.finishLoading(parsed))
    609             profile.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
     581        if (!profile)
     582            return;
     583        profile.finishHeapSnapshot();
    610584    },
    611585
     
    11171091        this.bubbleText = matches;
    11181092        this.bubbleElement.addStyleClass("search-matches");
     1093    },
     1094
     1095    handleContextMenuEvent: function(event)
     1096    {
     1097        var profile = this.profile;
     1098        if (!profile.canSave || !profile.canSave())
     1099            return;
     1100        var contextMenu = new WebInspector.ContextMenu();
     1101        contextMenu.appendItem(WebInspector.UIString("Save profile"), profile.save.bind(profile));
     1102        contextMenu.show(event);
    11191103    }
    11201104}
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r115569 r116218  
    10331033}
    10341034
    1035 WebInspector.save = function(url, content, forceSaveAs)
     1035WebInspector._saveCallbacks = [];
     1036
     1037WebInspector.save = function(url, content, forceSaveAs, callback)
    10361038{
    10371039    // Remove this url from the saved URLs while it is being saved.
     
    10391041    delete savedURLs[url];
    10401042    WebInspector.settings.savedURLs.set(savedURLs);
    1041 
     1043    if (callback)
     1044        WebInspector._saveCallbacks[url] = callback;
    10421045    InspectorFrontendHost.save(url, content, forceSaveAs);
    10431046}
     
    10481051    savedURLs[url] = true;
    10491052    WebInspector.settings.savedURLs.set(savedURLs);
     1053    var callback = WebInspector._saveCallbacks[url];
     1054    if (!callback)
     1055        return;
     1056    delete WebInspector._saveCallbacks[url];
     1057    callback.call(null, url);
    10501058}
    10511059
     
    10551063    return savedURLs[url];
    10561064}
     1065
     1066WebInspector._appendCallbacks = [];
     1067
     1068WebInspector.append = function(url, content, callback)
     1069{
     1070    if (callback)
     1071        WebInspector._appendCallbacks[url] = callback;
     1072    InspectorFrontendHost.append(url, content);
     1073}
     1074
     1075WebInspector.appendedToURL = function(url)
     1076{
     1077    var callback = WebInspector._appendCallbacks[url];
     1078    if (callback)
     1079        callback.call(null, url);
     1080}
     1081
Note: See TracChangeset for help on using the changeset viewer.