1 // 2 // Copyright 2014 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #include "config.h" 8 9 #include "core/inspector/InspectorTracingAgent.h" 10 11 #include "core/inspector/IdentifiersFactory.h" 12 #include "core/inspector/InspectorClient.h" 13 #include "core/inspector/InspectorState.h" 14 #include "core/inspector/InspectorWorkerAgent.h" 15 #include "platform/TraceEvent.h" 16 17 namespace blink { 18 19 namespace TracingAgentState { 20 const char sessionId[] = "sessionId"; 21 const char tracingStarted[] = "tracingStarted"; 22 } 23 24 namespace { 25 const char devtoolsMetadataEventCategory[] = TRACE_DISABLED_BY_DEFAULT("devtools.timeline"); 26 } 27 28 InspectorTracingAgent::InspectorTracingAgent(InspectorClient* client, InspectorWorkerAgent* workerAgent) 29 : InspectorBaseAgent<InspectorTracingAgent>("Tracing") 30 , m_layerTreeId(0) 31 , m_client(client) 32 , m_frontend(0) 33 , m_workerAgent(workerAgent) 34 { 35 } 36 37 void InspectorTracingAgent::restore() 38 { 39 emitMetadataEvents(); 40 } 41 42 void InspectorTracingAgent::start(ErrorString*, const String& categoryFilter, const String&, const double*) 43 { 44 if (m_state->getBoolean(TracingAgentState::tracingStarted)) 45 return; 46 m_state->setString(TracingAgentState::sessionId, IdentifiersFactory::createIdentifier()); 47 m_state->setBoolean(TracingAgentState::tracingStarted, true); 48 m_client->enableTracing(categoryFilter); 49 emitMetadataEvents(); 50 } 51 52 void InspectorTracingAgent::end(ErrorString* errorString) 53 { 54 m_client->disableTracing(); 55 m_state->setBoolean(TracingAgentState::tracingStarted, false); 56 m_workerAgent->setTracingSessionId(String()); 57 } 58 59 String InspectorTracingAgent::sessionId() 60 { 61 return m_state->getString(TracingAgentState::sessionId); 62 } 63 64 void InspectorTracingAgent::emitMetadataEvents() 65 { 66 if (!m_state->getBoolean(TracingAgentState::tracingStarted)) 67 return; 68 TRACE_EVENT_INSTANT1(devtoolsMetadataEventCategory, "TracingStartedInPage", "sessionId", sessionId().utf8()); 69 if (m_layerTreeId) 70 setLayerTreeId(m_layerTreeId); 71 m_workerAgent->setTracingSessionId(sessionId()); 72 } 73 74 void InspectorTracingAgent::setLayerTreeId(int layerTreeId) 75 { 76 m_layerTreeId = layerTreeId; 77 TRACE_EVENT_INSTANT2(devtoolsMetadataEventCategory, "SetLayerTreeId", "sessionId", sessionId().utf8(), "layerTreeId", m_layerTreeId); 78 } 79 80 void InspectorTracingAgent::setFrontend(InspectorFrontend* frontend) 81 { 82 m_frontend = frontend->tracing(); 83 } 84 85 } 86