| 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(false); |
| 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 |
| 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 |
| 207 void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c
onst bool* includeDomCounters, const bool* includeNativeMemoryStatistics) | 223 void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c
onst bool* includeDomCounters, const bool* includeNativeMemoryStatistics) |
| 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 return; |
| 211 | 231 |
| 212 releaseNodeIds(); | 232 releaseNodeIds(); |
| 213 if (maxCallStackDepth && *maxCallStackDepth >= 0) | 233 if (maxCallStackDepth && *maxCallStackDepth >= 0) |
| 214 m_maxCallStackDepth = *maxCallStackDepth; | 234 m_maxCallStackDepth = *maxCallStackDepth; |
| 215 else | 235 else |
| 216 m_maxCallStackDepth = 5; | 236 m_maxCallStackDepth = 5; |
| 217 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); | 237 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); |
| 218 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte
rs && *includeDomCounters); | 238 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte
rs && *includeDomCounters); |
| 219 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu
deNativeMemoryStatistics && *includeNativeMemoryStatistics); | 239 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu
deNativeMemoryStatistics && *includeNativeMemoryStatistics); |
| 240 innerStart(false); |
| 241 } |
| 242 |
| 243 bool InspectorTimelineAgent::isStarted() |
| 244 { |
| 245 return m_state->getBoolean(TimelineAgentState::started); |
| 246 } |
| 247 |
| 248 void InspectorTimelineAgent::innerStart(bool fromConsole) |
| 249 { |
| 250 m_state->setBoolean(TimelineAgentState::started, true); |
| 220 m_timeConverter.reset(); | 251 m_timeConverter.reset(); |
| 221 | |
| 222 m_instrumentingAgents->setInspectorTimelineAgent(this); | 252 m_instrumentingAgents->setInspectorTimelineAgent(this); |
| 223 ScriptGCEvent::addEventListener(this); | 253 ScriptGCEvent::addEventListener(this); |
| 224 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, true); | |
| 225 if (m_client && m_pageAgent) | 254 if (m_client && m_pageAgent) |
| 226 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF
actory.createWeakPtr(), m_client)); | 255 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF
actory.createWeakPtr(), m_client)); |
| 256 m_frontend->started(&fromConsole); |
| 227 } | 257 } |
| 228 | 258 |
| 229 void InspectorTimelineAgent::stop(ErrorString*) | 259 void InspectorTimelineAgent::stop(ErrorString*) |
| 230 { | 260 { |
| 231 if (!m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) | 261 m_state->setBoolean(TimelineAgentState::startedFromProtocol, false); |
| 232 return; | 262 if (isStarted()) |
| 263 innerStop(false); |
| 264 } |
| 265 |
| 266 void InspectorTimelineAgent::innerStop(bool fromConsole) |
| 267 { |
| 268 m_state->setBoolean(TimelineAgentState::started, false); |
| 233 | 269 |
| 234 if (m_traceEventProcessor) { | 270 if (m_traceEventProcessor) { |
| 235 m_traceEventProcessor->shutdown(); | 271 m_traceEventProcessor->shutdown(); |
| 236 m_traceEventProcessor.clear(); | 272 m_traceEventProcessor.clear(); |
| 237 } | 273 } |
| 238 m_weakFactory.revokeAll(); | 274 m_weakFactory.revokeAll(); |
| 239 m_instrumentingAgents->setInspectorTimelineAgent(0); | 275 m_instrumentingAgents->setInspectorTimelineAgent(0); |
| 240 ScriptGCEvent::removeEventListener(this); | 276 ScriptGCEvent::removeEventListener(this); |
| 241 | 277 |
| 242 clearRecordStack(); | 278 clearRecordStack(); |
| 243 m_gcEvents.clear(); | 279 m_gcEvents.clear(); |
| 244 | 280 |
| 245 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, false); | 281 for (size_t i = 0; i < m_consoleTimelines.size(); ++i) { |
| 282 String message = String::format("Timeline '%s' terminated.", m_consoleTi
melines[i].utf8().data()); |
| 283 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel,
message); |
| 284 } |
| 285 m_consoleTimelines.clear(); |
| 286 |
| 287 m_frontend->stopped(&fromConsole); |
| 246 } | 288 } |
| 247 | 289 |
| 248 void InspectorTimelineAgent::didBeginFrame() | 290 void InspectorTimelineAgent::didBeginFrame() |
| 249 { | 291 { |
| 250 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame); | 292 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame); |
| 251 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame); | 293 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame); |
| 252 } | 294 } |
| 253 | 295 |
| 254 void InspectorTimelineAgent::didCancelFrame() | 296 void InspectorTimelineAgent::didCancelFrame() |
| 255 { | 297 { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi
nishTime); | 601 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi
nishTime); |
| 560 | 602 |
| 561 didFinishLoadingResource(identifier, false, finishTime, loader->frame()); | 603 didFinishLoadingResource(identifier, false, finishTime, loader->frame()); |
| 562 } | 604 } |
| 563 | 605 |
| 564 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo
ader* loader, const ResourceError& error) | 606 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo
ader* loader, const ResourceError& error) |
| 565 { | 607 { |
| 566 didFinishLoadingResource(identifier, true, 0, loader->frame()); | 608 didFinishLoadingResource(identifier, true, 0, loader->frame()); |
| 567 } | 609 } |
| 568 | 610 |
| 569 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, P
assRefPtr<ScriptArguments> arguments) | 611 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, c
onst String& title) |
| 570 { | 612 { |
| 571 String message; | 613 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 } | 614 } |
| 575 | 615 |
| 576 void InspectorTimelineAgent::startConsoleTiming(ScriptExecutionContext* context,
const String& message) | 616 void InspectorTimelineAgent::consoleTime(ScriptExecutionContext* context, const
String& message) |
| 577 { | 617 { |
| 578 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::Time, true, frameForScriptExecutionContext(context)); | 618 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::Time, true, frameForScriptExecutionContext(context)); |
| 579 } | 619 } |
| 580 | 620 |
| 581 void InspectorTimelineAgent::stopConsoleTiming(ScriptExecutionContext* context,
const String& message, PassRefPtr<ScriptCallStack> stack) | 621 void InspectorTimelineAgent::consoleTimeEnd(ScriptExecutionContext* context, con
st String& message, ScriptState*) |
| 582 { | 622 { |
| 583 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeEnd, true, frameForScriptExecutionContext(context)); | 623 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeEnd, true, frameForScriptExecutionContext(context)); |
| 584 } | 624 } |
| 585 | 625 |
| 626 void InspectorTimelineAgent::consoleTimeline(ScriptExecutionContext* context, co
nst String& title, ScriptState* state) |
| 627 { |
| 628 if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| 629 return; |
| 630 |
| 631 String message = String::format("Timeline '%s' started.", title.utf8().data(
)); |
| 632 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes
sage, String(), 0, 0, 0, state); |
| 633 m_consoleTimelines.append(title); |
| 634 if (!isStarted()) |
| 635 innerStart(true); |
| 636 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| 637 } |
| 638 |
| 639 void InspectorTimelineAgent::consoleTimelineEnd(ScriptExecutionContext* context,
const String& title, ScriptState* state) |
| 640 { |
| 641 if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| 642 return; |
| 643 |
| 644 size_t index = m_consoleTimelines.find(title); |
| 645 if (index == notFound) { |
| 646 String message = String::format("Timeline '%s' was not started.", title.
utf8().data()); |
| 647 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel,
message, String(), 0, 0, 0, state); |
| 648 return; |
| 649 } |
| 650 |
| 651 String message = String::format("Timeline '%s' finished.", title.utf8().data
()); |
| 652 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe
cordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| 653 m_consoleTimelines.remove(index); |
| 654 if (!m_consoleTimelines.size() && isStarted() && !m_state->getBoolean(Timeli
neAgentState::startedFromProtocol)) |
| 655 innerStop(true); |
| 656 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes
sage, String(), 0, 0, 0, state); |
| 657 } |
| 586 | 658 |
| 587 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) | 659 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) |
| 588 { | 660 { |
| 589 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); | 661 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); |
| 590 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec
ordType::MarkDOMContent, false, frame); | 662 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec
ordType::MarkDOMContent, false, frame); |
| 591 } | 663 } |
| 592 | 664 |
| 593 void InspectorTimelineAgent::loadEventFired(Frame* frame) | 665 void InspectorTimelineAgent::loadEventFired(Frame* frame) |
| 594 { | 666 { |
| 595 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame(
)); | 667 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()); | 905 return m_timeConverter.fromMonotonicallyIncreasingTime(WTF::monotonicallyInc
reasingTime()); |
| 834 } | 906 } |
| 835 | 907 |
| 836 Page* InspectorTimelineAgent::page() | 908 Page* InspectorTimelineAgent::page() |
| 837 { | 909 { |
| 838 return m_pageAgent ? m_pageAgent->page() : 0; | 910 return m_pageAgent ? m_pageAgent->page() : 0; |
| 839 } | 911 } |
| 840 | 912 |
| 841 } // namespace WebCore | 913 } // namespace WebCore |
| 842 | 914 |
| OLD | NEW |