Home | History | Annotate | Download | only in sdk
      1 /**
      2  * @constructor
      3  * @extends {WebInspector.SDKModel}
      4  * @param {!WebInspector.Target} target
      5  */
      6 WebInspector.HeapProfilerModel = function(target)
      7 {
      8     WebInspector.SDKModel.call(this, WebInspector.HeapProfilerModel, target);
      9     target.registerHeapProfilerDispatcher(new WebInspector.HeapProfilerDispatcher(this));
     10     this._enabled = false;
     11     this._heapProfilerAgent = target.heapProfilerAgent();
     12 }
     13 
     14 WebInspector.HeapProfilerModel.Events = {
     15     HeapStatsUpdate: "HeapStatsUpdate",
     16     LastSeenObjectId: "LastSeenObjectId",
     17     AddHeapSnapshotChunk: "AddHeapSnapshotChunk",
     18     ReportHeapSnapshotProgress: "ReportHeapSnapshotProgress",
     19     ResetProfiles: "ResetProfiles"
     20 }
     21 
     22 WebInspector.HeapProfilerModel.prototype = {
     23 
     24     enable: function()
     25     {
     26         if (this._enabled)
     27             return;
     28 
     29         this._enabled = true;
     30         this._heapProfilerAgent.enable();
     31     },
     32 
     33     /**
     34      * @param {!Array.<number>} samples
     35      */
     36     heapStatsUpdate: function(samples)
     37     {
     38         this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.HeapStatsUpdate, samples);
     39     },
     40 
     41     /**
     42      * @param {number} lastSeenObjectId
     43      * @param {number} timestamp
     44      */
     45     lastSeenObjectId: function(lastSeenObjectId, timestamp)
     46     {
     47         this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.LastSeenObjectId ,{lastSeenObjectId: lastSeenObjectId, timestamp: timestamp});
     48     },
     49 
     50     /**
     51      * @param {string} chunk
     52      */
     53     addHeapSnapshotChunk: function(chunk)
     54     {
     55         this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.AddHeapSnapshotChunk, chunk);
     56     },
     57 
     58     /**
     59      * @param {number} done
     60      * @param {number} total
     61      * @param {boolean=} finished
     62      */
     63     reportHeapSnapshotProgress: function(done, total, finished)
     64     {
     65         this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.ReportHeapSnapshotProgress, {done: done, total: total, finished: finished});
     66     },
     67 
     68     resetProfiles: function()
     69     {
     70         this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.ResetProfiles);
     71     },
     72 
     73     __proto__: WebInspector.SDKModel.prototype
     74 }
     75 
     76 
     77 /**
     78  * @constructor
     79  * @implements {HeapProfilerAgent.Dispatcher}
     80  */
     81 WebInspector.HeapProfilerDispatcher = function(model)
     82 {
     83     this._heapProfilerModel = model;
     84 }
     85 
     86 WebInspector.HeapProfilerDispatcher.prototype = {
     87 
     88     /**
     89      * @param {!Array.<number>} samples
     90      */
     91     heapStatsUpdate: function(samples)
     92     {
     93         this._heapProfilerModel.heapStatsUpdate(samples);
     94     },
     95 
     96     /**
     97      * @param {number} lastSeenObjectId
     98      * @param {number} timestamp
     99      */
    100     lastSeenObjectId: function(lastSeenObjectId, timestamp)
    101     {
    102         this._heapProfilerModel.lastSeenObjectId(lastSeenObjectId, timestamp);
    103     },
    104 
    105     /**
    106      * @param {string} chunk
    107      */
    108     addHeapSnapshotChunk: function(chunk)
    109     {
    110         this._heapProfilerModel.addHeapSnapshotChunk(chunk);
    111     },
    112 
    113     /**
    114      * @param {number} done
    115      * @param {number} total
    116      * @param {boolean=} finished
    117      */
    118     reportHeapSnapshotProgress: function(done, total, finished)
    119     {
    120         this._heapProfilerModel.reportHeapSnapshotProgress(done, total, finished);
    121     },
    122 
    123     resetProfiles: function()
    124     {
    125         this._heapProfilerModel.resetProfiles();
    126     }
    127 }