Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "platform/TraceEvent.h" | |
| 15 | |
| 16 namespace WebCore { | |
| 17 | |
| 18 namespace TracingAgentState { | |
| 19 const char enabled[] = "enabled"; | |
| 20 const char sessionId[] = "sessionId"; | |
| 21 const char tracingCategoryFilter[] = "tracingCategoryFilter"; | |
| 22 } | |
| 23 | |
| 24 InspectorTracingAgent::InspectorTracingAgent(InspectorClient* client) | |
| 25 : InspectorBaseAgent<InspectorTracingAgent>("Tracing") | |
| 26 , m_frontend(0) | |
| 27 , m_client(client) | |
| 28 , m_shouldStopTracing(false) | |
| 29 , m_layerTreeId(0) | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 void InspectorTracingAgent::setFrontend(InspectorFrontend* frontend) | |
| 34 { | |
| 35 m_frontend = frontend->tracing(); | |
| 36 } | |
| 37 | |
| 38 void InspectorTracingAgent::clearFrontend() | |
| 39 { | |
| 40 ErrorString unused; | |
| 41 disable(&unused); | |
| 42 m_frontend = 0; | |
| 43 } | |
| 44 | |
| 45 void InspectorTracingAgent::restore() | |
| 46 { | |
| 47 emitMetadataEvents(); | |
| 48 } | |
| 49 | |
| 50 void InspectorTracingAgent::enable(ErrorString*, const String& categoryFilter) | |
| 51 { | |
| 52 m_state->setBoolean(TracingAgentState::enabled, true); | |
| 53 m_state->setString(TracingAgentState::tracingCategoryFilter, categoryFilter) ; | |
| 54 } | |
| 55 | |
| 56 void InspectorTracingAgent::disable(ErrorString*) | |
| 57 { | |
| 58 m_state->setBoolean(TracingAgentState::enabled, false); | |
| 59 } | |
| 60 | |
| 61 void InspectorTracingAgent::start(ErrorString*, const String&, const String&, co nst double*, String* outSessionId) | |
| 62 { | |
| 63 innerStart(); | |
| 64 *outSessionId = sessionId(); | |
| 65 } | |
| 66 | |
| 67 void InspectorTracingAgent::startFromBackend() | |
| 68 { | |
| 69 if (!m_state->getBoolean(TracingAgentState::enabled)) { | |
| 70 m_shouldStopTracing = false; | |
| 71 return; | |
| 72 } | |
| 73 m_shouldStopTracing = true; | |
| 74 String tracingCategoryFilter = m_state->getString(TracingAgentState::tracing CategoryFilter); | |
| 75 m_client->enableTracing(tracingCategoryFilter); | |
| 76 innerStart(); | |
| 77 } | |
| 78 | |
| 79 void InspectorTracingAgent::endFromBackend() | |
| 80 { | |
| 81 if (!m_shouldStopTracing) | |
| 82 return; | |
| 83 m_shouldStopTracing = true; | |
| 84 m_client->disableTracing(); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 void InspectorTracingAgent::innerStart() | |
| 89 { | |
| 90 String sessionId = IdentifiersFactory::createIdentifier(); | |
| 91 m_state->setString(TracingAgentState::sessionId, sessionId); | |
| 92 emitMetadataEvents(); | |
| 93 } | |
| 94 | |
| 95 String InspectorTracingAgent::sessionId() | |
| 96 { | |
| 97 return m_state->getString(TracingAgentState::sessionId); | |
| 98 } | |
| 99 | |
| 100 const char devtoolsMetadataEventCategory[] = TRACE_DISABLED_BY_DEFAULT("devtools .timeline"); | |
|
yurys
2014/04/25 09:13:00
Please move this into anonymous namespace at the t
| |
| 101 | |
| 102 void InspectorTracingAgent::emitMetadataEvents() | |
| 103 { | |
| 104 TRACE_EVENT_INSTANT1(devtoolsMetadataEventCategory, "TracingStartedInPage", "sessionId", sessionId().utf8()); | |
| 105 if (m_layerTreeId) | |
| 106 setLayerTreeId(m_layerTreeId); | |
| 107 } | |
| 108 | |
| 109 void InspectorTracingAgent::setLayerTreeId(int layerTreeId) | |
| 110 { | |
| 111 m_layerTreeId = layerTreeId; | |
| 112 TRACE_EVENT_INSTANT2(devtoolsMetadataEventCategory, "SetLayerTreeId", "sessi onId", sessionId().utf8(), "layerTreeId", m_layerTreeId); | |
| 113 } | |
| 114 | |
| 115 } | |
| OLD | NEW |