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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "InspectorHeapProfilerAgent.h" 32 #include "InspectorHeapProfilerAgent.h"
33 33
34 #include "InjectedScript.h" 34 #include "InjectedScript.h"
35 #include "InjectedScriptHost.h" 35 #include "InjectedScriptHost.h"
36 #include "InspectorState.h" 36 #include "InspectorState.h"
37 #include "InstrumentingAgents.h" 37 #include "InstrumentingAgents.h"
38 #include "ScriptProfiler.h" 38 #include "ScriptProfiler.h"
39 #include "WebCoreMemoryInstrumentation.h" 39 #include "WebCoreMemoryInstrumentation.h"
40 #include "core/platform/Timer.h"
41 #include <wtf/CurrentTime.h>
40 #include <wtf/MemoryInstrumentationHashMap.h> 42 #include <wtf/MemoryInstrumentationHashMap.h>
41 43
42 namespace WebCore { 44 namespace WebCore {
43 45
44 namespace HeapProfilerAgentState { 46 namespace HeapProfilerAgentState {
45 static const char profileHeadersRequested[] = "profileHeadersRequested"; 47 static const char profileHeadersRequested[] = "profileHeadersRequested";
46 } 48 }
47 49
48 static const char* const UserInitiatedProfileNameHeap = "org.webkit.profiles.use r-initiated"; 50 static const char* const UserInitiatedProfileNameHeap = "org.webkit.profiles.use r-initiated";
49 51
(...skipping 19 matching lines...) Expand all
69 void InspectorHeapProfilerAgent::clearProfiles(ErrorString*) 71 void InspectorHeapProfilerAgent::clearProfiles(ErrorString*)
70 { 72 {
71 m_snapshots.clear(); 73 m_snapshots.clear();
72 m_nextUserInitiatedHeapSnapshotNumber = 1; 74 m_nextUserInitiatedHeapSnapshotNumber = 1;
73 resetFrontendProfiles(); 75 resetFrontendProfiles();
74 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects(); 76 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects();
75 } 77 }
76 78
77 void InspectorHeapProfilerAgent::resetFrontendProfiles() 79 void InspectorHeapProfilerAgent::resetFrontendProfiles()
78 { 80 {
81 stopTrackingHeapObjects(0);
79 if (!m_frontend) 82 if (!m_frontend)
80 return; 83 return;
81 if (!m_state->getBoolean(HeapProfilerAgentState::profileHeadersRequested)) 84 if (!m_state->getBoolean(HeapProfilerAgentState::profileHeadersRequested))
82 return; 85 return;
83 if (m_snapshots.isEmpty()) 86 if (m_snapshots.isEmpty())
84 m_frontend->resetProfiles(); 87 m_frontend->resetProfiles();
85 } 88 }
86 89
87 void InspectorHeapProfilerAgent::setFrontend(InspectorFrontend* frontend) 90 void InspectorHeapProfilerAgent::setFrontend(InspectorFrontend* frontend)
88 { 91 {
(...skipping 18 matching lines...) Expand all
107 110
108 PassRefPtr<TypeBuilder::HeapProfiler::ProfileHeader> InspectorHeapProfilerAgent: :createSnapshotHeader(const ScriptHeapSnapshot& snapshot) 111 PassRefPtr<TypeBuilder::HeapProfiler::ProfileHeader> InspectorHeapProfilerAgent: :createSnapshotHeader(const ScriptHeapSnapshot& snapshot)
109 { 112 {
110 RefPtr<TypeBuilder::HeapProfiler::ProfileHeader> header = TypeBuilder::HeapP rofiler::ProfileHeader::create() 113 RefPtr<TypeBuilder::HeapProfiler::ProfileHeader> header = TypeBuilder::HeapP rofiler::ProfileHeader::create()
111 .setUid(snapshot.uid()) 114 .setUid(snapshot.uid())
112 .setTitle(snapshot.title()); 115 .setTitle(snapshot.title());
113 header->setMaxJSObjectId(snapshot.maxSnapshotJSObjectId()); 116 header->setMaxJSObjectId(snapshot.maxSnapshotJSObjectId());
114 return header.release(); 117 return header.release();
115 } 118 }
116 119
120 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.
121 public:
122 HeapStatsUpdateTask(InspectorHeapProfilerAgent*);
123 void startTimer();
124 void resetTimer() { m_timer.stop(); }
125 void onTimer(Timer<HeapStatsUpdateTask>*);
126
127 private:
128 InspectorHeapProfilerAgent* m_heapProfilerAgent;
129 Timer<HeapStatsUpdateTask> m_timer;
130 };
131
132 HeapStatsUpdateTask::HeapStatsUpdateTask(InspectorHeapProfilerAgent* heapProfile rAgent)
133 : m_heapProfilerAgent(heapProfilerAgent)
134 , m_timer(this, &HeapStatsUpdateTask::onTimer)
135 {
136 }
137
138 void HeapStatsUpdateTask::onTimer(Timer<HeapStatsUpdateTask>*)
139 {
140 // The timer is stopped on m_heapProfilerAgent destruction,
141 // so this method will never be called after m_heapProfilerAgent has been de stroyed.
142 m_heapProfilerAgent->requestHeapStatsUpdate();
143 }
144
145 void HeapStatsUpdateTask::startTimer()
146 {
147 ASSERT(!m_timer.isActive());
148 m_timer.startRepeating(0.05);
149 }
150
151 class HeapStatsStream : public ScriptProfiler::OutputStream {
152 public:
153 HeapStatsStream(InspectorHeapProfilerAgent* heapProfilerAgent)
154 : m_heapProfilerAgent(heapProfilerAgent)
155 {
156 }
157 virtual void write(const uint32_t* chunk, const int size) OVERRIDE
158 {
159 ASSERT(chunk);
160 ASSERT(size > 0);
161 m_heapProfilerAgent->pushHeapStatsUpdate(chunk, size);
162 }
163 private:
164 InspectorHeapProfilerAgent* m_heapProfilerAgent;
165 };
166
167 void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*)
168 {
169 if (m_heapStatsUpdateTask)
170 return;
171 ScriptProfiler::startTrackingHeapObjects();
172 m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this));
173 m_heapStatsUpdateTask->startTimer();
174 }
175
176 void InspectorHeapProfilerAgent::requestHeapStatsUpdate()
177 {
178 if (!m_frontend)
179 return;
180 HeapStatsStream stream(this);
181 SnapshotObjectId lastSeenObjectId = ScriptProfiler::requestHeapStatsUpdate(& stream);
182 m_frontend->lastSeenObjectId(lastSeenObjectId, WTF::currentTimeMS());
183 }
184
185 void InspectorHeapProfilerAgent::pushHeapStatsUpdate(const uint32_t* const data, const int size)
186 {
187 if (!m_frontend)
188 return;
189 RefPtr<TypeBuilder::Array<int> > statsDiff = TypeBuilder::Array<int>::create ();
190 for (int i = 0; i < size; ++i)
191 statsDiff->addItem(data[i]);
192 m_frontend->heapStatsUpdate(statsDiff.release());
193 }
194
195 void InspectorHeapProfilerAgent::stopTrackingHeapObjects(ErrorString*)
196 {
197 if (!m_heapStatsUpdateTask)
198 return;
199 ScriptProfiler::stopTrackingHeapObjects();
200 m_heapStatsUpdateTask->resetTimer();
201 m_heapStatsUpdateTask.release();
yurys 2013/04/25 12:23:15 m_heapStatsUpdateTask.clear() not release()
loislo 2013/04/25 13:33:56 Done.
202 }
203
117 void InspectorHeapProfilerAgent::getProfileHeaders(ErrorString*, RefPtr<TypeBuil der::Array<TypeBuilder::HeapProfiler::ProfileHeader> >& headers) 204 void InspectorHeapProfilerAgent::getProfileHeaders(ErrorString*, RefPtr<TypeBuil der::Array<TypeBuilder::HeapProfiler::ProfileHeader> >& headers)
118 { 205 {
119 m_state->setBoolean(HeapProfilerAgentState::profileHeadersRequested, true); 206 m_state->setBoolean(HeapProfilerAgentState::profileHeadersRequested, true);
120 headers = TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader>::crea te(); 207 headers = TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader>::crea te();
121 208
122 IdToHeapSnapshotMap::iterator snapshotsEnd = m_snapshots.end(); 209 IdToHeapSnapshotMap::iterator snapshotsEnd = m_snapshots.end();
123 for (IdToHeapSnapshotMap::iterator it = m_snapshots.begin(); it != snapshots End; ++it) 210 for (IdToHeapSnapshotMap::iterator it = m_snapshots.begin(); it != snapshots End; ++it)
124 headers->addItem(createSnapshotHeader(*it->value)); 211 headers->addItem(createSnapshotHeader(*it->value));
125 } 212 }
126 213
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 { 321 {
235 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorPr ofilerAgent); 322 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorPr ofilerAgent);
236 InspectorBaseAgent<InspectorHeapProfilerAgent>::reportMemoryUsage(memoryObje ctInfo); 323 InspectorBaseAgent<InspectorHeapProfilerAgent>::reportMemoryUsage(memoryObje ctInfo);
237 info.addMember(m_injectedScriptManager, "injectedScriptManager"); 324 info.addMember(m_injectedScriptManager, "injectedScriptManager");
238 info.addWeakPointer(m_frontend); 325 info.addWeakPointer(m_frontend);
239 info.addMember(m_snapshots, "snapshots"); 326 info.addMember(m_snapshots, "snapshots");
240 } 327 }
241 328
242 } // namespace WebCore 329 } // namespace WebCore
243 330
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698