| 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/V8InspectorImpl.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 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #define ENSURE_V8_VERSION(major, minor) \ | 16 #define ENSURE_V8_VERSION(major, minor) \ |
| 17 (V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= (major) * 1000 + (minor)) | 17 (V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= (major) * 1000 + (minor)) |
| 18 | 18 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 { | 98 { |
| 99 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() | 99 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() |
| 100 .setHead(buildInspectorObjectFor(isolate, v8profile->GetTopDownRoot())) | 100 .setHead(buildInspectorObjectFor(isolate, v8profile->GetTopDownRoot())) |
| 101 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) | 101 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) |
| 102 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil
d(); | 102 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil
d(); |
| 103 profile->setSamples(buildInspectorObjectForSamples(v8profile)); | 103 profile->setSamples(buildInspectorObjectForSamples(v8profile)); |
| 104 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); | 104 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); |
| 105 return profile; | 105 return profile; |
| 106 } | 106 } |
| 107 | 107 |
| 108 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8DebuggerImp
l* debugger) | 108 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) |
| 109 { | 109 { |
| 110 std::unique_ptr<V8StackTrace> callStack = debugger->captureStackTrace(1); | 110 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); |
| 111 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger:
:Location::create() | 111 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger:
:Location::create() |
| 112 .setScriptId(callStack->topScriptId()) | 112 .setScriptId(callStack->topScriptId()) |
| 113 .setLineNumber(callStack->topLineNumber()).build(); | 113 .setLineNumber(callStack->topLineNumber()).build(); |
| 114 location->setColumnNumber(callStack->topColumnNumber()); | 114 location->setColumnNumber(callStack->topColumnNumber()); |
| 115 return location; | 115 return location; |
| 116 } | 116 } |
| 117 | 117 |
| 118 volatile int s_lastProfileId = 0; | 118 volatile int s_lastProfileId = 0; |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 class V8ProfilerAgentImpl::ProfileDescriptor { | 122 class V8ProfilerAgentImpl::ProfileDescriptor { |
| 123 public: | 123 public: |
| 124 ProfileDescriptor(const String16& id, const String16& title) | 124 ProfileDescriptor(const String16& id, const String16& title) |
| 125 : m_id(id) | 125 : m_id(id) |
| 126 , m_title(title) { } | 126 , m_title(title) { } |
| 127 String16 m_id; | 127 String16 m_id; |
| 128 String16 m_title; | 128 String16 m_title; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc
ol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) | 131 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session, protoc
ol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) |
| 132 : m_session(session) | 132 : m_session(session) |
| 133 , m_isolate(m_session->debugger()->isolate()) | 133 , m_isolate(m_session->inspector()->isolate()) |
| 134 , m_profiler(nullptr) | 134 , m_profiler(nullptr) |
| 135 , m_state(state) | 135 , m_state(state) |
| 136 , m_frontend(frontendChannel) | 136 , m_frontend(frontendChannel) |
| 137 , m_enabled(false) | 137 , m_enabled(false) |
| 138 , m_recordingCPUProfile(false) | 138 , m_recordingCPUProfile(false) |
| 139 { | 139 { |
| 140 } | 140 } |
| 141 | 141 |
| 142 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() | 142 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() |
| 143 { | 143 { |
| 144 #if ENSURE_V8_VERSION(5, 4) | 144 #if ENSURE_V8_VERSION(5, 4) |
| 145 if (m_profiler) | 145 if (m_profiler) |
| 146 m_profiler->Dispose(); | 146 m_profiler->Dispose(); |
| 147 #endif | 147 #endif |
| 148 } | 148 } |
| 149 | 149 |
| 150 void V8ProfilerAgentImpl::consoleProfile(const String16& title) | 150 void V8ProfilerAgentImpl::consoleProfile(const String16& title) |
| 151 { | 151 { |
| 152 if (!m_enabled) | 152 if (!m_enabled) |
| 153 return; | 153 return; |
| 154 String16 id = nextProfileId(); | 154 String16 id = nextProfileId(); |
| 155 m_startedProfiles.push_back(ProfileDescriptor(id, title)); | 155 m_startedProfiles.push_back(ProfileDescriptor(id, title)); |
| 156 startProfiling(id); | 156 startProfiling(id); |
| 157 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->debugge
r()), title); | 157 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->inspect
or()), title); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) | 160 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) |
| 161 { | 161 { |
| 162 if (!m_enabled) | 162 if (!m_enabled) |
| 163 return; | 163 return; |
| 164 String16 id; | 164 String16 id; |
| 165 String16 resolvedTitle; | 165 String16 resolvedTitle; |
| 166 // Take last started profile if no title was passed. | 166 // Take last started profile if no title was passed. |
| 167 if (title.isEmpty()) { | 167 if (title.isEmpty()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 178 m_startedProfiles.erase(m_startedProfiles.begin() + i); | 178 m_startedProfiles.erase(m_startedProfiles.begin() + i); |
| 179 break; | 179 break; |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 if (id.isEmpty()) | 182 if (id.isEmpty()) |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 std::unique_ptr<protocol::Profiler::CPUProfile> profile = stopProfiling(id,
true); | 185 std::unique_ptr<protocol::Profiler::CPUProfile> profile = stopProfiling(id,
true); |
| 186 if (!profile) | 186 if (!profile) |
| 187 return; | 187 return; |
| 188 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio
n(m_session->debugger()); | 188 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio
n(m_session->inspector()); |
| 189 m_frontend.consoleProfileFinished(id, std::move(location), std::move(profile
), resolvedTitle); | 189 m_frontend.consoleProfileFinished(id, std::move(location), std::move(profile
), resolvedTitle); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void V8ProfilerAgentImpl::enable(ErrorString*) | 192 void V8ProfilerAgentImpl::enable(ErrorString*) |
| 193 { | 193 { |
| 194 if (m_enabled) | 194 if (m_enabled) |
| 195 return; | 195 return; |
| 196 m_enabled = true; | 196 m_enabled = true; |
| 197 #if ENSURE_V8_VERSION(5, 4) | 197 #if ENSURE_V8_VERSION(5, 4) |
| 198 DCHECK(!m_profiler); | 198 DCHECK(!m_profiler); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() | 311 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() |
| 312 { | 312 { |
| 313 #if ENSURE_V8_VERSION(5, 4) | 313 #if ENSURE_V8_VERSION(5, 4) |
| 314 return m_profiler; | 314 return m_profiler; |
| 315 #else | 315 #else |
| 316 return m_isolate->GetCpuProfiler(); | 316 return m_isolate->GetCpuProfiler(); |
| 317 #endif | 317 #endif |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace blink | 320 } // namespace blink |
| OLD | NEW |