diff --git a/base/profiler/native_stack_sampler_win.cc b/base/profiler/native_stack_sampler_win.cc index a39502d378ac87..bc935c0e588e12 100644 --- a/base/profiler/native_stack_sampler_win.cc +++ b/base/profiler/native_stack_sampler_win.cc @@ -266,7 +266,7 @@ bool NativeStackSamplerWin::GetModuleForHandle( module->filename = base::FilePath(module_name); - module->base_address = reinterpret_cast(module_handle); + module->base_address = reinterpret_cast(module_handle); module->id = GetBuildIDForModule(module_handle); if (module->id.empty()) @@ -305,7 +305,7 @@ void NativeStackSamplerWin::CopyToSample( for (int i = 0; i < stack_depth; ++i) { sample->push_back(StackSamplingProfiler::Frame( - instruction_pointers[i], + reinterpret_cast(instruction_pointers[i]), GetModuleIndex(module_handles[i], module))); } } diff --git a/base/profiler/stack_sampling_profiler.cc b/base/profiler/stack_sampling_profiler.cc index f2467c332d86a8..a197d844093d13 100644 --- a/base/profiler/stack_sampling_profiler.cc +++ b/base/profiler/stack_sampling_profiler.cc @@ -83,8 +83,8 @@ void AsyncRunner::RunCallbackAndDeleteInstance( // StackSamplingProfiler::Module ---------------------------------------------- -StackSamplingProfiler::Module::Module() : base_address(nullptr) {} -StackSamplingProfiler::Module::Module(const void* base_address, +StackSamplingProfiler::Module::Module() : base_address(0u) {} +StackSamplingProfiler::Module::Module(uintptr_t base_address, const std::string& id, const FilePath& filename) : base_address(base_address), id(id), filename(filename) {} @@ -93,13 +93,14 @@ StackSamplingProfiler::Module::~Module() {} // StackSamplingProfiler::Frame ----------------------------------------------- -StackSamplingProfiler::Frame::Frame(const void* instruction_pointer, +StackSamplingProfiler::Frame::Frame(uintptr_t instruction_pointer, size_t module_index) - : instruction_pointer(instruction_pointer), - module_index(module_index) {} + : instruction_pointer(instruction_pointer), module_index(module_index) {} StackSamplingProfiler::Frame::~Frame() {} +StackSamplingProfiler::Frame::Frame() {} + // StackSamplingProfiler::CallStackProfile ------------------------------------ StackSamplingProfiler::CallStackProfile::CallStackProfile() {} diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h index 9aad10fbeda7fb..9aa9c31d67afd3 100644 --- a/base/profiler/stack_sampling_profiler.h +++ b/base/profiler/stack_sampling_profiler.h @@ -63,12 +63,13 @@ class BASE_EXPORT StackSamplingProfiler { // Module represents the module (DLL or exe) corresponding to a stack frame. struct BASE_EXPORT Module { Module(); - Module(const void* base_address, const std::string& id, + Module(uintptr_t base_address, + const std::string& id, const FilePath& filename); ~Module(); // Points to the base address of the module. - const void* base_address; + uintptr_t base_address; // An opaque binary string that uniquely identifies a particular program // version with high probability. This is parsed from headers of the loaded @@ -88,11 +89,14 @@ class BASE_EXPORT StackSamplingProfiler { // Identifies an unknown module. static const size_t kUnknownModuleIndex = static_cast(-1); - Frame(const void* instruction_pointer, size_t module_index); + Frame(uintptr_t instruction_pointer, size_t module_index); ~Frame(); + // Default constructor to satisfy IPC macros. Do not use explicitly. + Frame(); + // The sampled instruction pointer within the function. - const void* instruction_pointer; + uintptr_t instruction_pointer; // Index of the module in CallStackProfile::modules. We don't represent // module state directly here to save space. diff --git a/base/profiler/stack_sampling_profiler_unittest.cc b/base/profiler/stack_sampling_profiler_unittest.cc index 1426f4647f6154..3fceed49ade64e 100644 --- a/base/profiler/stack_sampling_profiler_unittest.cc +++ b/base/profiler/stack_sampling_profiler_unittest.cc @@ -183,8 +183,9 @@ Sample::const_iterator FindFirstFrameWithinFunction( int function_size) { function_address = MaybeFixupFunctionAddressForILT(function_address); for (auto it = sample.begin(); it != sample.end(); ++it) { - if ((it->instruction_pointer >= function_address) && - (it->instruction_pointer < + if ((reinterpret_cast(it->instruction_pointer) >= + function_address) && + (reinterpret_cast(it->instruction_pointer) < (static_cast(function_address) + function_size))) return it; } @@ -198,7 +199,7 @@ std::string FormatSampleForDiagnosticOutput( std::string output; for (const Frame& frame: sample) { output += StringPrintf( - "0x%p %s\n", frame.instruction_pointer, + "0x%p %s\n", reinterpret_cast(frame.instruction_pointer), modules[frame.module_index].filename.AsUTF8Unsafe().c_str()); } return output; diff --git a/components/metrics/call_stack_profile_metrics_provider.h b/components/metrics/call_stack_profile_metrics_provider.h index d368c99c4ace94..90e3e6ae8fe550 100644 --- a/components/metrics/call_stack_profile_metrics_provider.h +++ b/components/metrics/call_stack_profile_metrics_provider.h @@ -18,11 +18,13 @@ class ChromeUserMetricsExtension; class CallStackProfileMetricsProvider : public MetricsProvider { public: // The event that triggered the profile collection. + // This enum should be kept in sync with content/common/profiled_stack_state.h enum Trigger { UNKNOWN, PROCESS_STARTUP, JANKY_TASK, - THREAD_HUNG + THREAD_HUNG, + TRIGGER_LAST = THREAD_HUNG }; // Parameters to pass back to the metrics provider. diff --git a/components/metrics/call_stack_profile_metrics_provider_unittest.cc b/components/metrics/call_stack_profile_metrics_provider_unittest.cc index 395ef8f053a7fd..9ffaf573b486fa 100644 --- a/components/metrics/call_stack_profile_metrics_provider_unittest.cc +++ b/components/metrics/call_stack_profile_metrics_provider_unittest.cc @@ -65,7 +65,7 @@ TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { const Module profile_modules[][2] = { { Module( - reinterpret_cast(module1_base_address), + module1_base_address, "ABCD", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\chrome.exe") @@ -74,7 +74,7 @@ TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { #endif ), Module( - reinterpret_cast(module2_base_address), + module2_base_address, "EFGH", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\third_party.dll") @@ -85,7 +85,7 @@ TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { }, { Module( - reinterpret_cast(module3_base_address), + module3_base_address, "MNOP", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\third_party2.dll") @@ -94,7 +94,7 @@ TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { #endif ), Module( // Repeated from the first profile. - reinterpret_cast(module1_base_address), + module1_base_address, "ABCD", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\chrome.exe") @@ -147,26 +147,26 @@ TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { const Frame profile_sample_frames[][2][3] = { { { - Frame(reinterpret_cast(module1_base_address + 0x10), 0), - Frame(reinterpret_cast(module2_base_address + 0x20), 1), - Frame(reinterpret_cast(module1_base_address + 0x30), 0) + Frame(module1_base_address + 0x10, 0), + Frame(module2_base_address + 0x20, 1), + Frame(module1_base_address + 0x30, 0) }, { - Frame(reinterpret_cast(module2_base_address + 0x10), 1), - Frame(reinterpret_cast(module1_base_address + 0x20), 0), - Frame(reinterpret_cast(module2_base_address + 0x30), 1) + Frame(module2_base_address + 0x10, 1), + Frame(module1_base_address + 0x20, 0), + Frame(module2_base_address + 0x30, 1) } }, { { - Frame(reinterpret_cast(module3_base_address + 0x10), 0), - Frame(reinterpret_cast(module1_base_address + 0x20), 1), - Frame(reinterpret_cast(module3_base_address + 0x30), 0) + Frame(module3_base_address + 0x10, 0), + Frame(module1_base_address + 0x20, 1), + Frame(module3_base_address + 0x30, 0) }, { - Frame(reinterpret_cast(module1_base_address + 0x10), 1), - Frame(reinterpret_cast(module3_base_address + 0x20), 0), - Frame(reinterpret_cast(module1_base_address + 0x30), 1) + Frame(module1_base_address + 0x10, 1), + Frame(module3_base_address + 0x20, 0), + Frame(module1_base_address + 0x30, 1) } } }; @@ -277,7 +277,7 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { const Module modules[] = { Module( - reinterpret_cast(module_base_address), + module_base_address, "ABCD", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\chrome.exe") @@ -289,10 +289,10 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { // Duplicate samples in slots 0, 2, and 3. const Frame sample_frames[][1] = { - { Frame(reinterpret_cast(module_base_address + 0x10), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x20), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x10), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x10), 0) } + { Frame(module_base_address + 0x10, 0), }, + { Frame(module_base_address + 0x20, 0), }, + { Frame(module_base_address + 0x10, 0), }, + { Frame(module_base_address + 0x10, 0) } }; Profile profile; @@ -356,7 +356,7 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { const Module modules[] = { Module( - reinterpret_cast(module_base_address), + module_base_address, "ABCD", #if defined(OS_WIN) base::FilePath(L"c:\\some\\path\\to\\chrome.exe") @@ -368,10 +368,10 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { // Duplicate samples in slots 0, 2, and 3. const Frame sample_frames[][1] = { - { Frame(reinterpret_cast(module_base_address + 0x10), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x20), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x10), 0), }, - { Frame(reinterpret_cast(module_base_address + 0x10), 0) } + { Frame(module_base_address + 0x10, 0), }, + { Frame(module_base_address + 0x20, 0), }, + { Frame(module_base_address + 0x10, 0), }, + { Frame(module_base_address + 0x10, 0) } }; Profile profile; @@ -390,9 +390,8 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { CallStackProfileMetricsProvider provider; provider.OnRecordingEnabled(); - AppendProfiles( - Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), - std::vector(1, profile)); + AppendProfiles(Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), + std::vector(1, profile)); ChromeUserMetricsExtension uma_proto; provider.ProvideGeneralMetrics(&uma_proto); @@ -430,8 +429,7 @@ TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { // Checks that unknown modules produce an empty Entry. TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { - const Frame frame(reinterpret_cast(0x1000), - Frame::kUnknownModuleIndex); + const Frame frame(0x1000, Frame::kUnknownModuleIndex); Profile profile; @@ -471,8 +469,8 @@ TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { CallStackProfileMetricsProvider provider; for (int i = 0; i < 2; ++i) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); // Use the sampling period to distinguish the two profiles. @@ -500,8 +498,8 @@ TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedWhenCollectedBeforeInstantiation) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); profile.sampling_period = base::TimeDelta::FromMilliseconds(10); @@ -522,8 +520,8 @@ TEST_F(CallStackProfileMetricsProviderTest, // while recording is disabled. TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); profile.sampling_period = base::TimeDelta::FromMilliseconds(10); @@ -544,8 +542,8 @@ TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedAfterChangeToDisabled) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); profile.sampling_period = base::TimeDelta::FromMilliseconds(10); @@ -569,8 +567,8 @@ TEST_F(CallStackProfileMetricsProviderTest, TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); profile.sampling_period = base::TimeDelta::FromMilliseconds(10); @@ -595,8 +593,8 @@ TEST_F(CallStackProfileMetricsProviderTest, TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedAfterChangeFromDisabled) { Profile profile; - profile.samples.push_back(Sample(1, Frame( - reinterpret_cast(0x1000), Frame::kUnknownModuleIndex))); + profile.samples.push_back( + Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); profile.profile_duration = base::TimeDelta::FromMilliseconds(100); profile.sampling_period = base::TimeDelta::FromMilliseconds(10);