Commit a415fc0d authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[Profiler]: Move IsSupportedForPlatform logic into base

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: default avatarMike Wittman <wittman@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784147}
parent 1f6464f5
......@@ -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 {
......@@ -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,
......
......@@ -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
......
......@@ -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();
......@@ -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.
......@@ -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";
......@@ -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
......@@ -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:
......
......@@ -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>
......@@ -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();
......
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