OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" | 5 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
6 | 6 |
7 #include "platform/v8_inspector/Atomics.h" | 7 #include "platform/v8_inspector/Atomics.h" |
8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
10 #include "platform/v8_inspector/V8StackTraceImpl.h" | 10 #include "platform/v8_inspector/V8StackTraceImpl.h" |
11 #include "platform/v8_inspector/V8StringUtil.h" | 11 #include "platform/v8_inspector/V8StringUtil.h" |
12 #include <v8-profiler.h> | 12 #include <v8-profiler.h> |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 namespace ProfilerAgentState { | 16 namespace ProfilerAgentState { |
17 static const char samplingInterval[] = "samplingInterval"; | 17 static const char samplingInterval[] = "samplingInterval"; |
18 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; | 18 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; |
| 19 static const char profilerEnabled[] = "profilerEnabled"; |
19 } | 20 } |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 PassOwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInspector
ObjectForPositionTicks(const v8::CpuProfileNode* node) | 24 PassOwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInspector
ObjectForPositionTicks(const v8::CpuProfileNode* node) |
24 { | 25 { |
25 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protoc
ol::Array<protocol::Profiler::PositionTickInfo>::create(); | 26 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protoc
ol::Array<protocol::Profiler::PositionTickInfo>::create(); |
26 unsigned lineCount = node->GetHitLineCount(); | 27 unsigned lineCount = node->GetHitLineCount(); |
27 if (!lineCount) | 28 if (!lineCount) |
28 return array.release(); | 29 return array.release(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return; | 177 return; |
177 OwnPtr<protocol::Debugger::Location> location = currentDebugLocation(m_sessi
on->debugger()); | 178 OwnPtr<protocol::Debugger::Location> location = currentDebugLocation(m_sessi
on->debugger()); |
178 m_frontend->consoleProfileFinished(id, location.release(), profile.release()
, resolvedTitle); | 179 m_frontend->consoleProfileFinished(id, location.release(), profile.release()
, resolvedTitle); |
179 } | 180 } |
180 | 181 |
181 void V8ProfilerAgentImpl::enable(ErrorString*) | 182 void V8ProfilerAgentImpl::enable(ErrorString*) |
182 { | 183 { |
183 if (m_enabled) | 184 if (m_enabled) |
184 return; | 185 return; |
185 m_enabled = true; | 186 m_enabled = true; |
| 187 m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); |
186 m_session->changeInstrumentationCounter(+1); | 188 m_session->changeInstrumentationCounter(+1); |
187 } | 189 } |
188 | 190 |
189 void V8ProfilerAgentImpl::disable(ErrorString* errorString) | 191 void V8ProfilerAgentImpl::disable(ErrorString* errorString) |
190 { | 192 { |
191 if (!m_enabled) | 193 if (!m_enabled) |
192 return; | 194 return; |
193 m_session->changeInstrumentationCounter(-1); | 195 m_session->changeInstrumentationCounter(-1); |
194 for (size_t i = m_startedProfiles.size(); i > 0; --i) | 196 for (size_t i = m_startedProfiles.size(); i > 0; --i) |
195 stopProfiling(m_startedProfiles[i - 1].m_id, false); | 197 stopProfiling(m_startedProfiles[i - 1].m_id, false); |
196 m_startedProfiles.clear(); | 198 m_startedProfiles.clear(); |
197 stop(nullptr, nullptr); | 199 stop(nullptr, nullptr); |
198 m_enabled = false; | 200 m_enabled = false; |
| 201 m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); |
199 } | 202 } |
200 | 203 |
201 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) | 204 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) |
202 { | 205 { |
203 if (m_recordingCPUProfile) { | 206 if (m_recordingCPUProfile) { |
204 *error = "Cannot change sampling interval when profiling."; | 207 *error = "Cannot change sampling interval when profiling."; |
205 return; | 208 return; |
206 } | 209 } |
207 m_state->setNumber(ProfilerAgentState::samplingInterval, interval); | 210 m_state->setNumber(ProfilerAgentState::samplingInterval, interval); |
208 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); | 211 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
209 } | 212 } |
210 | 213 |
211 void V8ProfilerAgentImpl::clearFrontend() | 214 void V8ProfilerAgentImpl::clearFrontend() |
212 { | 215 { |
213 ErrorString error; | 216 ErrorString error; |
214 disable(&error); | 217 disable(&error); |
215 ASSERT(m_frontend); | 218 ASSERT(m_frontend); |
216 m_frontend = nullptr; | 219 m_frontend = nullptr; |
217 } | 220 } |
218 | 221 |
219 void V8ProfilerAgentImpl::restore() | 222 void V8ProfilerAgentImpl::restore() |
220 { | 223 { |
221 ASSERT(!m_enabled); | 224 ASSERT(!m_enabled); |
| 225 if (!m_state->booleanProperty(ProfilerAgentState::profilerEnabled, false)) |
| 226 return; |
222 m_enabled = true; | 227 m_enabled = true; |
223 m_session->changeInstrumentationCounter(+1); | 228 m_session->changeInstrumentationCounter(+1); |
224 int interval = 0; | 229 int interval = 0; |
225 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); | 230 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); |
226 if (interval) | 231 if (interval) |
227 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); | 232 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); |
228 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal
se)) { | 233 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal
se)) { |
229 ErrorString error; | 234 ErrorString error; |
230 start(&error); | 235 start(&error); |
231 } | 236 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 profile->Delete(); | 293 profile->Delete(); |
289 return result.release(); | 294 return result.release(); |
290 } | 295 } |
291 | 296 |
292 bool V8ProfilerAgentImpl::isRecording() const | 297 bool V8ProfilerAgentImpl::isRecording() const |
293 { | 298 { |
294 return m_recordingCPUProfile || !m_startedProfiles.isEmpty(); | 299 return m_recordingCPUProfile || !m_startedProfiles.isEmpty(); |
295 } | 300 } |
296 | 301 |
297 } // namespace blink | 302 } // namespace blink |
OLD | NEW |