OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "core/inspector/InspectorPageAgent.h" | 41 #include "core/inspector/InspectorPageAgent.h" |
42 #include "core/inspector/InspectorState.h" | 42 #include "core/inspector/InspectorState.h" |
43 #include "core/inspector/InstrumentingAgents.h" | 43 #include "core/inspector/InstrumentingAgents.h" |
44 #include "core/inspector/ScriptCallStack.h" | 44 #include "core/inspector/ScriptCallStack.h" |
45 #include "core/inspector/TimelineRecordFactory.h" | 45 #include "core/inspector/TimelineRecordFactory.h" |
46 #include "core/inspector/TimelineTraceEventProcessor.h" | 46 #include "core/inspector/TimelineTraceEventProcessor.h" |
47 #include "core/loader/DocumentLoader.h" | 47 #include "core/loader/DocumentLoader.h" |
48 #include "core/page/DOMWindow.h" | 48 #include "core/page/DOMWindow.h" |
49 #include "core/page/Frame.h" | 49 #include "core/page/Frame.h" |
50 #include "core/page/FrameView.h" | 50 #include "core/page/FrameView.h" |
| 51 #include "core/page/PageConsole.h" |
51 #include "core/platform/MemoryUsageSupport.h" | 52 #include "core/platform/MemoryUsageSupport.h" |
52 #include "core/platform/chromium/TraceEvent.h" | 53 #include "core/platform/chromium/TraceEvent.h" |
53 #include "core/platform/network/ResourceRequest.h" | 54 #include "core/platform/network/ResourceRequest.h" |
54 #include "core/rendering/RenderObject.h" | 55 #include "core/rendering/RenderObject.h" |
55 #include "core/rendering/RenderView.h" | 56 #include "core/rendering/RenderView.h" |
56 #include "core/xml/XMLHttpRequest.h" | 57 #include "core/xml/XMLHttpRequest.h" |
57 | 58 |
58 #include "wtf/CurrentTime.h" | 59 #include "wtf/CurrentTime.h" |
59 | 60 |
60 namespace WebCore { | 61 namespace WebCore { |
61 | 62 |
62 namespace TimelineAgentState { | 63 namespace TimelineAgentState { |
63 static const char timelineAgentEnabled[] = "timelineAgentEnabled"; | 64 static const char enabled[] = "enabled"; |
| 65 static const char started[] = "started"; |
| 66 static const char startedFromProtocol[] = "startedFromProtocol"; |
64 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; | 67 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; |
65 static const char includeDomCounters[] = "includeDomCounters"; | 68 static const char includeDomCounters[] = "includeDomCounters"; |
66 static const char includeNativeMemoryStatistics[] = "includeNativeMemoryStatisti
cs"; | 69 static const char includeNativeMemoryStatistics[] = "includeNativeMemoryStatisti
cs"; |
67 } | 70 } |
68 | 71 |
69 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo
del.js | 72 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo
del.js |
70 namespace TimelineRecordType { | 73 namespace TimelineRecordType { |
71 static const char Program[] = "Program"; | 74 static const char Program[] = "Program"; |
72 | 75 |
73 static const char EventDispatch[] = "EventDispatch"; | 76 static const char EventDispatch[] = "EventDispatch"; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 185 |
183 void InspectorTimelineAgent::setFrontend(InspectorFrontend* frontend) | 186 void InspectorTimelineAgent::setFrontend(InspectorFrontend* frontend) |
184 { | 187 { |
185 m_frontend = frontend->timeline(); | 188 m_frontend = frontend->timeline(); |
186 } | 189 } |
187 | 190 |
188 void InspectorTimelineAgent::clearFrontend() | 191 void InspectorTimelineAgent::clearFrontend() |
189 { | 192 { |
190 ErrorString error; | 193 ErrorString error; |
191 stop(&error); | 194 stop(&error); |
| 195 disable(&error); |
192 releaseNodeIds(); | 196 releaseNodeIds(); |
193 m_frontend = 0; | 197 m_frontend = 0; |
194 } | 198 } |
195 | 199 |
196 void InspectorTimelineAgent::restore() | 200 void InspectorTimelineAgent::restore() |
197 { | 201 { |
198 if (m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) { | 202 if (m_state->getBoolean(TimelineAgentState::startedFromProtocol)) { |
199 m_maxCallStackDepth = m_state->getLong(TimelineAgentState::timelineMaxCa
llStackDepth); | 203 innerStart(); |
200 ErrorString error; | 204 } else if (isStarted()) { |
201 bool includeDomCounters = m_state->getBoolean(TimelineAgentState::includ
eDomCounters); | 205 // Timeline was started from console.timeline, it is not restored. |
202 bool includeNativeMemoryStatistics = m_state->getBoolean(TimelineAgentSt
ate::includeNativeMemoryStatistics); | 206 // Tell front-end timline is no longer collecting. |
203 start(&error, &m_maxCallStackDepth, &includeDomCounters, &includeNativeM
emoryStatistics); | 207 m_state->setBoolean(TimelineAgentState::started, false); |
| 208 bool fromConsole = true; |
| 209 m_frontend->stopped(&fromConsole); |
204 } | 210 } |
205 } | 211 } |
206 | 212 |
207 void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c
onst bool* includeDomCounters, const bool* includeNativeMemoryStatistics) | 213 void InspectorTimelineAgent::enable(ErrorString*) |
| 214 { |
| 215 m_state->setBoolean(TimelineAgentState::enabled, true); |
| 216 } |
| 217 |
| 218 void InspectorTimelineAgent::disable(ErrorString*) |
| 219 { |
| 220 m_state->setBoolean(TimelineAgentState::enabled, false); |
| 221 } |
| 222 |
| 223 void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS
tackDepth, const bool* includeDomCounters, const bool* includeNativeMemoryStatis
tics) |
208 { | 224 { |
209 if (!m_frontend) | 225 if (!m_frontend) |
210 return; | 226 return; |
| 227 m_state->setBoolean(TimelineAgentState::startedFromProtocol, true); |
| 228 |
| 229 if (isStarted()) { |
| 230 *errorString = "Timeline is already started"; |
| 231 return; |
| 232 } |
211 | 233 |
212 releaseNodeIds(); | 234 releaseNodeIds(); |
213 if (maxCallStackDepth && *maxCallStackDepth >= 0) | 235 if (maxCallStackDepth && *maxCallStackDepth >= 0) |
214 m_maxCallStackDepth = *maxCallStackDepth; | 236 m_maxCallStackDepth = *maxCallStackDepth; |
215 else | 237 else |
216 m_maxCallStackDepth = 5; | 238 m_maxCallStackDepth = 5; |
217 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); | 239 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); |
218 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte
rs && *includeDomCounters); | 240 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte
rs && *includeDomCounters); |
219 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu
deNativeMemoryStatistics && *includeNativeMemoryStatistics); | 241 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu
deNativeMemoryStatistics && *includeNativeMemoryStatistics); |
| 242 |
| 243 innerStart(); |
| 244 bool fromConsole = false; |
| 245 m_frontend->started(&fromConsole); |
| 246 } |
| 247 |
| 248 bool InspectorTimelineAgent::isStarted() |
| 249 { |
| 250 return m_state->getBoolean(TimelineAgentState::started); |
| 251 } |
| 252 |
| 253 void InspectorTimelineAgent::innerStart() |
| 254 { |
| 255 m_state->setBoolean(TimelineAgentState::started, true); |
220 m_timeConverter.reset(); | 256 m_timeConverter.reset(); |
221 | |
222 m_instrumentingAgents->setInspectorTimelineAgent(this); | 257 m_instrumentingAgents->setInspectorTimelineAgent(this); |
223 ScriptGCEvent::addEventListener(this); | 258 ScriptGCEvent::addEventListener(this); |
224 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, true); | |
225 if (m_client && m_pageAgent) | 259 if (m_client && m_pageAgent) |
226 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF
actory.createWeakPtr(), m_client)); | 260 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF
actory.createWeakPtr(), m_client)); |
227 } | 261 } |
228 | 262 |
229 void InspectorTimelineAgent::stop(ErrorString*) | 263 void InspectorTimelineAgent::stop(ErrorString* errorString) |
230 { | 264 { |
231 if (!m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) | 265 m_state->setBoolean(TimelineAgentState::startedFromProtocol, false); |
| 266 if (!isStarted()) { |
| 267 *errorString = "Timeline was not started"; |
232 return; | 268 return; |
| 269 } |
| 270 innerStop(false); |
| 271 } |
| 272 |
| 273 void InspectorTimelineAgent::innerStop(bool fromConsole) |
| 274 { |
| 275 m_state->setBoolean(TimelineAgentState::started, false); |
233 | 276 |
234 if (m_traceEventProcessor) { | 277 if (m_traceEventProcessor) { |
235 m_traceEventProcessor->shutdown(); | 278 m_traceEventProcessor->shutdown(); |
236 m_traceEventProcessor.clear(); | 279 m_traceEventProcessor.clear(); |
237 } | 280 } |
238 m_weakFactory.revokeAll(); | 281 m_weakFactory.revokeAll(); |
239 m_instrumentingAgents->setInspectorTimelineAgent(0); | 282 m_instrumentingAgents->setInspectorTimelineAgent(0); |
240 ScriptGCEvent::removeEventListener(this); | 283 ScriptGCEvent::removeEventListener(this); |
241 | 284 |
242 clearRecordStack(); | 285 clearRecordStack(); |
243 m_gcEvents.clear(); | 286 m_gcEvents.clear(); |
244 | 287 |
245 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, false); | 288 for (size_t i = 0; i < m_consoleTimelines.size(); ++i) { |
| 289 String message = String::format("Timeline '%s' terminated.", m_consoleTi
melines[i].utf8().data()); |
| 290 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel,
message); |
| 291 } |
| 292 m_consoleTimelines.clear(); |
| 293 |
| 294 m_frontend->stopped(&fromConsole); |
246 } | 295 } |
247 | 296 |
248 void InspectorTimelineAgent::didBeginFrame() | 297 void InspectorTimelineAgent::didBeginFrame() |
249 { | 298 { |
250 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame); | 299 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame); |
251 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame); | 300 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame); |
252 } | 301 } |
253 | 302 |
254 void InspectorTimelineAgent::didCancelFrame() | 303 void InspectorTimelineAgent::didCancelFrame() |
255 { | 304 { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi
nishTime); | 608 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi
nishTime); |
560 | 609 |
561 didFinishLoadingResource(identifier, false, finishTime, loader->frame()); | 610 didFinishLoadingResource(identifier, false, finishTime, loader->frame()); |
562 } | 611 } |
563 | 612 |
564 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo
ader* loader, const ResourceError& error) | 613 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo
ader* loader, const ResourceError& error) |
565 { | 614 { |
566 didFinishLoadingResource(identifier, true, 0, loader->frame()); | 615 didFinishLoadingResource(identifier, true, 0, loader->frame()); |
567 } | 616 } |
568 | 617 |
569 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, P
assRefPtr<ScriptArguments> arguments) | 618 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, c
onst String& title) |
570 { | 619 { |
571 String message; | 620 appendRecord(TimelineRecordFactory::createTimeStampData(title), TimelineReco
rdType::TimeStamp, true, frameForScriptExecutionContext(context)); |
572 arguments->getFirstArgumentAsString(message); | |
573 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeStamp, true, frameForScriptExecutionContext(context)); | |
574 } | 621 } |
575 | 622 |
576 void InspectorTimelineAgent::startConsoleTiming(ScriptExecutionContext* context,
const String& message) | 623 void InspectorTimelineAgent::consoleTime(ScriptExecutionContext* context, const
String& message) |
577 { | 624 { |
578 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::Time, true, frameForScriptExecutionContext(context)); | 625 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::Time, true, frameForScriptExecutionContext(context)); |
579 } | 626 } |
580 | 627 |
581 void InspectorTimelineAgent::stopConsoleTiming(ScriptExecutionContext* context,
const String& message, PassRefPtr<ScriptCallStack> stack) | 628 void InspectorTimelineAgent::consoleTimeEnd(ScriptExecutionContext* context, con
st String& message, ScriptState*) |
582 { | 629 { |
583 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeEnd, true, frameForScriptExecutionContext(context)); | 630 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeEnd, true, frameForScriptExecutionContext(context)); |
584 } | 631 } |
585 | 632 |
| 633 void InspectorTimelineAgent::consoleTimeline(ScriptExecutionContext* context, co
nst String& title, ScriptState* state) |
| 634 { |
| 635 if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| 636 return; |
| 637 |
| 638 String message = String::format("Timeline '%s' started.", title.utf8().data(
)); |
| 639 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes
sage, String(), 0, 0, 0, state); |
| 640 m_consoleTimelines.append(title); |
| 641 if (!isStarted()) { |
| 642 innerStart(); |
| 643 bool fromConsole = true; |
| 644 m_frontend->started(&fromConsole); |
| 645 } |
| 646 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| 647 } |
| 648 |
| 649 void InspectorTimelineAgent::consoleTimelineEnd(ScriptExecutionContext* context,
const String& title, ScriptState* state) |
| 650 { |
| 651 if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| 652 return; |
| 653 |
| 654 size_t index = m_consoleTimelines.find(title); |
| 655 if (index == notFound) { |
| 656 String message = String::format("Timeline '%s' was not started.", title.
utf8().data()); |
| 657 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel,
message, String(), 0, 0, 0, state); |
| 658 return; |
| 659 } |
| 660 |
| 661 String message = String::format("Timeline '%s' finished.", title.utf8().data
()); |
| 662 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| 663 m_consoleTimelines.remove(index); |
| 664 if (!m_consoleTimelines.size() && isStarted() && !m_state->getBoolean(Timeli
neAgentState::startedFromProtocol)) |
| 665 innerStop(true); |
| 666 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes
sage, String(), 0, 0, 0, state); |
| 667 } |
586 | 668 |
587 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) | 669 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) |
588 { | 670 { |
589 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); | 671 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); |
590 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec
ordType::MarkDOMContent, false, frame); | 672 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec
ordType::MarkDOMContent, false, frame); |
591 } | 673 } |
592 | 674 |
593 void InspectorTimelineAgent::loadEventFired(Frame* frame) | 675 void InspectorTimelineAgent::loadEventFired(Frame* frame) |
594 { | 676 { |
595 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); | 677 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 return m_timeConverter.fromMonotonicallyIncreasingTime(WTF::monotonicallyInc
reasingTime()); | 915 return m_timeConverter.fromMonotonicallyIncreasingTime(WTF::monotonicallyInc
reasingTime()); |
834 } | 916 } |
835 | 917 |
836 Page* InspectorTimelineAgent::page() | 918 Page* InspectorTimelineAgent::page() |
837 { | 919 { |
838 return m_pageAgent ? m_pageAgent->page() : 0; | 920 return m_pageAgent ? m_pageAgent->page() : 0; |
839 } | 921 } |
840 | 922 |
841 } // namespace WebCore | 923 } // namespace WebCore |
842 | 924 |
OLD | NEW |