Commit 742e391e authored by Mikhail Fomitchev's avatar Mikhail Fomitchev Committed by Commit Bot

Initialize a global instance of MojoUkmRecorder for the GPU process.

We need to be able to log UKM metrics from the compositor thread of the GPU
process, so initialize a global instance of MojoUkmRecorder to do that.

TBR=sky@chromium.org
(for DEPS change)

Bug: 717629
Change-Id: I69bedeed7c16bb69b50b7e12da590ba1c69a3c9c
Reviewed-on: https://chromium-review.googlesource.com/744544
Commit-Queue: Mikhail Fomitchev <mfomitchev@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516015}
parent 826f56b0
......@@ -24,6 +24,8 @@ source_set("main") {
"//gpu/ipc/service",
"//ipc",
"//mojo/public/cpp/system",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/interfaces",
"//services/service_manager/public/cpp",
"//services/viz/privileged/interfaces",
"//ui/gfx:memory_buffer",
......
......@@ -6,5 +6,7 @@ include_rules = [
"+gpu/ipc/common",
"+gpu/ipc/service",
"+mojo/public/cpp",
"+services/metrics/public",
"+services/service_manager/public/cpp",
"+services/viz/privileged/interfaces",
]
......@@ -21,6 +21,10 @@
#include "gpu/ipc/gpu_in_process_thread_service.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
#include "services/metrics/public/interfaces/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
namespace {
......@@ -105,6 +109,8 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
compositor_thread_task_runner_ = compositor_thread_->task_runner();
}
CreateUkmRecorderIfNeeded(dependencies.connector);
gpu_service_ = base::MakeUnique<GpuServiceImpl>(
gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(),
io_thread_ ? io_thread_->task_runner()
......@@ -114,6 +120,8 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
VizMainImpl::~VizMainImpl() {
DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
if (ukm_recorder_)
ukm::DelegatingUkmRecorder::Get()->RemoveDelegate(ukm_recorder_.get());
if (io_thread_)
io_thread_->Stop();
}
......@@ -194,6 +202,18 @@ void VizMainImpl::CreateGpuService(
delegate_->OnGpuServiceConnection(gpu_service_.get());
}
void VizMainImpl::CreateUkmRecorderIfNeeded(
service_manager::Connector* connector) {
// If GPU is running in the browser process, we can use browser's UKMRecorder.
if (gpu_init_->gpu_info().in_process_gpu)
return;
DCHECK(connector) << "Unable to initialize UKMRecorder in the GPU process - "
<< "no valid connector.";
ukm_recorder_ = ukm::MojoUkmRecorder::Create(connector);
ukm::DelegatingUkmRecorder::Get()->AddDelegate(ukm_recorder_->GetWeakPtr());
}
void VizMainImpl::CreateFrameSinkManager(
mojom::FrameSinkManagerRequest request,
mojom::FrameSinkManagerClientPtr client) {
......
......@@ -19,6 +19,14 @@ class GpuMemoryBufferFactory;
class SyncPointManager;
} // namespace gpu
namespace service_manager {
class Connector;
}
namespace ukm {
class MojoUkmRecorder;
}
namespace viz {
class DisplayProvider;
class FrameSinkManagerImpl;
......@@ -53,6 +61,7 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
gpu::SyncPointManager* sync_point_manager = nullptr;
base::WaitableEvent* shutdown_event = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner;
service_manager::Connector* connector = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(ExternalDependencies);
......@@ -85,6 +94,9 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
const GpuServiceImpl* gpu_service() const { return gpu_service_.get(); }
private:
// Initializes GPU's UkmRecorder if GPU is running in it's own process.
void CreateUkmRecorderIfNeeded(service_manager::Connector* connector);
void CreateFrameSinkManagerInternal(
mojom::FrameSinkManagerRequest request,
mojom::FrameSinkManagerClientPtrInfo client_info);
......@@ -134,6 +146,7 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
std::unique_ptr<base::Thread> compositor_thread_;
scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner_;
std::unique_ptr<ukm::MojoUkmRecorder> ukm_recorder_;
std::unique_ptr<base::PowerMonitor> power_monitor_;
mojo::Binding<mojom::VizMain> binding_;
mojo::AssociatedBinding<mojom::VizMain> associated_binding_;
......
......@@ -131,7 +131,8 @@ class QueueingConnectionFilter : public ConnectionFilter {
DISALLOW_COPY_AND_ASSIGN(QueueingConnectionFilter);
};
viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() {
viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies(
service_manager::Connector* connector) {
viz::VizMainImpl::ExternalDependencies deps;
deps.create_display_compositor =
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableViz);
......@@ -140,6 +141,7 @@ viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() {
auto* process = ChildProcess::current();
deps.shutdown_event = process->GetShutDownEvent();
deps.io_thread_task_runner = process->io_task_runner();
deps.connector = connector;
return deps;
}
......@@ -163,7 +165,9 @@ GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params,
GpuChildThread::GpuChildThread(const ChildThreadImpl::Options& options,
std::unique_ptr<gpu::GpuInit> gpu_init)
: ChildThreadImpl(options),
viz_main_(this, CreateVizMainDependencies(), std::move(gpu_init)),
viz_main_(this,
CreateVizMainDependencies(GetConnector()),
std::move(gpu_init)),
weak_factory_(this) {
if (in_process_gpu()) {
DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
......
......@@ -20,7 +20,8 @@
"requires": {
"*": [ "app" ],
"content_browser": [ "gpu" ],
"device": [ "device:power_monitor" ]
"device": [ "device:power_monitor" ],
"metrics": [ "url_keyed_metrics" ]
}
}
}
......
......@@ -12,7 +12,7 @@
namespace ukm {
MojoUkmRecorder::MojoUkmRecorder(mojom::UkmRecorderInterfacePtr interface)
: interface_(std::move(interface)) {}
: interface_(std::move(interface)), weak_factory_(this) {}
MojoUkmRecorder::~MojoUkmRecorder() = default;
// static
......@@ -28,6 +28,10 @@ void MojoUkmRecorder::UpdateSourceURL(SourceId source_id, const GURL& url) {
interface_->UpdateSourceURL(source_id, url.spec());
}
base::WeakPtr<MojoUkmRecorder> MojoUkmRecorder::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
void MojoUkmRecorder::AddEntry(mojom::UkmEntryPtr entry) {
interface_->AddEntry(std::move(entry));
}
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "base/memory/weak_ptr.h"
#include "services/metrics/public/cpp/metrics_export.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/interfaces/ukm_interface.mojom.h"
......@@ -43,12 +44,16 @@ class METRICS_EXPORT MojoUkmRecorder : public UkmRecorder {
static std::unique_ptr<MojoUkmRecorder> Create(
service_manager::Connector* connector);
base::WeakPtr<MojoUkmRecorder> GetWeakPtr();
private:
// UkmRecorder:
void AddEntry(mojom::UkmEntryPtr entry) override;
mojom::UkmRecorderInterfacePtr interface_;
base::WeakPtrFactory<MojoUkmRecorder> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MojoUkmRecorder);
};
......
......@@ -8,7 +8,7 @@
#include "services/viz/service.h"
MojoResult ServiceMain(MojoHandle service_request_handle) {
viz::Service* viz_service = new viz::Service;
viz::Service* viz_service = new viz::Service();
service_manager::ServiceRunner runner(viz_service);
runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
return runner.Run(service_request_handle);
......
......@@ -5,6 +5,7 @@
#include "services/viz/service.h"
#include "components/viz/service/main/viz_main_impl.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/viz/privileged/interfaces/viz_main.mojom.h"
namespace viz {
......@@ -20,6 +21,7 @@ void Service::OnStart() {
VizMainImpl::ExternalDependencies deps;
deps.create_display_compositor = true;
deps.connector = context()->connector();
viz_main_ = std::make_unique<VizMainImpl>(nullptr, std::move(deps));
}
......
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