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

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

Issue 254613002: DevTools: add Tracing agent on back-end (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: removed obsolete code Created 6 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 | 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 28 matching lines...) Expand all
39 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
40 #include "core/inspector/IdentifiersFactory.h" 40 #include "core/inspector/IdentifiersFactory.h"
41 #include "core/inspector/InspectorClient.h" 41 #include "core/inspector/InspectorClient.h"
42 #include "core/inspector/InspectorCounters.h" 42 #include "core/inspector/InspectorCounters.h"
43 #include "core/inspector/InspectorDOMAgent.h" 43 #include "core/inspector/InspectorDOMAgent.h"
44 #include "core/inspector/InspectorInstrumentation.h" 44 #include "core/inspector/InspectorInstrumentation.h"
45 #include "core/inspector/InspectorLayerTreeAgent.h" 45 #include "core/inspector/InspectorLayerTreeAgent.h"
46 #include "core/inspector/InspectorOverlay.h" 46 #include "core/inspector/InspectorOverlay.h"
47 #include "core/inspector/InspectorPageAgent.h" 47 #include "core/inspector/InspectorPageAgent.h"
48 #include "core/inspector/InspectorState.h" 48 #include "core/inspector/InspectorState.h"
49 #include "core/inspector/InspectorTracingAgent.h"
49 #include "core/inspector/InstrumentingAgents.h" 50 #include "core/inspector/InstrumentingAgents.h"
50 #include "core/inspector/ScriptCallStack.h" 51 #include "core/inspector/ScriptCallStack.h"
51 #include "core/inspector/TimelineRecordFactory.h" 52 #include "core/inspector/TimelineRecordFactory.h"
52 #include "core/inspector/TraceEventDispatcher.h" 53 #include "core/inspector/TraceEventDispatcher.h"
53 #include "core/loader/DocumentLoader.h" 54 #include "core/loader/DocumentLoader.h"
54 #include "core/page/Page.h" 55 #include "core/page/Page.h"
55 #include "core/rendering/RenderObject.h" 56 #include "core/rendering/RenderObject.h"
56 #include "core/rendering/RenderView.h" 57 #include "core/rendering/RenderView.h"
57 #include "core/xml/XMLHttpRequest.h" 58 #include "core/xml/XMLHttpRequest.h"
58 #include "platform/TraceEvent.h" 59 #include "platform/TraceEvent.h"
59 #include "platform/graphics/DeferredImageDecoder.h" 60 #include "platform/graphics/DeferredImageDecoder.h"
60 #include "platform/graphics/GraphicsLayer.h" 61 #include "platform/graphics/GraphicsLayer.h"
61 #include "platform/network/ResourceRequest.h" 62 #include "platform/network/ResourceRequest.h"
62 #include "wtf/CurrentTime.h" 63 #include "wtf/CurrentTime.h"
63 #include "wtf/DateMath.h" 64 #include "wtf/DateMath.h"
64 65
65 namespace WebCore { 66 namespace WebCore {
66 67
67 namespace TimelineAgentState { 68 namespace TimelineAgentState {
68 static const char enabled[] = "enabled"; 69 static const char enabled[] = "enabled";
69 static const char started[] = "started"; 70 static const char started[] = "started";
70 static const char startedFromProtocol[] = "startedFromProtocol"; 71 static const char startedFromProtocol[] = "startedFromProtocol";
71 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; 72 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth";
72 static const char includeCounters[] = "includeCounters"; 73 static const char includeCounters[] = "includeCounters";
73 static const char includeGPUEvents[] = "includeGPUEvents"; 74 static const char includeGPUEvents[] = "includeGPUEvents";
74 static const char bufferEvents[] = "bufferEvents"; 75 static const char bufferEvents[] = "bufferEvents";
75 static const char liveEvents[] = "liveEvents"; 76 static const char liveEvents[] = "liveEvents";
76 static const char traceEventCategoryFilter[] = "traceEventCategoryFilter";
77 } 77 }
78 78
79 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo del.js 79 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo del.js
80 namespace TimelineRecordType { 80 namespace TimelineRecordType {
81 static const char Program[] = "Program"; 81 static const char Program[] = "Program";
82 82
83 static const char EventDispatch[] = "EventDispatch"; 83 static const char EventDispatch[] = "EventDispatch";
84 static const char ScheduleStyleRecalculation[] = "ScheduleStyleRecalculation"; 84 static const char ScheduleStyleRecalculation[] = "ScheduleStyleRecalculation";
85 static const char RecalculateStyles[] = "RecalculateStyles"; 85 static const char RecalculateStyles[] = "RecalculateStyles";
86 static const char InvalidateLayout[] = "InvalidateLayout"; 86 static const char InvalidateLayout[] = "InvalidateLayout";
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 innerStart(); 293 innerStart();
294 } else if (isStarted()) { 294 } else if (isStarted()) {
295 // Timeline was started from console.timeline, it is not restored. 295 // Timeline was started from console.timeline, it is not restored.
296 // Tell front-end timline is no longer collecting. 296 // Tell front-end timline is no longer collecting.
297 m_state->setBoolean(TimelineAgentState::started, false); 297 m_state->setBoolean(TimelineAgentState::started, false);
298 bool fromConsole = true; 298 bool fromConsole = true;
299 m_frontend->stopped(&fromConsole); 299 m_frontend->stopped(&fromConsole);
300 } 300 }
301 } 301 }
302 302
303 void InspectorTimelineAgent::enable(ErrorString*, const String* traceEventCatego ryFilter) 303 void InspectorTimelineAgent::enable(ErrorString*)
304 { 304 {
305 m_state->setBoolean(TimelineAgentState::enabled, true); 305 m_state->setBoolean(TimelineAgentState::enabled, true);
306 m_state->setString(TimelineAgentState::traceEventCategoryFilter, traceEventC ategoryFilter ? *traceEventCategoryFilter : "");
307 } 306 }
308 307
309 void InspectorTimelineAgent::disable(ErrorString*) 308 void InspectorTimelineAgent::disable(ErrorString*)
310 { 309 {
311 m_state->setBoolean(TimelineAgentState::enabled, false); 310 m_state->setBoolean(TimelineAgentState::enabled, false);
312 } 311 }
313 312
314 void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS tackDepth, const bool* bufferEvents, const String* liveEvents, const bool* inclu deCounters, const bool* includeGPUEvents) 313 void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS tackDepth, const bool* bufferEvents, const String* liveEvents, const bool* inclu deCounters, const bool* includeGPUEvents)
315 { 314 {
316 if (!m_frontend) 315 if (!m_frontend)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 bool InspectorTimelineAgent::isStarted() 349 bool InspectorTimelineAgent::isStarted()
351 { 350 {
352 return m_state->getBoolean(TimelineAgentState::started); 351 return m_state->getBoolean(TimelineAgentState::started);
353 } 352 }
354 353
355 void InspectorTimelineAgent::innerStart() 354 void InspectorTimelineAgent::innerStart()
356 { 355 {
357 if (m_overlay) 356 if (m_overlay)
358 m_overlay->startedRecordingProfile(); 357 m_overlay->startedRecordingProfile();
359 m_state->setBoolean(TimelineAgentState::started, true); 358 m_state->setBoolean(TimelineAgentState::started, true);
360 String traceEventCategoryFilter = m_state->getString(TimelineAgentState::tra ceEventCategoryFilter);
361 if (!traceEventCategoryFilter.isEmpty()) {
362 m_client->enableTracing(traceEventCategoryFilter);
363 m_disableTracingOnStop = true;
364 } else {
365 m_disableTracingOnStop = false;
366 }
367 m_instrumentingAgents->setInspectorTimelineAgent(this); 359 m_instrumentingAgents->setInspectorTimelineAgent(this);
368 ScriptGCEvent::addEventListener(this); 360 ScriptGCEvent::addEventListener(this);
369 if (m_client) { 361 if (m_client) {
370 TraceEventDispatcher* dispatcher = TraceEventDispatcher::instance(); 362 TraceEventDispatcher* dispatcher = TraceEventDispatcher::instance();
371 dispatcher->addListener(InstrumentationEvents::BeginFrame, TRACE_EVENT_P HASE_INSTANT, this, &InspectorTimelineAgent::onBeginImplSideFrame, m_client); 363 dispatcher->addListener(InstrumentationEvents::BeginFrame, TRACE_EVENT_P HASE_INSTANT, this, &InspectorTimelineAgent::onBeginImplSideFrame, m_client);
372 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P HASE_BEGIN, this, &InspectorTimelineAgent::onPaintSetupBegin, m_client); 364 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P HASE_BEGIN, this, &InspectorTimelineAgent::onPaintSetupBegin, m_client);
373 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P HASE_END, this, &InspectorTimelineAgent::onPaintSetupEnd, m_client); 365 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P HASE_END, this, &InspectorTimelineAgent::onPaintSetupEnd, m_client);
374 dispatcher->addListener(InstrumentationEvents::RasterTask, TRACE_EVENT_P HASE_BEGIN, this, &InspectorTimelineAgent::onRasterTaskBegin, m_client); 366 dispatcher->addListener(InstrumentationEvents::RasterTask, TRACE_EVENT_P HASE_BEGIN, this, &InspectorTimelineAgent::onRasterTaskBegin, m_client);
375 dispatcher->addListener(InstrumentationEvents::RasterTask, TRACE_EVENT_P HASE_END, this, &InspectorTimelineAgent::onRasterTaskEnd, m_client); 367 dispatcher->addListener(InstrumentationEvents::RasterTask, TRACE_EVENT_P HASE_END, this, &InspectorTimelineAgent::onRasterTaskEnd, m_client);
376 dispatcher->addListener(InstrumentationEvents::Layer, TRACE_EVENT_PHASE_ DELETE_OBJECT, this, &InspectorTimelineAgent::onLayerDeleted, m_client); 368 dispatcher->addListener(InstrumentationEvents::Layer, TRACE_EVENT_PHASE_ DELETE_OBJECT, this, &InspectorTimelineAgent::onLayerDeleted, m_client);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 403
412 void InspectorTimelineAgent::innerStop(bool fromConsole) 404 void InspectorTimelineAgent::innerStop(bool fromConsole)
413 { 405 {
414 m_state->setBoolean(TimelineAgentState::started, false); 406 m_state->setBoolean(TimelineAgentState::started, false);
415 407
416 if (m_client) { 408 if (m_client) {
417 TraceEventDispatcher::instance()->removeAllListeners(this, m_client); 409 TraceEventDispatcher::instance()->removeAllListeners(this, m_client);
418 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents)) 410 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents))
419 m_client->stopGPUEventsRecording(); 411 m_client->stopGPUEventsRecording();
420 } 412 }
421 // If we have enabled tracing, disable it now.
422 if (m_disableTracingOnStop) {
423 m_client->disableTracing();
424 m_disableTracingOnStop = false;
425 }
426 m_instrumentingAgents->setInspectorTimelineAgent(0); 413 m_instrumentingAgents->setInspectorTimelineAgent(0);
427 ScriptGCEvent::removeEventListener(this); 414 ScriptGCEvent::removeEventListener(this);
428 415
429 clearRecordStack(); 416 clearRecordStack();
430 m_threadStates.clear(); 417 m_threadStates.clear();
431 m_gpuTask.clear(); 418 m_gpuTask.clear();
432 m_layerToNodeMap.clear(); 419 m_layerToNodeMap.clear();
433 m_pixelRefToImageInfo.clear(); 420 m_pixelRefToImageInfo.clear();
434 m_imageBeingPainted = 0; 421 m_imageBeingPainted = 0;
435 m_paintSetupStart = 0; 422 m_paintSetupStart = 0;
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 void InspectorTimelineAgent::consoleTimeline(ExecutionContext* context, const St ring& title, NewScriptState* scriptState) 811 void InspectorTimelineAgent::consoleTimeline(ExecutionContext* context, const St ring& title, NewScriptState* scriptState)
825 { 812 {
826 if (!m_state->getBoolean(TimelineAgentState::enabled)) 813 if (!m_state->getBoolean(TimelineAgentState::enabled))
827 return; 814 return;
828 815
829 String message = String::format("Timeline '%s' started.", title.utf8().data( )); 816 String message = String::format("Timeline '%s' started.", title.utf8().data( ));
830 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel , message, String(), 0, 0, nullptr, scriptState); 817 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel , message, String(), 0, 0, nullptr, scriptState);
831 m_consoleTimelines.append(title); 818 m_consoleTimelines.append(title);
832 if (!isStarted()) { 819 if (!isStarted()) {
833 innerStart(); 820 innerStart();
821 if (m_tracingAgent)
822 m_tracingAgent->startFromBackend();
834 bool fromConsole = true; 823 bool fromConsole = true;
835 m_frontend->started(&fromConsole); 824 m_frontend->started(&fromConsole);
836 } 825 }
837 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeStamp, true, frameForExecutionContext(context)); 826 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeStamp, true, frameForExecutionContext(context));
838 } 827 }
839 828
840 void InspectorTimelineAgent::consoleTimelineEnd(ExecutionContext* context, const String& title, NewScriptState* scriptState) 829 void InspectorTimelineAgent::consoleTimelineEnd(ExecutionContext* context, const String& title, NewScriptState* scriptState)
841 { 830 {
842 if (!m_state->getBoolean(TimelineAgentState::enabled)) 831 if (!m_state->getBoolean(TimelineAgentState::enabled))
843 return; 832 return;
844 833
845 size_t index = m_consoleTimelines.find(title); 834 size_t index = m_consoleTimelines.find(title);
846 if (index == kNotFound) { 835 if (index == kNotFound) {
847 String message = String::format("Timeline '%s' was not started.", title. utf8().data()); 836 String message = String::format("Timeline '%s' was not started.", title. utf8().data());
848 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageL evel, message, String(), 0, 0, nullptr, scriptState); 837 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageL evel, message, String(), 0, 0, nullptr, scriptState);
849 return; 838 return;
850 } 839 }
851 840
852 String message = String::format("Timeline '%s' finished.", title.utf8().data ()); 841 String message = String::format("Timeline '%s' finished.", title.utf8().data ());
853 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeStamp, true, frameForExecutionContext(context)); 842 appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRe cordType::TimeStamp, true, frameForExecutionContext(context));
854 m_consoleTimelines.remove(index); 843 m_consoleTimelines.remove(index);
855 if (!m_consoleTimelines.size() && isStarted() && !m_state->getBoolean(Timeli neAgentState::startedFromProtocol)) { 844 if (!m_consoleTimelines.size() && isStarted() && !m_state->getBoolean(Timeli neAgentState::startedFromProtocol)) {
856 unwindRecordStack(); 845 unwindRecordStack();
846 if (m_tracingAgent)
847 m_tracingAgent->endFromBackend();
857 innerStop(true); 848 innerStop(true);
858 } 849 }
859 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel , message, String(), 0, 0, nullptr, scriptState); 850 mainFrame()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel , message, String(), 0, 0, nullptr, scriptState);
860 } 851 }
861 852
862 void InspectorTimelineAgent::domContentLoadedEventFired(LocalFrame* frame) 853 void InspectorTimelineAgent::domContentLoadedEventFired(LocalFrame* frame)
863 { 854 {
864 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( )); 855 bool isMainFrame = frame && m_pageAgent && (frame == m_pageAgent->mainFrame( ));
865 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec ordType::MarkDOMContent, false, frame); 856 appendRecord(TimelineRecordFactory::createMarkData(isMainFrame), TimelineRec ordType::MarkDOMContent, false, frame);
866 if (isMainFrame) 857 if (isMainFrame)
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 } 1179 }
1189 1180
1190 void InspectorTimelineAgent::unwindRecordStack() 1181 void InspectorTimelineAgent::unwindRecordStack()
1191 { 1182 {
1192 while (!m_recordStack.isEmpty()) { 1183 while (!m_recordStack.isEmpty()) {
1193 TimelineRecordEntry& entry = m_recordStack.last(); 1184 TimelineRecordEntry& entry = m_recordStack.last();
1194 didCompleteCurrentRecord(entry.type); 1185 didCompleteCurrentRecord(entry.type);
1195 } 1186 }
1196 } 1187 }
1197 1188
1198 InspectorTimelineAgent::InspectorTimelineAgent(InspectorPageAgent* pageAgent, In spectorDOMAgent* domAgent, InspectorLayerTreeAgent* layerTreeAgent, 1189 InspectorTimelineAgent::InspectorTimelineAgent(InspectorPageAgent* pageAgent, In spectorDOMAgent* domAgent, InspectorLayerTreeAgent* layerTreeAgent, InspectorTra cingAgent* tracingAgent,
1199 InspectorOverlay* overlay, InspectorType type, InspectorClient* client) 1190 InspectorOverlay* overlay, InspectorType type, InspectorClient* client)
1200 : InspectorBaseAgent<InspectorTimelineAgent>("Timeline") 1191 : InspectorBaseAgent<InspectorTimelineAgent>("Timeline")
1201 , m_pageAgent(pageAgent) 1192 , m_pageAgent(pageAgent)
1202 , m_domAgent(domAgent) 1193 , m_domAgent(domAgent)
1203 , m_layerTreeAgent(layerTreeAgent) 1194 , m_layerTreeAgent(layerTreeAgent)
1195 , m_tracingAgent(tracingAgent)
1204 , m_frontend(0) 1196 , m_frontend(0)
1205 , m_client(client) 1197 , m_client(client)
1206 , m_overlay(overlay) 1198 , m_overlay(overlay)
1207 , m_inspectorType(type) 1199 , m_inspectorType(type)
1208 , m_id(1) 1200 , m_id(1)
1209 , m_layerTreeId(0) 1201 , m_layerTreeId(0)
1210 , m_maxCallStackDepth(5) 1202 , m_maxCallStackDepth(5)
1211 , m_platformInstrumentationClientInstalledAtStackDepth(0) 1203 , m_platformInstrumentationClientInstalledAtStackDepth(0)
1212 , m_imageBeingPainted(0) 1204 , m_imageBeingPainted(0)
1213 , m_paintSetupStart(0) 1205 , m_paintSetupStart(0)
1214 , m_styleRecalcElementCounter(0) 1206 , m_styleRecalcElementCounter(0)
1215 , m_mayEmitFirstPaint(false) 1207 , m_mayEmitFirstPaint(false)
1216 , m_lastProgressTimestamp(0) 1208 , m_lastProgressTimestamp(0)
1217 , m_disableTracingOnStop(false)
1218 { 1209 {
1219 } 1210 }
1220 1211
1221 void InspectorTimelineAgent::appendRecord(PassRefPtr<JSONObject> data, const Str ing& type, bool captureCallStack, LocalFrame* frame) 1212 void InspectorTimelineAgent::appendRecord(PassRefPtr<JSONObject> data, const Str ing& type, bool captureCallStack, LocalFrame* frame)
1222 { 1213 {
1223 double ts = timestamp(); 1214 double ts = timestamp();
1224 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ts , captureCallStack ? m_maxCallStackDepth : 0, type, data); 1215 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ts , captureCallStack ? m_maxCallStackDepth : 0, type, data);
1225 setFrameIdentifier(record.get(), frame); 1216 setFrameIdentifier(record.get(), frame);
1226 addRecordToTimeline(record.release(), ts); 1217 addRecordToTimeline(record.release(), ts);
1227 } 1218 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 1355
1365 #ifndef NDEBUG 1356 #ifndef NDEBUG
1366 bool TimelineRecordStack::isOpenRecordOfType(const String& type) 1357 bool TimelineRecordStack::isOpenRecordOfType(const String& type)
1367 { 1358 {
1368 return !m_stack.isEmpty() && m_stack.last().type == type; 1359 return !m_stack.isEmpty() && m_stack.last().type == type;
1369 } 1360 }
1370 #endif 1361 #endif
1371 1362
1372 } // namespace WebCore 1363 } // namespace WebCore
1373 1364
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698