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

Side by Side Diff: Source/core/inspector/InspectorTimelineAgent.cpp

Issue 24027002: DevTools: implement console.timeline/timelineEnd. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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
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 startedFromProtocol[] = "startedFromProtocol";
64 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; 65 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth";
65 static const char includeDomCounters[] = "includeDomCounters"; 66 static const char includeDomCounters[] = "includeDomCounters";
66 static const char includeNativeMemoryStatistics[] = "includeNativeMemoryStatisti cs"; 67 static const char includeNativeMemoryStatistics[] = "includeNativeMemoryStatisti cs";
67 } 68 }
68 69
69 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo del.js 70 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo del.js
70 namespace TimelineRecordType { 71 namespace TimelineRecordType {
71 static const char Program[] = "Program"; 72 static const char Program[] = "Program";
72 73
73 static const char EventDispatch[] = "EventDispatch"; 74 static const char EventDispatch[] = "EventDispatch";
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void InspectorTimelineAgent::clearFrontend() 189 void InspectorTimelineAgent::clearFrontend()
189 { 190 {
190 ErrorString error; 191 ErrorString error;
191 stop(&error); 192 stop(&error);
192 releaseNodeIds(); 193 releaseNodeIds();
193 m_frontend = 0; 194 m_frontend = 0;
194 } 195 }
195 196
196 void InspectorTimelineAgent::restore() 197 void InspectorTimelineAgent::restore()
197 { 198 {
198 if (m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) { 199 if (m_state->getBoolean(TimelineAgentState::startedFromProtocol)) {
199 m_maxCallStackDepth = m_state->getLong(TimelineAgentState::timelineMaxCa llStackDepth); 200 m_maxCallStackDepth = m_state->getLong(TimelineAgentState::timelineMaxCa llStackDepth);
200 ErrorString error; 201 ErrorString error;
201 bool includeDomCounters = m_state->getBoolean(TimelineAgentState::includ eDomCounters); 202 bool includeDomCounters = m_state->getBoolean(TimelineAgentState::includ eDomCounters);
202 bool includeNativeMemoryStatistics = m_state->getBoolean(TimelineAgentSt ate::includeNativeMemoryStatistics); 203 bool includeNativeMemoryStatistics = m_state->getBoolean(TimelineAgentSt ate::includeNativeMemoryStatistics);
203 start(&error, &m_maxCallStackDepth, &includeDomCounters, &includeNativeM emoryStatistics); 204 start(&error, &m_maxCallStackDepth, &includeDomCounters, &includeNativeM emoryStatistics);
204 } 205 }
205 } 206 }
206 207
207 void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c onst bool* includeDomCounters, const bool* includeNativeMemoryStatistics) 208 void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c onst bool* includeDomCounters, const bool* includeNativeMemoryStatistics)
208 { 209 {
209 if (!m_frontend) 210 if (!m_frontend)
210 return; 211 return;
212 m_state->setBoolean(TimelineAgentState::startedFromProtocol, true);
213
214 if (m_isStarted)
215 return;
211 216
212 releaseNodeIds(); 217 releaseNodeIds();
213 if (maxCallStackDepth && *maxCallStackDepth >= 0) 218 if (maxCallStackDepth && *maxCallStackDepth >= 0)
214 m_maxCallStackDepth = *maxCallStackDepth; 219 m_maxCallStackDepth = *maxCallStackDepth;
215 else 220 else
216 m_maxCallStackDepth = 5; 221 m_maxCallStackDepth = 5;
217 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta ckDepth); 222 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta ckDepth);
218 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte rs && *includeDomCounters); 223 m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounte rs && *includeDomCounters);
219 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu deNativeMemoryStatistics && *includeNativeMemoryStatistics); 224 m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, inclu deNativeMemoryStatistics && *includeNativeMemoryStatistics);
225 innerStart(false);
226 }
227
228 void InspectorTimelineAgent::innerStart(bool fromConsole)
229 {
230 if (m_isStarted)
231 return;
232 m_isStarted = true;
233
220 m_timeConverter.reset(); 234 m_timeConverter.reset();
221
222 m_instrumentingAgents->setInspectorTimelineAgent(this); 235 m_instrumentingAgents->setInspectorTimelineAgent(this);
223 ScriptGCEvent::addEventListener(this); 236 ScriptGCEvent::addEventListener(this);
224 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, true);
225 if (m_client && m_pageAgent) 237 if (m_client && m_pageAgent)
226 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF actory.createWeakPtr(), m_client)); 238 m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakF actory.createWeakPtr(), m_client));
239 m_frontend->started(&fromConsole);
227 } 240 }
228 241
229 void InspectorTimelineAgent::stop(ErrorString*) 242 void InspectorTimelineAgent::stop(ErrorString*)
230 { 243 {
231 if (!m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) 244 innerStop(false);
245 m_state->setBoolean(TimelineAgentState::startedFromProtocol, false);
246 }
247
248 void InspectorTimelineAgent::innerStop(bool fromConsole)
249 {
250 if (!m_isStarted)
232 return; 251 return;
252 m_isStarted = false;
233 253
234 if (m_traceEventProcessor) { 254 if (m_traceEventProcessor) {
235 m_traceEventProcessor->shutdown(); 255 m_traceEventProcessor->shutdown();
236 m_traceEventProcessor.clear(); 256 m_traceEventProcessor.clear();
237 } 257 }
238 m_weakFactory.revokeAll(); 258 m_weakFactory.revokeAll();
239 m_instrumentingAgents->setInspectorTimelineAgent(0); 259 m_instrumentingAgents->setInspectorTimelineAgent(0);
240 ScriptGCEvent::removeEventListener(this); 260 ScriptGCEvent::removeEventListener(this);
241 261
242 clearRecordStack(); 262 clearRecordStack();
243 m_gcEvents.clear(); 263 m_gcEvents.clear();
244 264
245 m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, false); 265 for (size_t i = 0; i < m_consoleTimelines.size(); ++i) {
266 String message = String::format("Timeline '%s' terminated.", m_consoleTi melines[i].utf8().data());
267 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message);
268 }
269 m_consoleTimelines.clear();
270
271 m_frontend->stopped(&fromConsole);
246 } 272 }
247 273
248 void InspectorTimelineAgent::didBeginFrame() 274 void InspectorTimelineAgent::didBeginFrame()
249 { 275 {
250 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame); 276 TRACE_EVENT_INSTANT0("webkit", InstrumentationEvents::BeginFrame);
251 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp( ), 0, TimelineRecordType::BeginFrame); 277 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp( ), 0, TimelineRecordType::BeginFrame);
252 } 278 }
253 279
254 void InspectorTimelineAgent::didCancelFrame() 280 void InspectorTimelineAgent::didCancelFrame()
255 { 281 {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi nishTime); 568 finishTime = loader->timing()->monotonicTimeToPseudoWallTime(monotonicFi nishTime);
543 569
544 didFinishLoadingResource(identifier, false, finishTime, loader->frame()); 570 didFinishLoadingResource(identifier, false, finishTime, loader->frame());
545 } 571 }
546 572
547 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo ader* loader, const ResourceError& error) 573 void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo ader* loader, const ResourceError& error)
548 { 574 {
549 didFinishLoadingResource(identifier, true, 0, loader->frame()); 575 didFinishLoadingResource(identifier, true, 0, loader->frame());
550 } 576 }
551 577
552 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, P assRefPtr<ScriptArguments> arguments) 578 void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, c onst String& title)
553 { 579 {
554 String message; 580 appendRecord(TimelineRecordFactory::createTimeStampData(title), TimelineReco rdType::TimeStamp, true, frameForScriptExecutionContext(context));
555 arguments->getFirstArgumentAsString(message);
556 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeStamp, true, frameForScriptExecutionContext(context));
557 } 581 }
558 582
559 void InspectorTimelineAgent::startConsoleTiming(ScriptExecutionContext* context, const String& message) 583 void InspectorTimelineAgent::consoleTime(ScriptExecutionContext* context, const String& message)
560 { 584 {
561 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::Time, true, frameForScriptExecutionContext(context)); 585 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::Time, true, frameForScriptExecutionContext(context));
562 } 586 }
563 587
564 void InspectorTimelineAgent::stopConsoleTiming(ScriptExecutionContext* context, const String& message, PassRefPtr<ScriptCallStack> stack) 588 void InspectorTimelineAgent::consoleTimeEnd(ScriptExecutionContext* context, con st String& message, ScriptState*)
565 { 589 {
566 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeEnd, true, frameForScriptExecutionContext(context)); 590 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeEnd, true, frameForScriptExecutionContext(context));
567 } 591 }
568 592
593 void InspectorTimelineAgent::consoleTimeline(ScriptExecutionContext* context, co nst String& title, ScriptState* state)
594 {
595 String message = String::format("Timeline '%s' started.", title.utf8().data( ));
596 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes sage, String(), 0, 0, 0, state);
597 m_consoleTimelines.append(title);
yurys 2013/09/06 07:56:45 What is the expected behavior when same timeline i
pfeldman 2013/09/06 16:10:30 console.timeline("one") console.timeline("one") co
598 innerStart(true);
599 appendRecord(TimelineRecordFactory::createTimeStampData(title), TimelineReco rdType::TimeStamp, true, frameForScriptExecutionContext(context));
600 }
601
602 void InspectorTimelineAgent::consoleTimelineEnd(ScriptExecutionContext* context, const String& title, ScriptState* state)
603 {
604 size_t index = m_consoleTimelines.find(title);
605 if (index == notFound) {
606 String message = String::format("Timeline '%s' was not started.", title. utf8().data());
607 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message, String(), 0, 0, 0, state);
608 return;
609 }
610
611 appendRecord(TimelineRecordFactory::createTimeStampData(title), TimelineReco rdType::TimeStamp, true, frameForScriptExecutionContext(context));
612 m_consoleTimelines.remove(index);
613 if (!m_consoleTimelines.size() && !m_state->getBoolean(TimelineAgentState::s tartedFromProtocol))
614 innerStop(true);
615
616 String message = String::format("Timeline '%s' finished.", title.utf8().data ());
617 page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, mes sage, String(), 0, 0, 0, state);
618 }
569 619
570 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) 620 void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame)
571 { 621 {
572 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( )); 622 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( ));
573 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec ordType::MarkDOMContent, false, frame); 623 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec ordType::MarkDOMContent, false, frame);
574 } 624 }
575 625
576 void InspectorTimelineAgent::loadEventFired(Frame* frame) 626 void InspectorTimelineAgent::loadEventFired(Frame* frame)
577 { 627 {
578 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( )); 628 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( ));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 , m_domAgent(domAgent) 772 , m_domAgent(domAgent)
723 , m_frontend(0) 773 , m_frontend(0)
724 , m_id(1) 774 , m_id(1)
725 , m_maxCallStackDepth(5) 775 , m_maxCallStackDepth(5)
726 , m_platformInstrumentationClientInstalledAtStackDepth(0) 776 , m_platformInstrumentationClientInstalledAtStackDepth(0)
727 , m_inspectorType(type) 777 , m_inspectorType(type)
728 , m_client(client) 778 , m_client(client)
729 , m_weakFactory(this) 779 , m_weakFactory(this)
730 , m_styleRecalcElementCounter(0) 780 , m_styleRecalcElementCounter(0)
731 , m_layerTreeId(0) 781 , m_layerTreeId(0)
782 , m_isStarted(false)
732 { 783 {
733 } 784 }
734 785
735 void InspectorTimelineAgent::appendRecord(PassRefPtr<JSONObject> data, const Str ing& type, bool captureCallStack, Frame* frame) 786 void InspectorTimelineAgent::appendRecord(PassRefPtr<JSONObject> data, const Str ing& type, bool captureCallStack, Frame* frame)
736 { 787 {
737 pushGCEventRecords(); 788 pushGCEventRecords();
738 RefPtr<JSONObject> record = TimelineRecordFactory::createGenericRecord(times tamp(), captureCallStack ? m_maxCallStackDepth : 0, type); 789 RefPtr<JSONObject> record = TimelineRecordFactory::createGenericRecord(times tamp(), captureCallStack ? m_maxCallStackDepth : 0, type);
739 record->setObject("data", data); 790 record->setObject("data", data);
740 setFrameIdentifier(record.get(), frame); 791 setFrameIdentifier(record.get(), frame);
741 addRecordToTimeline(record.release()); 792 addRecordToTimeline(record.release());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 return m_timeConverter.fromMonotonicallyIncreasingTime(WTF::monotonicallyInc reasingTime()); 860 return m_timeConverter.fromMonotonicallyIncreasingTime(WTF::monotonicallyInc reasingTime());
810 } 861 }
811 862
812 Page* InspectorTimelineAgent::page() 863 Page* InspectorTimelineAgent::page()
813 { 864 {
814 return m_pageAgent ? m_pageAgent->page() : 0; 865 return m_pageAgent ? m_pageAgent->page() : 0;
815 } 866 }
816 867
817 } // namespace WebCore 868 } // namespace WebCore
818 869
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698