Commit d6390811 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Enable sampling profiler for IO thread of GPU process at startup

Bug: 795672
Change-Id: I31c81b44d915e49e9f8b381ff14df44939fa99e4
Reviewed-on: https://chromium-review.googlesource.com/879074Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Xi Cheng <chengx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531392}
parent 3806eaae
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/threading/platform_thread.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/time/time.h"
#include "chrome/common/stack_sampling_configuration.h"
#include "components/metrics/child_call_stack_profile_collector.h"
......@@ -39,6 +40,32 @@ namespace {
base::LazyInstance<metrics::ChildCallStackProfileCollector>::Leaky
g_call_stack_profile_collector = LAZY_INSTANCE_INITIALIZER;
// The profiler object is stored in a SequenceLocalStorageSlot on the IO thread
// so that it will be destroyed when the IO thread stops.
base::LazyInstance<base::SequenceLocalStorageSlot<
std::unique_ptr<base::StackSamplingProfiler>>>::Leaky
io_thread_sampling_profiler = LAZY_INSTANCE_INITIALIZER;
// Starts to profile the IO thread.
void StartIOThreadProfiling() {
StackSamplingConfiguration* config = StackSamplingConfiguration::Get();
if (config->IsProfilerEnabledForCurrentProcess()) {
auto profiler = std::make_unique<base::StackSamplingProfiler>(
base::PlatformThread::CurrentId(),
config->GetSamplingParamsForCurrentProcess(),
g_call_stack_profile_collector.Get().GetProfilerCallback(
metrics::CallStackProfileParams(
metrics::CallStackProfileParams::GPU_PROCESS,
metrics::CallStackProfileParams::IO_THREAD,
metrics::CallStackProfileParams::PROCESS_STARTUP,
metrics::CallStackProfileParams::MAY_SHUFFLE)));
profiler->Start();
io_thread_sampling_profiler.Get().Set(std::move(profiler));
}
}
} // namespace
ChromeContentGpuClient::ChromeContentGpuClient()
......@@ -98,6 +125,11 @@ void ChromeContentGpuClient::GpuServiceInitialized(
std::move(browser_interface));
}
void ChromeContentGpuClient::PostIOThreadCreated(
base::SingleThreadTaskRunner* io_task_runner) {
io_task_runner->PostTask(FROM_HERE, base::BindOnce(&StartIOThreadProfiling));
}
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<media::CdmProxy> ChromeContentGpuClient::CreateCdmProxy(
const std::string& cdm_guid) {
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/single_thread_task_runner.h"
#include "content/public/gpu/content_gpu_client.h"
#if defined(OS_CHROMEOS)
......@@ -31,6 +32,8 @@ class ChromeContentGpuClient : public content::ContentGpuClient {
void InitializeRegistry(service_manager::BinderRegistry* registry) override;
void GpuServiceInitialized(
const gpu::GpuPreferences& gpu_preferences) override;
void PostIOThreadCreated(
base::SingleThreadTaskRunner* io_task_runner) override;
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<media::CdmProxy> CreateCdmProxy(
......
......@@ -311,6 +311,10 @@ int GpuMain(const MainFunctionParams& parameters) {
#endif
GpuProcess gpu_process(io_thread_priority);
if (client)
client->PostIOThreadCreated(gpu_process.io_task_runner());
GpuChildThread* child_thread = new GpuChildThread(
std::move(gpu_init), std::move(deferred_messages.Get()));
deferred_messages.Get().clear();
......
......@@ -9,6 +9,7 @@
#include <string>
#include "base/metrics/field_trial.h"
#include "base/single_thread_task_runner.h"
#include "content/public/common/content_client.h"
#include "media/media_features.h"
#include "services/service_manager/public/cpp/binder_registry.h"
......@@ -43,6 +44,10 @@ class CONTENT_EXPORT ContentGpuClient {
virtual void GpuServiceInitialized(
const gpu::GpuPreferences& gpu_preferences) {}
// Called right after the IO thread is created.
virtual void PostIOThreadCreated(
base::SingleThreadTaskRunner* io_task_runner) {}
// Allows client to supply a SyncPointManager instance instead of having
// content internally create one.
virtual gpu::SyncPointManager* GetSyncPointManager();
......
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