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-17 01:53:52 +00:00
parent 79e1b2e357
commit 7d435fc17a
2 changed files with 22 additions and 24 deletions

View File

@ -1622,10 +1622,17 @@ static void locked_profiler_stream_json_for_this_process(
AUTO_PROFILER_STATS(base_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); 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) { if (!aOnlyThreads) {
// Put shared library info // Put shared library info
aWriter.StartArrayProperty("libs"); aWriter.StartArrayProperty("libs");
@ -1672,15 +1679,15 @@ static void locked_profiler_stream_json_for_this_process(
aWriter.EndArray(); aWriter.EndArray();
} }
double collectionEnd = profiler_time(); const double collectionEndMs = profiler_time();
// Record timestamps for the collection into the buffer, so that consumers // Record timestamps for the collection into the buffer, so that consumers
// know why we didn't collect any samples for its duration. // know why we didn't collect any samples for its duration.
// We put these entries into the buffer after we've collected the profile, // 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 // so they'll be visible for the *next* profile collection (if they haven't
// been overwritten due to buffer wraparound by then). // been overwritten due to buffer wraparound by then).
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStart)); buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStartMs));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEnd)); buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEndMs));
} }
bool profiler_stream_json_for_this_process(SpliceableJSONWriter& aWriter, bool profiler_stream_json_for_this_process(SpliceableJSONWriter& aWriter,
@ -2093,14 +2100,6 @@ void SamplerThread::Run() {
countersSampled - expiredMarkersCleaned, countersSampled - expiredMarkersCleaned,
threadsSampled - countersSampled); 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. // gPSMutex is not held after this point.

View File

@ -2126,10 +2126,17 @@ static void locked_profiler_stream_json_for_this_process(
AUTO_PROFILER_STATS(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); 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 // Put shared library info
aWriter.StartArrayProperty("libs"); aWriter.StartArrayProperty("libs");
AppendSharedLibraries(aWriter); AppendSharedLibraries(aWriter);
@ -2224,15 +2231,15 @@ static void locked_profiler_stream_json_for_this_process(
{ buffer.StreamPausedRangesToJSON(aWriter, aSinceTime); } { buffer.StreamPausedRangesToJSON(aWriter, aSinceTime); }
aWriter.EndArray(); aWriter.EndArray();
double collectionEnd = profiler_time(); const double collectionEndMs = profiler_time();
// Record timestamps for the collection into the buffer, so that consumers // Record timestamps for the collection into the buffer, so that consumers
// know why we didn't collect any samples for its duration. // know why we didn't collect any samples for its duration.
// We put these entries into the buffer after we've collected the profile, // 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 // so they'll be visible for the *next* profile collection (if they haven't
// been overwritten due to buffer wraparound by then). // been overwritten due to buffer wraparound by then).
buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStart)); buffer.AddEntry(ProfileBufferEntry::CollectionStart(collectionStartMs));
buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEnd)); buffer.AddEntry(ProfileBufferEntry::CollectionEnd(collectionEndMs));
} }
bool profiler_stream_json_for_this_process( bool profiler_stream_json_for_this_process(
@ -2659,14 +2666,6 @@ void SamplerThread::Run() {
countersSampled - expiredMarkersCleaned, countersSampled - expiredMarkersCleaned,
threadsSampled - countersSampled); 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. // gPSMutex is not held after this point.