Commit ad7b955c authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Move worker reporting out of InspectorTraceAgent

The agent is going to be removed soon.

The ExecutionContextWorkerRegistry is made responsible for reporting workers.
Each worker is reported as a trace event when a worker starts.
Also all previously registred workers are reported on trace start.

Change-Id: I3cde31ae74e991ad522c476b606bee3c0a5f8587
Reviewed-on: https://chromium-review.googlesource.com/1038684Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555294}
parent e6431236
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h" #include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h" #include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h" #include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
#include "third_party/blink/renderer/core/workers/worker_inspector_proxy.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
namespace blink { namespace blink {
...@@ -38,23 +36,8 @@ void InspectorTracingAgent::Trace(blink::Visitor* visitor) { ...@@ -38,23 +36,8 @@ void InspectorTracingAgent::Trace(blink::Visitor* visitor) {
void InspectorTracingAgent::Restore() { void InspectorTracingAgent::Restore() {
state_->getString(TracingAgentState::kSessionId, &session_id_); state_->getString(TracingAgentState::kSessionId, &session_id_);
if (IsStarted()) { if (IsStarted())
instrumenting_agents_->addInspectorTracingAgent(this);
EmitMetadataEvents(); EmitMetadataEvents();
}
}
void InspectorTracingAgent::DidStartWorker(WorkerInspectorProxy* proxy, bool) {
// For now we assume this is document. TODO(kinuko): Fix this.
DCHECK(proxy->GetExecutionContext()->IsDocument());
LocalFrame* frame = ToDocument(proxy->GetExecutionContext())->GetFrame();
if (proxy->GetWorkerThread() && frame && inspected_frames_->Contains(frame)) {
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"TracingSessionIdForWorker", TRACE_EVENT_SCOPE_THREAD,
"data",
InspectorTracingSessionIdForWorkerEvent::Data(
frame, proxy->Url(), proxy->GetWorkerThread()));
}
} }
void InspectorTracingAgent::start(Maybe<String> categories, void InspectorTracingAgent::start(Maybe<String> categories,
...@@ -71,7 +54,6 @@ void InspectorTracingAgent::start(Maybe<String> categories, ...@@ -71,7 +54,6 @@ void InspectorTracingAgent::start(Maybe<String> categories,
return; return;
} }
instrumenting_agents_->addInspectorTracingAgent(this);
session_id_ = IdentifiersFactory::CreateIdentifier(); session_id_ = IdentifiersFactory::CreateIdentifier();
state_->setString(TracingAgentState::kSessionId, session_id_); state_->setString(TracingAgentState::kSessionId, session_id_);
...@@ -101,14 +83,6 @@ void InspectorTracingAgent::EmitMetadataEvents() { ...@@ -101,14 +83,6 @@ void InspectorTracingAgent::EmitMetadataEvents() {
TRACE_EVENT_SCOPE_THREAD, "data", TRACE_EVENT_SCOPE_THREAD, "data",
InspectorTracingStartedInFrame::Data( InspectorTracingStartedInFrame::Data(
session_id_, inspected_frames_->Root())); session_id_, inspected_frames_->Root()));
for (LocalFrame* frame : *inspected_frames_) {
for (WorkerInspectorProxy* proxy :
ExecutionContextWorkerRegistry::From(*frame->GetDocument())
->GetWorkerInspectorProxies()) {
DidStartWorker(proxy, false);
}
}
} }
Response InspectorTracingAgent::disable() { Response InspectorTracingAgent::disable() {
...@@ -117,7 +91,6 @@ Response InspectorTracingAgent::disable() { ...@@ -117,7 +91,6 @@ Response InspectorTracingAgent::disable() {
} }
void InspectorTracingAgent::InnerDisable() { void InspectorTracingAgent::InnerDisable() {
instrumenting_agents_->removeInspectorTracingAgent(this);
state_->remove(TracingAgentState::kSessionId); state_->remove(TracingAgentState::kSessionId);
session_id_ = String(); session_id_ = String();
} }
......
...@@ -11,13 +11,11 @@ ...@@ -11,13 +11,11 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/inspector/inspector_base_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_base_agent.h"
#include "third_party/blink/renderer/core/inspector/protocol/Tracing.h" #include "third_party/blink/renderer/core/inspector/protocol/Tracing.h"
#include "third_party/blink/renderer/core/loader/frame_loader_types.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
class InspectedFrames; class InspectedFrames;
class WorkerInspectorProxy;
class CORE_EXPORT InspectorTracingAgent final class CORE_EXPORT InspectorTracingAgent final
: public InspectorBaseAgent<protocol::Tracing::Metainfo> { : public InspectorBaseAgent<protocol::Tracing::Metainfo> {
...@@ -31,9 +29,6 @@ class CORE_EXPORT InspectorTracingAgent final ...@@ -31,9 +29,6 @@ class CORE_EXPORT InspectorTracingAgent final
void Restore() override; void Restore() override;
protocol::Response disable() override; protocol::Response disable() override;
// InspectorInstrumentation methods
void DidStartWorker(WorkerInspectorProxy*, bool);
// Protocol method implementations. // Protocol method implementations.
void start(protocol::Maybe<String> categories, void start(protocol::Maybe<String> categories,
protocol::Maybe<String> options, protocol::Maybe<String> options,
......
...@@ -203,11 +203,6 @@ ...@@ -203,11 +203,6 @@
"willSendRequest", "willSendRequest",
] ]
}, },
Tracing: {
probes: [
"didStartWorker",
]
},
Worker: { Worker: {
probes: [ probes: [
"didStartWorker", "didStartWorker",
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h" #include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
namespace blink { namespace blink {
const char ExecutionContextWorkerRegistry::kSupplementName[] = const char ExecutionContextWorkerRegistry::kSupplementName[] =
...@@ -11,7 +13,13 @@ const char ExecutionContextWorkerRegistry::kSupplementName[] = ...@@ -11,7 +13,13 @@ const char ExecutionContextWorkerRegistry::kSupplementName[] =
ExecutionContextWorkerRegistry::ExecutionContextWorkerRegistry( ExecutionContextWorkerRegistry::ExecutionContextWorkerRegistry(
ExecutionContext& context) ExecutionContext& context)
: Supplement<ExecutionContext>(context) {} : Supplement<ExecutionContext>(context), weak_factory_(this) {
TraceEvent::AddAsyncEnabledStateObserver(weak_factory_.GetWeakPtr());
}
ExecutionContextWorkerRegistry::~ExecutionContextWorkerRegistry() {
TraceEvent::RemoveAsyncEnabledStateObserver(this);
}
ExecutionContextWorkerRegistry* ExecutionContextWorkerRegistry::From( ExecutionContextWorkerRegistry* ExecutionContextWorkerRegistry::From(
ExecutionContext& context) { ExecutionContext& context) {
...@@ -29,6 +37,7 @@ ExecutionContextWorkerRegistry* ExecutionContextWorkerRegistry::From( ...@@ -29,6 +37,7 @@ ExecutionContextWorkerRegistry* ExecutionContextWorkerRegistry::From(
void ExecutionContextWorkerRegistry::AddWorkerInspectorProxy( void ExecutionContextWorkerRegistry::AddWorkerInspectorProxy(
WorkerInspectorProxy* proxy) { WorkerInspectorProxy* proxy) {
proxies_.insert(proxy); proxies_.insert(proxy);
EmitTraceEvent(proxy);
} }
void ExecutionContextWorkerRegistry::RemoveWorkerInspectorProxy( void ExecutionContextWorkerRegistry::RemoveWorkerInspectorProxy(
...@@ -41,6 +50,25 @@ ExecutionContextWorkerRegistry::GetWorkerInspectorProxies() { ...@@ -41,6 +50,25 @@ ExecutionContextWorkerRegistry::GetWorkerInspectorProxies() {
return proxies_; return proxies_;
} }
void ExecutionContextWorkerRegistry::OnTraceLogEnabled() {
for (WorkerInspectorProxy* proxy : proxies_)
EmitTraceEvent(proxy);
}
void ExecutionContextWorkerRegistry::OnTraceLogDisabled() {}
void ExecutionContextWorkerRegistry::EmitTraceEvent(
WorkerInspectorProxy* proxy) {
ExecutionContext* context = GetSupplementable();
LocalFrame* frame =
context->IsDocument() ? ToDocument(context)->GetFrame() : nullptr;
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"TracingSessionIdForWorker", TRACE_EVENT_SCOPE_THREAD,
"data",
InspectorTracingSessionIdForWorkerEvent::Data(
frame, proxy->Url(), proxy->GetWorkerThread()));
}
void ExecutionContextWorkerRegistry::Trace(Visitor* visitor) { void ExecutionContextWorkerRegistry::Trace(Visitor* visitor) {
visitor->Trace(proxies_); visitor->Trace(proxies_);
Supplement<ExecutionContext>::Trace(visitor); Supplement<ExecutionContext>::Trace(visitor);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/worker_inspector_proxy.h" #include "third_party/blink/renderer/core/workers/worker_inspector_proxy.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h" #include "third_party/blink/renderer/platform/wtf/hash_set.h"
...@@ -15,6 +16,7 @@ namespace blink { ...@@ -15,6 +16,7 @@ namespace blink {
// Tracks the WorkerInspectorProxy objects created by a given ExecutionContext. // Tracks the WorkerInspectorProxy objects created by a given ExecutionContext.
class ExecutionContextWorkerRegistry final class ExecutionContextWorkerRegistry final
: public GarbageCollectedFinalized<ExecutionContextWorkerRegistry>, : public GarbageCollectedFinalized<ExecutionContextWorkerRegistry>,
public TraceEvent::AsyncEnabledStateObserver,
public Supplement<ExecutionContext> { public Supplement<ExecutionContext> {
USING_GARBAGE_COLLECTED_MIXIN(ExecutionContextWorkerRegistry); USING_GARBAGE_COLLECTED_MIXIN(ExecutionContextWorkerRegistry);
...@@ -23,16 +25,25 @@ class ExecutionContextWorkerRegistry final ...@@ -23,16 +25,25 @@ class ExecutionContextWorkerRegistry final
static ExecutionContextWorkerRegistry* From(ExecutionContext& context); static ExecutionContextWorkerRegistry* From(ExecutionContext& context);
~ExecutionContextWorkerRegistry() override;
void AddWorkerInspectorProxy(WorkerInspectorProxy* proxy); void AddWorkerInspectorProxy(WorkerInspectorProxy* proxy);
void RemoveWorkerInspectorProxy(WorkerInspectorProxy* proxy); void RemoveWorkerInspectorProxy(WorkerInspectorProxy* proxy);
const HeapHashSet<Member<WorkerInspectorProxy>>& GetWorkerInspectorProxies(); const HeapHashSet<Member<WorkerInspectorProxy>>& GetWorkerInspectorProxies();
// blink::TraceEvent::AsyncEnabledStateObserver implementation:
void OnTraceLogEnabled() override;
void OnTraceLogDisabled() override;
void Trace(Visitor* visitor) override; void Trace(Visitor* visitor) override;
private: private:
explicit ExecutionContextWorkerRegistry(ExecutionContext& context); explicit ExecutionContextWorkerRegistry(ExecutionContext& context);
void EmitTraceEvent(WorkerInspectorProxy* proxy);
HeapHashSet<Member<WorkerInspectorProxy>> proxies_; HeapHashSet<Member<WorkerInspectorProxy>> proxies_;
base::WeakPtrFactory<ExecutionContextWorkerRegistry> weak_factory_;
}; };
} // namespace blink } // namespace blink
......
...@@ -19,5 +19,16 @@ void DisableTracing() { ...@@ -19,5 +19,16 @@ void DisableTracing() {
base::trace_event::TraceLog::GetInstance()->SetDisabled(); base::trace_event::TraceLog::GetInstance()->SetDisabled();
} }
void AddAsyncEnabledStateObserver(
base::WeakPtr<AsyncEnabledStateObserver> observer) {
base::trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
observer);
}
void RemoveAsyncEnabledStateObserver(AsyncEnabledStateObserver* observer) {
base::trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(
observer);
}
} // namespace TraceEvent } // namespace TraceEvent
} // namespace blink } // namespace blink
...@@ -29,6 +29,8 @@ namespace blink { ...@@ -29,6 +29,8 @@ namespace blink {
namespace TraceEvent { namespace TraceEvent {
using base::trace_event::TraceScopedTrackableObject; using base::trace_event::TraceScopedTrackableObject;
using AsyncEnabledStateObserver =
base::trace_event::TraceLog::AsyncEnabledStateObserver;
inline base::TimeTicks ToTraceTimestamp(double seconds) { inline base::TimeTicks ToTraceTimestamp(double seconds) {
return base::TimeTicks() + base::TimeDelta::FromSecondsD(seconds); return base::TimeTicks() + base::TimeDelta::FromSecondsD(seconds);
...@@ -40,6 +42,11 @@ void ToTraceTimestamp(int64_t); ...@@ -40,6 +42,11 @@ void ToTraceTimestamp(int64_t);
PLATFORM_EXPORT void EnableTracing(const String& category_filter); PLATFORM_EXPORT void EnableTracing(const String& category_filter);
PLATFORM_EXPORT void DisableTracing(); PLATFORM_EXPORT void DisableTracing();
PLATFORM_EXPORT void AddAsyncEnabledStateObserver(
base::WeakPtr<AsyncEnabledStateObserver>);
PLATFORM_EXPORT void RemoveAsyncEnabledStateObserver(
AsyncEnabledStateObserver*);
} // namespace TraceEvent } // namespace TraceEvent
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment