Bug 1578327 - Discard old data just before streaming - r=gregtatum

Since all profiler data is now stored inside ProfileBuffer, there is no real
need to continuously discard old data during sampling (this was particularly
useful to reclaim memory taken by old markers&payloads).

Instead, we can now just discard the old data once, just before starting to
stream it to JSON.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-09-18 01:21:32 +00:00
Родитель 58ac06a047
Коммит a8b053c3b1
2 изменённых файлов: 22 добавлений и 24 удалений

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

@ -1622,10 +1622,17 @@ static void locked_profiler_stream_json_for_this_process(
AUTO_PROFILER_STATS(base_locked_profiler_stream_json_for_this_process);
double collectionStart = profiler_time();
const double collectionStartMs = profiler_time();
ProfileBuffer& buffer = ActivePS::Buffer(aLock);
// If there is a set "Window length", discard older data.
Maybe<double> durationS = ActivePS::Duration(aLock);
if (durationS.isSome()) {
const double durationStartMs = collectionStartMs - *durationS * 1000;
buffer.DiscardSamplesBeforeTime(durationStartMs);
}
if (!aOnlyThreads) {
// Put shared library info
aWriter.StartArrayProperty("libs");
@ -1672,15 +1679,15 @@ static void locked_profiler_stream_json_for_this_process(
aWriter.EndArray();
}
double collectionEnd = profiler_time();
const double collectionEndMs = profiler_time();
// Record timestamps for the collection into the buffer, so that consumers
// know why we didn't collect any samples for its duration.
// We put these entries into the buffer after we've collected the profile,
// so they'll be visible for the *next* profile collection (if they haven't
// been overwritten due to buffer wraparound by then).
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStart));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEnd));
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStartMs));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEndMs));
}
bool profiler_stream_json_for_this_process(SpliceableJSONWriter& aWriter,
@ -2093,14 +2100,6 @@ void SamplerThread::Run() {
countersSampled - expiredMarkersCleaned,
threadsSampled - countersSampled);
}
Maybe<double> duration = ActivePS::Duration(lock);
if (duration) {
ActivePS::Buffer(lock).DiscardSamplesBeforeTime(
(TimeStamp::NowUnfuzzed() - TimeDuration::FromSeconds(*duration) -
CorePS::ProcessStartTime())
.ToMilliseconds());
}
}
// gPSMutex is not held after this point.

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

@ -2126,10 +2126,17 @@ static void locked_profiler_stream_json_for_this_process(
AUTO_PROFILER_STATS(locked_profiler_stream_json_for_this_process);
double collectionStart = profiler_time();
const double collectionStartMs = profiler_time();
ProfileBuffer& buffer = ActivePS::Buffer(aLock);
// If there is a set "Window length", discard older data.
Maybe<double> durationS = ActivePS::Duration(aLock);
if (durationS.isSome()) {
const double durationStartMs = collectionStartMs - *durationS * 1000;
buffer.DiscardSamplesBeforeTime(durationStartMs);
}
// Put shared library info
aWriter.StartArrayProperty("libs");
AppendSharedLibraries(aWriter);
@ -2224,15 +2231,15 @@ static void locked_profiler_stream_json_for_this_process(
{ buffer.StreamPausedRangesToJSON(aWriter, aSinceTime); }
aWriter.EndArray();
double collectionEnd = profiler_time();
const double collectionEndMs = profiler_time();
// Record timestamps for the collection into the buffer, so that consumers
// know why we didn't collect any samples for its duration.
// We put these entries into the buffer after we've collected the profile,
// so they'll be visible for the *next* profile collection (if they haven't
// been overwritten due to buffer wraparound by then).
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStart));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEnd));
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStartMs));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEndMs));
}
bool profiler_stream_json_for_this_process(
@ -2659,14 +2666,6 @@ void SamplerThread::Run() {
countersSampled - expiredMarkersCleaned,
threadsSampled - countersSampled);
}
Maybe<double> duration = ActivePS::Duration(lock);
if (duration) {
ActivePS::Buffer(lock).DiscardSamplesBeforeTime(
(TimeStamp::NowUnfuzzed() - TimeDuration::FromSeconds(*duration) -
CorePS::ProcessStartTime())
.ToMilliseconds());
}
}
// gPSMutex is not held after this point.