Bug 1384693 - Cull exit profiles that don't have any overlap with the parent process profile. r=njn

This avoids large gaps in the profiler output.

Sometimes we hold on to exit profiles for a long time before a profile is
gathered. During that time, the parent process's profile buffer might have
looped around several times. At that point, profiles from processes that have
exited long ago are no longer interesting.

MozReview-Commit-ID: 5C47vb69DfK

--HG--
extra : rebase_source : 57f0df2f21ab778ec689a08d0bbf010b10f18ed9
This commit is contained in:
Markus Stange 2017-07-25 20:29:17 -04:00
Родитель 4036fdd6b0
Коммит c7ea693fd8
2 изменённых файлов: 21 добавлений и 6 удалений

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

@ -538,7 +538,7 @@ nsProfiler::ReceiveShutdownProfile(const nsCString& aProfile)
if (mExitProfiles.Length() >= MAX_SUBPROCESS_EXIT_PROFILES) {
mExitProfiles.RemoveElementAt(0);
}
mExitProfiles.AppendElement(aProfile);
mExitProfiles.AppendElement(ExitProfile{ aProfile, TimeStamp::Now() });
}
RefPtr<nsProfiler::GatheringPromise>
@ -565,9 +565,12 @@ nsProfiler::StartGathering(double aSinceTime)
mWriter.emplace();
TimeStamp thisProcessFirstSampleTime;
// Start building up the JSON result and grab the profile from this process.
mWriter->Start(SpliceableJSONWriter::SingleLineStyle);
if (!profiler_stream_json_for_this_process(*mWriter, aSinceTime)) {
if (!profiler_stream_json_for_this_process(*mWriter, aSinceTime,
&thisProcessFirstSampleTime)) {
// The profiler is inactive. This either means that it was inactive even
// at the time that ProfileGatherer::Start() was called, or that it was
// stopped on a different thread since that call. Either way, we need to
@ -579,9 +582,15 @@ nsProfiler::StartGathering(double aSinceTime)
// If we have any process exit profiles, add them immediately, and clear
// mExitProfiles.
for (size_t i = 0; i < mExitProfiles.Length(); ++i) {
if (!mExitProfiles[i].IsEmpty()) {
mWriter->Splice(mExitProfiles[i].get());
for (auto& exitProfile : mExitProfiles) {
if (thisProcessFirstSampleTime &&
exitProfile.mGatherTime < thisProcessFirstSampleTime) {
// Don't include exit profiles that have no overlap with the profile
// from our own process.
continue;
}
if (!exitProfile.mJSON.IsEmpty()) {
mWriter->Splice(exitProfile.mJSON.get());
}
}
mExitProfiles.Clear();

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

@ -12,6 +12,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h"
#include "mozilla/TimeStamp.h"
#include "nsServiceManagerUtils.h"
#include "ProfileJSONWriter.h"
@ -46,8 +47,13 @@ private:
bool mLockedForPrivateBrowsing;
struct ExitProfile {
nsCString mJSON;
mozilla::TimeStamp mGatherTime;
};
// These fields are all related to profile gathering.
nsTArray<nsCString> mExitProfiles;
nsTArray<ExitProfile> mExitProfiles;
mozilla::Maybe<mozilla::MozPromiseHolder<GatheringPromise>> mPromiseHolder;
mozilla::Maybe<SpliceableChunkedJSONWriter> mWriter;
uint32_t mPendingProfiles;