Bug 1584190 - In JSON profile, counters' sample_groups should be an array of objects - r=canaltinova

profile.counters[n].sample_groups was mistakenly streamed as an object, which
prevents having more than one, and goes against the published format
documentation.

The front-end was implemented to process the incorrect format, so it will need
to be updated as well; hence the version change to 18.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-10-30 22:20:06 +00:00
parent 3846c79d32
commit 1824e6f651
4 changed files with 87 additions and 73 deletions

View File

@ -1079,7 +1079,7 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
aWriter.StringProperty("category", base_counter->mCategory);
aWriter.StringProperty("description", base_counter->mDescription);
aWriter.StartObjectProperty("sample_groups");
aWriter.StartArrayProperty("sample_groups");
for (auto counter_iter = counter.iter(); !counter_iter.done();
counter_iter.next()) {
CounterKeyedSamples& samples = counter_iter.get().value();
@ -1089,42 +1089,49 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
if (size == 0) {
continue;
}
aWriter.IntProperty("id", static_cast<int64_t>(key));
aWriter.StartObjectProperty("samples");
aWriter.StartObjectElement();
{
// XXX Can we assume a missing count means 0?
JSONSchemaWriter schema(aWriter);
schema.WriteField("time");
schema.WriteField("number");
schema.WriteField("count");
}
aWriter.StartArrayProperty("data");
uint64_t previousNumber = 0;
int64_t previousCount = 0;
for (size_t i = 0; i < size; i++) {
// Encode as deltas, and only encode if different than the last sample
if (i == 0 || samples[i].mNumber != previousNumber ||
samples[i].mCount != previousCount) {
MOZ_ASSERT(i == 0 || samples[i].mTime >= samples[i - 1].mTime);
MOZ_ASSERT(samples[i].mNumber >= previousNumber);
MOZ_ASSERT(samples[i].mNumber - previousNumber <=
uint64_t(std::numeric_limits<int64_t>::max()));
AutoArraySchemaWriter writer(aWriter);
writer.DoubleElement(TIME, samples[i].mTime);
writer.IntElement(NUMBER, static_cast<int64_t>(samples[i].mNumber -
previousNumber));
writer.IntElement(COUNT, samples[i].mCount - previousCount);
previousNumber = samples[i].mNumber;
previousCount = samples[i].mCount;
aWriter.IntProperty("id", static_cast<int64_t>(key));
aWriter.StartObjectProperty("samples");
{
// XXX Can we assume a missing count means 0?
JSONSchemaWriter schema(aWriter);
schema.WriteField("time");
schema.WriteField("number");
schema.WriteField("count");
}
aWriter.StartArrayProperty("data");
uint64_t previousNumber = 0;
int64_t previousCount = 0;
for (size_t i = 0; i < size; i++) {
// Encode as deltas, and only encode if different than the last
// sample
if (i == 0 || samples[i].mNumber != previousNumber ||
samples[i].mCount != previousCount) {
MOZ_ASSERT(i == 0 || samples[i].mTime >= samples[i - 1].mTime);
MOZ_ASSERT(samples[i].mNumber >= previousNumber);
MOZ_ASSERT(samples[i].mNumber - previousNumber <=
uint64_t(std::numeric_limits<int64_t>::max()));
AutoArraySchemaWriter writer(aWriter);
writer.DoubleElement(TIME, samples[i].mTime);
writer.IntElement(
NUMBER,
static_cast<int64_t>(samples[i].mNumber - previousNumber));
writer.IntElement(COUNT, samples[i].mCount - previousCount);
previousNumber = samples[i].mNumber;
previousCount = samples[i].mCount;
}
}
aWriter.EndArray(); // data
aWriter.EndObject(); // samples
}
aWriter.EndArray(); // data
aWriter.EndObject(); // samples
aWriter.EndObject(); // sample_groups item
}
aWriter.EndObject(); // sample groups
aWriter.End(); // for each counter
aWriter.EndArray(); // sample groups
aWriter.End(); // for each counter
}
aWriter.EndArray(); // counters
});

View File

@ -1622,7 +1622,7 @@ static void StreamMetaJSCustomObject(PSLockRef aLock,
bool aIsShuttingDown) {
MOZ_RELEASE_ASSERT(CorePS::Exists() && ActivePS::Exists(aLock));
aWriter.IntProperty("version", 17);
aWriter.IntProperty("version", 18);
// The "startTime" field holds the number of milliseconds since midnight
// January 1, 1970 GMT. This grotty code computes (Now - (Now -

View File

@ -1566,7 +1566,7 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
aWriter.StringProperty("category", base_counter->mCategory);
aWriter.StringProperty("description", base_counter->mDescription);
aWriter.StartObjectProperty("sample_groups");
aWriter.StartArrayProperty("sample_groups");
for (auto counter_iter = counter.iter(); !counter_iter.done();
counter_iter.next()) {
CounterKeyedSamples& samples = counter_iter.get().value();
@ -1576,47 +1576,54 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
if (size == 0) {
continue;
}
aWriter.IntProperty("id", static_cast<int64_t>(key));
aWriter.StartObjectProperty("samples");
aWriter.StartObjectElement();
{
// XXX Can we assume a missing count means 0?
JSONSchemaWriter schema(aWriter);
schema.WriteField("time");
schema.WriteField("number");
schema.WriteField("count");
}
aWriter.StartArrayProperty("data");
uint64_t previousNumber = 0;
int64_t previousCount = 0;
for (size_t i = 0; i < size; i++) {
// Encode as deltas, and only encode if different than the last sample
if (i == 0 || samples[i].mNumber != previousNumber ||
samples[i].mCount != previousCount) {
if (i != 0 && samples[i].mTime >= samples[i - 1].mTime) {
MOZ_LOG(sFuzzyfoxLog, mozilla::LogLevel::Error,
("Fuzzyfox Profiler Assertion: %f >= %f",
samples[i].mTime, samples[i - 1].mTime));
}
MOZ_ASSERT(i == 0 || samples[i].mTime >= samples[i - 1].mTime);
MOZ_ASSERT(samples[i].mNumber >= previousNumber);
MOZ_ASSERT(samples[i].mNumber - previousNumber <=
uint64_t(std::numeric_limits<int64_t>::max()));
AutoArraySchemaWriter writer(aWriter);
writer.DoubleElement(TIME, samples[i].mTime);
writer.IntElement(NUMBER, static_cast<int64_t>(samples[i].mNumber -
previousNumber));
writer.IntElement(COUNT, samples[i].mCount - previousCount);
previousNumber = samples[i].mNumber;
previousCount = samples[i].mCount;
aWriter.IntProperty("id", static_cast<int64_t>(key));
aWriter.StartObjectProperty("samples");
{
// XXX Can we assume a missing count means 0?
JSONSchemaWriter schema(aWriter);
schema.WriteField("time");
schema.WriteField("number");
schema.WriteField("count");
}
aWriter.StartArrayProperty("data");
uint64_t previousNumber = 0;
int64_t previousCount = 0;
for (size_t i = 0; i < size; i++) {
// Encode as deltas, and only encode if different than the last
// sample
if (i == 0 || samples[i].mNumber != previousNumber ||
samples[i].mCount != previousCount) {
if (i != 0 && samples[i].mTime >= samples[i - 1].mTime) {
MOZ_LOG(sFuzzyfoxLog, mozilla::LogLevel::Error,
("Fuzzyfox Profiler Assertion: %f >= %f",
samples[i].mTime, samples[i - 1].mTime));
}
MOZ_ASSERT(i == 0 || samples[i].mTime >= samples[i - 1].mTime);
MOZ_ASSERT(samples[i].mNumber >= previousNumber);
MOZ_ASSERT(samples[i].mNumber - previousNumber <=
uint64_t(std::numeric_limits<int64_t>::max()));
AutoArraySchemaWriter writer(aWriter);
writer.DoubleElement(TIME, samples[i].mTime);
writer.IntElement(
NUMBER,
static_cast<int64_t>(samples[i].mNumber - previousNumber));
writer.IntElement(COUNT, samples[i].mCount - previousCount);
previousNumber = samples[i].mNumber;
previousCount = samples[i].mCount;
}
}
aWriter.EndArray(); // data
aWriter.EndObject(); // samples
}
aWriter.EndArray(); // data
aWriter.EndObject(); // samples
aWriter.EndObject(); // sample_groups item
}
aWriter.EndObject(); // sample groups
aWriter.End(); // for each counter
aWriter.EndArray(); // sample groups
aWriter.End(); // for each counter
}
aWriter.EndArray(); // counters
});

View File

@ -2051,7 +2051,7 @@ static void StreamMetaJSCustomObject(PSLockRef aLock,
bool aIsShuttingDown) {
MOZ_RELEASE_ASSERT(CorePS::Exists() && ActivePS::Exists(aLock));
aWriter.IntProperty("version", 17);
aWriter.IntProperty("version", 18);
// The "startTime" field holds the number of milliseconds since midnight
// January 1, 1970 GMT. This grotty code computes (Now - (Now -