Bug 1527564 - Child forwards its process name to the profiler - r=mstange

Profiler was previously fetching process name at the time of shutdown
serialization, at which point that name could have already been destroyed.

Now the child process just forwards the name as soon as it is given, so
the profiler can store it for later.

Differential Revision: https://phabricator.services.mozilla.com/D19732

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-02-14 21:19:42 +00:00
Родитель 6ae3b86617
Коммит 349d4a5381
6 изменённых файлов: 30 добавлений и 12 удалений

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

@ -734,7 +734,11 @@ void ContentChild::SetProcessName(const nsAString& aName) {
}
mProcessName = aName;
mozilla::ipc::SetThisProcessName(NS_LossyConvertUTF16toASCII(aName).get());
NS_LossyConvertUTF16toASCII asciiName(aName);
mozilla::ipc::SetThisProcessName(asciiName.get());
#ifdef MOZ_GECKO_PROFILER
profiler_set_process_name(asciiName);
#endif
}
NS_IMETHODIMP

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

@ -40,6 +40,7 @@ ProfiledThreadData::~ProfiledThreadData() {
void ProfiledThreadData::StreamJSON(const ProfileBuffer& aBuffer,
JSContext* aCx,
SpliceableJSONWriter& aWriter,
const nsACString& aProcessName,
const mozilla::TimeStamp& aProcessStartTime,
double aSinceTime, bool JSTracerEnabled) {
if (mJITFrameInfoForPreviousJSContexts &&
@ -64,7 +65,7 @@ void ProfiledThreadData::StreamJSON(const ProfileBuffer& aBuffer,
aWriter.Start();
{
StreamSamplesAndMarkers(mThreadInfo->Name(), mThreadInfo->ThreadId(),
aBuffer, aWriter, aProcessStartTime,
aBuffer, aWriter, aProcessName, aProcessStartTime,
mThreadInfo->RegisterTime(), mUnregisterTime,
aSinceTime, uniqueStacks);
@ -204,6 +205,7 @@ void ProfiledThreadData::StreamTraceLoggerJSON(
void StreamSamplesAndMarkers(const char* aName, int aThreadId,
const ProfileBuffer& aBuffer,
SpliceableJSONWriter& aWriter,
const nsACString& aProcessName,
const mozilla::TimeStamp& aProcessStartTime,
const mozilla::TimeStamp& aRegisterTime,
const mozilla::TimeStamp& aUnregisterTime,
@ -213,16 +215,11 @@ void StreamSamplesAndMarkers(const char* aName, int aThreadId,
aWriter.StringProperty("name", aName);
// Use given process name (if any), unless we're the parent process.
if (XRE_IsParentProcess()) {
aWriter.StringProperty("processName", "Parent Process");
} else if (mozilla::dom::ContentChild* cc =
mozilla::dom::ContentChild::GetSingleton()) {
// Try to get the process name from ContentChild.
nsAutoCString processName;
cc->GetProcessName(processName);
if (!processName.IsEmpty()) {
aWriter.StringProperty("processName", processName.Data());
}
} else if (!aProcessName.IsEmpty()) {
aWriter.StringProperty("processName", aProcessName.Data());
}
aWriter.IntProperty("tid", static_cast<int64_t>(aThreadId));

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

@ -63,7 +63,7 @@ class ProfiledThreadData final {
mozilla::Maybe<uint64_t>& LastSample() { return mLastSample; }
void StreamJSON(const ProfileBuffer& aBuffer, JSContext* aCx,
SpliceableJSONWriter& aWriter,
SpliceableJSONWriter& aWriter, const nsACString& aProcessName,
const mozilla::TimeStamp& aProcessStartTime,
double aSinceTime, bool aJSTracerEnabled);
@ -130,6 +130,7 @@ class ProfiledThreadData final {
void StreamSamplesAndMarkers(const char* aName, int aThreadId,
const ProfileBuffer& aBuffer,
SpliceableJSONWriter& aWriter,
const nsACString& aProcessName,
const mozilla::TimeStamp& aProcessStartTime,
const mozilla::TimeStamp& aRegisterTime,
const mozilla::TimeStamp& aUnregisterTime,

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

@ -27,7 +27,7 @@ void ProfilerBacktrace::StreamJSON(SpliceableJSONWriter& aWriter,
// JitReturnAddr entries. For synchronous samples, JIT frames get expanded
// at sample time.
StreamSamplesAndMarkers(mName.get(), mThreadId, *mBuffer.get(), aWriter,
aProcessStartTime,
NS_LITERAL_CSTRING(""), aProcessStartTime,
/* aRegisterTime */ mozilla::TimeStamp(),
/* aUnregisterTime */ mozilla::TimeStamp(),
/* aSinceTime */ 0, aUniqueStacks);

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

@ -356,6 +356,8 @@ class CorePS {
}
#endif
PS_GET_AND_SET(const nsACString&, ProcessName)
private:
// The singleton instance
static CorePS* sInstance;
@ -378,6 +380,9 @@ class CorePS {
// LUL's state. Null prior to the first activation, non-null thereafter.
UniquePtr<lul::LUL> mLul;
#endif
// Process name, provided by child process initialization code.
nsAutoCString mProcessName;
};
CorePS* CorePS::sInstance = nullptr;
@ -2005,6 +2010,7 @@ static void locked_profiler_stream_json_for_this_process(
registeredThread ? registeredThread->GetJSContext() : nullptr;
ProfiledThreadData* profiledThreadData = thread.second();
profiledThreadData->StreamJSON(buffer, cx, aWriter,
CorePS::ProcessName(aLock),
CorePS::ProcessStartTime(), aSinceTime,
ActivePS::FeatureJSTracer(aLock));
}
@ -2022,6 +2028,7 @@ static void locked_profiler_stream_json_for_this_process(
ProfiledThreadData profiledThreadData(
threadInfo, nullptr, ActivePS::FeatureResponsiveness(aLock));
profiledThreadData.StreamJSON(*javaBuffer.get(), nullptr, aWriter,
CorePS::ProcessName(aLock),
CorePS::ProcessStartTime(), aSinceTime,
ActivePS::FeatureJSTracer(aLock));
@ -2897,6 +2904,12 @@ static bool WriteProfileToJSONWriter(SpliceableChunkedJSONWriter& aWriter,
return true;
}
void profiler_set_process_name(const nsACString& aProcessName) {
LOG("profiler_set_process_name(\"%s\")", aProcessName.Data());
PSAutoLock lock(gPSMutex);
CorePS::SetProcessName(lock, aProcessName);
}
UniquePtr<char[]> profiler_get_profile(double aSinceTime,
bool aIsShuttingDown) {
LOG("profiler_get_profile");

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

@ -774,6 +774,9 @@ class MOZ_RAII AutoProfilerTextMarker {
// Output profiles
//---------------------------------------------------------------------------
// Set a user-friendly process name, used in JSON stream.
void profiler_set_process_name(const nsACString& aProcessName);
// Get the profile encoded as a JSON string. A no-op (returning nullptr) if the
// profiler is inactive.
// If aIsShuttingDown is true, the current time is included as the process