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

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

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing 2 Created 4 years, 9 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/V8StackTraceImpl.h" 9 #include "platform/v8_inspector/V8StackTraceImpl.h"
10 #include "platform/v8_inspector/V8StringUtil.h" 10 #include "platform/v8_inspector/V8StringUtil.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 OwnPtr<protocol::Array<protocol::Profiler::CPUProfileNode>> children = proto col::Array<protocol::Profiler::CPUProfileNode>::create(); 46 OwnPtr<protocol::Array<protocol::Profiler::CPUProfileNode>> children = proto col::Array<protocol::Profiler::CPUProfileNode>::create();
47 const int childrenCount = node->GetChildrenCount(); 47 const int childrenCount = node->GetChildrenCount();
48 for (int i = 0; i < childrenCount; i++) { 48 for (int i = 0; i < childrenCount; i++) {
49 const v8::CpuProfileNode* child = node->GetChild(i); 49 const v8::CpuProfileNode* child = node->GetChild(i);
50 children->addItem(buildInspectorObjectFor(isolate, child)); 50 children->addItem(buildInspectorObjectFor(isolate, child));
51 } 51 }
52 52
53 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> positionTicks = buildInspectorObjectForPositionTicks(node); 53 OwnPtr<protocol::Array<protocol::Profiler::PositionTickInfo>> positionTicks = buildInspectorObjectForPositionTicks(node);
54 54
55 OwnPtr<protocol::Profiler::CPUProfileNode> result = protocol::Profiler::CPUP rofileNode::create() 55 OwnPtr<protocol::Profiler::CPUProfileNode> result = protocol::Profiler::CPUP rofileNode::create()
56 .setFunctionName(toWTFString(node->GetFunctionName())) 56 .setFunctionName(toProtocolString(node->GetFunctionName()))
57 .setScriptId(String::number(node->GetScriptId())) 57 .setScriptId(String16::number(node->GetScriptId()))
58 .setUrl(toWTFString(node->GetScriptResourceName())) 58 .setUrl(toProtocolString(node->GetScriptResourceName()))
59 .setLineNumber(node->GetLineNumber()) 59 .setLineNumber(node->GetLineNumber())
60 .setColumnNumber(node->GetColumnNumber()) 60 .setColumnNumber(node->GetColumnNumber())
61 .setHitCount(node->GetHitCount()) 61 .setHitCount(node->GetHitCount())
62 .setCallUID(node->GetCallUid()) 62 .setCallUID(node->GetCallUid())
63 .setChildren(children.release()) 63 .setChildren(children.release())
64 .setPositionTicks(positionTicks.release()) 64 .setPositionTicks(positionTicks.release())
65 .setDeoptReason(node->GetBailoutReason()) 65 .setDeoptReason(node->GetBailoutReason())
66 .setId(node->GetNodeId()).build(); 66 .setId(node->GetNodeId()).build();
67 return result.release(); 67 return result.release();
68 } 68 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 location->setColumnNumber(callStack->topColumnNumber()); 105 location->setColumnNumber(callStack->topColumnNumber());
106 return location.release(); 106 return location.release();
107 } 107 }
108 108
109 volatile int s_lastProfileId = 0; 109 volatile int s_lastProfileId = 0;
110 110
111 } // namespace 111 } // namespace
112 112
113 class V8ProfilerAgentImpl::ProfileDescriptor { 113 class V8ProfilerAgentImpl::ProfileDescriptor {
114 public: 114 public:
115 ProfileDescriptor(const String& id, const String& title) 115 ProfileDescriptor(const String16& id, const String16& title)
116 : m_id(id) 116 : m_id(id)
117 , m_title(title) { } 117 , m_title(title) { }
118 String m_id; 118 String16 m_id;
119 String m_title; 119 String16 m_title;
120 }; 120 };
121 121
122 PassOwnPtr<V8ProfilerAgent> V8ProfilerAgent::create(V8Debugger* debugger) 122 PassOwnPtr<V8ProfilerAgent> V8ProfilerAgent::create(V8Debugger* debugger)
123 { 123 {
124 return adoptPtr(new V8ProfilerAgentImpl(debugger)); 124 return adoptPtr(new V8ProfilerAgentImpl(debugger));
125 } 125 }
126 126
127 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8Debugger* debugger) 127 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8Debugger* debugger)
128 : m_debugger(static_cast<V8DebuggerImpl*>(debugger)) 128 : m_debugger(static_cast<V8DebuggerImpl*>(debugger))
129 , m_isolate(m_debugger->isolate()) 129 , m_isolate(m_debugger->isolate())
130 , m_state(nullptr) 130 , m_state(nullptr)
131 , m_frontend(nullptr) 131 , m_frontend(nullptr)
132 , m_enabled(false) 132 , m_enabled(false)
133 , m_recordingCPUProfile(false) 133 , m_recordingCPUProfile(false)
134 { 134 {
135 } 135 }
136 136
137 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() 137 V8ProfilerAgentImpl::~V8ProfilerAgentImpl()
138 { 138 {
139 } 139 }
140 140
141 void V8ProfilerAgentImpl::consoleProfile(const String& title) 141 void V8ProfilerAgentImpl::consoleProfile(const String16& title)
142 { 142 {
143 ASSERT(m_frontend && m_enabled); 143 ASSERT(m_frontend && m_enabled);
144 String id = nextProfileId(); 144 String16 id = nextProfileId();
145 m_startedProfiles.append(ProfileDescriptor(id, title)); 145 m_startedProfiles.append(ProfileDescriptor(id, title));
146 startProfiling(id); 146 startProfiling(id);
147 m_frontend->consoleProfileStarted(id, currentDebugLocation(m_debugger), titl e); 147 m_frontend->consoleProfileStarted(id, currentDebugLocation(m_debugger), titl e);
148 } 148 }
149 149
150 void V8ProfilerAgentImpl::consoleProfileEnd(const String& title) 150 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title)
151 { 151 {
152 ASSERT(m_frontend && m_enabled); 152 ASSERT(m_frontend && m_enabled);
153 String id; 153 String16 id;
154 String resolvedTitle; 154 String16 resolvedTitle;
155 // Take last started profile if no title was passed. 155 // Take last started profile if no title was passed.
156 if (title.isNull()) { 156 if (title.isNull()) {
157 if (m_startedProfiles.isEmpty()) 157 if (m_startedProfiles.isEmpty())
158 return; 158 return;
159 id = m_startedProfiles.last().m_id; 159 id = m_startedProfiles.last().m_id;
160 resolvedTitle = m_startedProfiles.last().m_title; 160 resolvedTitle = m_startedProfiles.last().m_title;
161 m_startedProfiles.removeLast(); 161 m_startedProfiles.removeLast();
162 } else { 162 } else {
163 for (size_t i = 0; i < m_startedProfiles.size(); i++) { 163 for (size_t i = 0; i < m_startedProfiles.size(); i++) {
164 if (m_startedProfiles[i].m_title == title) { 164 if (m_startedProfiles[i].m_title == title) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 *errorString = "No recording profiles found"; 244 *errorString = "No recording profiles found";
245 return; 245 return;
246 } 246 }
247 m_recordingCPUProfile = false; 247 m_recordingCPUProfile = false;
248 OwnPtr<protocol::Profiler::CPUProfile> cpuProfile = stopProfiling(m_frontend InitiatedProfileId, !!profile); 248 OwnPtr<protocol::Profiler::CPUProfile> cpuProfile = stopProfiling(m_frontend InitiatedProfileId, !!profile);
249 if (profile) { 249 if (profile) {
250 *profile = cpuProfile.release(); 250 *profile = cpuProfile.release();
251 if (!profile->get() && errorString) 251 if (!profile->get() && errorString)
252 *errorString = "Profile is not found"; 252 *errorString = "Profile is not found";
253 } 253 }
254 m_frontendInitiatedProfileId = String(); 254 m_frontendInitiatedProfileId = String16();
255 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false); 255 m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false);
256 } 256 }
257 257
258 String V8ProfilerAgentImpl::nextProfileId() 258 String16 V8ProfilerAgentImpl::nextProfileId()
259 { 259 {
260 return String::number(atomicIncrement(&s_lastProfileId)); 260 return String16::number(atomicIncrement(&s_lastProfileId));
261 } 261 }
262 262
263 void V8ProfilerAgentImpl::startProfiling(const String& title) 263 void V8ProfilerAgentImpl::startProfiling(const String16& title)
264 { 264 {
265 v8::HandleScope handleScope(m_isolate); 265 v8::HandleScope handleScope(m_isolate);
266 m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), tr ue); 266 m_isolate->GetCpuProfiler()->StartProfiling(toV8String(m_isolate, title), tr ue);
267 } 267 }
268 268
269 PassOwnPtr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(co nst String& title, bool serialize) 269 PassOwnPtr<protocol::Profiler::CPUProfile> V8ProfilerAgentImpl::stopProfiling(co nst String16& title, bool serialize)
270 { 270 {
271 v8::HandleScope handleScope(m_isolate); 271 v8::HandleScope handleScope(m_isolate);
272 v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8Str ing(m_isolate, title)); 272 v8::CpuProfile* profile = m_isolate->GetCpuProfiler()->StopProfiling(toV8Str ing(m_isolate, title));
273 if (!profile) 273 if (!profile)
274 return nullptr; 274 return nullptr;
275 OwnPtr<protocol::Profiler::CPUProfile> result; 275 OwnPtr<protocol::Profiler::CPUProfile> result;
276 if (serialize) 276 if (serialize)
277 result = createCPUProfile(m_isolate, profile); 277 result = createCPUProfile(m_isolate, profile);
278 profile->Delete(); 278 profile->Delete();
279 return result.release(); 279 return result.release();
(...skipping 12 matching lines...) Expand all
292 } 292 }
293 293
294 void V8ProfilerAgentImpl::idleStarted() 294 void V8ProfilerAgentImpl::idleStarted()
295 { 295 {
296 if (!isRecording()) 296 if (!isRecording())
297 return; 297 return;
298 m_isolate->GetCpuProfiler()->SetIdle(true); 298 m_isolate->GetCpuProfiler()->SetIdle(true);
299 } 299 }
300 300
301 } // namespace blink 301 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698