author | Gerald Squelart <gsquelart@mozilla.com> |
Tue, 11 Aug 2020 03:51:33 +0000 | |
changeset 544206 | 61871a38eb0ff8d9ebdc28db10f03e74e01912a3 |
parent 544205 | 7ae81a4ff37e3e5720d358d0615eb8079a3f46cc |
child 544207 | 56973e24eb3de1c2b809dc8a86eb0dbeb7eb345a |
push id | 37689 |
push user | ncsoregi@mozilla.com |
push date | Tue, 11 Aug 2020 09:17:31 +0000 |
treeherder | mozilla-central@3fa98e681edd [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | gregtatum |
bugs | 1658230 |
milestone | 81.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mozglue/baseprofiler/core/ProfileBufferEntry.cpp +++ b/mozglue/baseprofiler/core/ProfileBufferEntry.cpp @@ -201,17 +201,17 @@ UniqueJSONStrings::UniqueJSONStrings(con if (count != 0) { MOZ_RELEASE_ASSERT(mStringHashToIndexMap.reserve(count)); for (auto iter = aOther.mStringHashToIndexMap.iter(); !iter.done(); iter.next()) { mStringHashToIndexMap.putNewInfallible(iter.get().key(), iter.get().value()); } UniquePtr<char[]> stringTableJSON = - aOther.mStringTableWriter.WriteFunc()->CopyData(); + aOther.mStringTableWriter.ChunkedWriteFunc()->CopyData(); mStringTableWriter.Splice(stringTableJSON.get()); } } uint32_t UniqueJSONStrings::GetOrAddIndex(const char* aStr) { uint32_t count = mStringHashToIndexMap.count(); HashNumber hash = HashString(aStr); auto entry = mStringHashToIndexMap.lookupForAdd(hash); @@ -271,22 +271,22 @@ uint32_t UniqueStacks::GetOrAddFrameInde MOZ_RELEASE_ASSERT(mFrameToIndexMap.add(entry, aFrame, count)); StreamNonJITFrame(aFrame); return count; } void UniqueStacks::SpliceFrameTableElements(SpliceableJSONWriter& aWriter) { mFrameTableWriter.EndBareList(); - aWriter.TakeAndSplice(mFrameTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mFrameTableWriter.ChunkedWriteFunc()); } void UniqueStacks::SpliceStackTableElements(SpliceableJSONWriter& aWriter) { mStackTableWriter.EndBareList(); - aWriter.TakeAndSplice(mStackTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mStackTableWriter.ChunkedWriteFunc()); } void UniqueStacks::StreamStack(const StackKey& aStack) { enum Schema : uint32_t { PREFIX = 0, FRAME = 1 }; AutoArraySchemaWriter writer(mStackTableWriter, *mUniqueStrings); if (aStack.mPrefixStackIndex.isSome()) { writer.IntElement(PREFIX, *aStack.mPrefixStackIndex);
--- a/mozglue/baseprofiler/core/ProfileBufferEntry.h +++ b/mozglue/baseprofiler/core/ProfileBufferEntry.h @@ -138,17 +138,17 @@ class ProfileBufferEntry { static_assert(sizeof(ProfileBufferEntry) == 9, "bad ProfileBufferEntry size"); class UniqueJSONStrings { public: UniqueJSONStrings(); explicit UniqueJSONStrings(const UniqueJSONStrings& aOther); void SpliceStringTableElements(SpliceableJSONWriter& aWriter) { - aWriter.TakeAndSplice(mStringTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mStringTableWriter.ChunkedWriteFunc()); } void WriteProperty(JSONWriter& aWriter, const char* aName, const char* aStr) { aWriter.IntProperty(aName, GetOrAddIndex(aStr)); } void WriteElement(JSONWriter& aWriter, const char* aStr) { aWriter.IntElement(GetOrAddIndex(aStr));
--- a/mozglue/baseprofiler/core/platform.cpp +++ b/mozglue/baseprofiler/core/platform.cpp @@ -2791,30 +2791,30 @@ void profiler_set_process_name(const std UniquePtr<char[]> profiler_get_profile(double aSinceTime, bool aIsShuttingDown, bool aOnlyThreads) { LOG("profiler_get_profile"); SpliceableChunkedJSONWriter b; if (!WriteProfileToJSONWriter(b, aSinceTime, aIsShuttingDown, aOnlyThreads)) { return nullptr; } - return b.WriteFunc()->CopyData(); + return b.ChunkedWriteFunc()->CopyData(); } void profiler_get_profile_json_into_lazily_allocated_buffer( const std::function<char*(size_t)>& aAllocator, double aSinceTime, bool aIsShuttingDown) { LOG("profiler_get_profile_json_into_lazily_allocated_buffer"); SpliceableChunkedJSONWriter b; if (!WriteProfileToJSONWriter(b, aSinceTime, aIsShuttingDown)) { return; } - b.WriteFunc()->CopyDataIntoLazilyAllocatedBuffer(aAllocator); + b.ChunkedWriteFunc()->CopyDataIntoLazilyAllocatedBuffer(aAllocator); } void profiler_get_start_params(int* aCapacity, Maybe<double>* aDuration, double* aInterval, uint32_t* aFeatures, Vector<const char*>* aFilters) { MOZ_RELEASE_ASSERT(CorePS::Exists()); if (!aCapacity || !aDuration || !aInterval || !aFeatures || !aFilters) {
--- a/mozglue/baseprofiler/public/BaseProfileJSONWriter.h +++ b/mozglue/baseprofiler/public/BaseProfileJSONWriter.h @@ -24,17 +24,17 @@ namespace baseprofiler { class SpliceableJSONWriter; // On average, profile JSONs are large enough such that we want to avoid // reallocating its buffer when expanding. Additionally, the contents of the // profile are not accessed until the profile is entirely written. For these // reasons we use a chunked writer that keeps an array of chunks, which is // concatenated together after writing is finished. -class ChunkedJSONWriteFunc : public JSONWriteFunc { +class ChunkedJSONWriteFunc final : public JSONWriteFunc { public: friend class SpliceableJSONWriter; ChunkedJSONWriteFunc() : mChunkPtr{nullptr}, mChunkEnd{nullptr} { AllocChunk(kChunkSize); } bool IsEmpty() const { @@ -149,17 +149,17 @@ class ChunkedJSONWriteFunc : public JSON // List of chunks and their lengths. // // For all i, the length of the string in mChunkList[i] is // mChunkLengths[i]. Vector<UniquePtr<char[]>> mChunkList; Vector<size_t> mChunkLengths; }; -struct OStreamJSONWriteFunc : public JSONWriteFunc { +struct OStreamJSONWriteFunc final : public JSONWriteFunc { explicit OStreamJSONWriteFunc(std::ostream& aStream) : mStream(aStream) {} void Write(const char* aStr) override { mStream << aStr; } void Write(const char* aStr, size_t aLen) override { mStream << aStr; } std::ostream& mStream; }; @@ -203,29 +203,31 @@ class SpliceableJSONWriter : public JSON aFunc->mChunkPtr = nullptr; aFunc->mChunkEnd = nullptr; aFunc->mChunkList.clear(); aFunc->mChunkLengths.clear(); mNeedComma[mDepth] = true; } }; -class SpliceableChunkedJSONWriter : public SpliceableJSONWriter { +class SpliceableChunkedJSONWriter final : public SpliceableJSONWriter { public: explicit SpliceableChunkedJSONWriter() : SpliceableJSONWriter(MakeUnique<ChunkedJSONWriteFunc>()) {} - ChunkedJSONWriteFunc* WriteFunc() const { - return static_cast<ChunkedJSONWriteFunc*>(JSONWriter::WriteFunc()); + ChunkedJSONWriteFunc* ChunkedWriteFunc() const { + // The WriteFunc was initialized with a ChunkedJSONWriteFunc in the only + // constructor above, so it's safe to cast to ChunkedJSONWriteFunc*. + return static_cast<ChunkedJSONWriteFunc*>(WriteFunc()); } // Adopts the chunks from aFunc without copying. - virtual void TakeAndSplice(ChunkedJSONWriteFunc* aFunc) override { + void TakeAndSplice(ChunkedJSONWriteFunc* aFunc) override { Separator(); - WriteFunc()->Take(std::move(*aFunc)); + ChunkedWriteFunc()->Take(std::move(*aFunc)); mNeedComma[mDepth] = true; } }; class JSONSchemaWriter { JSONWriter& mWriter; uint32_t mIndex;
--- a/tools/profiler/core/ProfileBufferEntry.cpp +++ b/tools/profiler/core/ProfileBufferEntry.cpp @@ -213,17 +213,17 @@ UniqueJSONStrings::UniqueJSONStrings(con if (count != 0) { MOZ_RELEASE_ASSERT(mStringHashToIndexMap.reserve(count)); for (auto iter = aOther.mStringHashToIndexMap.iter(); !iter.done(); iter.next()) { mStringHashToIndexMap.putNewInfallible(iter.get().key(), iter.get().value()); } UniquePtr<char[]> stringTableJSON = - aOther.mStringTableWriter.WriteFunc()->CopyData(); + aOther.mStringTableWriter.ChunkedWriteFunc()->CopyData(); mStringTableWriter.Splice(stringTableJSON.get()); } } uint32_t UniqueJSONStrings::GetOrAddIndex(const char* aStr) { uint32_t count = mStringHashToIndexMap.count(); HashNumber hash = HashString(aStr); auto entry = mStringHashToIndexMap.lookupForAdd(hash); @@ -375,22 +375,22 @@ uint32_t UniqueStacks::GetOrAddFrameInde MOZ_RELEASE_ASSERT(mFrameToIndexMap.add(entry, aFrame, count)); StreamNonJITFrame(aFrame); return count; } void UniqueStacks::SpliceFrameTableElements(SpliceableJSONWriter& aWriter) { mFrameTableWriter.EndBareList(); - aWriter.TakeAndSplice(mFrameTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mFrameTableWriter.ChunkedWriteFunc()); } void UniqueStacks::SpliceStackTableElements(SpliceableJSONWriter& aWriter) { mStackTableWriter.EndBareList(); - aWriter.TakeAndSplice(mStackTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mStackTableWriter.ChunkedWriteFunc()); } void UniqueStacks::StreamStack(const StackKey& aStack) { enum Schema : uint32_t { PREFIX = 0, FRAME = 1 }; AutoArraySchemaWriter writer(mStackTableWriter, *mUniqueStrings); if (aStack.mPrefixStackIndex.isSome()) { writer.IntElement(PREFIX, *aStack.mPrefixStackIndex);
--- a/tools/profiler/core/ProfileBufferEntry.h +++ b/tools/profiler/core/ProfileBufferEntry.h @@ -146,17 +146,17 @@ class ProfileBufferEntry { static_assert(sizeof(ProfileBufferEntry) == 9, "bad ProfileBufferEntry size"); class UniqueJSONStrings { public: UniqueJSONStrings(); explicit UniqueJSONStrings(const UniqueJSONStrings& aOther); void SpliceStringTableElements(SpliceableJSONWriter& aWriter) { - aWriter.TakeAndSplice(mStringTableWriter.WriteFunc()); + aWriter.TakeAndSplice(mStringTableWriter.ChunkedWriteFunc()); } void WriteProperty(mozilla::JSONWriter& aWriter, const char* aName, const char* aStr) { aWriter.IntProperty(aName, GetOrAddIndex(aStr)); } void WriteElement(mozilla::JSONWriter& aWriter, const char* aStr) {
--- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -4224,34 +4224,34 @@ UniquePtr<char[]> profiler_get_profile(d UniquePtr<ProfilerCodeAddressService> service = profiler_code_address_service_for_presymbolication(); SpliceableChunkedJSONWriter b; if (!WriteProfileToJSONWriter(b, aSinceTime, aIsShuttingDown, service.get())) { return nullptr; } - return b.WriteFunc()->CopyData(); + return b.ChunkedWriteFunc()->CopyData(); } void profiler_get_profile_json_into_lazily_allocated_buffer( const std::function<char*(size_t)>& aAllocator, double aSinceTime, bool aIsShuttingDown) { LOG("profiler_get_profile_json_into_lazily_allocated_buffer"); UniquePtr<ProfilerCodeAddressService> service = profiler_code_address_service_for_presymbolication(); SpliceableChunkedJSONWriter b; if (!WriteProfileToJSONWriter(b, aSinceTime, aIsShuttingDown, service.get())) { return; } - b.WriteFunc()->CopyDataIntoLazilyAllocatedBuffer(aAllocator); + b.ChunkedWriteFunc()->CopyDataIntoLazilyAllocatedBuffer(aAllocator); } void profiler_get_start_params(int* aCapacity, Maybe<double>* aDuration, double* aInterval, uint32_t* aFeatures, Vector<const char*>* aFilters, uint64_t* aActiveBrowsingContextID) { MOZ_RELEASE_ASSERT(CorePS::Exists());
--- a/tools/profiler/gecko/nsProfiler.cpp +++ b/tools/profiler/gecko/nsProfiler.cpp @@ -992,17 +992,17 @@ void nsProfiler::FinishGathering() { MOZ_RELEASE_ASSERT(mPromiseHolder.isSome()); // Close the "processes" array property. mWriter->EndArray(); // Close the root object of the generated JSON. mWriter->End(); - UniquePtr<char[]> buf = mWriter->WriteFunc()->CopyData(); + UniquePtr<char[]> buf = mWriter->ChunkedWriteFunc()->CopyData(); size_t len = strlen(buf.get()); nsCString result; result.Adopt(buf.release(), len); mPromiseHolder->Resolve(std::move(result), __func__); ResetGathering(); }
--- a/tools/profiler/tests/gtest/GeckoProfiler.cpp +++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp @@ -835,17 +835,17 @@ TEST(GeckoProfiler, Markers) // The GTestMarkerPayloads should have been deserialized, streamed, and // destroyed. EXPECT_EQ(GTestMarkerPayload::sNumCreated, 10 + 0); EXPECT_EQ(GTestMarkerPayload::sNumSerialized, 10 + 0); EXPECT_EQ(GTestMarkerPayload::sNumDeserialized, 0 + 10); EXPECT_EQ(GTestMarkerPayload::sNumStreamed, 0 + 10); EXPECT_EQ(GTestMarkerPayload::sNumDestroyed, 10 + 10); - UniquePtr<char[]> profile = w.WriteFunc()->CopyData(); + UniquePtr<char[]> profile = w.ChunkedWriteFunc()->CopyData(); ASSERT_TRUE(!!profile.get()); // Expected markers, in order. enum State { S_tracing_event, S_tracing_start, S_tracing_end, S_tracing_event_with_stack, @@ -1538,30 +1538,30 @@ TEST(GeckoProfiler, Counters) PR_Sleep(PR_MillisecondsToInterval(200)); AUTO_PROFILER_COUNT_TOTAL(TestCounter, -17); PR_Sleep(PR_MillisecondsToInterval(200)); // Verify we got counters in the output SpliceableChunkedJSONWriter w; ASSERT_TRUE(::profiler_stream_json_for_this_process(w)); - UniquePtr<char[]> profile = w.WriteFunc()->CopyData(); + UniquePtr<char[]> profile = w.ChunkedWriteFunc()->CopyData(); // counter name and description should appear as is. ASSERT_TRUE(strstr(profile.get(), COUNTER_NAME)); ASSERT_TRUE(strstr(profile.get(), COUNTER_DESCRIPTION)); ASSERT_FALSE(strstr(profile.get(), COUNTER_NAME2)); ASSERT_FALSE(strstr(profile.get(), COUNTER_DESCRIPTION2)); AUTO_PROFILER_COUNT_TOTAL(TestCounter2, 10); PR_Sleep(PR_MillisecondsToInterval(200)); ASSERT_TRUE(::profiler_stream_json_for_this_process(w)); - profile = w.WriteFunc()->CopyData(); + profile = w.ChunkedWriteFunc()->CopyData(); ASSERT_TRUE(strstr(profile.get(), COUNTER_NAME)); ASSERT_TRUE(strstr(profile.get(), COUNTER_DESCRIPTION)); ASSERT_TRUE(strstr(profile.get(), COUNTER_NAME2)); ASSERT_TRUE(strstr(profile.get(), COUNTER_DESCRIPTION2)); profiler_stop(); } @@ -1638,17 +1638,17 @@ TEST(GeckoProfiler, StreamJSONForThisPro profiler_start(PROFILER_DEFAULT_ENTRIES, PROFILER_DEFAULT_INTERVAL, features, filters, MOZ_ARRAY_LENGTH(filters), 0); w.Start(); ASSERT_TRUE(::profiler_stream_json_for_this_process(w)); w.End(); - UniquePtr<char[]> profile = w.WriteFunc()->CopyData(); + UniquePtr<char[]> profile = w.ChunkedWriteFunc()->CopyData(); JSONOutputCheck(profile.get()); profiler_stop(); ASSERT_TRUE(!::profiler_stream_json_for_this_process(w)); } @@ -1675,17 +1675,17 @@ TEST(GeckoProfiler, StreamJSONForThisPro "GeckoProfiler_StreamJSONForThisProcessThreaded_Test::TestBody", [&]() { w.Start(); ASSERT_TRUE(::profiler_stream_json_for_this_process(w)); w.End(); }), NS_DISPATCH_SYNC); - UniquePtr<char[]> profile = w.WriteFunc()->CopyData(); + UniquePtr<char[]> profile = w.ChunkedWriteFunc()->CopyData(); JSONOutputCheck(profile.get()); // Stop the profiler and call profiler_stream_json_for_this_process on a // background thread. thread->Dispatch( NS_NewRunnableFunction( "GeckoProfiler_StreamJSONForThisProcessThreaded_Test::TestBody",