Commit 3b2682d7 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Add sampling native heap snapshots type to Memory panel.

The profile type is put behind a hidden experiment.

BUG=803276

Change-Id: Ieb16c0eda7653ac90ef5ce8fc2008b724b2af4e8
Reviewed-on: https://chromium-review.googlesource.com/884574
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532242}
parent 65a684af
...@@ -223,7 +223,75 @@ Profiler.SamplingNativeHeapProfileType = class extends Profiler.SamplingHeapProf ...@@ -223,7 +223,75 @@ Profiler.SamplingNativeHeapProfileType = class extends Profiler.SamplingHeapProf
} }
}; };
Profiler.SamplingNativeHeapProfileType.TypeId = 'SamplingNativeHeap'; Profiler.SamplingNativeHeapProfileType.TypeId = 'SamplingNativeHeapRecording';
/**
* @unrestricted
*/
Profiler.SamplingNativeHeapSnapshotType = class extends Profiler.SamplingHeapProfileTypeBase {
constructor() {
super(Profiler.SamplingNativeHeapSnapshotType.TypeId, Common.UIString('Take native memory allocations snapshot'));
Profiler.SamplingNativeHeapSnapshotType.instance = this;
}
/**
* @override
* @return {boolean}
*/
isInstantProfile() {
return true;
}
get treeItemTitle() {
return Common.UIString('NATIVE SNAPSHOTS');
}
get description() {
return Common.UIString(
'Native memory snapshots show sampled native allocations in the renderer process since start up. ' +
'Chrome has to be started with --sampling-heap-profiler flag. ' +
'Check flags at chrome://flags');
}
/**
* @override
* @return {boolean}
*/
buttonClicked() {
this._takeSnapshot();
return false;
}
/**
* @return {!Promise}
*/
async _takeSnapshot() {
if (this.profileBeingRecorded())
return;
var heapProfilerModel = UI.context.flavor(SDK.HeapProfilerModel);
if (!heapProfilerModel)
return;
var profile = new Profiler.SamplingHeapProfileHeader(
heapProfilerModel, this, Common.UIString('Snapshot %d', this.nextProfileUid()));
this.setProfileBeingRecorded(profile);
this.addProfile(profile);
profile.updateStatus(Common.UIString('Snapshotting\u2026'));
var protocolProfile = await heapProfilerModel.takeNativeSnapshot();
var recordedProfile = this.profileBeingRecorded();
if (recordedProfile) {
console.assert(protocolProfile);
recordedProfile.setProtocolProfile(protocolProfile);
recordedProfile.updateStatus('');
this.setProfileBeingRecorded(null);
}
this.dispatchEventToListeners(Profiler.ProfileType.Events.ProfileComplete, recordedProfile);
}
};
Profiler.SamplingNativeHeapSnapshotType.TypeId = 'SamplingNativeHeapSnapshot';
/** /**
* @unrestricted * @unrestricted
......
...@@ -12,7 +12,7 @@ Profiler.HeapProfilerPanel = class extends Profiler.ProfilesPanel { ...@@ -12,7 +12,7 @@ Profiler.HeapProfilerPanel = class extends Profiler.ProfilesPanel {
var profileTypes = var profileTypes =
[registry.heapSnapshotProfileType, registry.samplingHeapProfileType, registry.trackingHeapSnapshotProfileType]; [registry.heapSnapshotProfileType, registry.samplingHeapProfileType, registry.trackingHeapSnapshotProfileType];
if (Runtime.experiments.isEnabled('nativeHeapProfiler')) if (Runtime.experiments.isEnabled('nativeHeapProfiler'))
profileTypes.push(registry.samplingNativeHeapProfileType); profileTypes.push(registry.samplingNativeHeapProfileType, registry.samplingNativeHeapSnapshotType);
super('heap_profiler', profileTypes, 'profiler.heap-toggle-recording'); super('heap_profiler', profileTypes, 'profiler.heap-toggle-recording');
} }
......
...@@ -10,6 +10,7 @@ Profiler.ProfileTypeRegistry = class { ...@@ -10,6 +10,7 @@ Profiler.ProfileTypeRegistry = class {
this.heapSnapshotProfileType = new Profiler.HeapSnapshotProfileType(); this.heapSnapshotProfileType = new Profiler.HeapSnapshotProfileType();
this.samplingHeapProfileType = new Profiler.SamplingHeapProfileType(); this.samplingHeapProfileType = new Profiler.SamplingHeapProfileType();
this.samplingNativeHeapProfileType = new Profiler.SamplingNativeHeapProfileType(); this.samplingNativeHeapProfileType = new Profiler.SamplingNativeHeapProfileType();
this.samplingNativeHeapSnapshotType = new Profiler.SamplingNativeHeapSnapshotType();
this.trackingHeapSnapshotProfileType = new Profiler.TrackingHeapSnapshotProfileType(); this.trackingHeapSnapshotProfileType = new Profiler.TrackingHeapSnapshotProfileType();
} }
}; };
......
...@@ -63,6 +63,14 @@ SDK.HeapProfilerModel = class extends SDK.SDKModel { ...@@ -63,6 +63,14 @@ SDK.HeapProfilerModel = class extends SDK.SDKModel {
return this._convertNativeProfile(rawProfile); return this._convertNativeProfile(rawProfile);
} }
/**
* @return {!Promise<!Protocol.HeapProfiler.SamplingHeapProfile>}
*/
async takeNativeSnapshot() {
var rawProfile = await this._memoryAgent.getAllTimeSamplingProfile();
return this._convertNativeProfile(rawProfile);
}
/** /**
* @param {!Protocol.Memory.SamplingProfile} rawProfile * @param {!Protocol.Memory.SamplingProfile} rawProfile
* @return {!Protocol.HeapProfiler.SamplingHeapProfile} * @return {!Protocol.HeapProfiler.SamplingHeapProfile}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment