| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project 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 "src/inspector/v8-profiler-agent-impl.h" | 5 #include "src/inspector/v8-profiler-agent-impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "src/base/atomicops.h" | 9 #include "src/base/atomicops.h" |
| 10 #include "src/inspector/protocol/Protocol.h" | 10 #include "src/inspector/protocol/Protocol.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 String16 V8ProfilerAgentImpl::nextProfileId() { | 365 String16 V8ProfilerAgentImpl::nextProfileId() { |
| 366 return String16::fromInteger( | 366 return String16::fromInteger( |
| 367 v8::base::Relaxed_AtomicIncrement(&s_lastProfileId, 1)); | 367 v8::base::Relaxed_AtomicIncrement(&s_lastProfileId, 1)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void V8ProfilerAgentImpl::startProfiling(const String16& title) { | 370 void V8ProfilerAgentImpl::startProfiling(const String16& title) { |
| 371 v8::HandleScope handleScope(m_isolate); | 371 v8::HandleScope handleScope(m_isolate); |
| 372 if (!m_startedProfilesCount) { | 372 if (!m_startedProfilesCount) { |
| 373 DCHECK(!m_profiler); | 373 DCHECK(!m_profiler); |
| 374 m_profiler = v8::CpuProfiler::New(m_isolate); | 374 m_profiler = v8::CpuProfiler::New(m_isolate); |
| 375 m_profiler->SetIdle(m_idle); | |
| 376 int interval = | 375 int interval = |
| 377 m_state->integerProperty(ProfilerAgentState::samplingInterval, 0); | 376 m_state->integerProperty(ProfilerAgentState::samplingInterval, 0); |
| 378 if (interval) m_profiler->SetSamplingInterval(interval); | 377 if (interval) m_profiler->SetSamplingInterval(interval); |
| 379 } | 378 } |
| 380 ++m_startedProfilesCount; | 379 ++m_startedProfilesCount; |
| 381 m_profiler->StartProfiling(toV8String(m_isolate, title), true); | 380 m_profiler->StartProfiling(toV8String(m_isolate, title), true); |
| 382 } | 381 } |
| 383 | 382 |
| 384 std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling( | 383 std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling( |
| 385 const String16& title, bool serialize) { | 384 const String16& title, bool serialize) { |
| 386 v8::HandleScope handleScope(m_isolate); | 385 v8::HandleScope handleScope(m_isolate); |
| 387 v8::CpuProfile* profile = | 386 v8::CpuProfile* profile = |
| 388 m_profiler->StopProfiling(toV8String(m_isolate, title)); | 387 m_profiler->StopProfiling(toV8String(m_isolate, title)); |
| 389 std::unique_ptr<protocol::Profiler::Profile> result; | 388 std::unique_ptr<protocol::Profiler::Profile> result; |
| 390 if (profile) { | 389 if (profile) { |
| 391 if (serialize) result = createCPUProfile(m_isolate, profile); | 390 if (serialize) result = createCPUProfile(m_isolate, profile); |
| 392 profile->Delete(); | 391 profile->Delete(); |
| 393 } | 392 } |
| 394 --m_startedProfilesCount; | 393 --m_startedProfilesCount; |
| 395 if (!m_startedProfilesCount) { | 394 if (!m_startedProfilesCount) { |
| 396 m_profiler->Dispose(); | 395 m_profiler->Dispose(); |
| 397 m_profiler = nullptr; | 396 m_profiler = nullptr; |
| 398 } | 397 } |
| 399 return result; | 398 return result; |
| 400 } | 399 } |
| 401 | 400 |
| 402 bool V8ProfilerAgentImpl::idleStarted() { | |
| 403 m_idle = true; | |
| 404 if (m_profiler) m_profiler->SetIdle(m_idle); | |
| 405 return m_profiler; | |
| 406 } | |
| 407 | |
| 408 bool V8ProfilerAgentImpl::idleFinished() { | |
| 409 m_idle = false; | |
| 410 if (m_profiler) m_profiler->SetIdle(m_idle); | |
| 411 return m_profiler; | |
| 412 } | |
| 413 | |
| 414 } // namespace v8_inspector | 401 } // namespace v8_inspector |
| OLD | NEW |