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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 6 months 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
OLDNEW
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 static const char profilerEnabled[] = "profilerEnabled";
20 } 20 }
21 21
22 namespace { 22 namespace {
23 23
24 PassOwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInspector ObjectForPositionTicks(const v8::CpuProfileNode* node) 24 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp ectorObjectForPositionTicks(const v8::CpuProfileNode* node)
25 { 25 {
26 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protoc ol::Array<protocol::Profiler::PositionTickInfo>::create(); 26 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protocol::Array<protocol::Profiler::PositionTickInfo>::create();
27 unsigned lineCount = node->GetHitLineCount(); 27 unsigned lineCount = node->GetHitLineCount();
28 if (!lineCount) 28 if (!lineCount)
29 return array; 29 return array;
30 30
31 protocol::Vector<v8::CpuProfileNode::LineTick> entries(lineCount); 31 protocol::Vector<v8::CpuProfileNode::LineTick> entries(lineCount);
32 if (node->GetLineTicks(&entries[0], lineCount)) { 32 if (node->GetLineTicks(&entries[0], lineCount)) {
33 for (unsigned i = 0; i < lineCount; i++) { 33 for (unsigned i = 0; i < lineCount; i++) {
34 OwnPtr<protocol::Profiler::PositionTickInfo> line = protocol::Profil er::PositionTickInfo::create() 34 std::unique_ptr<protocol::Profiler::PositionTickInfo> line = protoco l::Profiler::PositionTickInfo::create()
35 .setLine(entries[i].line) 35 .setLine(entries[i].line)
36 .setTicks(entries[i].hit_count).build(); 36 .setTicks(entries[i].hit_count).build();
37 array->addItem(std::move(line)); 37 array->addItem(std::move(line));
38 } 38 }
39 } 39 }
40 40
41 return array; 41 return array;
42 } 42 }
43 43
44 PassOwnPtr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::Isola te* isolate, const v8::CpuProfileNode* node) 44 std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8:: Isolate* isolate, const v8::CpuProfileNode* node)
45 { 45 {
46 v8::HandleScope handleScope(isolate); 46 v8::HandleScope handleScope(isolate);
47 47
48 OwnPtr<protocol::Array<protocol::Profiler::CPUProfileNode>> children = proto col::Array<protocol::Profiler::CPUProfileNode>::create(); 48 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> childre n = protocol::Array<protocol::Profiler::CPUProfileNode>::create();
49 const int childrenCount = node->GetChildrenCount(); 49 const int childrenCount = node->GetChildrenCount();
50 for (int i = 0; i < childrenCount; i++) { 50 for (int i = 0; i < childrenCount; i++) {
51 const v8::CpuProfileNode* child = node->GetChild(i); 51 const v8::CpuProfileNode* child = node->GetChild(i);
52 children->addItem(buildInspectorObjectFor(isolate, child)); 52 children->addItem(buildInspectorObjectFor(isolate, child));
53 } 53 }
54 54
55 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> positionTicks = buildInspectorObjectForPositionTicks(node); 55 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> posit ionTicks = buildInspectorObjectForPositionTicks(node);
56 56
57 OwnPtr<protocol::Profiler::CPUProfileNode> result = protocol::Profiler::CPUP rofileNode::create() 57 std::unique_ptr<protocol::Profiler::CPUProfileNode> result = protocol::Profi ler::CPUProfileNode::create()
58 .setFunctionName(toProtocolString(node->GetFunctionName())) 58 .setFunctionName(toProtocolString(node->GetFunctionName()))
59 .setScriptId(String16::number(node->GetScriptId())) 59 .setScriptId(String16::number(node->GetScriptId()))
60 .setUrl(toProtocolString(node->GetScriptResourceName())) 60 .setUrl(toProtocolString(node->GetScriptResourceName()))
61 .setLineNumber(node->GetLineNumber()) 61 .setLineNumber(node->GetLineNumber())
62 .setColumnNumber(node->GetColumnNumber()) 62 .setColumnNumber(node->GetColumnNumber())
63 .setHitCount(node->GetHitCount()) 63 .setHitCount(node->GetHitCount())
64 .setCallUID(node->GetCallUid()) 64 .setCallUID(node->GetCallUid())
65 .setChildren(std::move(children)) 65 .setChildren(std::move(children))
66 .setPositionTicks(std::move(positionTicks)) 66 .setPositionTicks(std::move(positionTicks))
67 .setDeoptReason(node->GetBailoutReason()) 67 .setDeoptReason(node->GetBailoutReason())
68 .setId(node->GetNodeId()).build(); 68 .setId(node->GetNodeId()).build();
69 return result; 69 return result;
70 } 70 }
71 71
72 PassOwnPtr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProfile* v8profile) 72 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf ile* v8profile)
73 { 73 {
74 OwnPtr<protocol::Array<int>> array = protocol::Array<int>::create(); 74 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create() ;
75 int count = v8profile->GetSamplesCount(); 75 int count = v8profile->GetSamplesCount();
76 for (int i = 0; i < count; i++) 76 for (int i = 0; i < count; i++)
77 array->addItem(v8profile->GetSample(i)->GetNodeId()); 77 array->addItem(v8profile->GetSample(i)->GetNodeId());
78 return array; 78 return array;
79 } 79 }
80 80
81 PassOwnPtr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::CpuPro file* v8profile) 81 std::unique_ptr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::C puProfile* v8profile)
82 { 82 {
83 OwnPtr<protocol::Array<double>> array = protocol::Array<double>::create(); 83 std::unique_ptr<protocol::Array<double>> array = protocol::Array<double>::cr eate();
84 int count = v8profile->GetSamplesCount(); 84 int count = v8profile->GetSamplesCount();
85 for (int i = 0; i < count; i++) 85 for (int i = 0; i < count; i++)
86 array->addItem(v8profile->GetSampleTimestamp(i)); 86 array->addItem(v8profile->GetSampleTimestamp(i));
87 return array; 87 return array;
88 } 88 }
89 89
90 PassOwnPtr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* isolate , v8::CpuProfile* v8profile) 90 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is olate, v8::CpuProfile* v8profile)
91 { 91 {
92 OwnPtr<protocol::Profiler::CPUProfile> profile = protocol::Profiler::CPUProf ile::create() 92 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler ::CPUProfile::create()
93 .setHead(buildInspectorObjectFor(isolate, v8profile->GetTopDownRoot())) 93 .setHead(buildInspectorObjectFor(isolate, v8profile->GetTopDownRoot()))
94 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) 94 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000)
95 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil d(); 95 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil d();
96 profile->setSamples(buildInspectorObjectForSamples(v8profile)); 96 profile->setSamples(buildInspectorObjectForSamples(v8profile));
97 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); 97 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile));
98 return profile; 98 return profile;
99 } 99 }
100 100
101 PassOwnPtr<protocol::Debugger::Location> currentDebugLocation(V8DebuggerImpl* de bugger) 101 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8DebuggerImp l* debugger)
102 { 102 {
103 OwnPtr<V8StackTrace> callStack = debugger->captureStackTrace(1); 103 std::unique_ptr<V8StackTrace> callStack = debugger->captureStackTrace(1);
104 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create() 104 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger: :Location::create()
105 .setScriptId(callStack->topScriptId()) 105 .setScriptId(callStack->topScriptId())
106 .setLineNumber(callStack->topLineNumber()).build(); 106 .setLineNumber(callStack->topLineNumber()).build();
107 location->setColumnNumber(callStack->topColumnNumber()); 107 location->setColumnNumber(callStack->topColumnNumber());
108 return location; 108 return location;
109 } 109 }
110 110
111 volatile int s_lastProfileId = 0; 111 volatile int s_lastProfileId = 0;
112 112
113 } // namespace 113 } // namespace
114 114
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (m_startedProfiles[i].m_title == title) { 165 if (m_startedProfiles[i].m_title == title) {
166 resolvedTitle = title; 166 resolvedTitle = title;
167 id = m_startedProfiles[i].m_id; 167 id = m_startedProfiles[i].m_id;
168 m_startedProfiles.remove(i); 168 m_startedProfiles.remove(i);
169 break; 169 break;
170 } 170 }
171 } 171 }
172 if (id.isEmpty()) 172 if (id.isEmpty())
173 return; 173 return;
174 } 174 }
175 OwnPtr<protocol::Profiler::CPUProfile> profile = stopProfiling(id, true); 175 std::unique_ptr<protocol::Profiler::CPUProfile> profile = stopProfiling(id, true);
176 if (!profile) 176 if (!profile)
177 return; 177 return;
178 OwnPtr<protocol::Debugger::Location> location = currentDebugLocation(m_sessi on->debugger()); 178 std::unique_ptr<protocol::Debugger::Location> location = currentDebugLocatio n(m_session->debugger());
179 m_frontend->consoleProfileFinished(id, std::move(location), std::move(profil e), resolvedTitle); 179 m_frontend->consoleProfileFinished(id, std::move(location), std::move(profil e), resolvedTitle);
180 } 180 }
181 181
182 void V8ProfilerAgentImpl::enable(ErrorString*) 182 void V8ProfilerAgentImpl::enable(ErrorString*)
183 { 183 {
184 if (m_enabled) 184 if (m_enabled)
185 return; 185 return;
186 m_enabled = true; 186 m_enabled = true;
187 m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); 187 m_state->setBoolean(ProfilerAgentState::profilerEnabled, true);
188 m_session->changeInstrumentationCounter(+1); 188 m_session->changeInstrumentationCounter(+1);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 *error = "Profiler is not enabled"; 236 *error = "Profiler is not enabled";
237 return; 237 return;
238 } 238 }
239 m_recordingCPUProfile = true; 239 m_recordingCPUProfile = true;
240 m_frontendInitiatedProfileId = nextProfileId(); 240 m_frontendInitiatedProfileId = nextProfileId();
241 startProfiling(m_frontendInitiatedProfileId); 241 startProfiling(m_frontendInitiatedProfileId);
242 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true); 242 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true);
243 m_session->client()->profilingStarted(); 243 m_session->client()->profilingStarted();
244 } 244 }
245 245
246 void V8ProfilerAgentImpl::stop(ErrorString* errorString, OwnPtr<protocol::Profil er::CPUProfile>* profile) 246 void V8ProfilerAgentImpl::stop(ErrorString* errorString, std::unique_ptr<protoco l::Profiler::CPUProfile>* profile)
247 { 247 {
248 if (!m_recordingCPUProfile) { 248 if (!m_recordingCPUProfile) {
249 if (errorString) 249 if (errorString)
250 *errorString = "No recording profiles found"; 250 *errorString = "No recording profiles found";
251 return; 251 return;
252 } 252 }
253 m_recordingCPUProfile = false; 253 m_recordingCPUProfile = false;
254 OwnPtr<protocol::Profiler::CPUProfile> cpuProfile = stopProfiling(m_frontend InitiatedProfileId, !!profile); 254 std::unique_ptr<protocol::Profiler::CPUProfile> cpuProfile = stopProfiling(m _frontendInitiatedProfileId, !!profile);
255 if (profile) { 255 if (profile) {
256 *profile = std::move(cpuProfile); 256 *profile = std::move(cpuProfile);
257 if (!profile->get() && errorString) 257 if (!profile->get() && errorString)
258 *errorString = "Profile is not found"; 258 *errorString = "Profile is not found";
259 } 259 }
260 m_frontendInitiatedProfileId = String16(); 260 m_frontendInitiatedProfileId = String16();
261 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false); 261 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false);
262 m_session->client()->profilingStopped(); 262 m_session->client()->profilingStopped();
263 } 263 }
264 264
265 String16 V8ProfilerAgentImpl::nextProfileId() 265 String16 V8ProfilerAgentImpl::nextProfileId()
266 { 266 {
267 return String16::number(atomicIncrement(&s_lastProfileId)); 267 return String16::number(atomicIncrement(&s_lastProfileId));
268 } 268 }
269 269
270 void V8ProfilerAgentImpl::startProfiling(const String16& title) 270 void V8ProfilerAgentImpl::startProfiling(const String16& title)
271 { 271 {
272 v8::HandleScope handleScope(m_isolate); 272 v8::HandleScope handleScope(m_isolate);
273 m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), tr ue); 273 m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), tr ue);
274 } 274 }
275 275
276 PassOwnPtr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(co nst String16& title, bool serialize) 276 std::unique_ptr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfili ng(const String16& title, bool serialize)
277 { 277 {
278 v8::HandleScope handleScope(m_isolate); 278 v8::HandleScope handleScope(m_isolate);
279 v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8Str ing(m_isolate, title)); 279 v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8Str ing(m_isolate, title));
280 if (!profile) 280 if (!profile)
281 return nullptr; 281 return nullptr;
282 OwnPtr<protocol::Profiler::CPUProfile> result; 282 std::unique_ptr<protocol::Profiler::CPUProfile> result;
283 if (serialize) 283 if (serialize)
284 result = createCPUProfile(m_isolate, profile); 284 result = createCPUProfile(m_isolate, profile);
285 profile->Delete(); 285 profile->Delete();
286 return result; 286 return result;
287 } 287 }
288 288
289 bool V8ProfilerAgentImpl::isRecording() const 289 bool V8ProfilerAgentImpl::isRecording() const
290 { 290 {
291 return m_recordingCPUProfile || !m_startedProfiles.isEmpty(); 291 return m_recordingCPUProfile || !m_startedProfiles.isEmpty();
292 } 292 }
293 293
294 } // namespace blink 294 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698