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

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

Issue 1907663005: [DevTools] Move v8-related instrumentation from agents to InspectorSession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@1889533002
Patch Set: profiler agent restore starts instrumenting Created 4 years, 8 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"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 class V8ProfilerAgentImpl::ProfileDescriptor { 114 class V8ProfilerAgentImpl::ProfileDescriptor {
115 public: 115 public:
116 ProfileDescriptor(const String16& id, const String16& title) 116 ProfileDescriptor(const String16& id, const String16& title)
117 : m_id(id) 117 : m_id(id)
118 , m_title(title) { } 118 , m_title(title) { }
119 String16 m_id; 119 String16 m_id;
120 String16 m_title; 120 String16 m_title;
121 }; 121 };
122 122
123 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session) 123 V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session)
124 : m_debugger(session->debugger()) 124 : m_session(session)
125 , m_isolate(m_debugger->isolate()) 125 , m_isolate(m_session->debugger()->isolate())
126 , m_state(nullptr) 126 , m_state(nullptr)
127 , m_frontend(nullptr) 127 , m_frontend(nullptr)
128 , m_enabled(false) 128 , m_enabled(false)
129 , m_recordingCPUProfile(false) 129 , m_recordingCPUProfile(false)
130 { 130 {
131 } 131 }
132 132
133 V8ProfilerAgentImpl::~V8ProfilerAgentImpl() 133 V8ProfilerAgentImpl::~V8ProfilerAgentImpl()
134 { 134 {
135 } 135 }
136 136
137 void V8ProfilerAgentImpl::consoleProfile(const String16& title) 137 void V8ProfilerAgentImpl::consoleProfile(const String16& title)
138 { 138 {
139 ASSERT(m_frontend && m_enabled); 139 if (!m_enabled)
140 return;
141 ASSERT(m_frontend);
140 String16 id = nextProfileId(); 142 String16 id = nextProfileId();
141 m_startedProfiles.append(ProfileDescriptor(id, title)); 143 m_startedProfiles.append(ProfileDescriptor(id, title));
142 startProfiling(id); 144 startProfiling(id);
143 m_frontend->consoleProfileStarted(id, currentDebugLocation(m_debugger), titl e); 145 m_frontend->consoleProfileStarted(id, currentDebugLocation(m_session->debugg er()), title);
144 } 146 }
145 147
146 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) 148 void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title)
147 { 149 {
148 ASSERT(m_frontend && m_enabled); 150 if (!m_enabled)
151 return;
152 ASSERT(m_frontend);
149 String16 id; 153 String16 id;
150 String16 resolvedTitle; 154 String16 resolvedTitle;
151 // Take last started profile if no title was passed. 155 // Take last started profile if no title was passed.
152 if (title.isEmpty()) { 156 if (title.isEmpty()) {
153 if (m_startedProfiles.isEmpty()) 157 if (m_startedProfiles.isEmpty())
154 return; 158 return;
155 id = m_startedProfiles.last().m_id; 159 id = m_startedProfiles.last().m_id;
156 resolvedTitle = m_startedProfiles.last().m_title; 160 resolvedTitle = m_startedProfiles.last().m_title;
157 m_startedProfiles.removeLast(); 161 m_startedProfiles.removeLast();
158 } else { 162 } else {
159 for (size_t i = 0; i < m_startedProfiles.size(); i++) { 163 for (size_t i = 0; i < m_startedProfiles.size(); i++) {
160 if (m_startedProfiles[i].m_title == title) { 164 if (m_startedProfiles[i].m_title == title) {
161 resolvedTitle = title; 165 resolvedTitle = title;
162 id = m_startedProfiles[i].m_id; 166 id = m_startedProfiles[i].m_id;
163 m_startedProfiles.remove(i); 167 m_startedProfiles.remove(i);
164 break; 168 break;
165 } 169 }
166 } 170 }
167 if (id.isEmpty()) 171 if (id.isEmpty())
168 return; 172 return;
169 } 173 }
170 OwnPtr<protocol::Profiler::CPUProfile> profile = stopProfiling(id, true); 174 OwnPtr<protocol::Profiler::CPUProfile> profile = stopProfiling(id, true);
171 if (!profile) 175 if (!profile)
172 return; 176 return;
173 OwnPtr<protocol::Debugger::Location> location = currentDebugLocation(m_debug ger); 177 OwnPtr<protocol::Debugger::Location> location = currentDebugLocation(m_sessi on->debugger());
174 m_frontend->consoleProfileFinished(id, location.release(), profile.release() , resolvedTitle); 178 m_frontend->consoleProfileFinished(id, location.release(), profile.release() , resolvedTitle);
175 } 179 }
176 180
177 void V8ProfilerAgentImpl::enable(ErrorString*) 181 void V8ProfilerAgentImpl::enable(ErrorString*)
178 { 182 {
183 if (m_enabled)
184 return;
179 m_enabled = true; 185 m_enabled = true;
186 m_session->changeInstrumentationCounter(+1);
180 } 187 }
181 188
182 void V8ProfilerAgentImpl::disable(ErrorString* errorString) 189 void V8ProfilerAgentImpl::disable(ErrorString* errorString)
183 { 190 {
191 if (!m_enabled)
192 return;
193 m_session->changeInstrumentationCounter(-1);
184 for (size_t i = m_startedProfiles.size(); i > 0; --i) 194 for (size_t i = m_startedProfiles.size(); i > 0; --i)
185 stopProfiling(m_startedProfiles[i - 1].m_id, false); 195 stopProfiling(m_startedProfiles[i - 1].m_id, false);
186 m_startedProfiles.clear(); 196 m_startedProfiles.clear();
187 stop(nullptr, nullptr); 197 stop(nullptr, nullptr);
188 m_enabled = false; 198 m_enabled = false;
189 } 199 }
190 200
191 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval) 201 void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error, int interval)
192 { 202 {
193 if (m_recordingCPUProfile) { 203 if (m_recordingCPUProfile) {
194 *error = "Cannot change sampling interval when profiling."; 204 *error = "Cannot change sampling interval when profiling.";
195 return; 205 return;
196 } 206 }
197 m_state->setNumber(ProfilerAgentState::samplingInterval, interval); 207 m_state->setNumber(ProfilerAgentState::samplingInterval, interval);
198 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); 208 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval);
199 } 209 }
200 210
201 void V8ProfilerAgentImpl::clearFrontend() 211 void V8ProfilerAgentImpl::clearFrontend()
202 { 212 {
203 ErrorString error; 213 ErrorString error;
204 disable(&error); 214 disable(&error);
205 ASSERT(m_frontend); 215 ASSERT(m_frontend);
206 m_frontend = nullptr; 216 m_frontend = nullptr;
207 } 217 }
208 218
209 void V8ProfilerAgentImpl::restore() 219 void V8ProfilerAgentImpl::restore()
210 { 220 {
221 ASSERT(!m_enabled);
211 m_enabled = true; 222 m_enabled = true;
223 m_session->changeInstrumentationCounter(+1);
212 int interval = 0; 224 int interval = 0;
213 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); 225 m_state->getNumber(ProfilerAgentState::samplingInterval, &interval);
214 if (interval) 226 if (interval)
215 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval); 227 m_isolate->GetCpuProfiler()->SetSamplingInterval(interval);
216 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal se)) { 228 if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling, fal se)) {
217 ErrorString error; 229 ErrorString error;
218 start(&error); 230 start(&error);
219 } 231 }
220 } 232 }
221 233
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 300 }
289 301
290 void V8ProfilerAgentImpl::idleStarted() 302 void V8ProfilerAgentImpl::idleStarted()
291 { 303 {
292 if (!isRecording()) 304 if (!isRecording())
293 return; 305 return;
294 m_isolate->GetCpuProfiler()->SetIdle(true); 306 m_isolate->GetCpuProfiler()->SetIdle(true);
295 } 307 }
296 308
297 } // namespace blink 309 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698