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

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

Issue 116273003: Stop recording CPU profiles when Profiler agent is disabled (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comments addressed Created 7 years 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
« no previous file with comments | « LayoutTests/inspector-protocol/cpu-profiler/record-cpu-profile.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 doEnable(); 150 doEnable();
151 } 151 }
152 152
153 void InspectorProfilerAgent::doEnable() 153 void InspectorProfilerAgent::doEnable()
154 { 154 {
155 m_instrumentingAgents->setInspectorProfilerAgent(this); 155 m_instrumentingAgents->setInspectorProfilerAgent(this);
156 } 156 }
157 157
158 void InspectorProfilerAgent::disable(ErrorString*) 158 void InspectorProfilerAgent::disable(ErrorString*)
159 { 159 {
160 for (Vector<ProfileDescriptor>::const_reverse_iterator it = m_startedProfile s.rbegin(); it != m_startedProfiles.rend(); ++it)
161 m_keepAliveProfile = ScriptProfiler::stop(it->m_id);
162 m_startedProfiles.clear();
163 stop(0, 0);
164
160 m_keepAliveProfile.clear(); 165 m_keepAliveProfile.clear();
161 m_instrumentingAgents->setInspectorProfilerAgent(0); 166 m_instrumentingAgents->setInspectorProfilerAgent(0);
162 m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); 167 m_state->setBoolean(ProfilerAgentState::profilerEnabled, false);
163 } 168 }
164 169
165 bool InspectorProfilerAgent::enabled() 170 bool InspectorProfilerAgent::enabled()
166 { 171 {
167 return m_state->getBoolean(ProfilerAgentState::profilerEnabled); 172 return m_state->getBoolean(ProfilerAgentState::profilerEnabled);
168 } 173 }
169 174
170 void InspectorProfilerAgent::setSamplingInterval(ErrorString* error, int interva l) 175 void InspectorProfilerAgent::setSamplingInterval(ErrorString* error, int interva l)
171 { 176 {
172 if (m_recordingCPUProfile) { 177 if (m_recordingCPUProfile) {
173 *error = "Cannot change sampling interval when profiling."; 178 *error = "Cannot change sampling interval when profiling.";
174 return; 179 return;
175 } 180 }
176 m_state->setLong(ProfilerAgentState::samplingInterval, interval); 181 m_state->setLong(ProfilerAgentState::samplingInterval, interval);
177 ScriptProfiler::setSamplingInterval(interval); 182 ScriptProfiler::setSamplingInterval(interval);
178 } 183 }
179 184
180 void InspectorProfilerAgent::setFrontend(InspectorFrontend* frontend) 185 void InspectorProfilerAgent::setFrontend(InspectorFrontend* frontend)
181 { 186 {
182 m_frontend = frontend->profiler(); 187 m_frontend = frontend->profiler();
183 } 188 }
184 189
185 void InspectorProfilerAgent::clearFrontend() 190 void InspectorProfilerAgent::clearFrontend()
186 { 191 {
187 m_frontend = 0; 192 m_frontend = 0;
188 stop(0, 0);
189 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects();
190 ErrorString error; 193 ErrorString error;
191 disable(&error); 194 disable(&error);
195 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects();
192 } 196 }
193 197
194 void InspectorProfilerAgent::restore() 198 void InspectorProfilerAgent::restore()
195 { 199 {
196 if (m_state->getBoolean(ProfilerAgentState::profilerEnabled)) { 200 if (m_state->getBoolean(ProfilerAgentState::profilerEnabled)) {
197 doEnable(); 201 doEnable();
198 m_frontend->resetProfiles(); 202 m_frontend->resetProfiles();
199 } 203 }
200 if (long interval = m_state->getLong(ProfilerAgentState::samplingInterval, 0 )) 204 if (long interval = m_state->getLong(ProfilerAgentState::samplingInterval, 0 ))
201 ScriptProfiler::setSamplingInterval(interval); 205 ScriptProfiler::setSamplingInterval(interval);
202 if (m_state->getBoolean(ProfilerAgentState::userInitiatedProfiling)) 206 if (m_state->getBoolean(ProfilerAgentState::userInitiatedProfiling))
203 start(); 207 start();
204 } 208 }
205 209
206 void InspectorProfilerAgent::start(ErrorString* error) 210 void InspectorProfilerAgent::start(ErrorString* error)
207 { 211 {
208 if (m_recordingCPUProfile) 212 if (m_recordingCPUProfile)
209 return; 213 return;
210 if (!enabled()) { 214 if (!enabled()) {
211 ErrorString error; 215 *error = "Profiler is not enabled";
212 enable(&error); 216 return;
213 } 217 }
214 m_recordingCPUProfile = true; 218 m_recordingCPUProfile = true;
215 if (m_overlay) 219 if (m_overlay)
216 m_overlay->startedRecordingProfile(); 220 m_overlay->startedRecordingProfile();
217 m_frontendInitiatedProfileId = String::number(m_nextProfileId++); 221 m_frontendInitiatedProfileId = String::number(m_nextProfileId++);
218 ScriptProfiler::start(m_frontendInitiatedProfileId); 222 ScriptProfiler::start(m_frontendInitiatedProfileId);
219 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true); 223 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true);
220 } 224 }
221 225
222 void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder:: Profiler::CPUProfile>& profile) 226 void InspectorProfilerAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder:: Profiler::CPUProfile>& profile)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 idleStarted(); 288 idleStarted();
285 } 289 }
286 290
287 void InspectorProfilerAgent::didLeaveNestedRunLoop() 291 void InspectorProfilerAgent::didLeaveNestedRunLoop()
288 { 292 {
289 idleFinished(); 293 idleFinished();
290 } 294 }
291 295
292 } // namespace WebCore 296 } // namespace WebCore
293 297
OLDNEW
« no previous file with comments | « LayoutTests/inspector-protocol/cpu-profiler/record-cpu-profile.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698