Bug 1585697 - Move CycleCollectorStats definition to the top of the file r=mccr8

This needs to be defined before FireForgetSkippable for the subsequnt patches.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2019-10-02 17:18:44 +00:00
Родитель a26feaed9e
Коммит acce9ba546
1 изменённых файлов: 107 добавлений и 108 удалений

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

@ -97,8 +97,6 @@
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
const size_t gStackSize = 8192;
// Thank you Microsoft! // Thank you Microsoft!
#ifdef CompareString #ifdef CompareString
# undef CompareString # undef CompareString
@ -202,6 +200,58 @@ static bool sIsCompactingOnUserInactive = false;
static TimeDuration sGCUnnotifiedTotalTime; static TimeDuration sGCUnnotifiedTotalTime;
struct CycleCollectorStats {
constexpr CycleCollectorStats() = default;
void Init();
void Clear();
void PrepareForCycleCollectionSlice(TimeStamp aDeadline = TimeStamp());
void FinishCycleCollectionSlice();
void RunForgetSkippable();
// Time the current slice began, including any GC finishing.
TimeStamp mBeginSliceTime;
// Time the previous slice of the current CC ended.
TimeStamp mEndSliceTime;
// Time the current cycle collection began.
TimeStamp mBeginTime;
// The longest GC finishing duration for any slice of the current CC.
TimeDuration mMaxGCDuration;
// True if we ran sync forget skippable in any slice of the current CC.
bool mRanSyncForgetSkippable = false;
// Number of suspected objects at the start of the current CC.
uint32_t mSuspected = 0;
// The longest duration spent on sync forget skippable in any slice of the
// current CC.
TimeDuration mMaxSkippableDuration;
// The longest pause of any slice in the current CC.
TimeDuration mMaxSliceTime;
// The longest slice time since ClearMaxCCSliceTime() was called.
TimeDuration mMaxSliceTimeSinceClear;
// The total amount of time spent actually running the current CC.
TimeDuration mTotalSliceTime;
// True if we were locked out by the GC in any slice of the current CC.
bool mAnyLockedOut = false;
// A file to dump CC activity to; set by MOZ_CCTIMER environment variable.
FILE* mFile = nullptr;
// In case CC slice was triggered during idle time, set to the end of the idle
// period.
TimeStamp mIdleDeadline;
};
CycleCollectorStats gCCStats;
static const char* ProcessNameForCollectorLog() { static const char* ProcessNameForCollectorLog() {
return XRE_GetProcessType() == GeckoProcessType_Default ? "default" return XRE_GetProcessType() == GeckoProcessType_Default ? "default"
: "content"; : "content";
@ -1245,118 +1295,67 @@ static TimeDuration TimeUntilNow(TimeStamp start) {
return TimeBetween(start, TimeStamp::Now()); return TimeBetween(start, TimeStamp::Now());
} }
struct CycleCollectorStats { void CycleCollectorStats::Init() {
constexpr CycleCollectorStats() = default; Clear();
void Init() { char* env = getenv("MOZ_CCTIMER");
Clear(); if (!env) {
return;
char* env = getenv("MOZ_CCTIMER"); }
if (!env) { if (strcmp(env, "none") == 0) {
return; mFile = nullptr;
} else if (strcmp(env, "stdout") == 0) {
mFile = stdout;
} else if (strcmp(env, "stderr") == 0) {
mFile = stderr;
} else {
mFile = fopen(env, "a");
if (!mFile) {
MOZ_CRASH("Failed to open MOZ_CCTIMER log file.");
} }
if (strcmp(env, "none") == 0) { }
mFile = nullptr; }
} else if (strcmp(env, "stdout") == 0) {
mFile = stdout; void CycleCollectorStats::Clear() {
} else if (strcmp(env, "stderr") == 0) { if (mFile && mFile != stdout && mFile != stderr) {
mFile = stderr; fclose(mFile);
} else { }
mFile = fopen(env, "a"); *this = CycleCollectorStats();
if (!mFile) { }
MOZ_CRASH("Failed to open MOZ_CCTIMER log file.");
void CycleCollectorStats::FinishCycleCollectionSlice() {
if (mBeginSliceTime.IsNull()) {
// We already called this method from EndCycleCollectionCallback for this
// slice.
return;
}
mEndSliceTime = TimeStamp::Now();
TimeDuration duration = mEndSliceTime - mBeginSliceTime;
if (duration.ToSeconds()) {
TimeDuration idleDuration;
if (!mIdleDeadline.IsNull()) {
if (mIdleDeadline < mEndSliceTime) {
// This slice overflowed the idle period.
idleDuration = mIdleDeadline - mBeginSliceTime;
} else {
idleDuration = duration;
} }
} }
uint32_t percent =
uint32_t(idleDuration.ToSeconds() / duration.ToSeconds() * 100);
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_SLICE_DURING_IDLE,
percent);
} }
void Clear() { TimeDuration sliceTime = TimeBetween(mBeginSliceTime, mEndSliceTime);
if (mFile && mFile != stdout && mFile != stderr) { mMaxSliceTime = std::max(mMaxSliceTime, sliceTime);
fclose(mFile); mMaxSliceTimeSinceClear = std::max(mMaxSliceTimeSinceClear, sliceTime);
} mTotalSliceTime += sliceTime;
*this = CycleCollectorStats(); mBeginSliceTime = TimeStamp();
} }
void PrepareForCycleCollectionSlice(TimeStamp aDeadline = TimeStamp());
void FinishCycleCollectionSlice() {
if (mBeginSliceTime.IsNull()) {
// We already called this method from EndCycleCollectionCallback for this
// slice.
return;
}
mEndSliceTime = TimeStamp::Now();
TimeDuration duration = mEndSliceTime - mBeginSliceTime;
if (duration.ToSeconds()) {
TimeDuration idleDuration;
if (!mIdleDeadline.IsNull()) {
if (mIdleDeadline < mEndSliceTime) {
// This slice overflowed the idle period.
idleDuration = mIdleDeadline - mBeginSliceTime;
} else {
idleDuration = duration;
}
}
uint32_t percent =
uint32_t(idleDuration.ToSeconds() / duration.ToSeconds() * 100);
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_SLICE_DURING_IDLE,
percent);
}
TimeDuration sliceTime = TimeBetween(mBeginSliceTime, mEndSliceTime);
mMaxSliceTime = std::max(mMaxSliceTime, sliceTime);
mMaxSliceTimeSinceClear = std::max(mMaxSliceTimeSinceClear, sliceTime);
mTotalSliceTime += sliceTime;
mBeginSliceTime = TimeStamp();
}
void RunForgetSkippable();
// Time the current slice began, including any GC finishing.
TimeStamp mBeginSliceTime;
// Time the previous slice of the current CC ended.
TimeStamp mEndSliceTime;
// Time the current cycle collection began.
TimeStamp mBeginTime;
// The longest GC finishing duration for any slice of the current CC.
TimeDuration mMaxGCDuration;
// True if we ran sync forget skippable in any slice of the current CC.
bool mRanSyncForgetSkippable = false;
// Number of suspected objects at the start of the current CC.
uint32_t mSuspected = 0;
// The longest duration spent on sync forget skippable in any slice of the
// current CC.
TimeDuration mMaxSkippableDuration;
// The longest pause of any slice in the current CC.
TimeDuration mMaxSliceTime;
// The longest slice time since ClearMaxCCSliceTime() was called.
TimeDuration mMaxSliceTimeSinceClear;
// The total amount of time spent actually running the current CC.
TimeDuration mTotalSliceTime;
// True if we were locked out by the GC in any slice of the current CC.
bool mAnyLockedOut = false;
// A file to dump CC activity to; set by MOZ_CCTIMER environment variable.
FILE* mFile = nullptr;
// In case CC slice was triggered during idle time, set to the end of the idle
// period.
TimeStamp mIdleDeadline;
};
CycleCollectorStats gCCStats;
void CycleCollectorStats::PrepareForCycleCollectionSlice(TimeStamp aDeadline) { void CycleCollectorStats::PrepareForCycleCollectionSlice(TimeStamp aDeadline) {
mBeginSliceTime = TimeStamp::Now(); mBeginSliceTime = TimeStamp::Now();