Changeset 117234 in webkit


Ignore:
Timestamp:
May 16, 2012 1:47:59 AM (12 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: use separate fields for storing HeapSnapshotLoaderProxy and HeapSnapshotProxy
https://bugs.webkit.org/show_bug.cgi?id=86488

Reviewed by Pavel Feldman.

Source/WebCore:

Simplified heap profiler snapshot loading code. Introduced dedicated fields for
snapshot loader proxy and for snapshot proxy.

  • inspector/front-end/HeapSnapshotProxy.js:

(WebInspector.HeapSnapshotWorker):
(WebInspector.HeapSnapshotLoaderProxy):
(WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading.updateStaticData):
(WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading.callLoadCallbacks):
(WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):
(WebInspector.HeapSnapshotLoaderProxy.prototype.get loaded):
(WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
(WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):

  • inspector/front-end/HeapSnapshotView.js:

(WebInspector.HeapSnapshotView.profileCallback):
(WebInspector.HeapSnapshotView):
(WebInspector.HeapSnapshotView.prototype.dispose):
(WebInspector.HeapSnapshotView.prototype.get baseProfileWrapper):
(WebInspector.HeapSnapshotView.prototype.wasShown.profileCallback1):
(WebInspector.HeapSnapshotView.prototype._changeView):
(WebInspector.HeapProfileHeader): split _proxy field into _loaderProxy and _snapshotProxy
(WebInspector.HeapProfileHeader.prototype.snapshotProxy):
(WebInspector.HeapProfileHeader.prototype.load):
(WebInspector.HeapProfileHeader.prototype._setupWorker):
(WebInspector.HeapProfileHeader.prototype.dispose):
(WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
(WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
(WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
(WebInspector.HeapProfileHeader.prototype.canSaveToFile):
(WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
(WebInspector.HeapProfileHeader.prototype.loadFromFile):

LayoutTests:

  • inspector/profiler/heap-snapshot-inspect-dom-wrapper.html: instead of sniffing a method

call we can use HeapProfileHeader.load directly.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r117232 r117234  
     12012-05-15  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: use separate fields for storing HeapSnapshotLoaderProxy and HeapSnapshotProxy
     4        https://bugs.webkit.org/show_bug.cgi?id=86488
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/profiler/heap-snapshot-inspect-dom-wrapper.html: instead of sniffing a method
     9        call we can use HeapProfileHeader.load directly.
     10
    1112012-05-16  Kenichi Ishibashi  <bashi@chromium.org>
    212
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-inspect-dom-wrapper.html

    r116218 r117234  
    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        profile.load(step2.bind(this));
    3131    }
    3232
    33     function step2(loadCallbacks, snapshotProxy)
     33    function step2(snapshotProxy)
    3434    {
    3535        InspectorTest.addResult("_callLoadCallbacks");
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js

    r117051 r117234  
    161161        // so we provide synthetic snapshots.
    162162        InspectorTest._panelReset = InspectorTest.override(WebInspector.panels.profiles, "_reset", function(){}, true);
    163         InspectorTest.addSniffer(WebInspector.HeapSnapshotView.prototype, "_loadProfile", InspectorTest._snapshotViewShown, true);
     163        InspectorTest.addSniffer(WebInspector.HeapSnapshotView.prototype, "show", InspectorTest._snapshotViewShown, true);
    164164
    165165        detailedHeapProfilesEnabled();
  • trunk/Source/WebCore/ChangeLog

    r117233 r117234  
     12012-05-15  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: use separate fields for storing HeapSnapshotLoaderProxy and HeapSnapshotProxy
     4        https://bugs.webkit.org/show_bug.cgi?id=86488
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Simplified heap profiler snapshot loading code. Introduced dedicated fields for
     9        snapshot loader proxy and for snapshot proxy.
     10
     11        * inspector/front-end/HeapSnapshotProxy.js:
     12        (WebInspector.HeapSnapshotWorker):
     13        (WebInspector.HeapSnapshotLoaderProxy):
     14        (WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading.updateStaticData):
     15        (WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading.callLoadCallbacks):
     16        (WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):
     17        (WebInspector.HeapSnapshotLoaderProxy.prototype.get loaded):
     18        (WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
     19        (WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):
     20        * inspector/front-end/HeapSnapshotView.js:
     21        (WebInspector.HeapSnapshotView.profileCallback):
     22        (WebInspector.HeapSnapshotView):
     23        (WebInspector.HeapSnapshotView.prototype.dispose):
     24        (WebInspector.HeapSnapshotView.prototype.get baseProfileWrapper):
     25        (WebInspector.HeapSnapshotView.prototype.wasShown.profileCallback1):
     26        (WebInspector.HeapSnapshotView.prototype._changeView):
     27        (WebInspector.HeapProfileHeader): split _proxy field into _loaderProxy and _snapshotProxy
     28        (WebInspector.HeapProfileHeader.prototype.snapshotProxy):
     29        (WebInspector.HeapProfileHeader.prototype.load):
     30        (WebInspector.HeapProfileHeader.prototype._setupWorker):
     31        (WebInspector.HeapProfileHeader.prototype.dispose):
     32        (WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
     33        (WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
     34        (WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
     35        (WebInspector.HeapProfileHeader.prototype.canSaveToFile):
     36        (WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
     37        (WebInspector.HeapProfileHeader.prototype.loadFromFile):
     38
    1392012-05-16  Eugene Klyuchnikov  <eustas.bug@gmail.com>
    240
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js

    r117227 r117234  
    301301{
    302302    WebInspector.HeapSnapshotProxyObject.call(this, worker, objectId);
    303     this._loading = false;
    304     this._loaded = false;
     303    this._onLoadCallbacks = [];
    305304}
    306305
    307306WebInspector.HeapSnapshotLoaderProxy.prototype = {
     307    /**
     308     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     309     */
    308310    finishLoading: function(callback)
    309311    {
    310         if (!this._loading)
    311             return false;
    312         var loadCallbacks = this._onLoadCallbacks;
    313         loadCallbacks.splice(0, 0, callback);
    314         delete this._onLoadCallbacks;
    315         this._loading = false;
    316         this._loaded = true;
    317         var self = this;
     312        this._onLoadCallbacks.unshift(callback);
     313
    318314        function updateStaticData(snapshotProxy)
    319315        {
    320316            this.dispose();
    321             snapshotProxy.updateStaticData(this._callLoadCallbacks.bind(this, loadCallbacks));
     317            snapshotProxy.updateStaticData(callLoadCallbacks.bind(this));
     318        }
     319        function callLoadCallbacks(snapshotProxy)
     320        {
     321            for (var i = 0; i < this._onLoadCallbacks.length; ++i)
     322                this._onLoadCallbacks[i](snapshotProxy);
     323            this._onLoadCallbacks = null;
    322324        }
    323325        this.callFactoryMethod(updateStaticData.bind(this), "finishLoading", "WebInspector.HeapSnapshotProxy");
    324         return true;
    325     },
    326 
    327     _callLoadCallbacks: function(loadCallbacks, snapshotProxy)
    328     {
    329         for (var i = 0; i < loadCallbacks.length; ++i)
    330             loadCallbacks[i](snapshotProxy);
    331     },
    332 
    333     get loaded()
    334     {
    335         return this._loaded;
    336     },
    337 
     326    },
     327
     328    /**
     329     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     330     * @return {boolean}
     331     */
    338332    startLoading: function(callback)
    339333    {
    340         if (!this._loading) {
    341             this._onLoadCallbacks = [callback];
    342             this._loading = true;
    343             return true;
    344         } else {
    345             this._onLoadCallbacks.push(callback);
    346             return false;
    347         }
     334        var loadingHasJustStarted = !this._onLoadCallbacks.length;
     335        this._onLoadCallbacks.push(callback);
     336        return loadingHasJustStarted;
    348337    },
    349338
    350339    pushJSONChunk: function(chunk)
    351340    {
    352         if (!this._loading)
    353             return;
    354341        this.callMethod(null, "pushJSONChunk", chunk);
    355342    }
     
    431418    {
    432419        this.disposeWorker();
    433     },
    434 
    435     finishLoading: function()
    436     {
    437         return false;
    438     },
    439 
    440     get loaded()
    441     {
    442         return !!this._objectId;
    443420    },
    444421
     
    468445    },
    469446
    470     startLoading: function(callback)
    471     {
    472         setTimeout(callback.bind(null, this), 0);
    473         return false;
    474     },
    475 
    476447    get totalSize()
    477448    {
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js

    r116959 r117234  
    136136    this._popoverHelper = new WebInspector.ObjectPopoverHelper(this.element, this._getHoverAnchor.bind(this), this._resolveObjectForPopover.bind(this), undefined, true);
    137137
    138     this._loadProfile(this._profileUid, profileCallback.bind(this));
    139 
    140     function profileCallback()
     138    this.profile.load(profileCallback.bind(this));
     139
     140    function profileCallback(heapSnapshotProxy)
    141141    {
    142142        var list = this._profiles();
     
    153153        else
    154154            this.baseSelectElement.selectedIndex = profileIndex;
    155         this.dataGrid.setDataSource(this, this.profileWrapper);
     155        this.dataGrid.setDataSource(this, heapSnapshotProxy);
    156156    }
    157157}
     
    160160    dispose: function()
    161161    {
    162         this.profileWrapper.dispose();
     162        this.profile.dispose();
    163163        if (this.baseProfile)
    164             this.baseProfileWrapper.dispose();
     164            this.baseProfile.dispose();
    165165        this.containmentDataGrid.dispose();
    166166        this.constructorsDataGrid.dispose();
     
    180180    },
    181181
    182     get profileWrapper()
    183     {
    184         return this.profile._proxy;
    185     },
    186 
    187182    get baseProfile()
    188183    {
     
    190185    },
    191186
    192     get baseProfileWrapper()
    193     {
    194         return this.baseProfile._proxy;
    195     },
    196 
    197187    wasShown: function()
    198188    {
    199         if (!this.profileWrapper.loaded)
    200             this._loadProfile(this._profileUid, profileCallback1.bind(this));
    201         else
    202             profileCallback1.call(this);
     189        // FIXME: load base and current snapshots in parallel
     190        this.profile.load(profileCallback1.bind(this));
    203191
    204192        function profileCallback1() {
    205             if (this.baseProfile && !this.baseProfileWrapper.loaded)
    206                 this._loadProfile(this._baseProfileUid, profileCallback2.bind(this));
     193            if (this.baseProfile)
     194                this.baseProfile.load(profileCallback2.bind(this));
    207195            else
    208196                profileCallback2.call(this);
     
    371359        this._baseProfileUid = this._profiles()[this.baseSelectElement.selectedIndex].uid;
    372360        var dataGrid = /** @type {WebInspector.HeapSnapshotDiffDataGrid} */ this.dataGrid;
    373         this._loadProfile(this._baseProfileUid, dataGrid.setBaseDataSource.bind(dataGrid));
     361        // Change set base data source only if main data source is already set.
     362        if (dataGrid.snapshot)
     363            this.baseProfile.load(dataGrid.setBaseDataSource.bind(dataGrid));
    374364
    375365        if (!this.currentQuery || !this._searchFinishedCallback || !this._searchResults)
     
    421411    },
    422412
    423     _loadProfile: function(profileUid, callback)
    424     {
    425         WebInspector.panels.profiles.loadHeapSnapshot(profileUid, callback);
    426     },
    427 
    428413    isDetailedSnapshot: function(snapshot)
    429414    {
     
    500485    },
    501486
     487    _updateDataSourceAndView: function()
     488    {
     489        var dataGrid = this.dataGrid;
     490        if (dataGrid.snapshotView)
     491            return;
     492
     493        this.profile.load(didLoadSnapshot.bind(this));
     494        function didLoadSnapshot(snapshotProxy)
     495        {
     496            if (this.dataGrid !== dataGrid)
     497                return;
     498            if (dataGrid.snapshot !== snapshotProxy)
     499                dataGrid.setDataSource(this, snapshotProxy);
     500            if (dataGrid === this.diffDataGrid) {
     501                if (!this._baseProfileUid)
     502                    this._baseProfileUid = this._profiles()[this.baseSelectElement.selectedIndex].uid;
     503                this.baseProfile.load(didLoadBaseSnaphot.bind(this));
     504            }
     505        }
     506
     507        function didLoadBaseSnaphot(baseSnapshotProxy)
     508        {
     509            if (this.diffDataGrid.baseSnapshot !== baseSnapshotProxy)
     510                this.diffDataGrid.setBaseDataSource(baseSnapshotProxy);
     511        }
     512    },
     513
    502514    _changeView: function(event)
    503515    {
     
    516528        this.dataGrid.updateWidths();
    517529
    518         if (this.currentView === this.diffView) {
     530        if (this.currentView === this.diffView)
    519531            this.baseSelectElement.removeStyleClass("hidden");
    520             if (!this.dataGrid.snapshotView) {
    521                 this._changeBase();
    522                 this.dataGrid.setDataSource(this, this.profileWrapper);
    523             }
    524         } else {
     532        else
    525533            this.baseSelectElement.addStyleClass("hidden");
    526             if (!this.dataGrid.snapshotView)
    527                 this.dataGrid.setDataSource(this, this.profileWrapper);
    528         }
     534
     535        this._updateDataSourceAndView();
    529536
    530537        if (this.currentView === this.constructorsView)
     
    795802    WebInspector.ProfileHeader.call(this, WebInspector.HeapSnapshotProfileType.TypeId, title, uid);
    796803    this.maxJSObjectId = maxJSObjectId;
    797     this._loaded = false;
     804    /**
     805     * @type {WebInspector.HeapSnapshotLoaderProxy}
     806     */
     807    this._loaderProxy = null;
     808    /**
     809     * @type {WebInspector.HeapSnapshotProxy}
     810     */
     811    this._snapshotProxy = null;
    798812    this._totalNumberOfChunks = 0;
    799813}
    800814
    801815WebInspector.HeapProfileHeader.prototype = {
     816    snapshotProxy: function()
     817    {
     818        return this._snapshotProxy;
     819    },
     820
    802821    /**
    803822     * @override
     
    806825    load: function(callback)
    807826    {
    808         if (this._loaded) {
    809             callback(this._proxy);
    810             return;
    811         }
    812 
    813         if (!this._proxy)
     827        if (this._snapshotProxy) {
     828            callback(this._snapshotProxy);
     829            return;
     830        }
     831
     832        if (!this._loaderProxy)
    814833            this._setupWorker();
    815834
    816         if (this._proxy.startLoading(callback)) {
     835        if (this._loaderProxy.startLoading(callback)) {
    817836            this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
    818837            this.sidebarElement.wait = true;
    819             function done()
    820             {
    821                 this._loaded = true;
    822             }
    823             ProfilerAgent.getProfile(this.typeId, this.uid, done.bind(this));
     838            ProfilerAgent.getProfile(this.typeId, this.uid);
    824839        }
    825840    },
     
    832847        var worker = new WebInspector.HeapSnapshotWorker();
    833848        worker.addEventListener("wait", setProfileWait, this);
    834         this._proxy = worker.createObject("WebInspector.HeapSnapshotLoader");
     849        this._loaderProxy = worker.createObject("WebInspector.HeapSnapshotLoader");
     850    },
     851
     852    dispose: function()
     853    {
     854        if (this._loaderProxy)
     855            this._loaderProxy.dispose();
     856        else if (this._snapshotProxy)
     857            this._snapshotProxy.dispose();
    835858    },
    836859
     
    843866            return;
    844867        if (++this._savedChunksCount === this._totalNumberOfChunks) {
    845             this.sidebarElement.subtitle = Number.bytesToString(this._proxy.totalSize);
     868            this.sidebarElement.subtitle = Number.bytesToString(this._snapshotProxy.totalSize);
    846869            this.sidebarElement.wait = false;
    847870            this._savedChunksCount = 0;
     
    856879    pushJSONChunk: function(chunk)
    857880    {
    858         if (this._loaded) {
     881        if (this._loaderProxy) {
     882            ++this._totalNumberOfChunks;
     883            this._loaderProxy.pushJSONChunk(chunk);
     884        } else {
    859885            this.sidebarElement.wait = true;
    860886            WebInspector.fileManager.append(this._fileName, chunk);
    861         } else {
    862             ++this._totalNumberOfChunks;
    863             this._proxy.pushJSONChunk(chunk);
    864887        }
    865888    },
     
    869892        function parsed(snapshotProxy)
    870893        {
    871             this._proxy = snapshotProxy;
     894            this._loaderProxy = null;
     895            this._snapshotProxy = snapshotProxy;
    872896            this.sidebarElement.subtitle = Number.bytesToString(snapshotProxy.totalSize);
    873897            this.sidebarElement.wait = false;
     
    876900            worker.startCheckingForLongRunningCalls();
    877901        }
    878         if (this._proxy.finishLoading(parsed.bind(this)))
     902        if (this._loaderProxy.finishLoading(parsed.bind(this)))
    879903            this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
    880904    },
     
    886910    canSaveToFile: function()
    887911    {
    888         return !this.fromFile() && this._loaded && !this._savedChunksCount && WebInspector.fileManager.canAppend();
     912        return !this.fromFile() && this._snapshotProxy && !this._savedChunksCount && WebInspector.fileManager.canAppend();
    889913    },
    890914
     
    948972        this.sidebarElement.wait = true;
    949973        this._setupWorker();
    950         this._proxy.startLoading(function() { });
     974        this._loaderProxy.startLoading(function(ignoredSnapshotProxy) { });
    951975
    952976        function loadNextChunk(file, reader, loadedSize)
     
    967991
    968992            this._loadedSize += event.target.result.length;
    969             this._proxy.pushJSONChunk(event.target.result);
     993            this._loaderProxy.pushJSONChunk(event.target.result);
    970994            this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / file.size).toFixed(2));
    971995
    972996            if (this._loadedSize === file.size) {
    973                 this._loaded = true;
    974997                this.finishHeapSnapshot();
    975998                return;
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js

    r117051 r117234  
    646646    /**
    647647     * @param {number} uid
    648      * @param {Function} callback
    649      */
    650     loadHeapSnapshot: function(uid, callback)
    651     {
    652         var profile = this._profilesIdMap[this._makeKey(uid, WebInspector.HeapSnapshotProfileType.TypeId)];
    653         if (!profile)
    654             return;
    655         profile.load(callback);
    656     },
    657 
    658     /**
    659      * @param {number} uid
    660648     * @param {string} chunk
    661649     */
Note: See TracChangeset for help on using the changeset viewer.