Bug 1685938 - Add RunningTimes::mPostMeasurementTimeStamp and use as sample timestamp - r=canaltinova

mPostMeasurementTimeStamp records the time right after CPU measurements (point-based or interval) ended.
It is then used as the main sample timestamp, to both avoid another TimeStamp::Now() call, and to keep measurements and timestamp as close together as possible (and even closer in the next patch).

Differential Revision: https://phabricator.services.mozilla.com/D101545
This commit is contained in:
Gerald Squelart 2021-01-19 02:54:43 +00:00
Родитель 0688b80ad5
Коммит 73c0a73dad
5 изменённых файлов: 38 добавлений и 6 удалений

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

@ -342,6 +342,9 @@ static RunningTimes GetThreadRunningTimesDiff(
}
}
// Reminder: This must stay *after* the CPU measurements.
newRunningTimes.SetPostMeasurementTimeStamp(TimeStamp::NowUnfuzzed());
RunningTimes diff =
newRunningTimes - platformData->PreviousThreadRunningTimesRef();
platformData->PreviousThreadRunningTimesRef() = newRunningTimes;

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

@ -109,6 +109,9 @@ static RunningTimes GetThreadRunningTimesDiff(
newRunningTimes.SetThreadCPUDelta(userTimeUs + systemTimeUs);
}
// Reminder: This must stay *after* the CPU measurements.
newRunningTimes.SetPostMeasurementTimeStamp(TimeStamp::NowUnfuzzed());
RunningTimes diff =
newRunningTimes - platformData->PreviousThreadRunningTimesRef();
platformData->PreviousThreadRunningTimesRef() = newRunningTimes;

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

@ -150,6 +150,9 @@ static RunningTimes GetThreadRunningTimesDiff(
}
}
// Reminder: This must stay *after* the CPU measurements.
newRunningTimes.SetPostMeasurementTimeStamp(TimeStamp::NowUnfuzzed());
RunningTimes diff =
newRunningTimes - platformData->PreviousThreadRunningTimesRef();
platformData->PreviousThreadRunningTimesRef() = newRunningTimes;

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

@ -3369,13 +3369,15 @@ void SamplerThread::Run() {
thread.mProfiledThreadData.get();
RefPtr<ThreadInfo> info = registeredThread->Info();
RunningTimes runningTimesDiff;
if (cpuUtilization) {
runningTimesDiff =
GetThreadRunningTimesDiff(lock, *registeredThread);
const RunningTimes runningTimesDiff = [&]() {
if (!cpuUtilization) {
// If we don't need CPU measurements, we only need a timestamp.
return RunningTimes(TimeStamp::NowUnfuzzed());
}
return GetThreadRunningTimesDiff(lock, *registeredThread);
}();
TimeStamp now = TimeStamp::NowUnfuzzed();
const TimeStamp& now = runningTimesDiff.PostMeasurementTimeStamp();
double threadSampleDeltaMs =
(now - CorePS::ProcessStartTime()).ToMilliseconds();

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

@ -34,6 +34,7 @@
#include "mozilla/Logging.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/ProfileBufferEntrySerialization.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Vector.h"
#include "nsString.h"
@ -141,10 +142,24 @@ class RunningTimes {
public:
constexpr RunningTimes() = default;
// Constructor with only a timestamp, useful when no measurements will be
// taken.
constexpr explicit RunningTimes(const mozilla::TimeStamp& aTimeStamp)
: mPostMeasurementTimeStamp(aTimeStamp) {}
constexpr void Clear() { *this = RunningTimes{}; }
constexpr bool IsEmpty() const { return mKnownBits == 0; }
// This should be called right after CPU measurements have been taken.
void SetPostMeasurementTimeStamp(const mozilla::TimeStamp& aTimeStamp) {
mPostMeasurementTimeStamp = aTimeStamp;
}
const mozilla::TimeStamp& PostMeasurementTimeStamp() const {
return mPostMeasurementTimeStamp;
}
// Should be filled for any registered thread.
#define RUNNING_TIME_MEMBER(index, name, unit, jsonProperty) \
@ -187,8 +202,12 @@ class RunningTimes {
}
// Difference from `aBefore` to `this`. Any unknown makes the result unknown.
// PostMeasurementTimeStamp set to `this` PostMeasurementTimeStamp, to keep
// the most recent timestamp associated with the end of the interval over
// which the difference applies.
RunningTimes operator-(const RunningTimes& aBefore) const {
RunningTimes diff;
diff.mPostMeasurementTimeStamp = mPostMeasurementTimeStamp;
#define RUNNING_TIME_SUB(index, name, unit, jsonProperty) \
if (Is##name##unit##Known() && aBefore.Is##name##unit##Known()) { \
diff.Set##name##unit(m##name##unit - aBefore.m##name##unit); \
@ -204,6 +223,8 @@ class RunningTimes {
friend mozilla::ProfileBufferEntryWriter::Serializer<RunningTimes>;
friend mozilla::ProfileBufferEntryReader::Deserializer<RunningTimes>;
mozilla::TimeStamp mPostMeasurementTimeStamp;
uint32_t mKnownBits = 0u;
#define RUNNING_TIME_MEMBER(index, name, unit, jsonProperty) \