From 6550e4931ea215e102b14ef46fa6e86cb89c5e0b Mon Sep 17 00:00:00 2001 From: Gerald Squelart Date: Tue, 26 Nov 2019 23:01:14 +0000 Subject: [PATCH] Bug 1598992 - Add test for profile hand-off from Base to Gecko Profiler - r=gregtatum Differential Revision: https://phabricator.services.mozilla.com/D54446 --HG-- extra : moz-landing-system : lando --- tools/profiler/tests/gtest/GeckoProfiler.cpp | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/profiler/tests/gtest/GeckoProfiler.cpp b/tools/profiler/tests/gtest/GeckoProfiler.cpp index b733d8ff6342..86aeee8a18db 100644 --- a/tools/profiler/tests/gtest/GeckoProfiler.cpp +++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp @@ -1722,3 +1722,52 @@ TEST(GeckoProfiler, PostSamplingCallback) ASSERT_TRUE(!profiler_callback_after_sampling( [&](SamplingState) { ASSERT_TRUE(false); })); } + +#ifdef MOZ_BASE_PROFILER +TEST(GeckoProfiler, BaseProfilerHandOff) +{ + const char* filters[] = {"GeckoMain"}; + + ASSERT_TRUE(!baseprofiler::profiler_is_active()); + ASSERT_TRUE(!profiler_is_active()); + + // Start the Base Profiler. + baseprofiler::profiler_start( + PROFILER_DEFAULT_ENTRIES, PROFILER_DEFAULT_INTERVAL, + ProfilerFeature::StackWalk, filters, MOZ_ARRAY_LENGTH(filters)); + + ASSERT_TRUE(baseprofiler::profiler_is_active()); + ASSERT_TRUE(!profiler_is_active()); + + // Add at least a marker, which should go straight into the buffer. + Maybe info0 = + baseprofiler::profiler_get_buffer_info(); + BASE_PROFILER_ADD_MARKER("Marker from base profiler", OTHER); + Maybe info1 = + baseprofiler::profiler_get_buffer_info(); + ASSERT_GT(info1->mRangeEnd, info0->mRangeEnd); + + // Start the Gecko Profiler, which should grab the Base Profiler profile and + // stop it. + profiler_start(PROFILER_DEFAULT_ENTRIES, PROFILER_DEFAULT_INTERVAL, + ProfilerFeature::StackWalk, filters, + MOZ_ARRAY_LENGTH(filters)); + + ASSERT_TRUE(!baseprofiler::profiler_is_active()); + ASSERT_TRUE(profiler_is_active()); + + // Write some Gecko Profiler samples. + ASSERT_EQ(WaitForSamplingState(), SamplingState::SamplingCompleted); + + // Check that the Gecko Profiler profile contains at least the Base Profiler + // main thread samples. + UniquePtr profile = profiler_get_profile(); + ASSERT_TRUE(profile); + ASSERT_TRUE(profile[0] == '{'); + ASSERT_TRUE(strstr(profile.get(), "GeckoMain (pre-xul)")); + ASSERT_TRUE(strstr(profile.get(), "Marker from base profiler")); + + profiler_stop(); + ASSERT_TRUE(!profiler_is_active()); +} +#endif // MOZ_BASE_PROFILER