Bug 1646266 - ProfileChunkedBuffer::IsEmpty() and Serializer<ProfileChunkedBuffer*> - r=gregtatum

`IsEmpty()` makes it easier for users to determine if there is anything stored in the `ProfileChunkedBuffer`.

And `ProfileChunkedBuffer` can now be serialized from a raw pointer, which will be useful when adding markers with an optional stack.
Deserialization should be done to a `UniquePtr<ProfileChunkedBuffer>`, which is already implemented.

Differential Revision: https://phabricator.services.mozilla.com/D87246
This commit is contained in:
Gerald Squelart 2020-09-01 01:33:44 +00:00
Родитель 718ef431b3
Коммит b44f966142
1 изменённых файлов: 32 добавлений и 0 удалений

Просмотреть файл

@ -587,6 +587,11 @@ class ProfileChunkedBuffer {
return {mRangeStart, mRangeEnd, mPushedBlockCount, mClearedBlockCount};
}
[[nodiscard]] bool IsEmpty() const {
baseprofiler::detail::BaseProfilerMaybeAutoLock lock(mMutex);
return mRangeStart == mRangeEnd;
}
// True if this buffer is already locked on this thread.
// This should be used if some functions may call an already-locked buffer,
// e.g.: Put -> memory hook -> profiler_add_native_allocation_marker -> Put.
@ -1744,6 +1749,33 @@ struct ProfileBufferEntryWriter::Serializer<UniquePtr<ProfileChunkedBuffer>> {
}
};
// Serialization of a raw pointer to ProfileChunkedBuffer.
// Use Deserializer<UniquePtr<ProfileChunkedBuffer>> to read it back.
template <>
struct ProfileBufferEntryWriter::Serializer<ProfileChunkedBuffer*> {
static Length Bytes(ProfileChunkedBuffer* aBufferUPtr) {
if (!aBufferUPtr) {
// Null pointer, treat it like an empty buffer, i.e., write length of 0.
return ULEB128Size<Length>(0);
}
// Otherwise write the pointed-at ProfileChunkedBuffer (which could be
// out-of-session or empty.)
return SumBytes(*aBufferUPtr);
}
static void Write(ProfileBufferEntryWriter& aEW,
ProfileChunkedBuffer* aBufferUPtr) {
if (!aBufferUPtr) {
// Null pointer, treat it like an empty buffer, i.e., write length of 0.
aEW.WriteULEB128<Length>(0);
return;
}
// Otherwise write the pointed-at ProfileChunkedBuffer (which could be
// out-of-session or empty.)
aEW.WriteObject(*aBufferUPtr);
}
};
template <>
struct ProfileBufferEntryReader::Deserializer<UniquePtr<ProfileChunkedBuffer>> {
static void ReadInto(ProfileBufferEntryReader& aER,