Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Unified Diff: Source/core/inspector/InspectorHeapProfilerAgent.cpp

Issue 14373016: DevTools: [HeapProfiler] Provide API for heap objects tracking info. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: description was slightly changed Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/inspector/InspectorHeapProfilerAgent.cpp
diff --git a/Source/core/inspector/InspectorHeapProfilerAgent.cpp b/Source/core/inspector/InspectorHeapProfilerAgent.cpp
index caf386c6e4e3f4b2075d99aec3295022e9549de8..5be2c0d0ba354ecc42282d7df74df6d2c451f6f4 100644
--- a/Source/core/inspector/InspectorHeapProfilerAgent.cpp
+++ b/Source/core/inspector/InspectorHeapProfilerAgent.cpp
@@ -37,6 +37,8 @@
#include "InstrumentingAgents.h"
#include "ScriptProfiler.h"
#include "WebCoreMemoryInstrumentation.h"
+#include "core/platform/Timer.h"
+#include <wtf/CurrentTime.h>
#include <wtf/MemoryInstrumentationHashMap.h>
namespace WebCore {
@@ -76,6 +78,7 @@ void InspectorHeapProfilerAgent::clearProfiles(ErrorString*)
void InspectorHeapProfilerAgent::resetFrontendProfiles()
{
+ stopTrackingHeapObjects(0);
if (!m_frontend)
return;
if (!m_state->getBoolean(HeapProfilerAgentState::profileHeadersRequested))
@@ -114,6 +117,90 @@ PassRefPtr<TypeBuilder::HeapProfiler::ProfileHeader> InspectorHeapProfilerAgent:
return header.release();
}
+class HeapStatsUpdateTask {
yurys 2013/04/25 12:23:15 Please move class definitions to the top before me
loislo 2013/04/25 13:33:56 Done.
+public:
+ HeapStatsUpdateTask(InspectorHeapProfilerAgent*);
+ void startTimer();
+ void resetTimer() { m_timer.stop(); }
+ void onTimer(Timer<HeapStatsUpdateTask>*);
+
+private:
+ InspectorHeapProfilerAgent* m_heapProfilerAgent;
+ Timer<HeapStatsUpdateTask> m_timer;
+};
+
+HeapStatsUpdateTask::HeapStatsUpdateTask(InspectorHeapProfilerAgent* heapProfilerAgent)
+ : m_heapProfilerAgent(heapProfilerAgent)
+ , m_timer(this, &HeapStatsUpdateTask::onTimer)
+{
+}
+
+void HeapStatsUpdateTask::onTimer(Timer<HeapStatsUpdateTask>*)
+{
+ // The timer is stopped on m_heapProfilerAgent destruction,
+ // so this method will never be called after m_heapProfilerAgent has been destroyed.
+ m_heapProfilerAgent->requestHeapStatsUpdate();
+}
+
+void HeapStatsUpdateTask::startTimer()
+{
+ ASSERT(!m_timer.isActive());
+ m_timer.startRepeating(0.05);
+}
+
+class HeapStatsStream : public ScriptProfiler::OutputStream {
+public:
+ HeapStatsStream(InspectorHeapProfilerAgent* heapProfilerAgent)
+ : m_heapProfilerAgent(heapProfilerAgent)
+ {
+ }
+ virtual void write(const uint32_t* chunk, const int size) OVERRIDE
+ {
+ ASSERT(chunk);
+ ASSERT(size > 0);
+ m_heapProfilerAgent->pushHeapStatsUpdate(chunk, size);
+ }
+private:
+ InspectorHeapProfilerAgent* m_heapProfilerAgent;
+};
+
+void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*)
+{
+ if (m_heapStatsUpdateTask)
+ return;
+ ScriptProfiler::startTrackingHeapObjects();
+ m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this));
+ m_heapStatsUpdateTask->startTimer();
+}
+
+void InspectorHeapProfilerAgent::requestHeapStatsUpdate()
+{
+ if (!m_frontend)
+ return;
+ HeapStatsStream stream(this);
+ SnapshotObjectId lastSeenObjectId = ScriptProfiler::requestHeapStatsUpdate(&stream);
+ m_frontend->lastSeenObjectId(lastSeenObjectId, WTF::currentTimeMS());
+}
+
+void InspectorHeapProfilerAgent::pushHeapStatsUpdate(const uint32_t* const data, const int size)
+{
+ if (!m_frontend)
+ return;
+ RefPtr<TypeBuilder::Array<int> > statsDiff = TypeBuilder::Array<int>::create();
+ for (int i = 0; i < size; ++i)
+ statsDiff->addItem(data[i]);
+ m_frontend->heapStatsUpdate(statsDiff.release());
+}
+
+void InspectorHeapProfilerAgent::stopTrackingHeapObjects(ErrorString*)
+{
+ if (!m_heapStatsUpdateTask)
+ return;
+ ScriptProfiler::stopTrackingHeapObjects();
+ m_heapStatsUpdateTask->resetTimer();
+ m_heapStatsUpdateTask.release();
yurys 2013/04/25 12:23:15 m_heapStatsUpdateTask.clear() not release()
loislo 2013/04/25 13:33:56 Done.
+}
+
void InspectorHeapProfilerAgent::getProfileHeaders(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader> >& headers)
{
m_state->setBoolean(HeapProfilerAgentState::profileHeadersRequested, true);

Powered by Google App Engine
This is Rietveld 408576698