Commit e28a736c authored by yurys@chromium.org's avatar yurys@chromium.org

Continue recording object allocation after navigation

Old profile is removed on HeapProfiler.resetProfiles message and a new one is added immediately to collect all object allocation events from the backend after navigation.

BUG=None

Review URL: https://codereview.chromium.org/172163005

git-svn-id: svn://svn.chromium.org/blink/trunk@168565 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 09b7776e
...@@ -45,6 +45,8 @@ typedef uint32_t SnapshotObjectId; ...@@ -45,6 +45,8 @@ typedef uint32_t SnapshotObjectId;
namespace HeapProfilerAgentState { namespace HeapProfilerAgentState {
static const char heapProfilerEnabled[] = "heapProfilerEnabled"; static const char heapProfilerEnabled[] = "heapProfilerEnabled";
static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled";
static const char allocationTrackingEnabled[] = "allocationTrackingEnabled";
} }
class InspectorHeapProfilerAgent::HeapStatsUpdateTask { class InspectorHeapProfilerAgent::HeapStatsUpdateTask {
...@@ -97,6 +99,8 @@ void InspectorHeapProfilerAgent::restore() ...@@ -97,6 +99,8 @@ void InspectorHeapProfilerAgent::restore()
{ {
if (m_state->getBoolean(HeapProfilerAgentState::heapProfilerEnabled)) if (m_state->getBoolean(HeapProfilerAgentState::heapProfilerEnabled))
m_frontend->resetProfiles(); m_frontend->resetProfiles();
if (m_state->getBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled))
startTrackingHeapObjectsInternal(m_state->getBoolean(HeapProfilerAgentState::allocationTrackingEnabled));
} }
void InspectorHeapProfilerAgent::collectGarbage(WebCore::ErrorString*) void InspectorHeapProfilerAgent::collectGarbage(WebCore::ErrorString*)
...@@ -142,11 +146,10 @@ private: ...@@ -142,11 +146,10 @@ private:
void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*, const bool* trackAllocations) void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*, const bool* trackAllocations)
{ {
if (m_heapStatsUpdateTask) m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, true);
return; bool allocationTrackingEnabled = trackAllocations && *trackAllocations;
ScriptProfiler::startTrackingHeapObjects(trackAllocations && *trackAllocations); m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, allocationTrackingEnabled);
m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this)); startTrackingHeapObjectsInternal(allocationTrackingEnabled);
m_heapStatsUpdateTask->startTimer();
} }
void InspectorHeapProfilerAgent::requestHeapStatsUpdate() void InspectorHeapProfilerAgent::requestHeapStatsUpdate()
...@@ -179,6 +182,15 @@ void InspectorHeapProfilerAgent::stopTrackingHeapObjects(ErrorString* error, con ...@@ -179,6 +182,15 @@ void InspectorHeapProfilerAgent::stopTrackingHeapObjects(ErrorString* error, con
stopTrackingHeapObjectsInternal(); stopTrackingHeapObjectsInternal();
} }
void InspectorHeapProfilerAgent::startTrackingHeapObjectsInternal(bool trackAllocations)
{
if (m_heapStatsUpdateTask)
return;
ScriptProfiler::startTrackingHeapObjects(trackAllocations);
m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this));
m_heapStatsUpdateTask->startTimer();
}
void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal() void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal()
{ {
if (!m_heapStatsUpdateTask) if (!m_heapStatsUpdateTask)
...@@ -186,6 +198,8 @@ void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal() ...@@ -186,6 +198,8 @@ void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal()
ScriptProfiler::stopTrackingHeapObjects(); ScriptProfiler::stopTrackingHeapObjects();
m_heapStatsUpdateTask->resetTimer(); m_heapStatsUpdateTask->resetTimer();
m_heapStatsUpdateTask.clear(); m_heapStatsUpdateTask.clear();
m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, false);
m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, false);
} }
void InspectorHeapProfilerAgent::enable(ErrorString*) void InspectorHeapProfilerAgent::enable(ErrorString*)
......
...@@ -79,6 +79,7 @@ private: ...@@ -79,6 +79,7 @@ private:
void requestHeapStatsUpdate(); void requestHeapStatsUpdate();
void pushHeapStatsUpdate(const uint32_t* const data, const int size); void pushHeapStatsUpdate(const uint32_t* const data, const int size);
void startTrackingHeapObjectsInternal(bool trackAllocations);
void stopTrackingHeapObjectsInternal(); void stopTrackingHeapObjectsInternal();
InjectedScriptManager* m_injectedScriptManager; InjectedScriptManager* m_injectedScriptManager;
......
...@@ -1005,6 +1005,12 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = { ...@@ -1005,6 +1005,12 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = {
{ {
if (this.profileBeingRecorded()) if (this.profileBeingRecorded())
return; return;
this._addNewProfile();
HeapProfilerAgent.startTrackingHeapObjects(WebInspector.experimentsSettings.allocationProfiler.isEnabled());
},
_addNewProfile: function()
{
this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this); this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this);
this._lastSeenIndex = -1; this._lastSeenIndex = -1;
this._profileSamples = { this._profileSamples = {
...@@ -1018,7 +1024,6 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = { ...@@ -1018,7 +1024,6 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = {
this._recording = true; this._recording = true;
this.addProfile(this._profileBeingRecorded); this.addProfile(this._profileBeingRecorded);
this._profileBeingRecorded.updateStatus(WebInspector.UIString("Recording\u2026")); this._profileBeingRecorded.updateStatus(WebInspector.UIString("Recording\u2026"));
HeapProfilerAgent.startTrackingHeapObjects(WebInspector.experimentsSettings.allocationProfiler.isEnabled());
this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted); this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted);
}, },
...@@ -1066,11 +1071,14 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = { ...@@ -1066,11 +1071,14 @@ WebInspector.TrackingHeapSnapshotProfileType.prototype = {
_reset: function() _reset: function()
{ {
var wasRecording = this._recording;
// Clear current profile to avoid stopping backend.
this._profileBeingRecorded = null;
WebInspector.HeapSnapshotProfileType.prototype._reset.call(this); WebInspector.HeapSnapshotProfileType.prototype._reset.call(this);
if (this._recording)
this._stopRecordingProfile();
this._profileSamples = null; this._profileSamples = null;
this._lastSeenIndex = -1; this._lastSeenIndex = -1;
if (wasRecording)
this._addNewProfile();
}, },
/** /**
...@@ -1158,6 +1166,7 @@ WebInspector.HeapProfileHeader.prototype = { ...@@ -1158,6 +1166,7 @@ WebInspector.HeapProfileHeader.prototype = {
_finishLoad: function() _finishLoad: function()
{ {
if (!this._wasDisposed)
this._receiver.close(function() {}); this._receiver.close(function() {});
if (this._bufferedWriter) { if (this._bufferedWriter) {
this._bufferedWriter.close(this._didWriteToTempFile.bind(this)); this._bufferedWriter.close(this._didWriteToTempFile.bind(this));
...@@ -1167,6 +1176,11 @@ WebInspector.HeapProfileHeader.prototype = { ...@@ -1167,6 +1176,11 @@ WebInspector.HeapProfileHeader.prototype = {
_didWriteToTempFile: function(tempFile) _didWriteToTempFile: function(tempFile)
{ {
if (this._wasDisposed) {
if (tempFile)
tempFile.remove();
return;
}
this._tempFile = tempFile; this._tempFile = tempFile;
if (!tempFile) if (!tempFile)
this._failedToCreateTempFile = true; this._failedToCreateTempFile = true;
......
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