Bug 1763176 - Don't move to the next entry after streaming a counter, as it would skip an immediately-adjacent counter - r=canaltinova

If the sampler records more than one counter (e.g.: memory and per-process CPU), both counters could appear right next to each other in the buffer.
But then the current streaming code goes something like this:
1. Read entry
2. If entry is a counter, go to the next entry (which should be a timestamp) and output the full counter.
3. Go to the next entry.
4: Return to step 1 (until there are no more entries).

The problem is this unconditional 3rd step:
If we've just read a counter at step 2, we're located at the entry *past* that counter's data, which could be the start of the next counter, that the 3rd step now effectively skips!

Also:
- After reading the time, we can do e.Next() to skip it before testing if it's too old, this may save one loop.
- After reading the optional "number", we can also do e.Next() to skip it, which will save one loop as well.

Differential Revision: https://phabricator.services.mozilla.com/D145056
This commit is contained in:
Gerald Squelart 2022-04-29 12:30:50 +00:00
parent 354c6e226c
commit 8f08153522
2 changed files with 8 additions and 4 deletions

View File

@ -1039,8 +1039,8 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
ERROR_AND_CONTINUE("expected a Time entry");
}
double time = e.Get().GetDouble();
e.Next();
if (time >= aSinceTime) {
e.Next();
while (e.Has() && e.Get().IsCounterKey()) {
uint64_t key = e.Get().GetUint64();
CounterKeyedSamples& data = LookupOrAdd(counter, key);
@ -1055,6 +1055,7 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
number = 0;
} else {
number = e.Get().GetInt64();
e.Next();
}
CounterKeyedSample sample = {time, number, count};
MOZ_RELEASE_ASSERT(data.append(sample));
@ -1063,8 +1064,9 @@ void ProfileBuffer::StreamCountersToJSON(SpliceableJSONWriter& aWriter,
// skip counter sample - only need to skip the initial counter
// id, then let the loop at the top skip the rest
}
} else {
e.Next();
}
e.Next();
}
// we have a map of a map of counter entries; dump them to JSON
if (counters.count() == 0) {

View File

@ -1733,8 +1733,8 @@ void ProfileBuffer::StreamCountersToJSON(
ERROR_AND_CONTINUE("expected a Time entry");
}
double time = e.Get().GetDouble();
e.Next();
if (time >= aSinceTime) {
e.Next();
while (e.Has() && e.Get().IsCounterKey()) {
uint64_t key = e.Get().GetUint64();
CounterKeyedSamples& data = LookupOrAdd(counter, key);
@ -1749,6 +1749,7 @@ void ProfileBuffer::StreamCountersToJSON(
number = 0;
} else {
number = e.Get().GetInt64();
e.Next();
}
CounterKeyedSample sample = {time, number, count};
MOZ_RELEASE_ASSERT(data.append(sample));
@ -1757,8 +1758,9 @@ void ProfileBuffer::StreamCountersToJSON(
// skip counter sample - only need to skip the initial counter
// id, then let the loop at the top skip the rest
}
} else {
e.Next();
}
e.Next();
}
// we have a map of a map of counter entries; dump them to JSON
if (counters.count() == 0) {