| OLD | NEW |
| 1 // | 1 // |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 // | 5 // |
| 6 | 6 |
| 7 #include "config.h" | 7 #include "config.h" |
| 8 | 8 |
| 9 #include "core/inspector/InspectorTracingAgent.h" | 9 #include "core/inspector/InspectorTracingAgent.h" |
| 10 | 10 |
| 11 #include "core/inspector/IdentifiersFactory.h" | 11 #include "core/inspector/IdentifiersFactory.h" |
| 12 #include "core/inspector/InspectorClient.h" | 12 #include "core/inspector/InspectorClient.h" |
| 13 #include "core/inspector/InspectorState.h" | 13 #include "core/inspector/InspectorState.h" |
| 14 #include "core/inspector/InspectorWorkerAgent.h" |
| 14 #include "platform/TraceEvent.h" | 15 #include "platform/TraceEvent.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 namespace TracingAgentState { | 19 namespace TracingAgentState { |
| 19 const char sessionId[] = "sessionId"; | 20 const char sessionId[] = "sessionId"; |
| 20 const char tracingStartedFromProtocol[] = "tracingStartedFromProtocol"; | 21 const char tracingStartedFromProtocol[] = "tracingStartedFromProtocol"; |
| 21 const char tracingStarted[] = "tracingStarted"; | 22 const char tracingStarted[] = "tracingStarted"; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 const char devtoolsMetadataEventCategory[] = TRACE_DISABLED_BY_DEFAULT("devtools
.timeline"); | 26 const char devtoolsMetadataEventCategory[] = TRACE_DISABLED_BY_DEFAULT("devtools
.timeline"); |
| 26 } | 27 } |
| 27 | 28 |
| 28 InspectorTracingAgent::InspectorTracingAgent(InspectorClient* client) | 29 InspectorTracingAgent::InspectorTracingAgent(InspectorClient* client, InspectorW
orkerAgent* workerAgent) |
| 29 : InspectorBaseAgent<InspectorTracingAgent>("Tracing") | 30 : InspectorBaseAgent<InspectorTracingAgent>("Tracing") |
| 30 , m_layerTreeId(0) | 31 , m_layerTreeId(0) |
| 31 , m_client(client) | 32 , m_client(client) |
| 32 , m_frontend(0) | 33 , m_frontend(0) |
| 34 , m_workerAgent(workerAgent) |
| 33 { | 35 { |
| 34 } | 36 } |
| 35 | 37 |
| 36 void InspectorTracingAgent::restore() | 38 void InspectorTracingAgent::restore() |
| 37 { | 39 { |
| 38 emitMetadataEvents(); | 40 emitMetadataEvents(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void InspectorTracingAgent::start(ErrorString*, const String& categoryFilter, co
nst String&, const double*) | 43 void InspectorTracingAgent::start(ErrorString*, const String& categoryFilter, co
nst String&, const double*) |
| 42 { | 44 { |
| 43 m_state->setBoolean(TracingAgentState::tracingStartedFromProtocol, true); | 45 m_state->setBoolean(TracingAgentState::tracingStartedFromProtocol, true); |
| 44 innerStart(categoryFilter, false); | 46 innerStart(categoryFilter, false); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void InspectorTracingAgent::end(ErrorString* errorString) | 49 void InspectorTracingAgent::end(ErrorString* errorString) |
| 48 { | 50 { |
| 49 m_state->setBoolean(TracingAgentState::tracingStarted, false); | 51 m_state->setBoolean(TracingAgentState::tracingStarted, false); |
| 50 m_consoleTimelines.clear(); | 52 m_consoleTimelines.clear(); |
| 51 m_frontend->stopped(); | 53 notifyTracingStopped(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void InspectorTracingAgent::innerStart(const String& categoryFilter, bool fromCo
nsole) | 56 void InspectorTracingAgent::innerStart(const String& categoryFilter, bool fromCo
nsole) |
| 55 { | 57 { |
| 56 m_state->setString(TracingAgentState::sessionId, IdentifiersFactory::createI
dentifier()); | 58 m_state->setString(TracingAgentState::sessionId, IdentifiersFactory::createI
dentifier()); |
| 57 m_state->setBoolean(TracingAgentState::tracingStarted, true); | 59 m_state->setBoolean(TracingAgentState::tracingStarted, true); |
| 58 m_client->enableTracing(categoryFilter); | 60 m_client->enableTracing(categoryFilter); |
| 59 emitMetadataEvents(); | 61 emitMetadataEvents(); |
| 60 m_frontend->started(fromConsole, sessionId()); | 62 m_frontend->started(fromConsole, sessionId()); |
| 61 } | 63 } |
| 62 | 64 |
| 63 String InspectorTracingAgent::sessionId() | 65 String InspectorTracingAgent::sessionId() |
| 64 { | 66 { |
| 65 return m_state->getString(TracingAgentState::sessionId); | 67 return m_state->getString(TracingAgentState::sessionId); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void InspectorTracingAgent::emitMetadataEvents() | 70 void InspectorTracingAgent::emitMetadataEvents() |
| 69 { | 71 { |
| 70 if (!m_state->getBoolean(TracingAgentState::tracingStarted)) | 72 if (!m_state->getBoolean(TracingAgentState::tracingStarted)) |
| 71 return; | 73 return; |
| 72 TRACE_EVENT_INSTANT1(devtoolsMetadataEventCategory, "TracingStartedInPage",
"sessionId", sessionId().utf8()); | 74 TRACE_EVENT_INSTANT1(devtoolsMetadataEventCategory, "TracingStartedInPage",
"sessionId", sessionId().utf8()); |
| 73 if (m_layerTreeId) | 75 if (m_layerTreeId) |
| 74 setLayerTreeId(m_layerTreeId); | 76 setLayerTreeId(m_layerTreeId); |
| 77 m_workerAgent->setTracingSessionId(sessionId()); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void InspectorTracingAgent::setLayerTreeId(int layerTreeId) | 80 void InspectorTracingAgent::setLayerTreeId(int layerTreeId) |
| 78 { | 81 { |
| 79 m_layerTreeId = layerTreeId; | 82 m_layerTreeId = layerTreeId; |
| 80 TRACE_EVENT_INSTANT2(devtoolsMetadataEventCategory, "SetLayerTreeId", "sessi
onId", sessionId().utf8(), "layerTreeId", m_layerTreeId); | 83 TRACE_EVENT_INSTANT2(devtoolsMetadataEventCategory, "SetLayerTreeId", "sessi
onId", sessionId().utf8(), "layerTreeId", m_layerTreeId); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void InspectorTracingAgent::consoleTimeline(const String& title) | 86 void InspectorTracingAgent::consoleTimeline(const String& title) |
| 84 { | 87 { |
| 85 m_consoleTimelines.append(title); | 88 m_consoleTimelines.append(title); |
| 86 if (m_state->getBoolean(TracingAgentState::tracingStarted)) | 89 if (m_state->getBoolean(TracingAgentState::tracingStarted)) |
| 87 return; | 90 return; |
| 88 innerStart("-*,disabled-by-default-devtools.timeline", true); | 91 innerStart("-*,disabled-by-default-devtools.timeline", true); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void InspectorTracingAgent::consoleTimelineEnd(const String& title) | 94 void InspectorTracingAgent::consoleTimelineEnd(const String& title) |
| 92 { | 95 { |
| 93 size_t index = m_consoleTimelines.find(title); | 96 size_t index = m_consoleTimelines.find(title); |
| 94 if (index == kNotFound) | 97 if (index == kNotFound) |
| 95 return; | 98 return; |
| 96 | 99 |
| 97 m_consoleTimelines.remove(index); | 100 m_consoleTimelines.remove(index); |
| 98 if (!m_consoleTimelines.size() | 101 if (!m_consoleTimelines.size() |
| 99 && m_state->getBoolean(TracingAgentState::tracingStarted) | 102 && m_state->getBoolean(TracingAgentState::tracingStarted) |
| 100 && !m_state->getBoolean(TracingAgentState::tracingStartedFromProtocol)) | 103 && !m_state->getBoolean(TracingAgentState::tracingStartedFromProtocol)) |
| 101 m_frontend->stopped(); | 104 notifyTracingStopped(); |
| 102 m_state->setBoolean(TracingAgentState::tracingStarted, false); | 105 m_state->setBoolean(TracingAgentState::tracingStarted, false); |
| 103 } | 106 } |
| 104 | 107 |
| 108 void InspectorTracingAgent::notifyTracingStopped() |
| 109 { |
| 110 m_frontend->stopped(); |
| 111 m_workerAgent->setTracingSessionId(String()); |
| 112 } |
| 113 |
| 105 void InspectorTracingAgent::setFrontend(InspectorFrontend* frontend) | 114 void InspectorTracingAgent::setFrontend(InspectorFrontend* frontend) |
| 106 { | 115 { |
| 107 m_frontend = frontend->tracing(); | 116 m_frontend = frontend->tracing(); |
| 108 } | 117 } |
| 109 | 118 |
| 110 } | 119 } |
| OLD | NEW |