Changeset 118742 in webkit


Ignore:
Timestamp:
May 29, 2012 2:17:36 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: REGRESSION: load heap snapshot doesn't work.
https://bugs.webkit.org/show_bug.cgi?id=87642

Source/WebCore:

HeapSnapshotReceiver interface was introduced.
It declares the API for HeapSnapshotLoader, HeapSnapshotLoaderProxy and HeapSnapshotSaveToFileReceiver.
The HeapProfileHeader was refactored and tests were added.

Reviewed by Yury Semikhatsky.

  • inspector/front-end/HeapSnapshotLoader.js:

(WebInspector.HeapSnapshotLoader):
(WebInspector.HeapSnapshotLoader.prototype.startLoading):
(WebInspector.HeapSnapshotLoader.prototype.dispose):
(WebInspector.HeapSnapshotLoader.prototype._reset):
(WebInspector.HeapSnapshotLoader.prototype.finishLoading):

  • inspector/front-end/HeapSnapshotProxy.js:

(WebInspector.HeapSnapshotWorker.prototype.startCheckingForLongRunningCalls):
(WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
(WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):

  • inspector/front-end/HeapSnapshotView.js:

(WebInspector.HeapSnapshotReceiver):
(WebInspector.HeapSnapshotReceiver.prototype.startLoading):
(WebInspector.HeapSnapshotReceiver.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotReceiver.prototype.finishLoading):
(WebInspector.HeapSnapshotReceiver.prototype.dispose):
(WebInspector.HeapProfileHeader):
(WebInspector.HeapProfileHeader.prototype.load):
(WebInspector.HeapProfileHeader.prototype._setupWorker):
(WebInspector.HeapProfileHeader.prototype.dispose):
(WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
(WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
(WebInspector.HeapProfileHeader.prototype._parsed):
(WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
(WebInspector.HeapProfileHeader.prototype.saveToFile):
(WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
(WebInspector.HeapProfileHeader.prototype.loadFromFile):
(WebInspector.HeapProfileHeader.prototype._loadNextChunk):
(WebInspector.HeapProfileHeader.prototype._nextChunkLoaded):
(WebInspector.HeapProfileHeader.prototype._createFileReader):
(WebInspector.HeapSnapshotSaveToFileReceiver):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.startLoading):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.finishLoading):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.dispose):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype._startSavingSnapshot):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype._saveStatusUpdate):

  • inspector/front-end/ProfilesPanel.js:

(WebInspector.ProfilesPanel.prototype._createFileSelectorElement.onChange):
(WebInspector.ProfilesPanel.prototype._createFileSelectorElement):
(WebInspector.ProfilesPanel.prototype._loadFromFile):

LayoutTests:

HeapSnapshotReceiver interface was introduced.
It declares the API for HSLoader, HSLoaderProxy and HSSaveToFileReceiver.
The HeapProfileHeader was refactored and tests were added.

Reviewed by Yury Semikhatsky.

  • inspector/profiler/heap-snapshot-loader-expected.txt:
  • inspector/profiler/heap-snapshot-loader.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r118741 r118742  
     12012-05-29  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: REGRESSION: load heap snapshot doesn't work.
     4        https://bugs.webkit.org/show_bug.cgi?id=87642
     5
     6        HeapSnapshotReceiver interface was introduced.
     7        It declares the API for HSLoader, HSLoaderProxy and HSSaveToFileReceiver.
     8        The HeapProfileHeader was refactored and tests were added.
     9
     10        Reviewed by Yury Semikhatsky.
     11
     12        * inspector/profiler/heap-snapshot-loader-expected.txt:
     13        * inspector/profiler/heap-snapshot-loader.html:
     14
     152012-05-29  Marcus Bulach  <bulach@chromium.org>
     16
     17        Test expectation pngs missing checksums are treated as MISSING by bots
     18        https://bugs.webkit.org/show_bug.cgi?id=87552
     19
     20        Unreviewed gardening.
     21
     22        This test was already failing for IMAGE and TEXT reasons prior to r118566.
     23        On r118566, new images were added, probably without an embedded checksum.
     24        It looks like our test infrastructure thinks that these images are MISSING.
     25        Temporarily add MISSING expectations, so that we can proceed with this (failing) test.
     26
     27        * platform/chromium/test_expectations.txt:
     28
    1292012-05-29  Marcus Bulach  <bulach@chromium.org>
    230
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-loader-expected.txt

    r116771 r118742  
    44Running: heapSnapshotLoaderTest
    55
     6Running: heapSnapshotSaveToFileTest
     7
     8Running: heapSnapshotLoadFromFileTest
     9
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html

    r116771 r118742  
    1212    }
    1313
     14    var source = InspectorTest.createHeapSnapshotMockRaw();
     15    var sourceStringified = JSON.stringify(source);
     16    var partSize = sourceStringified.length >> 3;
     17
    1418    InspectorTest.runTestSuite([
    1519        function heapSnapshotLoaderTest(next)
    1620        {
    17             var source = InspectorTest.createHeapSnapshotMockRaw();
    18             var sourceStringified = JSON.stringify(source);
    19             var partSize = sourceStringified.length >> 3;
    2021            var loader = new WebInspector.HeapSnapshotLoader();
    2122            for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
     
    2627            InspectorTest.assertSnapshotEquals(new WebInspector.HeapSnapshot(InspectorTest.createHeapSnapshotMock()), result);
    2728            next();
     29        },
     30
     31        function heapSnapshotSaveToFileTest(next)
     32        {
     33            var profileUID = 42;
     34
     35            var dispatcher = InspectorBackend._domainDispatchers["Profiler"];
     36            var panel = WebInspector.panels.profiles;
     37
     38            dispatcher.addProfileHeader({
     39                typeId: WebInspector.HeapSnapshotProfileType.TypeId,
     40                title: "heapSnapshotSaveToFileTest",
     41                uid: profileUID,
     42                maxJSObjectId: 6
     43            });
     44
     45            var profileHeader = panel._profiles[0];
     46
     47            var oldGetProfile = ProfilerAgent.getProfile;
     48            ProfilerAgent.getProfile = function getProfileMock(profileTypeName, uid) {
     49                for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
     50                    dispatcher.addHeapSnapshotChunk(uid, sourceStringified.slice(i, i + partSize));
     51                dispatcher.finishHeapSnapshot(uid);
     52            };
     53
     54            var savedSnapshotData;
     55            var oldSave = InspectorFrontendHost.save;
     56            InspectorFrontendHost.save = function saveMock(url, data)
     57            {
     58                savedSnapshotData = data;
     59                WebInspector.fileManager.savedURL(url);
     60            }
     61
     62            var oldAppend = InspectorFrontendHost.append;
     63            InspectorFrontendHost.append = function appendMock(url, data)
     64            {
     65                savedSnapshotData += data;
     66                WebInspector.fileManager.appendedToURL(url);
     67            }
     68
     69            function parsed()
     70            {
     71                profileHeader.saveToFile();
     72                InspectorTest.assertEquals(sourceStringified, savedSnapshotData, "Saved snapshot data");
     73
     74                InspectorFrontendHost.save = oldSave;
     75                InspectorFrontendHost.append = oldAppend;
     76                ProfilerAgent.getProfile = oldGetProfile;
     77                next();
     78            }
     79            InspectorTest.addSniffer(profileHeader, "_parsed", parsed);
     80
     81            panel.showProfile(profileHeader);
     82        },
     83
     84        function heapSnapshotLoadFromFileTest(next)
     85        {
     86            var panel = WebInspector.panels.profiles;
     87
     88            var fileMock = {
     89                name: "mock.heapsnapshot",
     90                size: sourceStringified.length,
     91                webkitSlice: function(begin, end) {
     92                    return this;
     93                }
     94            };
     95
     96            WebInspector.HeapProfileHeader.prototype._createFileReader = function() {
     97                return {
     98                    readAsText: function(filePart) {
     99                        var profileHeader = panel._profiles[panel._profiles.length - 1];
     100                        InspectorTest.addSniffer(profileHeader, "_parsed", function parsed() { next(); });
     101                        profileHeader._nextChunkLoaded(sourceStringified);
     102                    }
     103                };
     104            }
     105            panel._loadFromFile(fileMock);
    28106        }
    29107    ]);
  • trunk/Source/WebCore/ChangeLog

    r118737 r118742  
     12012-05-29  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: REGRESSION: load heap snapshot doesn't work.
     4        https://bugs.webkit.org/show_bug.cgi?id=87642
     5
     6        HeapSnapshotReceiver interface was introduced.
     7        It declares the API for HeapSnapshotLoader, HeapSnapshotLoaderProxy and HeapSnapshotSaveToFileReceiver.
     8        The HeapProfileHeader was refactored and tests were added.
     9
     10        Reviewed by Yury Semikhatsky.
     11
     12        * inspector/front-end/HeapSnapshotLoader.js:
     13        (WebInspector.HeapSnapshotLoader):
     14        (WebInspector.HeapSnapshotLoader.prototype.startLoading):
     15        (WebInspector.HeapSnapshotLoader.prototype.dispose):
     16        (WebInspector.HeapSnapshotLoader.prototype._reset):
     17        (WebInspector.HeapSnapshotLoader.prototype.finishLoading):
     18        * inspector/front-end/HeapSnapshotProxy.js:
     19        (WebInspector.HeapSnapshotWorker.prototype.startCheckingForLongRunningCalls):
     20        (WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
     21        (WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):
     22        (WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):
     23        * inspector/front-end/HeapSnapshotView.js:
     24        (WebInspector.HeapSnapshotReceiver):
     25        (WebInspector.HeapSnapshotReceiver.prototype.startLoading):
     26        (WebInspector.HeapSnapshotReceiver.prototype.pushJSONChunk):
     27        (WebInspector.HeapSnapshotReceiver.prototype.finishLoading):
     28        (WebInspector.HeapSnapshotReceiver.prototype.dispose):
     29        (WebInspector.HeapProfileHeader):
     30        (WebInspector.HeapProfileHeader.prototype.load):
     31        (WebInspector.HeapProfileHeader.prototype._setupWorker):
     32        (WebInspector.HeapProfileHeader.prototype.dispose):
     33        (WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
     34        (WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
     35        (WebInspector.HeapProfileHeader.prototype._parsed):
     36        (WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
     37        (WebInspector.HeapProfileHeader.prototype.saveToFile):
     38        (WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
     39        (WebInspector.HeapProfileHeader.prototype.loadFromFile):
     40        (WebInspector.HeapProfileHeader.prototype._loadNextChunk):
     41        (WebInspector.HeapProfileHeader.prototype._nextChunkLoaded):
     42        (WebInspector.HeapProfileHeader.prototype._createFileReader):
     43        (WebInspector.HeapSnapshotSaveToFileReceiver):
     44        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.startLoading):
     45        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.pushJSONChunk):
     46        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.finishLoading):
     47        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.dispose):
     48        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype._startSavingSnapshot):
     49        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype._saveStatusUpdate):
     50        * inspector/front-end/ProfilesPanel.js:
     51        (WebInspector.ProfilesPanel.prototype._createFileSelectorElement.onChange):
     52        (WebInspector.ProfilesPanel.prototype._createFileSelectorElement):
     53        (WebInspector.ProfilesPanel.prototype._loadFromFile):
     54
    1552012-05-29  Eric Seidel  <eric@webkit.org>
    256
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js

    r118521 r118742  
    3131/**
    3232 * @constructor
     33 * @implements {WebInspector.HeapSnapshotReceiver}
    3334 */
    3435WebInspector.HeapSnapshotLoader = function()
    3536{
    36     this._json = "";
    37     this._state = "find-snapshot-info";
    38     this._snapshot = {};
     37    this._reset();
    3938}
    4039
    4140WebInspector.HeapSnapshotLoader.prototype = {
     41    /**
     42     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     43     * @return {boolean}
     44     */
     45    startLoading: function(callback)
     46    {
     47        return true;
     48    },
     49
     50    dispose: function()
     51    {
     52        this._reset();
     53    },
     54
     55    _reset: function()
     56    {
     57        this._json = "";
     58        this._state = "find-snapshot-info";
     59        this._snapshot = {};
     60    },
     61
    4262    _findBalancedCurlyBrackets: function()
    4363    {
     
    6181            return null;
    6282        this._parseStringsArray();
    63         this._json = "";
    6483        var result = new WebInspector.HeapSnapshot(this._snapshot);
    65         this._json = "";
    66         this._snapshot = {};
     84        this._reset();
    6785        return result;
    6886    },
     
    115133    },
    116134
     135    /**
     136     * @param {string} chunk
     137     */
    117138    pushJSONChunk: function(chunk)
    118139    {
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js

    r118348 r118742  
    246246    startCheckingForLongRunningCalls: function()
    247247    {
     248        if (this._interval)
     249            return;
    248250        this._checkLongRunningCalls();
    249251        this._interval = setInterval(this._checkLongRunningCalls.bind(this), 300);
     
    354356 * @constructor
    355357 * @extends {WebInspector.HeapSnapshotProxyObject}
     358 * @implements {WebInspector.HeapSnapshotReceiver}
    356359 */
    357360WebInspector.HeapSnapshotLoaderProxy = function(worker, objectId)
     
    362365
    363366WebInspector.HeapSnapshotLoaderProxy.prototype = {
     367    /**
     368     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     369     * @return {boolean}
     370     */
     371    startLoading: function(callback)
     372    {
     373        var loadingHasJustStarted = !this._onLoadCallbacks.length;
     374        this._onLoadCallbacks.push(callback);
     375        return loadingHasJustStarted;
     376    },
     377
     378    /**
     379     * @param {string} chunk
     380     */
     381    pushJSONChunk: function(chunk)
     382    {
     383        this.callMethod(null, "pushJSONChunk", chunk);
     384    },
     385
    364386    /**
    365387     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     
    381403        }
    382404        this.callFactoryMethod(updateStaticData.bind(this), "finishLoading", "WebInspector.HeapSnapshotProxy");
    383     },
    384 
    385     /**
    386      * @param {function(WebInspector.HeapSnapshotProxy)} callback
    387      * @return {boolean}
    388      */
    389     startLoading: function(callback)
    390     {
    391         var loadingHasJustStarted = !this._onLoadCallbacks.length;
    392         this._onLoadCallbacks.push(callback);
    393         return loadingHasJustStarted;
    394     },
    395 
    396     pushJSONChunk: function(chunk)
    397     {
    398         this.callMethod(null, "pushJSONChunk", chunk);
    399405    }
    400406};
  • trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js

    r118350 r118742  
    786786WebInspector.HeapSnapshotProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
    787787
     788
     789/**
     790 * @interface
     791 */
     792WebInspector.HeapSnapshotReceiver = function()
     793{
     794}
     795
     796WebInspector.HeapSnapshotReceiver.prototype = {
     797    /**
     798     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     799     * @return {boolean}
     800     */
     801    startLoading: function(callback)
     802    {
     803    },
     804
     805    /**
     806     * @param {string} chunk
     807     */
     808    pushJSONChunk: function(chunk)
     809    {
     810    },
     811
     812    /**
     813     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     814     */
     815    finishLoading: function(callback)
     816    {
     817    },
     818
     819    dispose: function()
     820    {
     821    }
     822};
     823
    788824/**
    789825 * @constructor
     
    799835    this.maxJSObjectId = maxJSObjectId;
    800836    /**
    801      * @type {WebInspector.HeapSnapshotLoaderProxy}
    802      */
    803     this._loaderProxy = null;
     837     * @type {WebInspector.HeapSnapshotReceiver}
     838     */
     839    this._receiver = null;
    804840    /**
    805841     * @type {WebInspector.HeapSnapshotProxy}
     
    842878        }
    843879
    844         if (!this._loaderProxy)
     880        if (!this._receiver)
    845881            this._setupWorker();
    846882
    847         if (this._loaderProxy.startLoading(callback)) {
     883        this._numberOfChunks = 0;
     884        if (this._receiver.startLoading(callback)) {
    848885            this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
    849886            this.sidebarElement.wait = true;
     
    859896        var worker = new WebInspector.HeapSnapshotWorker();
    860897        worker.addEventListener("wait", setProfileWait, this);
    861         this._loaderProxy = worker.createObject("WebInspector.HeapSnapshotLoader");
     898        this._receiver = worker.createObject("WebInspector.HeapSnapshotLoader");
    862899    },
    863900
    864901    dispose: function()
    865902    {
    866         if (this._loaderProxy)
    867             this._loaderProxy.dispose();
     903        if (this._receiver)
     904            this._receiver.dispose();
    868905        else if (this._snapshotProxy)
    869906            this._snapshotProxy.dispose();
     
    871908
    872909    /**
    873      * @param {WebInspector.Event} event
    874      */
    875     _saveStatusUpdate: function(event)
    876     {
    877         if (event.data !== this._fileName)
    878             return;
    879         if (++this._savedChunksCount === this._totalNumberOfChunks) {
     910     * @param {number} savedChunksCount
     911     */
     912    _saveStatusUpdate: function(savedChunksCount)
     913    {
     914        if (savedChunksCount === this._totalNumberOfChunks) {
    880915            this.sidebarElement.subtitle = Number.bytesToString(this._snapshotProxy.totalSize);
    881916            this.sidebarElement.wait = false;
    882917            this._savedChunksCount = 0;
    883             WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
    884918        } else
    885             this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", (this._savedChunksCount * 100 / this._totalNumberOfChunks).toFixed(2));
     919            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", (savedChunksCount * 100 / this._totalNumberOfChunks).toFixed(2));
    886920    },
    887921
     
    891925    pushJSONChunk: function(chunk)
    892926    {
    893         if (this._loaderProxy) {
    894             ++this._totalNumberOfChunks;
    895             this._loaderProxy.pushJSONChunk(chunk);
    896         } else {
    897             this.sidebarElement.wait = true;
    898             WebInspector.fileManager.append(this._fileName, chunk);
    899         }
     927        ++this._numberOfChunks;
     928        this._receiver.pushJSONChunk(chunk);
     929    },
     930
     931    _parsed: function(snapshotProxy)
     932    {
     933        this._receiver = null;
     934        if (snapshotProxy)
     935            this._snapshotProxy = snapshotProxy;
     936        this.sidebarElement.subtitle = Number.bytesToString(this._snapshotProxy.totalSize);
     937        this.sidebarElement.wait = false;
     938        var worker = /** @type {WebInspector.HeapSnapshotWorker} */ this._snapshotProxy.worker;
     939        this.isTemporary = false;
     940        worker.startCheckingForLongRunningCalls();
    900941    },
    901942
    902943    finishHeapSnapshot: function()
    903944    {
    904         function parsed(snapshotProxy)
    905         {
    906             this._loaderProxy = null;
    907             this._snapshotProxy = snapshotProxy;
    908             this.sidebarElement.subtitle = Number.bytesToString(snapshotProxy.totalSize);
    909             this.sidebarElement.wait = false;
    910             var worker = /** @type {WebInspector.HeapSnapshotWorker} */ snapshotProxy.worker;
    911             this.isTemporary = false;
    912             worker.startCheckingForLongRunningCalls();
    913         }
    914         if (this._loaderProxy.finishLoading(parsed.bind(this)))
     945        this._totalNumberOfChunks = this._numberOfChunks;
     946        if (this._receiver.finishLoading(this._parsed.bind(this)))
    915947            this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
    916948    },
     
    930962    saveToFile: function()
    931963    {
    932         /**
    933          * @param {WebInspector.Event} event
    934          */
    935         function startSavingSnapshot(event)
    936         {
    937             if (event.data !== this._fileName)
    938                 return;
    939             this.sidebarElement.wait = true;
    940             this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", 0);
    941             this._savedChunksCount = 0;
    942             WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, startSavingSnapshot, this);
    943             WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
    944             ProfilerAgent.getProfile(this.profileType().id, this.uid);
    945         }
    946 
    947964        this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";
    948         WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, startSavingSnapshot, this);
    949         WebInspector.fileManager.save(this._fileName, "", true);
     965        this._receiver = new WebInspector.HeapSnapshotSaveToFileReceiver(this._fileName, this);
     966        this._receiver.startLoading(function(snapshot) { });
    950967    },
    951968
     
    9841001        this.sidebarElement.wait = true;
    9851002        this._setupWorker();
    986         this._loaderProxy.startLoading(function(ignoredSnapshotProxy) { });
    987 
    988         function loadNextChunk(file, reader, loadedSize)
    989         {
    990             var chunkSize = 10000000;
    991             var size = file.size < loadedSize + chunkSize ? file.size - loadedSize : chunkSize;
    992             var nextPart = file.webkitSlice(loadedSize, loadedSize + size);
    993             reader.readAsText(nextPart);
    994         }
     1003        this._numberOfChunks = 0;
     1004        this._receiver.startLoading(function(ignoredSnapshotProxy) { });
    9951005
    9961006        /**
     
    10011011            if (event.target.readyState !== FileReader.DONE)
    10021012                return;
    1003 
    1004             this._loadedSize += event.target.result.length;
    1005             this._loaderProxy.pushJSONChunk(event.target.result);
    1006             this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / file.size).toFixed(2));
    1007 
    1008             if (this._loadedSize === file.size) {
    1009                 this.finishHeapSnapshot();
    1010                 return;
    1011             }
    1012 
    1013             loadNextChunk(file, reader, this._loadedSize);
    1014         }
    1015 
    1016         var reader = new FileReader();
    1017         reader.onload = onLoad.bind(this);
    1018         reader.onerror = onError;
     1013            this._nextChunkLoaded(event.target.result);
     1014        }
     1015
     1016        this._file = file;
     1017        this._expectedSize = file.size;
    10191018        this._loadedSize = 0;
    1020         loadNextChunk(file, reader, this._loadedSize);
     1019        this._reader = this._createFileReader();
     1020        this._reader.onload = onLoad.bind(this);
     1021        this._reader.onerror = onError;
     1022        this._loadNextChunk();
     1023    },
     1024
     1025    _loadNextChunk: function()
     1026    {
     1027        var loadedSize = this._loadedSize;
     1028        var chunkSize = 10000000;
     1029        var size = this._expectedSize < loadedSize + chunkSize ? this._expectedSize - loadedSize : chunkSize;
     1030        var nextPart = this._file.webkitSlice(loadedSize, loadedSize + size);
     1031        this._reader.readAsText(nextPart);
     1032    },
     1033
     1034    _nextChunkLoaded: function(data)
     1035    {
     1036        this._loadedSize += data.length;
     1037        this._receiver.pushJSONChunk(data);
     1038        this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / this._expectedSize).toFixed(2));
     1039
     1040        if (this._loadedSize === this._expectedSize) {
     1041            this._file = null;
     1042            this._reader = null;
     1043            this.finishHeapSnapshot();
     1044            return;
     1045        }
     1046        this._loadNextChunk();
     1047    },
     1048
     1049    _createFileReader: function()
     1050    {
     1051        return new FileReader();
    10211052    }
    10221053}
    10231054
    10241055WebInspector.HeapProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;
     1056
     1057
     1058/**
     1059 * @constructor
     1060 * @implements {WebInspector.HeapSnapshotReceiver}
     1061 */
     1062WebInspector.HeapSnapshotSaveToFileReceiver = function(fileName, snapshotHeader)
     1063{
     1064    this._fileName = fileName;
     1065    this._snapshotHeader = snapshotHeader;
     1066    this._savedChunks = 0;
     1067    this._finishLoadingCallbacks = [];
     1068}
     1069
     1070WebInspector.HeapSnapshotSaveToFileReceiver.prototype = {
     1071    /**
     1072     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     1073     * @return {boolean}
     1074     */
     1075    startLoading: function(callback)
     1076    {
     1077        WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
     1078        WebInspector.fileManager.save(this._fileName, "", true);
     1079        if (callback)
     1080            this._finishLoadingCallbacks.push(callback);
     1081        return true;
     1082    },
     1083
     1084    /**
     1085     * @param {string} chunk
     1086     */
     1087    pushJSONChunk: function(chunk)
     1088    {
     1089        WebInspector.fileManager.append(this._fileName, chunk);
     1090    },
     1091
     1092    /**
     1093     * @param {function(WebInspector.HeapSnapshotProxy)} callback
     1094     */
     1095    finishLoading: function(callback)
     1096    {
     1097        this._finishLoadingCallbacks.push(callback);
     1098        for (var i = 0; i < this._finishLoadingCallbacks.length; ++i)
     1099            this._finishLoadingCallbacks[i](null);
     1100    },
     1101
     1102    dispose: function()
     1103    {
     1104    },
     1105
     1106    /**
     1107     * @param {WebInspector.Event} event
     1108     */
     1109    _startSavingSnapshot: function(event)
     1110    {
     1111        if (event.data !== this._fileName)
     1112            return;
     1113        this._snapshotHeader._saveStatusUpdate(0);
     1114        WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
     1115        WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
     1116        ProfilerAgent.getProfile(this._snapshotHeader.profileType().id, this._snapshotHeader.uid);
     1117    },
     1118
     1119    /**
     1120     * @param {WebInspector.Event} event
     1121     */
     1122    _saveStatusUpdate: function(event)
     1123    {
     1124        if (event.data !== this._fileName)
     1125            return;
     1126        this._snapshotHeader._saveStatusUpdate(++this._savedChunks);
     1127        if (this._savedChunks === this._snapshotHeader._totalNumberOfChunks)
     1128            WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
     1129    }
     1130};
     1131
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js

    r118662 r118742  
    265265        fileSelectorElement.style.zIndex = -1;
    266266        fileSelectorElement.style.position = "absolute";
    267         fileSelectorElement.onchange = this._loadFromFile.bind(this);
     267        function onChange(event) {
     268            this._loadFromFile(this._fileSelectorElement.files[0]);
     269        }
     270        fileSelectorElement.onchange = onChange.bind(this);
    268271        this.element.appendChild(fileSelectorElement);
    269272        this._fileSelectorElement = fileSelectorElement;
    270273    },
    271274
    272     _loadFromFile: function(event)
    273     {
    274         var file = this._fileSelectorElement.files[0];
     275    _loadFromFile: function(file)
     276    {
    275277        if (!file.name.endsWith(".heapsnapshot")) {
    276278            WebInspector.log(WebInspector.UIString("Only heap snapshots from files with extension '.heapsnapshot' can be loaded."));
Note: See TracChangeset for help on using the changeset viewer.