Changeset 120621 in webkit


Ignore:
Timestamp:
Jun 18, 2012 1:17:32 PM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: Implement native memory bar diagram
https://bugs.webkit.org/show_bug.cgi?id=89106

Patch by Alexei Filippov <alexeif@chromium.org> on 2012-06-18
Reviewed by Pavel Feldman.

  • inspector/front-end/NativeMemorySnapshotView.js:

(WebInspector.NativeMemoryBarChart):
(WebInspector.NativeMemoryBarChart.prototype._updateStats):
(WebInspector.NativeMemoryBarChart.prototype.willHide):
(WebInspector.NativeMemoryBarChart.prototype.wasShown):
(WebInspector.NativeMemoryBarChart.prototype._updateView):

  • inspector/front-end/ProfileLauncherView.js:

(WebInspector.ProfileLauncherView):

  • inspector/front-end/nativeMemoryProfiler.css:

(.memory-bar-chart-name):
(.memory-bar-chart-bar):
(.memory-bar-chart-size):
(.memory-bar-chart-total):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r120617 r120621  
     12012-06-18  Alexei Filippov  <alexeif@chromium.org>
     2
     3        Web Inspector: Implement native memory bar diagram
     4        https://bugs.webkit.org/show_bug.cgi?id=89106
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/front-end/NativeMemorySnapshotView.js:
     9        (WebInspector.NativeMemoryBarChart):
     10        (WebInspector.NativeMemoryBarChart.prototype._updateStats):
     11        (WebInspector.NativeMemoryBarChart.prototype.willHide):
     12        (WebInspector.NativeMemoryBarChart.prototype.wasShown):
     13        (WebInspector.NativeMemoryBarChart.prototype._updateView):
     14        * inspector/front-end/ProfileLauncherView.js:
     15        (WebInspector.ProfileLauncherView):
     16        * inspector/front-end/nativeMemoryProfiler.css:
     17        (.memory-bar-chart-name):
     18        (.memory-bar-chart-bar):
     19        (.memory-bar-chart-size):
     20        (.memory-bar-chart-total):
     21
    1222012-06-18  Mike West  <mkwst@chromium.org>
    223
  • trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js

    r120589 r120621  
    366366
    367367WebInspector.NativeMemoryPieChart.prototype.__proto__ = WebInspector.View.prototype;
     368
     369/**
     370 * @constructor
     371 * @extends {WebInspector.View}
     372 */
     373WebInspector.NativeMemoryBarChart = function()
     374{
     375    WebInspector.View.call(this);
     376    this.registerRequiredCSS("nativeMemoryProfiler.css");
     377    this._memorySnapshot = null;
     378    this.element = document.createElement("div");
     379    this._table = this.element.createChild("table");
     380    this._bars = {};
     381    this._sizes = {};
     382    var row = this._table.insertRow();
     383    this._totalDiv = row.insertCell().createChild("div");
     384    this._totalDiv.addStyleClass("memory-bar-chart-total");
     385    row.insertCell();
     386}
     387
     388WebInspector.NativeMemoryBarChart.prototype = {
     389    _updateStats: function()
     390    {
     391        function didReceiveMemorySnapshot(error, memoryBlock)
     392        {
     393            if (memoryBlock.size && memoryBlock.children) {
     394                var knownSize = 0;
     395                for (var i = 0; i < memoryBlock.children.length; i++) {
     396                    var size = memoryBlock.children[i].size;
     397                    if (size)
     398                        knownSize += size;
     399                }
     400                var otherSize = memoryBlock.size - knownSize;
     401
     402                if (otherSize) {
     403                    memoryBlock.children.push({
     404                        name: "Other",
     405                        size: otherSize
     406                    });
     407                }
     408            }
     409            this._memorySnapshot = memoryBlock;
     410            this._updateView();
     411        }
     412        MemoryAgent.getProcessMemoryDistribution(didReceiveMemorySnapshot.bind(this));
     413    },
     414
     415    /**
     416     * @override
     417     */
     418    willHide: function()
     419    {
     420        clearInterval(this._timerId);
     421    },
     422
     423    /**
     424     * @override
     425     */
     426    wasShown: function()
     427    {
     428        this._timerId = setInterval(this._updateStats.bind(this), 200);
     429    },
     430
     431    _updateView: function()
     432    {
     433        var memoryBlock = this._memorySnapshot;
     434        if (!memoryBlock)
     435            return;
     436
     437        var MB = 1024 * 1024;
     438        var maxSize = 100 * MB;
     439        for (var i = 0; i < memoryBlock.children.length; ++i)
     440            maxSize = Math.max(maxSize, memoryBlock.children[i].size);
     441        var maxBarLength = 500;
     442        var barLengthSizeRatio = maxBarLength / maxSize;
     443
     444        for (var i = memoryBlock.children.length - 1; i >= 0 ; --i) {
     445            var child = memoryBlock.children[i];
     446            var name = child.name;
     447            var barDiv = this._bars[name];
     448            if (!barDiv) {
     449                var row = this._table.insertRow();
     450                var nameDiv = row.insertCell(-1).createChild("div");
     451                var viewProperties = WebInspector.MemoryBlockViewProperties._forMemoryBlock(child);
     452                var title = viewProperties._description;
     453                nameDiv.textContent = title;
     454                nameDiv.addStyleClass("memory-bar-chart-name");
     455                var barCell = row.insertCell(-1);
     456                barDiv = barCell.createChild("div");
     457                barDiv.addStyleClass("memory-bar-chart-bar");
     458                var viewProperties = WebInspector.MemoryBlockViewProperties._forMemoryBlock(child);
     459                barDiv.style.backgroundColor = viewProperties._fillStyle;
     460                this._bars[name] = barDiv;
     461                var sizeDiv = barCell.createChild("div");
     462                sizeDiv.addStyleClass("memory-bar-chart-size");
     463                this._sizes[name] = sizeDiv;
     464            }
     465            barDiv.style.width = child.size * barLengthSizeRatio + "px";
     466            barDiv.textContent = (child.size / memoryBlock.size * 100).toFixed(0) + "%";
     467            var sizeDiv = this._sizes[name];
     468            sizeDiv.textContent = (child.size / MB).toFixed(1) + "\u2009MB";
     469        }
     470
     471        var viewProperties = WebInspector.MemoryBlockViewProperties._forMemoryBlock(memoryBlock);
     472        this._totalDiv.textContent = viewProperties._description + ": " + (memoryBlock.size / MB).toFixed(1) + "\u2009MB";
     473    }
     474}
     475
     476WebInspector.NativeMemoryBarChart.prototype.__proto__ = WebInspector.View.prototype;
  • trunk/Source/WebCore/inspector/front-end/ProfileLauncherView.js

    r118503 r120621  
    5151
    5252    this._profileTypeSelectorForm = this._contentElement.createChild("form");
     53
     54    this._nativeMemoryElement = document.createElement("div");
     55    this._contentElement.appendChild(this._nativeMemoryElement);
     56    this._nativeMemoryLiveChart = new WebInspector.NativeMemoryBarChart();
     57    this._nativeMemoryLiveChart.show(this._nativeMemoryElement);
     58
    5359    this._contentElement.createChild("div", "flexible-space");
    5460
  • trunk/Source/WebCore/inspector/front-end/nativeMemoryProfiler.css

    r119197 r120621  
    5050    margin: 10px;
    5151}
     52
     53.memory-bar-chart-name {
     54    text-align: right;
     55    white-space: nowrap;
     56}
     57
     58.memory-bar-chart-bar {
     59    border: 1px solid #bbb;
     60    border-radius: 3px;
     61    float: left;
     62    height: 20px;
     63    text-align: center;
     64    overflow: hidden;
     65}
     66
     67.memory-bar-chart-size {
     68    text-indent: 6px;
     69    white-space: nowrap;
     70}
     71
     72.memory-bar-chart-total {
     73    font-weight: bold;
     74}
Note: See TracChangeset for help on using the changeset viewer.