Bug 1658232 - Use std::string for ProfilerBacktrace::mName - r=gregtatum

Instead of keeping a pointer to a null-terminated string, it's simpler to keep a proper `std::string`, and it helps to keep the length ready for streaming.

Differential Revision: https://phabricator.services.mozilla.com/D86511
This commit is contained in:
Gerald Squelart 2020-08-13 03:29:34 +00:00
Родитель ab7dd1effd
Коммит d4fa7a1fda
4 изменённых файлов: 15 добавлений и 15 удалений

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

@ -20,7 +20,7 @@ ProfilerBacktrace::ProfilerBacktrace(
const char* aName, int aThreadId,
UniquePtr<ProfileChunkedBuffer> aProfileChunkedBuffer,
UniquePtr<ProfileBuffer> aProfileBuffer)
: mName(strdup(aName)),
: mName(aName),
mThreadId(aThreadId),
mProfileChunkedBuffer(std::move(aProfileChunkedBuffer)),
mProfileBuffer(std::move(aProfileBuffer)) {
@ -44,8 +44,8 @@ void ProfilerBacktrace::StreamJSON(SpliceableJSONWriter& aWriter,
// ProfileBuffer::AddJITInfoForRange because mProfileBuffer does not contain
// any JitReturnAddr entries. For synchronous samples, JIT frames get expanded
// at sample time.
StreamSamplesAndMarkers(mName.get(), mThreadId, *mProfileBuffer, aWriter, "",
"", aProcessStartTime,
StreamSamplesAndMarkers(mName.c_str(), mThreadId, *mProfileBuffer, aWriter,
"", "", aProcessStartTime,
/* aRegisterTime */ TimeStamp(),
/* aUnregisterTime */ TimeStamp(),
/* aSinceTime */ 0, aUniqueStacks);

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

@ -9,6 +9,8 @@
#include "mozilla/UniquePtrExtensions.h"
#include <string>
namespace mozilla {
class ProfileChunkedBuffer;
@ -44,7 +46,7 @@ class ProfilerBacktrace {
friend struct ProfileBufferEntryWriter::Serializer<ProfilerBacktrace>;
friend struct ProfileBufferEntryReader::Deserializer<ProfilerBacktrace>;
UniqueFreePtr<char> mName;
std::string mName;
int mThreadId;
// `ProfileChunkedBuffer` in which `mProfileBuffer` stores its data; must be
// located before `mProfileBuffer` so that it's destroyed after.
@ -68,9 +70,7 @@ struct ProfileBufferEntryWriter::Serializer<baseprofiler::ProfilerBacktrace> {
// Empty backtrace buffer.
return ULEB128Size<Length>(0);
}
return bufferBytes +
SumBytes(aBacktrace.mThreadId,
WrapProfileBufferUnownedCString(aBacktrace.mName.get()));
return bufferBytes + SumBytes(aBacktrace.mThreadId, aBacktrace.mName);
}
static void Write(ProfileBufferEntryWriter& aEW,
@ -83,7 +83,7 @@ struct ProfileBufferEntryWriter::Serializer<baseprofiler::ProfilerBacktrace> {
}
aEW.WriteObject(aBacktrace.mProfileChunkedBuffer);
aEW.WriteObject(aBacktrace.mThreadId);
aEW.WriteObject(WrapProfileBufferUnownedCString(aBacktrace.mName.get()));
aEW.WriteObject(aBacktrace.mName);
}
};

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

@ -16,7 +16,7 @@ ProfilerBacktrace::ProfilerBacktrace(
const char* aName, int aThreadId,
mozilla::UniquePtr<mozilla::ProfileChunkedBuffer> aProfileChunkedBuffer,
mozilla::UniquePtr<ProfileBuffer> aProfileBuffer)
: mName(strdup(aName)),
: mName(aName),
mThreadId(aThreadId),
mProfileChunkedBuffer(std::move(aProfileChunkedBuffer)),
mProfileBuffer(std::move(aProfileBuffer)) {
@ -41,7 +41,7 @@ void ProfilerBacktrace::StreamJSON(SpliceableJSONWriter& aWriter,
// ProfileBuffer::AddJITInfoForRange because mProfileBuffer does not contain
// any JitReturnAddr entries. For synchronous samples, JIT frames get expanded
// at sample time.
StreamSamplesAndMarkers(mName.get(), mThreadId, *mProfileBuffer, aWriter,
StreamSamplesAndMarkers(mName.c_str(), mThreadId, *mProfileBuffer, aWriter,
""_ns, ""_ns, aProcessStartTime,
/* aRegisterTime */ mozilla::TimeStamp(),
/* aUnregisterTime */ mozilla::TimeStamp(),

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

@ -12,6 +12,8 @@
#include "mozilla/ProfileBufferEntrySerialization.h"
#include "mozilla/UniquePtrExtensions.h"
#include <string>
class ProfileBuffer;
class ProfilerCodeAddressService;
class ThreadInfo;
@ -51,7 +53,7 @@ class ProfilerBacktrace {
friend struct mozilla::ProfileBufferEntryReader::Deserializer<
ProfilerBacktrace>;
mozilla::UniqueFreePtr<char> mName;
std::string mName;
int mThreadId;
// `ProfileChunkedBuffer` in which `mProfileBuffer` stores its data; must be
// located before `mProfileBuffer` so that it's destroyed after.
@ -73,9 +75,7 @@ struct mozilla::ProfileBufferEntryWriter::Serializer<ProfilerBacktrace> {
if (bufferBytes == 0) {
return ULEB128Size<Length>(0);
}
return bufferBytes +
SumBytes(aBacktrace.mThreadId,
WrapProfileBufferUnownedCString(aBacktrace.mName.get()));
return bufferBytes + SumBytes(aBacktrace.mThreadId, aBacktrace.mName);
}
static void Write(mozilla::ProfileBufferEntryWriter& aEW,
const ProfilerBacktrace& aBacktrace) {
@ -86,7 +86,7 @@ struct mozilla::ProfileBufferEntryWriter::Serializer<ProfilerBacktrace> {
}
aEW.WriteObject(*aBacktrace.mProfileChunkedBuffer);
aEW.WriteObject(aBacktrace.mThreadId);
aEW.WriteObject(WrapProfileBufferUnownedCString(aBacktrace.mName.get()));
aEW.WriteObject(aBacktrace.mName);
}
};