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