зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1745318 - In the parent process, assert that profiles are only generated on the main thread - r=mstange
This is to avoid situations where a developer may call this from another thread, and get a confusingly incomplete profile. Differential Revision: https://phabricator.services.mozilla.com/D133478
This commit is contained in:
Родитель
7ed0417539
Коммит
927382bab0
|
@ -3085,7 +3085,8 @@ static void locked_profiler_stream_json_for_this_process(
|
|||
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEndMs));
|
||||
}
|
||||
|
||||
bool profiler_stream_json_for_this_process(
|
||||
// Keep this internal function non-static, so it may be used by tests.
|
||||
bool do_profiler_stream_json_for_this_process(
|
||||
SpliceableJSONWriter& aWriter, double aSinceTime, bool aIsShuttingDown,
|
||||
ProfilerCodeAddressService* aService) {
|
||||
LOG("profiler_stream_json_for_this_process");
|
||||
|
@ -3110,6 +3111,17 @@ bool profiler_stream_json_for_this_process(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool profiler_stream_json_for_this_process(
|
||||
SpliceableJSONWriter& aWriter, double aSinceTime, bool aIsShuttingDown,
|
||||
ProfilerCodeAddressService* aService) {
|
||||
MOZ_RELEASE_ASSERT(
|
||||
!XRE_IsParentProcess() || NS_IsMainThread(),
|
||||
"In the parent process, profiles should only be generated from the main "
|
||||
"thread, otherwise they will be incomplete.");
|
||||
return do_profiler_stream_json_for_this_process(aWriter, aSinceTime,
|
||||
aIsShuttingDown, aService);
|
||||
}
|
||||
|
||||
// END saving/streaming code
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -3572,6 +3572,13 @@ TEST(GeckoProfiler, StreamJSONForThisProcess)
|
|||
ASSERT_TRUE(!::profiler_stream_json_for_this_process(w));
|
||||
}
|
||||
|
||||
// Internal version of profiler_stream_json_for_this_process, which allows being
|
||||
// called from a non-main thread of the parent process, at the risk of getting
|
||||
// an incomplete profile.
|
||||
bool do_profiler_stream_json_for_this_process(
|
||||
SpliceableJSONWriter& aWriter, double aSinceTime, bool aIsShuttingDown,
|
||||
ProfilerCodeAddressService* aService);
|
||||
|
||||
TEST(GeckoProfiler, StreamJSONForThisProcessThreaded)
|
||||
{
|
||||
// Same as the previous test, but calling some things on background threads.
|
||||
|
@ -3595,7 +3602,10 @@ TEST(GeckoProfiler, StreamJSONForThisProcessThreaded)
|
|||
"GeckoProfiler_StreamJSONForThisProcessThreaded_Test::TestBody",
|
||||
[&]() {
|
||||
w.Start();
|
||||
ASSERT_TRUE(::profiler_stream_json_for_this_process(w));
|
||||
ASSERT_TRUE(::do_profiler_stream_json_for_this_process(
|
||||
w, /* double aSinceTime */ 0.0,
|
||||
/* bool aIsShuttingDown */ false,
|
||||
/* ProfilerCodeAddressService* aService */ nullptr));
|
||||
w.End();
|
||||
}),
|
||||
NS_DISPATCH_SYNC);
|
||||
|
@ -3611,7 +3621,10 @@ TEST(GeckoProfiler, StreamJSONForThisProcessThreaded)
|
|||
"GeckoProfiler_StreamJSONForThisProcessThreaded_Test::TestBody",
|
||||
[&]() {
|
||||
profiler_stop();
|
||||
ASSERT_TRUE(!::profiler_stream_json_for_this_process(w));
|
||||
ASSERT_TRUE(!::do_profiler_stream_json_for_this_process(
|
||||
w, /* double aSinceTime */ 0.0,
|
||||
/* bool aIsShuttingDown */ false,
|
||||
/* ProfilerCodeAddressService* aService */ nullptr));
|
||||
}),
|
||||
NS_DISPATCH_SYNC);
|
||||
thread->Shutdown();
|
||||
|
|
Загрузка…
Ссылка в новой задаче