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

Side by Side Diff: Source/core/inspector/InspectorHeapProfilerAgent.cpp

Issue 172163005: Continue recording object allocation after navigation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 27 matching lines...) Expand all
38 #include "core/inspector/InspectorState.h" 38 #include "core/inspector/InspectorState.h"
39 #include "platform/Timer.h" 39 #include "platform/Timer.h"
40 #include "wtf/CurrentTime.h" 40 #include "wtf/CurrentTime.h"
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 typedef uint32_t SnapshotObjectId; 44 typedef uint32_t SnapshotObjectId;
45 45
46 namespace HeapProfilerAgentState { 46 namespace HeapProfilerAgentState {
47 static const char heapProfilerEnabled[] = "heapProfilerEnabled"; 47 static const char heapProfilerEnabled[] = "heapProfilerEnabled";
48 static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled";
49 static const char allocationTrackingEnabled[] = "allocationTrackingEnabled";
48 } 50 }
49 51
50 class InspectorHeapProfilerAgent::HeapStatsUpdateTask { 52 class InspectorHeapProfilerAgent::HeapStatsUpdateTask {
51 public: 53 public:
52 HeapStatsUpdateTask(InspectorHeapProfilerAgent*); 54 HeapStatsUpdateTask(InspectorHeapProfilerAgent*);
53 void startTimer(); 55 void startTimer();
54 void resetTimer() { m_timer.stop(); } 56 void resetTimer() { m_timer.stop(); }
55 void onTimer(Timer<HeapStatsUpdateTask>*); 57 void onTimer(Timer<HeapStatsUpdateTask>*);
56 58
57 private: 59 private:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects(); 92 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects();
91 93
92 ErrorString error; 94 ErrorString error;
93 disable(&error); 95 disable(&error);
94 } 96 }
95 97
96 void InspectorHeapProfilerAgent::restore() 98 void InspectorHeapProfilerAgent::restore()
97 { 99 {
98 if (m_state->getBoolean(HeapProfilerAgentState::heapProfilerEnabled)) 100 if (m_state->getBoolean(HeapProfilerAgentState::heapProfilerEnabled))
99 m_frontend->resetProfiles(); 101 m_frontend->resetProfiles();
102 if (m_state->getBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled))
103 startTrackingHeapObjectsInternal(m_state->getBoolean(HeapProfilerAgentSt ate::allocationTrackingEnabled));
100 } 104 }
101 105
102 void InspectorHeapProfilerAgent::collectGarbage(WebCore::ErrorString*) 106 void InspectorHeapProfilerAgent::collectGarbage(WebCore::ErrorString*)
103 { 107 {
104 ScriptProfiler::collectGarbage(); 108 ScriptProfiler::collectGarbage();
105 } 109 }
106 110
107 InspectorHeapProfilerAgent::HeapStatsUpdateTask::HeapStatsUpdateTask(InspectorHe apProfilerAgent* heapProfilerAgent) 111 InspectorHeapProfilerAgent::HeapStatsUpdateTask::HeapStatsUpdateTask(InspectorHe apProfilerAgent* heapProfilerAgent)
108 : m_heapProfilerAgent(heapProfilerAgent) 112 : m_heapProfilerAgent(heapProfilerAgent)
109 , m_timer(this, &HeapStatsUpdateTask::onTimer) 113 , m_timer(this, &HeapStatsUpdateTask::onTimer)
(...skipping 25 matching lines...) Expand all
135 ASSERT(chunk); 139 ASSERT(chunk);
136 ASSERT(size > 0); 140 ASSERT(size > 0);
137 m_heapProfilerAgent->pushHeapStatsUpdate(chunk, size); 141 m_heapProfilerAgent->pushHeapStatsUpdate(chunk, size);
138 } 142 }
139 private: 143 private:
140 InspectorHeapProfilerAgent* m_heapProfilerAgent; 144 InspectorHeapProfilerAgent* m_heapProfilerAgent;
141 }; 145 };
142 146
143 void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*, const bo ol* trackAllocations) 147 void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*, const bo ol* trackAllocations)
144 { 148 {
145 if (m_heapStatsUpdateTask) 149 m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, true );
146 return; 150 bool allocationTrackingEnabled = trackAllocations && *trackAllocations;
147 ScriptProfiler::startTrackingHeapObjects(trackAllocations && *trackAllocatio ns); 151 m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, alloc ationTrackingEnabled);
148 m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this)); 152 startTrackingHeapObjectsInternal(allocationTrackingEnabled);
149 m_heapStatsUpdateTask->startTimer();
150 } 153 }
151 154
152 void InspectorHeapProfilerAgent::requestHeapStatsUpdate() 155 void InspectorHeapProfilerAgent::requestHeapStatsUpdate()
153 { 156 {
154 if (!m_frontend) 157 if (!m_frontend)
155 return; 158 return;
156 HeapStatsStream stream(this); 159 HeapStatsStream stream(this);
157 SnapshotObjectId lastSeenObjectId = ScriptProfiler::requestHeapStatsUpdate(& stream); 160 SnapshotObjectId lastSeenObjectId = ScriptProfiler::requestHeapStatsUpdate(& stream);
158 m_frontend->lastSeenObjectId(lastSeenObjectId, WTF::currentTimeMS()); 161 m_frontend->lastSeenObjectId(lastSeenObjectId, WTF::currentTimeMS());
159 } 162 }
(...skipping 12 matching lines...) Expand all
172 { 175 {
173 if (!m_heapStatsUpdateTask) { 176 if (!m_heapStatsUpdateTask) {
174 *error = "Heap object tracking is not started."; 177 *error = "Heap object tracking is not started.";
175 return; 178 return;
176 } 179 }
177 requestHeapStatsUpdate(); 180 requestHeapStatsUpdate();
178 takeHeapSnapshot(error, reportProgress); 181 takeHeapSnapshot(error, reportProgress);
179 stopTrackingHeapObjectsInternal(); 182 stopTrackingHeapObjectsInternal();
180 } 183 }
181 184
185 void InspectorHeapProfilerAgent::startTrackingHeapObjectsInternal(bool trackAllo cations)
186 {
187 if (m_heapStatsUpdateTask)
188 return;
189 ScriptProfiler::startTrackingHeapObjects(trackAllocations);
190 m_heapStatsUpdateTask = adoptPtr(new HeapStatsUpdateTask(this));
191 m_heapStatsUpdateTask->startTimer();
192 }
193
182 void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal() 194 void InspectorHeapProfilerAgent::stopTrackingHeapObjectsInternal()
183 { 195 {
184 if (!m_heapStatsUpdateTask) 196 if (!m_heapStatsUpdateTask)
185 return; 197 return;
186 ScriptProfiler::stopTrackingHeapObjects(); 198 ScriptProfiler::stopTrackingHeapObjects();
187 m_heapStatsUpdateTask->resetTimer(); 199 m_heapStatsUpdateTask->resetTimer();
188 m_heapStatsUpdateTask.clear(); 200 m_heapStatsUpdateTask.clear();
201 m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, fals e);
202 m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, false );
189 } 203 }
190 204
191 void InspectorHeapProfilerAgent::enable(ErrorString*) 205 void InspectorHeapProfilerAgent::enable(ErrorString*)
192 { 206 {
193 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, true); 207 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, true);
194 } 208 }
195 209
196 void InspectorHeapProfilerAgent::disable(ErrorString* error) 210 void InspectorHeapProfilerAgent::disable(ErrorString* error)
197 { 211 {
198 stopTrackingHeapObjectsInternal(); 212 stopTrackingHeapObjectsInternal();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (value.hasNoValue() || value.isUndefined()) { 300 if (value.hasNoValue() || value.isUndefined()) {
287 *errorString = "Object with given id not found"; 301 *errorString = "Object with given id not found";
288 return; 302 return;
289 } 303 }
290 unsigned id = ScriptProfiler::getHeapObjectId(value); 304 unsigned id = ScriptProfiler::getHeapObjectId(value);
291 *heapSnapshotObjectId = String::number(id); 305 *heapSnapshotObjectId = String::number(id);
292 } 306 }
293 307
294 } // namespace WebCore 308 } // namespace WebCore
295 309
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorHeapProfilerAgent.h ('k') | Source/devtools/front_end/HeapSnapshotView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698