Skip to content

Commit

Permalink
[DevTools] Do not access heapProfilerAgent directly.
Browse files Browse the repository at this point in the history
This patch wraps all calls to heapProfilerAgent with HeapProfilerModel methods.

Next patch will create HeapProfilerModel conditionally, ensuring proper JS capability check,
and adapt all callers to account for that.

BUG=none

Review-Url: https://codereview.chromium.org/2710963003
Cr-Commit-Position: refs/heads/master@{#452604}
  • Loading branch information
dgozman authored and Commit bot committed Feb 23, 2017
1 parent 6bf08d2 commit 50551ed
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 34 deletions.
3 changes: 2 additions & 1 deletion front_end/main/GCActionDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Main.GCActionDelegate = class {
* @return {boolean}
*/
handleAction(context, actionId) {
SDK.targetManager.targets().forEach(target => target.heapProfilerAgent().collectGarbage());
for (var heapProfilerModel of SDK.targetManager.models(SDK.HeapProfilerModel))
heapProfilerModel.collectGarbage();
return true;
}
};
20 changes: 9 additions & 11 deletions front_end/profiler/HeapProfilerPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@ Profiler.HeapProfilerPanel = class extends Profiler.ProfilesPanel {
if (!heapProfiles.length)
return;

/**
* @this {Profiler.ProfilesPanel}
*/
function revealInView(viewName) {
object.target().heapProfilerAgent().getHeapObjectId(objectId, didReceiveHeapObjectId.bind(this, viewName));
}
var heapProfilerModel = object.target().heapProfilerModel;
if (!heapProfilerModel)
return;

/**
* @param {string} viewName
* @this {Profiler.ProfilesPanel}
*/
function didReceiveHeapObjectId(viewName, error, result) {
if (!this.isShowing())
return;
if (!error)
this.showObject(result, viewName);
function revealInView(viewName) {
heapProfilerModel.snapshotObjectIdForObjectId(objectId, result => {
if (this.isShowing() && result)
this.showObject(result, viewName);
});
}

contextMenu.appendItem(Common.UIString.capitalize('Reveal in Summary ^view'), revealInView.bind(this, 'Summary'));
Expand Down
19 changes: 10 additions & 9 deletions front_end/profiler/HeapSnapshotGridNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,21 @@ Profiler.HeapSnapshotGenericObjectNode = class extends Profiler.HeapSnapshotGrid
*/
queryObjectContent(target, callback, objectGroupName) {
/**
* @param {?Protocol.Error} error
* @param {!Protocol.Runtime.RemoteObject} object
* @param {?SDK.RemoteObject} object
*/
function formatResult(error, object) {
if (!error && object.type)
callback(target.runtimeModel.createRemoteObject(object));
else
callback(target.runtimeModel.createRemoteObjectFromPrimitiveValue(Common.UIString('Preview is not available')));
function onResult(object) {
callback(
object ||
target.runtimeModel.createRemoteObjectFromPrimitiveValue(Common.UIString('Preview is not available')));
}

var heapProfilerModel = target.heapProfilerModel;
if (this._type === 'string')
callback(target.runtimeModel.createRemoteObjectFromPrimitiveValue(this._name));
onResult(target.runtimeModel.createRemoteObjectFromPrimitiveValue(this._name));
else if (!heapProfilerModel)
onResult(null);
else
target.heapProfilerAgent().getObjectByHeapObjectId(String(this.snapshotNodeId), objectGroupName, formatResult);
heapProfilerModel.objectForSnapshotObjectId(String(this.snapshotNodeId), objectGroupName).then(onResult);
}

updateHasChildren() {
Expand Down
21 changes: 8 additions & 13 deletions front_end/profiler/HeapSnapshotView.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Profiler.HeapSnapshotView = class extends UI.SimpleView {
var selectedNode = /** @type {!DataGrid.DataGridNode} */ (event.data);
var target = this._profile.target();
if (target && selectedNode instanceof Profiler.HeapSnapshotGenericObjectNode)
target.heapProfilerAgent().addInspectedHeapObject(String(selectedNode.snapshotNodeId));
target.heapProfilerModel.addInspectedHeapObject(String(selectedNode.snapshotNodeId));
}

/**
Expand Down Expand Up @@ -1045,19 +1045,14 @@ Profiler.HeapSnapshotProfileType = class extends Profiler.ProfileType {
this.addProfile(profile);
profile.updateStatus(Common.UIString('Snapshotting\u2026'));

/**
* @param {?string} error
* @this {Profiler.HeapSnapshotProfileType}
*/
function didTakeHeapSnapshot(error) {
target.heapProfilerModel.takeHeapSnapshot(true).then(success => {
var profile = this.profileBeingRecorded();
profile.title = Common.UIString('Snapshot %d', profile.uid);
profile._finishLoad();
this.setProfileBeingRecorded(null);
this.dispatchEventToListeners(Profiler.ProfileType.Events.ProfileComplete, profile);
callback();
}
target.heapProfilerAgent().takeHeapSnapshot(true, didTakeHeapSnapshot.bind(this));
});
}

/**
Expand Down Expand Up @@ -1201,7 +1196,7 @@ Profiler.TrackingHeapSnapshotProfileType = class extends Profiler.HeapSnapshotPr
return;
this._addNewProfile();
var recordAllocationStacks = Common.moduleSetting('recordAllocationStacks').get();
this.profileBeingRecorded().target().heapProfilerAgent().startTrackingHeapObjects(recordAllocationStacks);
this.profileBeingRecorded().target().heapProfilerModel.startTrackingHeapObjects(recordAllocationStacks);
}

_addNewProfile() {
Expand All @@ -1218,10 +1213,10 @@ Profiler.TrackingHeapSnapshotProfileType = class extends Profiler.HeapSnapshotPr
_stopRecordingProfile() {
this.profileBeingRecorded().updateStatus(Common.UIString('Snapshotting\u2026'));
/**
* @param {?string} error
* @param {boolean} success
* @this {Profiler.HeapSnapshotProfileType}
*/
function didTakeHeapSnapshot(error) {
function didTakeHeapSnapshot(success) {
var profile = this.profileBeingRecorded();
if (!profile)
return;
Expand All @@ -1231,8 +1226,8 @@ Profiler.TrackingHeapSnapshotProfileType = class extends Profiler.HeapSnapshotPr
this.dispatchEventToListeners(Profiler.ProfileType.Events.ProfileComplete, profile);
}

this.profileBeingRecorded().target().heapProfilerAgent().stopTrackingHeapObjects(
true, didTakeHeapSnapshot.bind(this));
this.profileBeingRecorded().target().heapProfilerModel.stopTrackingHeapObjects(true).then(
didTakeHeapSnapshot.bind(this));
this._recording = false;
this.dispatchEventToListeners(Profiler.TrackingHeapSnapshotProfileType.TrackingStopped);
}
Expand Down
60 changes: 60 additions & 0 deletions front_end/sdk/HeapProfilerModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,66 @@ SDK.HeapProfilerModel = class extends SDK.SDKModel {
return this._heapProfilerAgent.stopSampling((error, profile) => error ? null : profile);
}

/**
* @return {!Promise}
*/
collectGarbage() {
return this._heapProfilerAgent.collectGarbage();
}

/**
* @param {string} objectId
* @return {!Promise<?string>}
*/
snapshotObjectIdForObjectId(objectId) {
return this._heapProfilerAgent.getHeapObjectId(objectId, (error, result) => error ? null : result);
}

/**
* @param {string} snapshotObjectId
* @param {string} objectGroupName
* @return {!Promise<?SDK.RemoteObject>}
*/
objectForSnapshotObjectId(snapshotObjectId, objectGroupName) {
return this._heapProfilerAgent.getObjectByHeapObjectId(snapshotObjectId, objectGroupName, (error, result) => {
if (error || !result.type)
return null;
return this.target().runtimeModel.createRemoteObject(result);
});
}

/**
* @param {string} snapshotObjectId
* @return {!Promise}
*/
addInspectedHeapObject(snapshotObjectId) {
return this._heapProfilerAgent.addInspectedHeapObject(snapshotObjectId);
}

/**
* @param {boolean} reportProgress
* @return {!Promise<boolean>}
*/
takeHeapSnapshot(reportProgress) {
return this._heapProfilerAgent.takeHeapSnapshot(reportProgress, error => !error);
}

/**
* @param {boolean} recordAllocationStacks
* @return {!Promise}
*/
startTrackingHeapObjects(recordAllocationStacks) {
return this._heapProfilerAgent.startTrackingHeapObjects(recordAllocationStacks);
}

/**
* @param {boolean} reportProgress
* @return {!Promise<boolean>}
*/
stopTrackingHeapObjects(reportProgress) {
return this._heapProfilerAgent.stopTrackingHeapObjects(reportProgress, error => !error);
}

/**
* @param {!Array.<number>} samples
*/
Expand Down

0 comments on commit 50551ed

Please sign in to comment.