Changeset 145357 in webkit


Ignore:
Timestamp:
Mar 11, 2013 5:43:10 AM (11 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: extract common parts of native profiles
https://bugs.webkit.org/show_bug.cgi?id=111965

Reviewed by Alexander Pavlov.

Extracted common parts of native profiles into NativeProfileTypeBase. Memory
domain dispatcher is now a separate class as it is shared by two native memory
profile types.

Both native memory profile types now capture native heap graph.

  • inspector/front-end/NativeMemorySnapshotView.js:

(WebInspector.MemoryAgentDispatcher.instance):
(WebInspector.NativeProfileTypeBase.prototype.buttonClicked.didReceiveMemorySnapshot):
(WebInspector.NativeProfileTypeBase.prototype.buttonClicked):
(WebInspector.NativeSnapshotProfileType):
(WebInspector.NativeSnapshotProfileHeader.prototype._didReceiveMemorySnapshot):
(WebInspector.NativeMemoryProfileType):
(WebInspector.NativeMemoryProfileHeader.prototype._updateSnapshotStatus):
(WebInspector.NativeMemoryProfileHeader.prototype._didReceiveMemorySnapshot):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145354 r145357  
     12013-03-11  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: extract common parts of native profiles
     4        https://bugs.webkit.org/show_bug.cgi?id=111965
     5
     6        Reviewed by Alexander Pavlov.
     7
     8        Extracted common parts of native profiles into NativeProfileTypeBase. Memory
     9        domain dispatcher is now a separate class as it is shared by two native memory
     10        profile types.
     11
     12        Both native memory profile types now capture native heap graph.
     13
     14        * inspector/front-end/NativeMemorySnapshotView.js:
     15        (WebInspector.MemoryAgentDispatcher.instance):
     16        (WebInspector.NativeProfileTypeBase.prototype.buttonClicked.didReceiveMemorySnapshot):
     17        (WebInspector.NativeProfileTypeBase.prototype.buttonClicked):
     18        (WebInspector.NativeSnapshotProfileType):
     19        (WebInspector.NativeSnapshotProfileHeader.prototype._didReceiveMemorySnapshot):
     20        (WebInspector.NativeMemoryProfileType):
     21        (WebInspector.NativeMemoryProfileHeader.prototype._updateSnapshotStatus):
     22        (WebInspector.NativeMemoryProfileHeader.prototype._didReceiveMemorySnapshot):
     23
    1242013-03-11  Sheriff Bot  <webkit.review.bot@gmail.com>
    225
  • trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js

    r145074 r145357  
    233233}
    234234
     235
     236/**
     237 * @constructor
     238 * @implements {MemoryAgent.Dispatcher}
     239 */
     240WebInspector.MemoryAgentDispatcher = function()
     241{
     242    InspectorBackend.registerMemoryDispatcher(this);
     243    this._currentProfileHeader = null;
     244}
     245
     246WebInspector.MemoryAgentDispatcher.instance = function()
     247{
     248    if (!WebInspector.MemoryAgentDispatcher._instance)
     249        WebInspector.MemoryAgentDispatcher._instance = new WebInspector.MemoryAgentDispatcher();
     250    return WebInspector.MemoryAgentDispatcher._instance;
     251}
     252
     253WebInspector.MemoryAgentDispatcher.prototype = {
     254    /**
     255     * @override
     256     * @param {MemoryAgent.HeapSnapshotChunk} chunk
     257     */
     258    addNativeSnapshotChunk: function(chunk)
     259    {
     260        if (this._currentProfileHeader)
     261            this._currentProfileHeader.addNativeSnapshotChunk(chunk);
     262    },
     263
     264    _onRemoveProfileHeader: function(event)
     265    {
     266        if (event.data === this._currentProfileHeader)
     267            this._currentProfileHeader = null;
     268    }
     269};
     270
     271
    235272/**
    236273 * @constructor
    237274 * @extends {WebInspector.ProfileType}
    238  * @implements {MemoryAgent.Dispatcher}
    239  */
    240 WebInspector.NativeSnapshotProfileType = function()
    241 {
    242     WebInspector.ProfileType.call(this, WebInspector.NativeSnapshotProfileType.TypeId, WebInspector.UIString("Take Native Heap Snapshot"));
    243     InspectorBackend.registerMemoryDispatcher(this);
     275 * @param {string} id
     276 * @param {string} name
     277 */
     278WebInspector.NativeProfileTypeBase = function(profileHeaderConstructor, id, name)
     279{
     280    WebInspector.ProfileType.call(this, id, name);
     281    this._profileHeaderConstructor = profileHeaderConstructor;
    244282    this._nextProfileUid = 1;
    245 }
    246 
    247 WebInspector.NativeSnapshotProfileType.TypeId = "NATIVE_SNAPSHOT";
    248 
    249 WebInspector.NativeSnapshotProfileType.prototype = {
    250     get buttonTooltip()
    251     {
    252         return WebInspector.UIString("Capture native heap graph.");
    253     },
    254 
     283    this.addEventListener(WebInspector.ProfileType.Events.RemoveProfileHeader,
     284                          WebInspector.MemoryAgentDispatcher.prototype._onRemoveProfileHeader,
     285                          WebInspector.MemoryAgentDispatcher.instance());
     286}
     287
     288WebInspector.NativeProfileTypeBase.prototype = {
    255289    /**
    256290     * @override
     
    268302    buttonClicked: function()
    269303    {
    270         var profileHeader = new WebInspector.NativeSnapshotProfileHeader(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid);
     304        if (WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader)
     305            return false;
     306
     307        var profileHeader = new this._profileHeaderConstructor(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid);
    271308        ++this._nextProfileUid;
    272309        profileHeader.isTemporary = true;
    273310        this.addProfile(profileHeader);
     311        WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = profileHeader;
    274312        profileHeader.load(function() { });
     313
    275314
    276315        /**
     
    281320        function didReceiveMemorySnapshot(error, memoryBlock, graphMetaInformation)
    282321        {
    283             var metaInformation = /** @type{HeapSnapshotMetainfo} */(graphMetaInformation);
    284             this.isTemporary = false;
    285             this.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */(memoryBlock.size));
    286 
    287             var edgeFieldCount = metaInformation.edge_fields.length;
    288             var nodeFieldCount = metaInformation.node_fields.length;
    289             var nodeIdFieldOffset = metaInformation.node_fields.indexOf("id");
    290             var toNodeIdFieldOffset = metaInformation.edge_fields.indexOf("to_node");
    291 
    292             var baseToRealNodeIdMap = {};
    293             for (var i = 0; i < this._baseToRealNodeId.length; i += 2)
    294                 baseToRealNodeIdMap[this._baseToRealNodeId[i]] = this._baseToRealNodeId[i + 1];
    295 
    296             var nodeId2NodeIndex = {};
    297             for (var i = nodeIdFieldOffset; i < this._nodes.length; i += nodeFieldCount)
    298                 nodeId2NodeIndex[this._nodes[i]] = i - nodeIdFieldOffset;
    299 
    300             // Translate nodeId to nodeIndex.
    301             var edges = this._edges;
    302             for (var i = toNodeIdFieldOffset; i < edges.length; i += edgeFieldCount) {
    303                 if (edges[i] in baseToRealNodeIdMap)
    304                     edges[i] = baseToRealNodeIdMap[edges[i]];
    305                 edges[i] = nodeId2NodeIndex[edges[i]];
    306             }
    307 
    308             var heapSnapshot = {
    309                 "snapshot": {
    310                     "meta": metaInformation,
    311                     node_count: this._nodes.length / nodeFieldCount,
    312                     edge_count: this._edges.length / edgeFieldCount,
    313                     root_index: this._nodes.length - nodeFieldCount
    314                 },
    315                 nodes: this._nodes,
    316                 edges: this._edges,
    317                 strings: this._strings
    318             };
    319 
    320             var chunk = JSON.stringify(heapSnapshot);
    321             this.transferChunk(chunk);
    322             this.finishHeapSnapshot();
     322            console.assert(this === WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader);
     323            WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = null;
     324            this._didReceiveMemorySnapshot(error, memoryBlock, graphMetaInformation);
    323325        }
    324 
    325326        MemoryAgent.getProcessMemoryDistribution(true, didReceiveMemorySnapshot.bind(profileHeader));
    326327        return false;
    327328    },
    328329
    329     get treeItemTitle()
    330     {
    331         return WebInspector.UIString("NATIVE SNAPSHOT");
    332     },
    333 
    334     get description()
    335     {
    336         return WebInspector.UIString("Native memory snapshot profiles show native heap graph.");
     330    /**
     331     * @override
     332     * @param {!WebInspector.ProfileHeader} profile
     333     */
     334    removeProfile: function(profile)
     335    {
     336        if (WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader === profile)
     337            WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = null;
     338        WebInspector.ProfileType.prototype.removeProfile.call(this, profile);
    337339    },
    338340
     
    345347    {
    346348        title = title || WebInspector.UIString("Snapshotting\u2026");
    347         return new WebInspector.NativeSnapshotProfileHeader(this, title);
     349        return new this._profileHeaderConstructor(this, title);
    348350    },
    349351
     
    355357    createProfile: function(profile)
    356358    {
    357         return new WebInspector.NativeSnapshotProfileHeader(this, profile.title, -1);
    358     },
    359 
    360     /**
    361      * @override
    362      * @param {MemoryAgent.HeapSnapshotChunk} chunk
    363      */
    364     addNativeSnapshotChunk: function(chunk)
    365     {
    366         var tempProfile = this.findTemporaryProfile();
    367         if (tempProfile)
    368             tempProfile.addNativeSnapshotChunk(chunk);
     359        return new this._profileHeaderConstructor(this, profile.title, -1);
    369360    },
    370361
     
    372363}
    373364
     365/**
     366 * @constructor
     367 * @extends {WebInspector.NativeProfileTypeBase}
     368 */
     369WebInspector.NativeSnapshotProfileType = function()
     370{
     371    WebInspector.NativeProfileTypeBase.call(this, WebInspector.NativeSnapshotProfileHeader,  WebInspector.NativeSnapshotProfileType.TypeId, WebInspector.UIString("Take Native Heap Snapshot"));
     372}
     373
     374WebInspector.NativeSnapshotProfileType.TypeId = "NATIVE_SNAPSHOT";
     375
     376WebInspector.NativeSnapshotProfileType.prototype = {
     377    get buttonTooltip()
     378    {
     379        return WebInspector.UIString("Capture native heap graph.");
     380    },
     381
     382    get treeItemTitle()
     383    {
     384        return WebInspector.UIString("NATIVE SNAPSHOT");
     385    },
     386
     387    get description()
     388    {
     389        return WebInspector.UIString("Native memory snapshot profiles show native heap graph.");
     390    },
     391
     392    __proto__: WebInspector.NativeProfileTypeBase.prototype
     393}
     394
    374395
    375396/**
    376397 * @constructor
    377398 * @extends {WebInspector.HeapProfileHeader}
    378  * @param {!WebInspector.NativeSnapshotProfileType} type
     399 * @param {!WebInspector.ProfileType} type
    379400 * @param {string} title
    380401 * @param {number=} uid
     
    416437    },
    417438
     439    /**
     440     * @param {?string} error
     441     * @param {?MemoryAgent.MemoryBlock} memoryBlock
     442     * @param {Object=} graphMetaInformation
     443     */
     444    _didReceiveMemorySnapshot: function(error, memoryBlock, graphMetaInformation)
     445    {
     446        var metaInformation = /** @type{HeapSnapshotMetainfo} */ (graphMetaInformation);
     447        this.isTemporary = false;
     448
     449        var edgeFieldCount = metaInformation.edge_fields.length;
     450        var nodeFieldCount = metaInformation.node_fields.length;
     451        var nodeIdFieldOffset = metaInformation.node_fields.indexOf("id");
     452        var toNodeIdFieldOffset = metaInformation.edge_fields.indexOf("to_node");
     453
     454        var baseToRealNodeIdMap = {};
     455        for (var i = 0; i < this._baseToRealNodeId.length; i += 2)
     456            baseToRealNodeIdMap[this._baseToRealNodeId[i]] = this._baseToRealNodeId[i + 1];
     457
     458        var nodeId2NodeIndex = {};
     459        for (var i = nodeIdFieldOffset; i < this._nodes.length; i += nodeFieldCount)
     460            nodeId2NodeIndex[this._nodes[i]] = i - nodeIdFieldOffset;
     461
     462        // Translate nodeId to nodeIndex.
     463        var edges = this._edges;
     464        for (var i = toNodeIdFieldOffset; i < edges.length; i += edgeFieldCount) {
     465            if (edges[i] in baseToRealNodeIdMap)
     466                edges[i] = baseToRealNodeIdMap[edges[i]];
     467            edges[i] = nodeId2NodeIndex[edges[i]];
     468        }
     469
     470        var heapSnapshot = {
     471            "snapshot": {
     472                "meta": metaInformation,
     473                node_count: this._nodes.length / nodeFieldCount,
     474                edge_count: this._edges.length / edgeFieldCount,
     475                root_index: this._nodes.length - nodeFieldCount
     476            },
     477            nodes: this._nodes,
     478            edges: this._edges,
     479            strings: this._strings
     480        };
     481
     482        var chunk = JSON.stringify(heapSnapshot);
     483        this.transferChunk(chunk);
     484        this.finishHeapSnapshot();
     485    },
     486
    418487    __proto__: WebInspector.HeapProfileHeader.prototype
    419488}
     
    445514/**
    446515 * @constructor
    447  * @extends {WebInspector.ProfileType}
     516 * @extends {WebInspector.NativeProfileTypeBase}
    448517 */
    449518WebInspector.NativeMemoryProfileType = function()
    450519{
    451     WebInspector.ProfileType.call(this, WebInspector.NativeMemoryProfileType.TypeId, WebInspector.UIString("Capture Native Memory Distribution"));
    452     this._nextProfileUid = 1;
     520    WebInspector.NativeProfileTypeBase.call(this, WebInspector.NativeMemoryProfileHeader, WebInspector.NativeMemoryProfileType.TypeId, WebInspector.UIString("Capture Native Memory Distribution"));
    453521}
    454522
     
    461529    },
    462530
    463     /**
    464      * @override
    465      * @return {boolean}
    466      */
    467     isInstantProfile: function()
    468     {
    469         return true;
    470     },
    471 
    472     /**
    473      * @override
    474      * @return {boolean}
    475      */
    476     buttonClicked: function()
    477     {
    478         var profileHeader = new WebInspector.NativeMemoryProfileHeader(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid);
    479         ++this._nextProfileUid;
    480         profileHeader.isTemporary = true;
    481         this.addProfile(profileHeader);
    482         /**
    483          * @param {?string} error
    484          * @param {?MemoryAgent.MemoryBlock} memoryBlock
    485          */
    486         function didReceiveMemorySnapshot(error, memoryBlock)
    487         {
    488             if (memoryBlock.size && memoryBlock.children) {
    489                 var knownSize = 0;
    490                 for (var i = 0; i < memoryBlock.children.length; i++) {
    491                     var size = memoryBlock.children[i].size;
    492                     if (size)
    493                         knownSize += size;
    494                 }
    495                 var otherSize = memoryBlock.size - knownSize;
    496 
    497                 if (otherSize) {
    498                     memoryBlock.children.push({
    499                         name: "Other",
    500                         size: otherSize
    501                     });
    502                 }
    503             }
    504             profileHeader._memoryBlock = memoryBlock;
    505             profileHeader.isTemporary = false;
    506             profileHeader.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */(memoryBlock.size));
    507         }
    508         MemoryAgent.getProcessMemoryDistribution(false, didReceiveMemorySnapshot.bind(this));
    509         return false;
    510     },
    511 
    512531    get treeItemTitle()
    513532    {
     
    520539    },
    521540
    522     /**
    523      * @override
    524      * @param {string=} title
    525      * @return {WebInspector.ProfileHeader}
    526      */
    527     createTemporaryProfile: function(title)
    528     {
    529         title = title || WebInspector.UIString("Snapshotting\u2026");
    530         return new WebInspector.NativeMemoryProfileHeader(this, title);
    531     },
    532 
    533     /**
    534      * @override
    535      * @param {ProfilerAgent.ProfileHeader} profile
    536      * @return {WebInspector.ProfileHeader}
    537      */
    538     createProfile: function(profile)
    539     {
    540         return new WebInspector.NativeMemoryProfileHeader(this, profile.title, -1);
    541     },
    542 
    543     __proto__: WebInspector.ProfileType.prototype
    544 }
    545 
    546 /**
    547  * @constructor
    548  * @extends {WebInspector.ProfileHeader}
    549  * @param {!WebInspector.NativeMemoryProfileType} type
     541    __proto__: WebInspector.NativeProfileTypeBase.prototype
     542}
     543
     544/**
     545 * @constructor
     546 * @extends {WebInspector.NativeSnapshotProfileHeader}
     547 * @param {!WebInspector.ProfileType} type
    550548 * @param {string} title
    551549 * @param {number=} uid
     
    553551WebInspector.NativeMemoryProfileHeader = function(type, title, uid)
    554552{
    555     WebInspector.ProfileHeader.call(this, type, title, uid);
     553    WebInspector.NativeSnapshotProfileHeader.call(this, type, title, uid);
    556554
    557555    /**
     
    579577    },
    580578
    581     __proto__: WebInspector.ProfileHeader.prototype
     579    /**
     580     * @override
     581     */
     582    _updateSnapshotStatus: function()
     583    {
     584        WebInspector.NativeSnapshotProfileHeader.prototype._updateSnapshotStatus.call(this);
     585        this.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */ (this._memoryBlock.size));
     586    },
     587
     588    /**
     589     * @override
     590     * @param {?string} error
     591     * @param {?MemoryAgent.MemoryBlock} memoryBlock
     592     * @param {Object=} graphMetaInformation
     593     */
     594    _didReceiveMemorySnapshot: function(error, memoryBlock, graphMetaInformation)
     595    {
     596        WebInspector.NativeSnapshotProfileHeader.prototype._didReceiveMemorySnapshot.call(this, error, memoryBlock, graphMetaInformation);
     597        if (memoryBlock.size && memoryBlock.children) {
     598            var knownSize = 0;
     599            for (var i = 0; i < memoryBlock.children.length; i++) {
     600                var size = memoryBlock.children[i].size;
     601                if (size)
     602                    knownSize += size;
     603            }
     604            var otherSize = memoryBlock.size - knownSize;
     605
     606            if (otherSize) {
     607                memoryBlock.children.push({
     608                    name: "Other",
     609                    size: otherSize
     610                });
     611            }
     612        }
     613        this._memoryBlock = memoryBlock;
     614    },
     615
     616    __proto__: WebInspector.NativeSnapshotProfileHeader.prototype
    582617}
    583618
Note: See TracChangeset for help on using the changeset viewer.