Bug 1171612 - Use C++11 features to make Statistics module nicer; r=sfink

--HG--
extra : rebase_source : e12798c4a3af966b9db41db75a3c3acf08920721
This commit is contained in:
Terrence Cole 2015-06-04 11:49:31 -07:00
parent e2e18c19e1
commit 43469776bf
2 changed files with 26 additions and 22 deletions

View File

@ -7,6 +7,7 @@
#include "gc/Statistics.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/IntegerRange.h"
#include "mozilla/PodOperations.h"
#include "mozilla/UniquePtr.h"
@ -27,6 +28,7 @@ using namespace js;
using namespace js::gc;
using namespace js::gcstats;
using mozilla::MakeRange;
using mozilla::PodArrayZero;
using mozilla::PodZero;
@ -185,7 +187,7 @@ static ExtraPhaseInfo phaseExtra[PHASE_LIMIT] = { { 0, 0 } };
// Mapping from all nodes with a multi-parented child to a Vector of all
// multi-parented children and their descendants. (Single-parented children will
// not show up in this list.)
static mozilla::Vector<Phase> dagDescendants[Statistics::MAX_MULTIPARENT_PHASES + 1];
static mozilla::Vector<Phase> dagDescendants[Statistics::NumTimingArrays];
struct AllPhaseIterator {
int current;
@ -193,7 +195,7 @@ struct AllPhaseIterator {
size_t activeSlot;
mozilla::Vector<Phase>::Range descendants;
explicit AllPhaseIterator(Statistics::PhaseTimeTable table)
explicit AllPhaseIterator(const Statistics::PhaseTimeTable table)
: current(0)
, baseLevel(0)
, activeSlot(PHASE_DAG_NONE)
@ -293,7 +295,7 @@ Join(const FragmentVector& fragments, const char* separator = "") {
}
static int64_t
SumChildTimes(size_t phaseSlot, Phase phase, Statistics::PhaseTimeTable phaseTimes)
SumChildTimes(size_t phaseSlot, Phase phase, const Statistics::PhaseTimeTable phaseTimes)
{
// Sum the contributions from single-parented children.
int64_t total = 0;
@ -398,7 +400,7 @@ Statistics::formatCompactSummaryMessage() const
}
UniqueChars
Statistics::formatCompactSlicePhaseTimes(PhaseTimeTable phaseTimes) const
Statistics::formatCompactSlicePhaseTimes(const PhaseTimeTable phaseTimes) const
{
static const int64_t MaxUnaccountedTimeUS = 100;
@ -524,7 +526,7 @@ Statistics::formatDetailedSliceDescription(unsigned i, const SliceData& slice)
}
UniqueChars
Statistics::formatDetailedPhaseTimes(PhaseTimeTable phaseTimes)
Statistics::formatDetailedPhaseTimes(const PhaseTimeTable phaseTimes)
{
static const char* LevelToIndent[] = { "", " ", " ", " " };
static const int64_t MaxUnaccountedChildTimeUS = 50;
@ -711,7 +713,7 @@ FilterJsonKey(const char*const buffer)
}
UniqueChars
Statistics::formatJsonPhaseTimes(PhaseTimeTable phaseTimes)
Statistics::formatJsonPhaseTimes(const PhaseTimeTable phaseTimes)
{
FragmentVector fragments;
char buffer[128];
@ -749,7 +751,7 @@ Statistics::Statistics(JSRuntime* rt)
PodArrayZero(phaseTotals);
PodArrayZero(counts);
PodArrayZero(phaseStartTimes);
for (size_t d = 0; d < MAX_MULTIPARENT_PHASES + 1; d++)
for (auto d : MakeRange(NumTimingArrays))
PodArrayZero(phaseTimes[d]);
static bool initialized = false;
@ -778,7 +780,7 @@ Statistics::Statistics(JSRuntime* rt)
j++;
} while (j != PHASE_LIMIT && phases[j].parent != PHASE_MULTI_PARENTS);
}
MOZ_ASSERT(dagSlot <= MAX_MULTIPARENT_PHASES);
MOZ_ASSERT(dagSlot <= MaxMultiparentPhases - 1);
// Fill in the depth of each node in the tree. Multi-parented nodes
// have depth 0.
@ -846,7 +848,7 @@ static int64_t
SumPhase(Phase phase, Statistics::PhaseTimeTable times)
{
int64_t sum = 0;
for (size_t i = 0; i < Statistics::MAX_MULTIPARENT_PHASES + 1; i++)
for (auto i : MakeRange(Statistics::NumTimingArrays))
sum += times[i][phase];
return sum;
}
@ -878,7 +880,7 @@ Statistics::beginGC(JSGCInvocationKind kind)
void
Statistics::endGC()
{
for (size_t j = 0; j < MAX_MULTIPARENT_PHASES + 1; j++)
for (auto j : MakeRange(NumTimingArrays))
for (int i = 0; i < PHASE_LIMIT; i++)
phaseTotals[j][i] += phaseTimes[j][i];
@ -913,7 +915,7 @@ Statistics::endGC()
// Clear the timers at the end of a GC because we accumulate time in
// between GCs for some (which come before PHASE_GC_BEGIN in the list.)
PodZero(&phaseStartTimes[PHASE_GC_BEGIN], PHASE_LIMIT - PHASE_GC_BEGIN);
for (size_t d = PHASE_DAG_NONE; d < MAX_MULTIPARENT_PHASES + 1; d++)
for (size_t d = PHASE_DAG_NONE; d < NumTimingArrays; d++)
PodZero(&phaseTimes[d][PHASE_GC_BEGIN], PHASE_LIMIT - PHASE_GC_BEGIN);
aborted = false;

View File

@ -8,6 +8,7 @@
#define gc_Statistics_h
#include "mozilla/DebugOnly.h"
#include "mozilla/IntegerRange.h"
#include "mozilla/PodOperations.h"
#include "mozilla/UniquePtr.h"
@ -151,7 +152,11 @@ struct Statistics
* the few hundred bytes of savings. If we want to extend things to full
* DAGs, this decision should be reconsidered.
*/
static const size_t MAX_MULTIPARENT_PHASES = 6;
static const size_t MaxMultiparentPhases = 6;
static const size_t NumTimingArrays = MaxMultiparentPhases + 1;
/* Create a convenient type for referring to tables of phase times. */
using PhaseTimeTable = int64_t[NumTimingArrays][PHASE_LIMIT];
explicit Statistics(JSRuntime* rt);
~Statistics();
@ -211,7 +216,7 @@ struct Statistics
resetReason(nullptr),
start(start), startFaults(startFaults)
{
for (size_t i = 0; i < MAX_MULTIPARENT_PHASES + 1; i++)
for (auto i : mozilla::MakeRange(NumTimingArrays))
mozilla::PodArrayZero(phaseTimes[i]);
}
@ -220,7 +225,7 @@ struct Statistics
const char* resetReason;
int64_t start, end;
size_t startFaults, endFaults;
int64_t phaseTimes[MAX_MULTIPARENT_PHASES + 1][PHASE_LIMIT];
PhaseTimeTable phaseTimes;
int64_t duration() const { return end - start; }
};
@ -231,9 +236,6 @@ struct Statistics
SliceRange sliceRange() const { return slices.all(); }
size_t slicesLength() const { return slices.length(); }
/* Create a convenient typedef for referring tables of phase times. */
typedef int64_t const (*PhaseTimeTable)[PHASE_LIMIT];
private:
JSRuntime* runtime;
@ -264,10 +266,10 @@ struct Statistics
int64_t timedGCTime;
/* Total time in a given phase for this GC. */
int64_t phaseTimes[MAX_MULTIPARENT_PHASES + 1][PHASE_LIMIT];
PhaseTimeTable phaseTimes;
/* Total time in a given phase over all GCs. */
int64_t phaseTotals[MAX_MULTIPARENT_PHASES + 1][PHASE_LIMIT];
PhaseTimeTable phaseTotals;
/* Number of events of this type for this GC. */
unsigned int counts[STAT_LIMIT];
@ -312,16 +314,16 @@ struct Statistics
void sccDurations(int64_t* total, int64_t* maxPause);
void printStats();
UniqueChars formatCompactSlicePhaseTimes(PhaseTimeTable phaseTimes) const;
UniqueChars formatCompactSlicePhaseTimes(const PhaseTimeTable phaseTimes) const;
UniqueChars formatDetailedDescription();
UniqueChars formatDetailedSliceDescription(unsigned i, const SliceData& slice);
UniqueChars formatDetailedPhaseTimes(PhaseTimeTable phaseTimes);
UniqueChars formatDetailedPhaseTimes(const PhaseTimeTable phaseTimes);
UniqueChars formatDetailedTotals();
UniqueChars formatJsonDescription(uint64_t timestamp);
UniqueChars formatJsonSliceDescription(unsigned i, const SliceData& slice);
UniqueChars formatJsonPhaseTimes(PhaseTimeTable phaseTimes);
UniqueChars formatJsonPhaseTimes(const PhaseTimeTable phaseTimes);
double computeMMU(int64_t resolution) const;
};