Skip to content

Commit

Permalink
[Profiler]: Move IsSupportedForPlatform logic into base
Browse files Browse the repository at this point in the history
To re-use the same logic in ThreadProfiler and TracingSamplerProfiler.

Bug: 1098119
Change-Id: I3ae23af070e8a9798a2cc771c8fc347bb4fc3570
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2269741
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Mike Wittman <wittman@chromium.org>
Reviewed-by: oysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784147}
  • Loading branch information
Etienne Pierre-doray authored and Commit Bot committed Jun 30, 2020
1 parent 1f6464f commit a415fc0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
34 changes: 34 additions & 0 deletions base/profiler/stack_sampling_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"

#if defined(OS_WIN)
#include "base/win/static_constants.h"
#endif

#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif

namespace base {

Expand Down Expand Up @@ -729,6 +738,31 @@ TimeTicks StackSamplingProfiler::TestPeer::GetNextSampleTime(
now);
}

// static
// The profiler is currently only implemented for Windows x64 and MacOSX.
// TODO(https://crbug.com/1004855): enable for Android arm.
bool StackSamplingProfiler::IsSupported() {
#if (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) || \
(defined(OS_MACOSX) && !defined(OS_IOS))
#if defined(OS_MACOSX)
// TODO(https://crbug.com/1098119): Fix unwinding on OS X 10.16. The OS
// has moved all system libraries into the dyld shared cache and this
// seems to break the sampling profiler.
if (base::mac::IsOSLaterThan10_15_DontCallThis())
return false;
#endif
#if defined(OS_WIN)
// Do not start the profiler when Application Verifier is in use; running them
// simultaneously can cause crashes and has no known use case.
if (GetModuleHandleA(base::win::kApplicationVerifierDllName))
return false;
#endif
return true;
#else
return false;
#endif
}

StackSamplingProfiler::StackSamplingProfiler(
SamplingProfilerThreadToken thread_token,
const SamplingParams& params,
Expand Down
4 changes: 4 additions & 0 deletions base/profiler/stack_sampling_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class BASE_EXPORT StackSamplingProfiler {
TimeDelta sampling_interval = TimeDelta::FromMilliseconds(100);
};

// Returns true if the profiler is supported on the current platform
// configuration.
static bool IsSupported();

// Creates a profiler for the specified thread. |unwinders| is required on
// Android since the unwinder is provided outside StackSamplingProfiler, but
// must be empty on other platforms. When attempting to unwind, the relative
Expand Down
29 changes: 6 additions & 23 deletions chrome/common/profiler/stack_sampling_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ namespace {
base::LazyInstance<StackSamplingConfiguration>::Leaky g_configuration =
LAZY_INSTANCE_INITIALIZER;

// The profiler is currently only implemented for Windows x64 and Mac x64.
// TODO(https://crbug.com/1004855): enable for Android arm.
bool IsProfilerSupportedForPlatformAndChannel() {
#if (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) || defined(OS_MACOSX)
bool IsProfilerEnabledForChannel() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Only run on canary and dev.
const version_info::Channel channel = chrome::GetChannel();
Expand All @@ -49,9 +46,6 @@ bool IsProfilerSupportedForPlatformAndChannel() {
#else
return true;
#endif
#else
return false;
#endif
}

// Returns true if the current execution is taking place in the browser process.
Expand Down Expand Up @@ -131,7 +125,9 @@ bool StackSamplingConfiguration::GetSyntheticFieldTrial(
std::string* group_name) const {
DCHECK(IsBrowserProcess());

if (!IsProfilerSupportedForPlatformAndChannel())
if (!base::StackSamplingProfiler::IsSupported())
return false;
if (!IsProfilerEnabledForChannel())
return false;

*trial_name = "SyntheticStackProfilingConfiguration";
Expand Down Expand Up @@ -224,16 +220,10 @@ StackSamplingConfiguration::GenerateConfiguration() {
if (!IsBrowserProcess())
return PROFILE_FROM_COMMAND_LINE;

if (!IsProfilerSupportedForPlatformAndChannel())
if (!base::StackSamplingProfiler::IsSupported())
return PROFILE_DISABLED;

#if defined(OS_MACOSX)
// TODO(https://crbug.com/1098119): Fix unwinding on OS X 10.16. The OS has
// moved all system libraries into the dyld shared cache and this seems to
// break the sampling profiler.
if (base::mac::IsOSLaterThan10_15_DontCallThis())
if (!IsProfilerEnabledForChannel())
return PROFILE_DISABLED;
#endif

#if defined(OS_ANDROID)
// Allow profiling if the Android Java/native unwinder module is available at
Expand All @@ -258,13 +248,6 @@ StackSamplingConfiguration::GenerateConfiguration() {
}
#endif

#if defined(OS_WIN)
// Do not start the profiler when Application Verifier is in use; running them
// simultaneously can cause crashes and has no known use case.
if (GetModuleHandleA(base::win::kApplicationVerifierDllName))
return PROFILE_DISABLED;
#endif

switch (chrome::GetChannel()) {
// Enable the profiler unconditionally for development/waterfall builds.
case version_info::Channel::UNKNOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
#include "base/android/reached_code_profiler.h"
#endif

#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif

#if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && \
defined(OFFICIAL_BUILD)
#include <dlfcn.h>
Expand Down Expand Up @@ -665,13 +661,8 @@ void TracingSamplerProfiler::StartTracing(
return;
#endif

#if defined(OS_MACOSX)
// TODO(https://crbug.com/1098119): Fix unwinding on OS X 10.16. The OS has
// moved all system libraries into the dyld shared cache and this seems to
// break the sampling profiler.
if (base::mac::IsOSLaterThan10_15_DontCallThis())
if (!base::StackSamplingProfiler::IsSupported())
return;
#endif

base::StackSamplingProfiler::SamplingParams params;
params.samples_per_profile = std::numeric_limits<int>::max();
Expand Down

0 comments on commit a415fc0

Please sign in to comment.