Bug 736643 - Add timestamp support to GC/CC JSON output (r=terrence)

This commit is contained in:
Bill McCloskey 2012-03-16 16:36:26 -07:00
Родитель fe514e3410
Коммит 65e1d5406f
5 изменённых файлов: 31 добавлений и 28 удалений

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

@ -3163,7 +3163,8 @@ nsJSContext::CycleCollectNow(nsICycleCollectorListener *aListener,
}
NS_NAMED_MULTILINE_LITERAL_STRING(kJSONFmt,
NS_LL("{ \"duration\": %llu, ")
NS_LL("{ \"timestamp\": %llu, ")
NS_LL("\"duration\": %llu, ")
NS_LL("\"suspected\": %lu, ")
NS_LL("\"visited\": { ")
NS_LL("\"RCed\": %lu, ")
@ -3183,18 +3184,18 @@ nsJSContext::CycleCollectNow(nsICycleCollectorListener *aListener,
NS_LL("}"));
nsString json;
json.Adopt(nsTextFormatter::smprintf(kJSONFmt.get(),
(now - start) / PR_USEC_PER_MSEC, suspected,
ccResults.mVisitedRefCounted, ccResults.mVisitedGCed,
ccResults.mFreedRefCounted, ccResults.mFreedGCed,
sCCollectedWaitingForGC,
ccResults.mForcedGC,
sForgetSkippableBeforeCC,
sMinForgetSkippableTime / PR_USEC_PER_MSEC,
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
(sTotalForgetSkippableTime / cleanups) /
PR_USEC_PER_MSEC,
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
sRemovedPurples));
now, (now - start) / PR_USEC_PER_MSEC, suspected,
ccResults.mVisitedRefCounted, ccResults.mVisitedGCed,
ccResults.mFreedRefCounted, ccResults.mFreedGCed,
sCCollectedWaitingForGC,
ccResults.mForcedGC,
sForgetSkippableBeforeCC,
sMinForgetSkippableTime / PR_USEC_PER_MSEC,
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
(sTotalForgetSkippableTime / cleanups) /
PR_USEC_PER_MSEC,
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
sRemovedPurples));
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(nsnull, "cycle-collection-statistics", json.get());
@ -3506,6 +3507,11 @@ DOMGCSliceCallback(JSRuntime *aRt, js::GCProgress aProgress, const js::GCDescrip
if (cs) {
cs->LogStringMessage(msg.get());
}
nsString json;
json.Adopt(aDesc.formatJSON(aRt, now));
nsRefPtr<NotifyGCEndRunnable> notify = new NotifyGCEndRunnable(json);
NS_DispatchToMainThread(notify);
}
// Prevent cycle collections and shrinking during incremental GC.
@ -3529,11 +3535,6 @@ DOMGCSliceCallback(JSRuntime *aRt, js::GCProgress aProgress, const js::GCDescrip
sCCollectedWaitingForGC = 0;
sCleanupSinceLastGC = false;
nsString json;
json.Adopt(aDesc.formatJSON(aRt));
nsRefPtr<NotifyGCEndRunnable> notify = new NotifyGCEndRunnable(json);
NS_DispatchToMainThread(notify);
if (aDesc.isCompartment) {
// If this is a compartment GC, restart it. We still want
// a full GC to happen. Compartment GCs usually happen as a

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

@ -310,7 +310,7 @@ formatPhases(StatisticsSerializer &ss, const char *name, int64_t *times)
}
bool
Statistics::formatData(StatisticsSerializer &ss)
Statistics::formatData(StatisticsSerializer &ss, uint64_t timestamp)
{
int64_t total = 0, longest = 0;
for (SliceData *slice = slices.begin(); slice != slices.end(); slice++) {
@ -323,6 +323,8 @@ Statistics::formatData(StatisticsSerializer &ss)
double mmu50 = computeMMU(50 * PRMJ_USEC_PER_MSEC);
ss.beginObject(NULL);
if (ss.isJSON())
ss.appendNumber("Timestamp", "%llu", "", (unsigned long long)timestamp);
ss.appendNumber("Total Time", "%.1f", "ms", t(total));
ss.appendString("Type", compartment ? "compartment" : "global");
ss.appendNumber("MMU (20ms)", "%d", "%", int(mmu20 * 100));
@ -377,15 +379,15 @@ jschar *
Statistics::formatMessage()
{
StatisticsSerializer ss(StatisticsSerializer::AsText);
formatData(ss);
formatData(ss, 0);
return ss.finishJSString();
}
jschar *
Statistics::formatJSON()
Statistics::formatJSON(uint64_t timestamp)
{
StatisticsSerializer ss(StatisticsSerializer::AsJSON);
formatData(ss);
formatData(ss, timestamp);
return ss.finishJSString();
}
@ -449,7 +451,7 @@ Statistics::printStats()
{
if (fullFormat) {
StatisticsSerializer ss(StatisticsSerializer::AsText);
formatData(ss);
formatData(ss, 0);
char *msg = ss.finishCString();
if (msg) {
fprintf(fp, "GC(T+%.3fs) %s\n", t(slices[0].start - startupTime) / 1000.0, msg);

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

@ -106,7 +106,7 @@ struct Statistics {
}
jschar *formatMessage();
jschar *formatJSON();
jschar *formatJSON(uint64_t timestamp);
private:
JSRuntime *runtime;
@ -156,7 +156,7 @@ struct Statistics {
int64_t gcDuration();
void printStats();
bool formatData(StatisticsSerializer &ss);
bool formatData(StatisticsSerializer &ss, uint64_t timestamp);
double computeMMU(int64_t resolution);
};

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

@ -724,9 +724,9 @@ GCDescription::formatMessage(JSRuntime *rt) const
}
jschar *
GCDescription::formatJSON(JSRuntime *rt) const
GCDescription::formatJSON(JSRuntime *rt, uint64_t timestamp) const
{
return rt->gcStats.formatJSON();
return rt->gcStats.formatJSON(timestamp);
}
JS_FRIEND_API(bool)

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

@ -706,7 +706,7 @@ struct JS_FRIEND_API(GCDescription) {
: isCompartment(isCompartment) {}
jschar *formatMessage(JSRuntime *rt) const;
jschar *formatJSON(JSRuntime *rt) const;
jschar *formatJSON(JSRuntime *rt, uint64_t timestamp) const;
};
typedef void