Bug 1071056 - preserve unpaired START markers until next pop. r=bgirard

This commit is contained in:
Tom Tromey 2014-10-14 13:06:19 +02:00
parent b536647980
commit dc1e15620c
2 changed files with 27 additions and 3 deletions

View File

@ -2858,6 +2858,11 @@ nsDocShell::PopProfileTimelineMarkers(JSContext* aCx,
nsTArray<mozilla::dom::ProfileTimelineMarker> profileTimelineMarkers;
// If we see an unpaired START, we keep it around for the next call
// to PopProfileTimelineMarkers. We store the kept START objects in
// this array.
decltype(mProfileTimelineMarkers) keptMarkers;
for (uint32_t i = 0; i < mProfileTimelineMarkers.Length(); ++i) {
ProfilerMarkerTracing* startPayload = static_cast<ProfilerMarkerTracing*>(
mProfileTimelineMarkers[i]->mPayload);
@ -2866,6 +2871,8 @@ nsDocShell::PopProfileTimelineMarkers(JSContext* aCx,
bool hasSeenPaintedLayer = false;
if (startPayload->GetMetaData() == TRACING_INTERVAL_START) {
bool hasSeenEnd = false;
// The assumption is that the devtools timeline flushes markers frequently
// enough for the amount of markers to always be small enough that the
// nested for loop isn't going to be a performance problem.
@ -2893,15 +2900,26 @@ nsDocShell::PopProfileTimelineMarkers(JSContext* aCx,
profileTimelineMarkers.AppendElement(marker);
}
// We want the start to be dropped either way.
hasSeenEnd = true;
break;
}
}
// If we did not see the corresponding END, keep the START.
if (!hasSeenEnd) {
keptMarkers.AppendElement(mProfileTimelineMarkers[i]);
mProfileTimelineMarkers.RemoveElementAt(i);
--i;
}
}
}
ToJSValue(aCx, profileTimelineMarkers, aProfileTimelineMarkers);
ClearProfileTimelineMarkers();
mProfileTimelineMarkers.SwapElements(keptMarkers);
return NS_OK;
#else
@ -2952,8 +2970,7 @@ nsDocShell::ClearProfileTimelineMarkers()
{
#ifdef MOZ_ENABLE_PROFILER_SPS
for (uint32_t i = 0; i < mProfileTimelineMarkers.Length(); ++i) {
delete mProfileTimelineMarkers[i]->mPayload;
mProfileTimelineMarkers[i]->mPayload = nullptr;
delete mProfileTimelineMarkers[i];
}
mProfileTimelineMarkers.Clear();
#endif

View File

@ -21,6 +21,7 @@
#include "mozilla/WeakPtr.h"
#include "mozilla/TimeStamp.h"
#include "GeckoProfiler.h"
#include "ProfilerMarkers.h"
// Helper Classes
#include "nsCOMPtr.h"
@ -959,11 +960,17 @@ private:
, mPayload(aPayload)
, mTime(aTime)
{}
~InternalProfileTimelineMarker()
{
delete mPayload;
}
const char* mName;
ProfilerMarkerTracing* mPayload;
float mTime;
};
nsTArray<nsAutoPtr<InternalProfileTimelineMarker>> mProfileTimelineMarkers;
nsTArray<InternalProfileTimelineMarker*> mProfileTimelineMarkers;
// Get the elapsed time (in millis) since the profile timeline recording
// started