Commit 2e07c5d5 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Move CompletedCallback type to CallStackProfileBuilder class

Bug: 851163
Change-Id: I2346efb2fc9c7ac5e0be425ac9484babd6b6544d
Reviewed-on: https://chromium-review.googlesource.com/1123657Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Xi Cheng <chengx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572348}
parent 0b284c23
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/atomicops.h" #include "base/atomicops.h"
#include "base/base_export.h" #include "base/base_export.h"
#include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -270,18 +269,6 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -270,18 +269,6 @@ class BASE_EXPORT StackSamplingProfiler {
DISALLOW_COPY_AND_ASSIGN(ProfileBuilder); DISALLOW_COPY_AND_ASSIGN(ProfileBuilder);
}; };
// The callback type used to collect a completed profile. The passed |profile|
// is move-only. Other threads, including the UI thread, may block on callback
// completion so this should run as quickly as possible.
//
// IMPORTANT NOTE: The callback is invoked on a thread the profiler
// constructs, rather than on the thread used to construct the profiler, and
// thus the callback must be callable on any thread. For threads with message
// loops that create StackSamplingProfilers, posting a task to the message
// loop with the moved (i.e. std::move) profile is the thread-safe callback
// implementation.
using CompletedCallback = Callback<void(CallStackProfile)>;
// Creates a profiler for the CURRENT thread. An optional |test_delegate| can // Creates a profiler for the CURRENT thread. An optional |test_delegate| can
// be supplied by tests. The caller must ensure that this object gets // be supplied by tests. The caller must ensure that this object gets
// destroyed before the current thread exits. // destroyed before the current thread exits.
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
#include "base/threading/sequence_local_storage_slot.h" #include "base/threading/sequence_local_storage_slot.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/common/stack_sampling_configuration.h" #include "chrome/common/stack_sampling_configuration.h"
#include "components/metrics/call_stack_profile_builder.h"
#include "components/metrics/call_stack_profile_metrics_provider.h" #include "components/metrics/call_stack_profile_metrics_provider.h"
#include "components/metrics/call_stack_profile_params.h"
#include "components/metrics/child_call_stack_profile_collector.h" #include "components/metrics/child_call_stack_profile_collector.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
...@@ -221,7 +219,7 @@ ThreadProfiler::ThreadProfiler( ...@@ -221,7 +219,7 @@ ThreadProfiler::ThreadProfiler(
ScheduleNextPeriodicCollection(); ScheduleNextPeriodicCollection();
} }
StackSamplingProfiler::CompletedCallback ThreadProfiler::GetReceiverCallback( CallStackProfileBuilder::CompletedCallback ThreadProfiler::GetReceiverCallback(
const CallStackProfileParams& profile_params) { const CallStackProfileParams& profile_params) {
// TODO(wittman): Simplify the approach to getting the profiler callback // TODO(wittman): Simplify the approach to getting the profiler callback
// across CallStackProfileMetricsProvider and // across CallStackProfileMetricsProvider and
...@@ -247,14 +245,14 @@ StackSamplingProfiler::CompletedCallback ThreadProfiler::GetReceiverCallback( ...@@ -247,14 +245,14 @@ StackSamplingProfiler::CompletedCallback ThreadProfiler::GetReceiverCallback(
// static // static
void ThreadProfiler::ReceiveStartupProfile( void ThreadProfiler::ReceiveStartupProfile(
const StackSamplingProfiler::CompletedCallback& receiver_callback, const CallStackProfileBuilder::CompletedCallback& receiver_callback,
StackSamplingProfiler::CallStackProfile profile) { StackSamplingProfiler::CallStackProfile profile) {
receiver_callback.Run(std::move(profile)); receiver_callback.Run(std::move(profile));
} }
// static // static
void ThreadProfiler::ReceivePeriodicProfile( void ThreadProfiler::ReceivePeriodicProfile(
const StackSamplingProfiler::CompletedCallback& receiver_callback, const CallStackProfileBuilder::CompletedCallback& receiver_callback,
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner, scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner,
base::WeakPtr<ThreadProfiler> thread_profiler, base::WeakPtr<ThreadProfiler> thread_profiler,
StackSamplingProfiler::CallStackProfile profile) { StackSamplingProfiler::CallStackProfile profile) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/metrics/call_stack_profile_builder.h"
#include "components/metrics/call_stack_profile_params.h" #include "components/metrics/call_stack_profile_params.h"
namespace service_manager { namespace service_manager {
...@@ -92,19 +93,19 @@ class ThreadProfiler { ...@@ -92,19 +93,19 @@ class ThreadProfiler {
scoped_refptr<base::SingleThreadTaskRunner>()); scoped_refptr<base::SingleThreadTaskRunner>());
// Gets the completed callback for the ultimate receiver of the profile. // Gets the completed callback for the ultimate receiver of the profile.
base::StackSamplingProfiler::CompletedCallback GetReceiverCallback( CallStackProfileBuilder::CompletedCallback GetReceiverCallback(
const metrics::CallStackProfileParams& profile_params); const metrics::CallStackProfileParams& profile_params);
// Receives |profile| from the StackSamplingProfiler and forwards it on to // Receives |profile| from the CallStackProfileBuilder and forwards it on to
// the original |receiver_callback|. Note that we must obtain and bind the // the original |receiver_callback|. Note that we must obtain and bind the
// original receiver callback prior to the start of collection because the // original receiver callback prior to the start of collection because the
// collection start time is currently recorded when obtaining the callback in // collection start time is currently recorded when obtaining the callback in
// some collection scenarios. The implementation contains a TODO to fix this. // some collection scenarios. The implementation contains a TODO to fix this.
static void ReceiveStartupProfile( static void ReceiveStartupProfile(
const base::StackSamplingProfiler::CompletedCallback& receiver_callback, const CallStackProfileBuilder::CompletedCallback& receiver_callback,
base::StackSamplingProfiler::CallStackProfile profile); base::StackSamplingProfiler::CallStackProfile profile);
static void ReceivePeriodicProfile( static void ReceivePeriodicProfile(
const base::StackSamplingProfiler::CompletedCallback& receiver_callback, const CallStackProfileBuilder::CompletedCallback& receiver_callback,
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner, scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner,
base::WeakPtr<ThreadProfiler> thread_profiler, base::WeakPtr<ThreadProfiler> thread_profiler,
base::StackSamplingProfiler::CallStackProfile profile); base::StackSamplingProfiler::CallStackProfile profile);
......
...@@ -6,8 +6,6 @@ import("//testing/test.gni") ...@@ -6,8 +6,6 @@ import("//testing/test.gni")
static_library("metrics") { static_library("metrics") {
sources = [ sources = [
"call_stack_profile_builder.cc",
"call_stack_profile_builder.h",
"call_stack_profile_metrics_provider.cc", "call_stack_profile_metrics_provider.cc",
"call_stack_profile_metrics_provider.h", "call_stack_profile_metrics_provider.h",
"clean_exit_beacon.cc", "clean_exit_beacon.cc",
...@@ -107,7 +105,7 @@ static_library("metrics") { ...@@ -107,7 +105,7 @@ static_library("metrics") {
] ]
public_deps = [ public_deps = [
":call_stack_profile_params", ":call_stack_profile",
"//third_party/metrics_proto", "//third_party/metrics_proto",
] ]
...@@ -258,8 +256,10 @@ static_library("single_sample_metrics") { ...@@ -258,8 +256,10 @@ static_library("single_sample_metrics") {
] ]
} }
source_set("call_stack_profile_params") { source_set("call_stack_profile") {
sources = [ sources = [
"call_stack_profile_builder.cc",
"call_stack_profile_builder.h",
"call_stack_profile_params.h", "call_stack_profile_params.h",
] ]
...@@ -285,6 +285,7 @@ source_set("child_call_stacks") { ...@@ -285,6 +285,7 @@ source_set("child_call_stacks") {
"child_call_stack_profile_collector.h", "child_call_stack_profile_collector.h",
] ]
deps = [ deps = [
":call_stack_profile",
"//components/metrics/public/interfaces:call_stack_mojo_bindings", "//components/metrics/public/interfaces:call_stack_mojo_bindings",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
...@@ -360,7 +361,7 @@ source_set("unit_tests") { ...@@ -360,7 +361,7 @@ source_set("unit_tests") {
] ]
deps = [ deps = [
":call_stack_profile_params", ":call_stack_profile",
":child_call_stacks", ":child_call_stacks",
":component_metrics", ":component_metrics",
":metrics", ":metrics",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
using StackSamplingProfiler = base::StackSamplingProfiler; using StackSamplingProfiler = base::StackSamplingProfiler;
CallStackProfileBuilder::CallStackProfileBuilder( CallStackProfileBuilder::CallStackProfileBuilder(
const StackSamplingProfiler::CompletedCallback& callback) const CompletedCallback& callback)
: callback_(callback) {} : callback_(callback) {}
CallStackProfileBuilder::~CallStackProfileBuilder() = default; CallStackProfileBuilder::~CallStackProfileBuilder() = default;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <map> #include <map>
#include "base/callback.h"
// CallStackProfileBuilder builds a CallStackProfile from the collected sampling // CallStackProfileBuilder builds a CallStackProfile from the collected sampling
// data. // data.
// //
...@@ -20,8 +22,20 @@ ...@@ -20,8 +22,20 @@
class CallStackProfileBuilder class CallStackProfileBuilder
: public base::StackSamplingProfiler::ProfileBuilder { : public base::StackSamplingProfiler::ProfileBuilder {
public: public:
CallStackProfileBuilder( // The callback type used to collect a completed profile. The passed
const base::StackSamplingProfiler::CompletedCallback& callback); // CallStackProfile is move-only. Other threads, including the UI thread, may
// block on callback completion so this should run as quickly as possible.
//
// IMPORTANT NOTE: The callback is invoked on a thread the profiler
// constructs, rather than on the thread used to construct the profiler, and
// thus the callback must be callable on any thread. For threads with message
// loops that create CallStackProfileBuilders, posting a task to the message
// loop with the moved (i.e. std::move) profile is the thread-safe callback
// implementation.
using CompletedCallback =
base::Callback<void(base::StackSamplingProfiler::CallStackProfile)>;
CallStackProfileBuilder(const CompletedCallback& callback);
~CallStackProfileBuilder() override; ~CallStackProfileBuilder() override;
...@@ -43,7 +57,7 @@ class CallStackProfileBuilder ...@@ -43,7 +57,7 @@ class CallStackProfileBuilder
std::map<uintptr_t, size_t> module_index_; std::map<uintptr_t, size_t> module_index_;
// Callback made when sampling a profile completes. // Callback made when sampling a profile completes.
const base::StackSamplingProfiler::CompletedCallback callback_; const CompletedCallback callback_;
DISALLOW_COPY_AND_ASSIGN(CallStackProfileBuilder); DISALLOW_COPY_AND_ASSIGN(CallStackProfileBuilder);
}; };
......
...@@ -414,7 +414,7 @@ CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() {} ...@@ -414,7 +414,7 @@ CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() {}
CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() {} CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() {}
StackSamplingProfiler::CompletedCallback CallStackProfileBuilder::CompletedCallback
CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess( CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess(
const CallStackProfileParams& params) { const CallStackProfileParams& params) {
// Ignore the profile if the collection is disabled. If the collection state // Ignore the profile if the collection is disabled. If the collection state
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/profiler/stack_sampling_profiler.h" #include "base/profiler/stack_sampling_profiler.h"
#include "components/metrics/call_stack_profile_builder.h"
#include "components/metrics/call_stack_profile_params.h" #include "components/metrics/call_stack_profile_params.h"
#include "components/metrics/metrics_provider.h" #include "components/metrics/metrics_provider.h"
...@@ -36,10 +37,11 @@ class CallStackProfileMetricsProvider : public MetricsProvider { ...@@ -36,10 +37,11 @@ class CallStackProfileMetricsProvider : public MetricsProvider {
CallStackProfileMetricsProvider(); CallStackProfileMetricsProvider();
~CallStackProfileMetricsProvider() override; ~CallStackProfileMetricsProvider() override;
// Returns a callback for use with StackSamplingProfiler that sets up // Returns a callback for use with CallStackProfileBuilder that sets up
// parameters for general browser process sampling. The callback should be // parameters for general browser process sampling. The callback should be
// immediately passed to the StackSamplingProfiler, and should not be reused. // immediately passed to the CallStackProfileBuilder, and should not be
static base::StackSamplingProfiler::CompletedCallback // reused.
static CallStackProfileBuilder::CompletedCallback
GetProfilerCallbackForBrowserProcess(const CallStackProfileParams& params); GetProfilerCallbackForBrowserProcess(const CallStackProfileParams& params);
// Provides completed stack profile to the metrics provider. Intended for use // Provides completed stack profile to the metrics provider. Intended for use
......
...@@ -481,7 +481,7 @@ TEST_F(CallStackProfileMetricsProviderTest, ...@@ -481,7 +481,7 @@ TEST_F(CallStackProfileMetricsProviderTest,
CallStackProfileParams::MAIN_THREAD, CallStackProfileParams::MAIN_THREAD,
CallStackProfileParams::PROCESS_STARTUP, CallStackProfileParams::PROCESS_STARTUP,
CallStackProfileParams::MAY_SHUFFLE); CallStackProfileParams::MAY_SHUFFLE);
base::StackSamplingProfiler::CompletedCallback callback = CallStackProfileBuilder::CompletedCallback callback =
CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess( CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess(
params); params);
provider.OnRecordingDisabled(); provider.OnRecordingDisabled();
...@@ -507,7 +507,7 @@ TEST_F(CallStackProfileMetricsProviderTest, ...@@ -507,7 +507,7 @@ TEST_F(CallStackProfileMetricsProviderTest,
CallStackProfileParams::MAIN_THREAD, CallStackProfileParams::MAIN_THREAD,
CallStackProfileParams::PROCESS_STARTUP, CallStackProfileParams::PROCESS_STARTUP,
CallStackProfileParams::MAY_SHUFFLE); CallStackProfileParams::MAY_SHUFFLE);
base::StackSamplingProfiler::CompletedCallback callback = CallStackProfileBuilder::CompletedCallback callback =
CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess( CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess(
params); params);
provider.OnRecordingDisabled(); provider.OnRecordingDisabled();
...@@ -534,7 +534,7 @@ TEST_F(CallStackProfileMetricsProviderTest, ...@@ -534,7 +534,7 @@ TEST_F(CallStackProfileMetricsProviderTest,
CallStackProfileParams::MAIN_THREAD, CallStackProfileParams::MAIN_THREAD,
CallStackProfileParams::PROCESS_STARTUP, CallStackProfileParams::PROCESS_STARTUP,
CallStackProfileParams::MAY_SHUFFLE); CallStackProfileParams::MAY_SHUFFLE);
base::StackSamplingProfiler::CompletedCallback callback = CallStackProfileBuilder::CompletedCallback callback =
CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess( CallStackProfileMetricsProvider::GetProfilerCallbackForBrowserProcess(
params); params);
provider.OnRecordingEnabled(); provider.OnRecordingEnabled();
......
...@@ -38,7 +38,7 @@ ChildCallStackProfileCollector::ChildCallStackProfileCollector() {} ...@@ -38,7 +38,7 @@ ChildCallStackProfileCollector::ChildCallStackProfileCollector() {}
ChildCallStackProfileCollector::~ChildCallStackProfileCollector() {} ChildCallStackProfileCollector::~ChildCallStackProfileCollector() {}
base::StackSamplingProfiler::CompletedCallback CallStackProfileBuilder::CompletedCallback
ChildCallStackProfileCollector::GetProfilerCallback( ChildCallStackProfileCollector::GetProfilerCallback(
const CallStackProfileParams& params, const CallStackProfileParams& params,
base::TimeTicks profile_start_time) { base::TimeTicks profile_start_time) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "components/metrics/call_stack_profile_builder.h"
#include "components/metrics/public/interfaces/call_stack_profile_collector.mojom.h" #include "components/metrics/public/interfaces/call_stack_profile_collector.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -41,7 +42,7 @@ namespace metrics { ...@@ -41,7 +42,7 @@ namespace metrics {
// g_call_stack_profile_collector = LAZY_INSTANCE_INITIALIZER; // g_call_stack_profile_collector = LAZY_INSTANCE_INITIALIZER;
// //
// Then, invoke CreateCompletedCallback() to generate the CompletedCallback to // Then, invoke CreateCompletedCallback() to generate the CompletedCallback to
// pass when creating the StackSamplingProfiler. // pass when creating the CallStackProfileBuilder.
// //
// When the mojo InterfaceProvider becomes available, provide it via // When the mojo InterfaceProvider becomes available, provide it via
// SetParentProfileCollector(). // SetParentProfileCollector().
...@@ -50,11 +51,11 @@ class ChildCallStackProfileCollector { ...@@ -50,11 +51,11 @@ class ChildCallStackProfileCollector {
ChildCallStackProfileCollector(); ChildCallStackProfileCollector();
~ChildCallStackProfileCollector(); ~ChildCallStackProfileCollector();
// Get a callback for use with StackSamplingProfiler that provides the // Get a callback for use with CallStackProfileBuilder that provides the
// completed profile to this object. The callback should be immediately passed // completed profile to this object. The callback should be immediately passed
// to the StackSamplingProfiler, and should not be reused between // to the CallStackProfileBuilder, and should not be reused between
// StackSamplingProfilers. This function may be called on any thread. // CallStackProfileBuilders. This function may be called on any thread.
base::StackSamplingProfiler::CompletedCallback GetProfilerCallback( CallStackProfileBuilder::CompletedCallback GetProfilerCallback(
const CallStackProfileParams& params, const CallStackProfileParams& params,
base::TimeTicks profile_start_time); base::TimeTicks profile_start_time);
......
...@@ -2,3 +2,5 @@ per-file *.mojom=set noparent ...@@ -2,3 +2,5 @@ per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_struct_traits*.*=set noparent per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
...@@ -12,7 +12,7 @@ traits_headers = ...@@ -12,7 +12,7 @@ traits_headers =
[ "//components/metrics/public/cpp/call_stack_profile_struct_traits.h" ] [ "//components/metrics/public/cpp/call_stack_profile_struct_traits.h" ]
deps = [ deps = [
"//base", "//base",
"//components/metrics:call_stack_profile_params", "//components/metrics:call_stack_profile",
] ]
type_mappings = [ type_mappings = [
"metrics.mojom.CallStackModule=base::StackSamplingProfiler::Module", "metrics.mojom.CallStackModule=base::StackSamplingProfiler::Module",
......
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