OLD | NEW |
1 /** | 1 /** |
2 * @constructor | 2 * @unrestricted |
3 * @extends {WebInspector.SDKModel} | |
4 * @param {!WebInspector.Target} target | |
5 */ | 3 */ |
6 WebInspector.HeapProfilerModel = function(target) | 4 WebInspector.HeapProfilerModel = class extends WebInspector.SDKModel { |
7 { | 5 /** |
8 WebInspector.SDKModel.call(this, WebInspector.HeapProfilerModel, target); | 6 * @param {!WebInspector.Target} target |
| 7 */ |
| 8 constructor(target) { |
| 9 super(WebInspector.HeapProfilerModel, target); |
9 target.registerHeapProfilerDispatcher(new WebInspector.HeapProfilerDispatche
r(this)); | 10 target.registerHeapProfilerDispatcher(new WebInspector.HeapProfilerDispatche
r(this)); |
10 this._enabled = false; | 11 this._enabled = false; |
11 this._heapProfilerAgent = target.heapProfilerAgent(); | 12 this._heapProfilerAgent = target.heapProfilerAgent(); |
| 13 } |
| 14 enable() { |
| 15 if (this._enabled) |
| 16 return; |
| 17 |
| 18 this._enabled = true; |
| 19 this._heapProfilerAgent.enable(); |
| 20 } |
| 21 |
| 22 startSampling() { |
| 23 var defaultSamplingIntervalInBytes = 16384; |
| 24 this._heapProfilerAgent.startSampling(defaultSamplingIntervalInBytes); |
| 25 } |
| 26 |
| 27 /** |
| 28 * @return {!Promise.<?ProfilerAgent.Profile>} |
| 29 */ |
| 30 stopSampling() { |
| 31 this._isRecording = false; |
| 32 return this._heapProfilerAgent.stopSampling((error, profile) => error ? null
: profile); |
| 33 } |
| 34 |
| 35 /** |
| 36 * @param {!Array.<number>} samples |
| 37 */ |
| 38 heapStatsUpdate(samples) { |
| 39 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.HeapStat
sUpdate, samples); |
| 40 } |
| 41 |
| 42 /** |
| 43 * @param {number} lastSeenObjectId |
| 44 * @param {number} timestamp |
| 45 */ |
| 46 lastSeenObjectId(lastSeenObjectId, timestamp) { |
| 47 this.dispatchEventToListeners( |
| 48 WebInspector.HeapProfilerModel.Events.LastSeenObjectId, |
| 49 {lastSeenObjectId: lastSeenObjectId, timestamp: timestamp}); |
| 50 } |
| 51 |
| 52 /** |
| 53 * @param {string} chunk |
| 54 */ |
| 55 addHeapSnapshotChunk(chunk) { |
| 56 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.AddHeapS
napshotChunk, chunk); |
| 57 } |
| 58 |
| 59 /** |
| 60 * @param {number} done |
| 61 * @param {number} total |
| 62 * @param {boolean=} finished |
| 63 */ |
| 64 reportHeapSnapshotProgress(done, total, finished) { |
| 65 this.dispatchEventToListeners( |
| 66 WebInspector.HeapProfilerModel.Events.ReportHeapSnapshotProgress, |
| 67 {done: done, total: total, finished: finished}); |
| 68 } |
| 69 |
| 70 resetProfiles() { |
| 71 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.ResetPro
files); |
| 72 } |
12 }; | 73 }; |
13 | 74 |
14 /** @enum {symbol} */ | 75 /** @enum {symbol} */ |
15 WebInspector.HeapProfilerModel.Events = { | 76 WebInspector.HeapProfilerModel.Events = { |
16 HeapStatsUpdate: Symbol("HeapStatsUpdate"), | 77 HeapStatsUpdate: Symbol('HeapStatsUpdate'), |
17 LastSeenObjectId: Symbol("LastSeenObjectId"), | 78 LastSeenObjectId: Symbol('LastSeenObjectId'), |
18 AddHeapSnapshotChunk: Symbol("AddHeapSnapshotChunk"), | 79 AddHeapSnapshotChunk: Symbol('AddHeapSnapshotChunk'), |
19 ReportHeapSnapshotProgress: Symbol("ReportHeapSnapshotProgress"), | 80 ReportHeapSnapshotProgress: Symbol('ReportHeapSnapshotProgress'), |
20 ResetProfiles: Symbol("ResetProfiles") | 81 ResetProfiles: Symbol('ResetProfiles') |
21 }; | 82 }; |
22 | 83 |
23 WebInspector.HeapProfilerModel.prototype = { | 84 /** |
24 enable: function() | 85 * @implements {HeapProfilerAgent.Dispatcher} |
25 { | 86 * @unrestricted |
26 if (this._enabled) | 87 */ |
27 return; | 88 WebInspector.HeapProfilerDispatcher = class { |
| 89 constructor(model) { |
| 90 this._heapProfilerModel = model; |
| 91 } |
28 | 92 |
29 this._enabled = true; | 93 /** |
30 this._heapProfilerAgent.enable(); | 94 * @override |
31 }, | 95 * @param {!Array.<number>} samples |
| 96 */ |
| 97 heapStatsUpdate(samples) { |
| 98 this._heapProfilerModel.heapStatsUpdate(samples); |
| 99 } |
32 | 100 |
33 startSampling: function() | 101 /** |
34 { | 102 * @override |
35 var defaultSamplingIntervalInBytes = 16384; | 103 * @param {number} lastSeenObjectId |
36 this._heapProfilerAgent.startSampling(defaultSamplingIntervalInBytes); | 104 * @param {number} timestamp |
37 }, | 105 */ |
| 106 lastSeenObjectId(lastSeenObjectId, timestamp) { |
| 107 this._heapProfilerModel.lastSeenObjectId(lastSeenObjectId, timestamp); |
| 108 } |
38 | 109 |
39 /** | 110 /** |
40 * @return {!Promise.<?ProfilerAgent.Profile>} | 111 * @override |
41 */ | 112 * @param {string} chunk |
42 stopSampling: function() | 113 */ |
43 { | 114 addHeapSnapshotChunk(chunk) { |
44 this._isRecording = false; | 115 this._heapProfilerModel.addHeapSnapshotChunk(chunk); |
45 return this._heapProfilerAgent.stopSampling((error, profile) => error ?
null : profile); | 116 } |
46 }, | |
47 | 117 |
48 /** | 118 /** |
49 * @param {!Array.<number>} samples | 119 * @override |
50 */ | 120 * @param {number} done |
51 heapStatsUpdate: function(samples) | 121 * @param {number} total |
52 { | 122 * @param {boolean=} finished |
53 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.Heap
StatsUpdate, samples); | 123 */ |
54 }, | 124 reportHeapSnapshotProgress(done, total, finished) { |
| 125 this._heapProfilerModel.reportHeapSnapshotProgress(done, total, finished); |
| 126 } |
55 | 127 |
56 /** | 128 /** |
57 * @param {number} lastSeenObjectId | 129 * @override |
58 * @param {number} timestamp | 130 */ |
59 */ | 131 resetProfiles() { |
60 lastSeenObjectId: function(lastSeenObjectId, timestamp) | 132 this._heapProfilerModel.resetProfiles(); |
61 { | 133 } |
62 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.Last
SeenObjectId ,{lastSeenObjectId: lastSeenObjectId, timestamp: timestamp}); | |
63 }, | |
64 | |
65 /** | |
66 * @param {string} chunk | |
67 */ | |
68 addHeapSnapshotChunk: function(chunk) | |
69 { | |
70 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.AddH
eapSnapshotChunk, chunk); | |
71 }, | |
72 | |
73 /** | |
74 * @param {number} done | |
75 * @param {number} total | |
76 * @param {boolean=} finished | |
77 */ | |
78 reportHeapSnapshotProgress: function(done, total, finished) | |
79 { | |
80 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.Repo
rtHeapSnapshotProgress, {done: done, total: total, finished: finished}); | |
81 }, | |
82 | |
83 resetProfiles: function() | |
84 { | |
85 this.dispatchEventToListeners(WebInspector.HeapProfilerModel.Events.Rese
tProfiles); | |
86 }, | |
87 | |
88 __proto__: WebInspector.SDKModel.prototype | |
89 }; | 134 }; |
90 | |
91 | |
92 /** | |
93 * @constructor | |
94 * @implements {HeapProfilerAgent.Dispatcher} | |
95 */ | |
96 WebInspector.HeapProfilerDispatcher = function(model) | |
97 { | |
98 this._heapProfilerModel = model; | |
99 }; | |
100 | |
101 WebInspector.HeapProfilerDispatcher.prototype = { | |
102 /** | |
103 * @override | |
104 * @param {!Array.<number>} samples | |
105 */ | |
106 heapStatsUpdate: function(samples) | |
107 { | |
108 this._heapProfilerModel.heapStatsUpdate(samples); | |
109 }, | |
110 | |
111 /** | |
112 * @override | |
113 * @param {number} lastSeenObjectId | |
114 * @param {number} timestamp | |
115 */ | |
116 lastSeenObjectId: function(lastSeenObjectId, timestamp) | |
117 { | |
118 this._heapProfilerModel.lastSeenObjectId(lastSeenObjectId, timestamp); | |
119 }, | |
120 | |
121 /** | |
122 * @override | |
123 * @param {string} chunk | |
124 */ | |
125 addHeapSnapshotChunk: function(chunk) | |
126 { | |
127 this._heapProfilerModel.addHeapSnapshotChunk(chunk); | |
128 }, | |
129 | |
130 /** | |
131 * @override | |
132 * @param {number} done | |
133 * @param {number} total | |
134 * @param {boolean=} finished | |
135 */ | |
136 reportHeapSnapshotProgress: function(done, total, finished) | |
137 { | |
138 this._heapProfilerModel.reportHeapSnapshotProgress(done, total, finished
); | |
139 }, | |
140 | |
141 /** | |
142 * @override | |
143 */ | |
144 resetProfiles: function() | |
145 { | |
146 this._heapProfilerModel.resetProfiles(); | |
147 } | |
148 }; | |
OLD | NEW |