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 #include <vector> |
| 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 namespace ProfilerAgentState { | 18 namespace ProfilerAgentState { |
17 static const char samplingInterval[] = "samplingInterval"; | 19 static const char samplingInterval[] = "samplingInterval"; |
18 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; | 20 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; |
19 static const char profilerEnabled[] = "profilerEnabled"; | 21 static const char profilerEnabled[] = "profilerEnabled"; |
20 } | 22 } |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp
ectorObjectForPositionTicks(const v8::CpuProfileNode* node) | 26 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp
ectorObjectForPositionTicks(const v8::CpuProfileNode* node) |
25 { | 27 { |
26 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array
= protocol::Array<protocol::Profiler::PositionTickInfo>::create(); | 28 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array
= protocol::Array<protocol::Profiler::PositionTickInfo>::create(); |
27 unsigned lineCount = node->GetHitLineCount(); | 29 unsigned lineCount = node->GetHitLineCount(); |
28 if (!lineCount) | 30 if (!lineCount) |
29 return array; | 31 return array; |
30 | 32 |
31 protocol::Vector<v8::CpuProfileNode::LineTick> entries(lineCount); | 33 std::vector<v8::CpuProfileNode::LineTick> entries(lineCount); |
32 if (node->GetLineTicks(&entries[0], lineCount)) { | 34 if (node->GetLineTicks(&entries[0], lineCount)) { |
33 for (unsigned i = 0; i < lineCount; i++) { | 35 for (unsigned i = 0; i < lineCount; i++) { |
34 std::unique_ptr<protocol::Profiler::PositionTickInfo> line = protoco
l::Profiler::PositionTickInfo::create() | 36 std::unique_ptr<protocol::Profiler::PositionTickInfo> line = protoco
l::Profiler::PositionTickInfo::create() |
35 .setLine(entries[i].line) | 37 .setLine(entries[i].line) |
36 .setTicks(entries[i].hit_count).build(); | 38 .setTicks(entries[i].hit_count).build(); |
37 array->addItem(std::move(line)); | 39 array->addItem(std::move(line)); |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 return array; | 43 return array; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 135 |
134 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() | 136 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() |
135 { | 137 { |
136 } | 138 } |
137 | 139 |
138 void V8ProfilerAgentImpl::consoleProfile(const String16& title) | 140 void V8ProfilerAgentImpl::consoleProfile(const String16& title) |
139 { | 141 { |
140 if (!m_enabled) | 142 if (!m_enabled) |
141 return; | 143 return; |
142 String16 id = nextProfileId(); | 144 String16 id = nextProfileId(); |
143 m_startedProfiles.append(ProfileDescriptor(id, title)); | 145 m_startedProfiles.push_back(ProfileDescriptor(id, title)); |
144 startProfiling(id); | 146 startProfiling(id); |
145 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->debugge
r()), title); | 147 m_frontend.consoleProfileStarted(id, currentDebugLocation(m_session->debugge
r()), title); |
146 } | 148 } |
147 | 149 |
148 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) | 150 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) |
149 { | 151 { |
150 if (!m_enabled) | 152 if (!m_enabled) |
151 return; | 153 return; |
152 String16 id; | 154 String16 id; |
153 String16 resolvedTitle; | 155 String16 resolvedTitle; |
154 // Take last started profile if no title was passed. | 156 // Take last started profile if no title was passed. |
155 if (title.isEmpty()) { | 157 if (title.isEmpty()) { |
156 if (m_startedProfiles.isEmpty()) | 158 if (m_startedProfiles.empty()) |
157 return; | 159 return; |
158 id = m_startedProfiles.last().m_id; | 160 id = m_startedProfiles.back().m_id; |
159 resolvedTitle = m_startedProfiles.last().m_title; | 161 resolvedTitle = m_startedProfiles.back().m_title; |
160 m_startedProfiles.removeLast(); | 162 m_startedProfiles.pop_back(); |
161 } else { | 163 } else { |
162 for (size_t i = 0; i < m_startedProfiles.size(); i++) { | 164 for (size_t i = 0; i < m_startedProfiles.size(); i++) { |
163 if (m_startedProfiles[i].m_title == title) { | 165 if (m_startedProfiles[i].m_title == title) { |
164 resolvedTitle = title; | 166 resolvedTitle = title; |
165 id = m_startedProfiles[i].m_id; | 167 id = m_startedProfiles[i].m_id; |
166 m_startedProfiles.remove(i); | 168 m_startedProfiles.erase(m_startedProfiles.begin() + i); |
167 break; | 169 break; |
168 } | 170 } |
169 } | 171 } |
170 if (id.isEmpty()) | 172 if (id.isEmpty()) |
171 return; | 173 return; |
172 } | 174 } |
173 std::unique_ptr<protocol::Profiler::CPUProfile> profile = stopProfiling(id,
true); | 175 std::unique_ptr<protocol::Profiler::CPUProfile> profile = stopProfiling(id,
true); |
174 if (!profile) | 176 if (!profile) |
175 return; | 177 return; |
176 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio
n(m_session->debugger()); | 178 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio
n(m_session->debugger()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 return nullptr; | 281 return nullptr; |
280 std::unique_ptr<protocol::Profiler::CPUProfile> result; | 282 std::unique_ptr<protocol::Profiler::CPUProfile> result; |
281 if (serialize) | 283 if (serialize) |
282 result = createCPUProfile(m_isolate, profile); | 284 result = createCPUProfile(m_isolate, profile); |
283 profile->Delete(); | 285 profile->Delete(); |
284 return result; | 286 return result; |
285 } | 287 } |
286 | 288 |
287 bool V8ProfilerAgentImpl::isRecording() const | 289 bool V8ProfilerAgentImpl::isRecording() const |
288 { | 290 { |
289 return m_recordingCPUProfile || !m_startedProfiles.isEmpty(); | 291 return m_recordingCPUProfile || !m_startedProfiles.empty(); |
290 } | 292 } |
291 | 293 |
292 } // namespace blink | 294 } // namespace blink |
OLD | NEW |