Bug 929791 - Fix invalid JSON generation when dumping memory reports to file after viewing about:memory in the presence of child processes. r=mccr8.

This commit is contained in:
Nicholas Nethercote 2013-10-22 16:58:33 -07:00
Родитель 4ff2db0e59
Коммит eba1059de2
1 изменённых файлов: 9 добавлений и 14 удалений

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

@ -610,12 +610,10 @@ namespace mozilla {
} while (0) } while (0)
static nsresult static nsresult
DumpReport(nsIGZFileWriter *aWriter, bool aIsFirst, DumpReport(nsIGZFileWriter *aWriter, bool *aIsFirstPtr,
const nsACString &aProcess, const nsACString &aPath, int32_t aKind, const nsACString &aProcess, const nsACString &aPath, int32_t aKind,
int32_t aUnits, int64_t aAmount, const nsACString &aDescription) int32_t aUnits, int64_t aAmount, const nsACString &aDescription)
{ {
DUMP(aWriter, aIsFirst ? "[" : ",");
// We only want to dump reports for this process. If |aProcess| is // We only want to dump reports for this process. If |aProcess| is
// non-nullptr that means we've received it from another process in response // non-nullptr that means we've received it from another process in response
// to a "child-memory-reporter-request" event; ignore such reports. // to a "child-memory-reporter-request" event; ignore such reports.
@ -623,6 +621,9 @@ DumpReport(nsIGZFileWriter *aWriter, bool aIsFirst,
return NS_OK; return NS_OK;
} }
DUMP(aWriter, *aIsFirstPtr ? "[" : ",");
*aIsFirstPtr = false;
// Generate the process identifier, which is of the form "$PROCESS_NAME // Generate the process identifier, which is of the form "$PROCESS_NAME
// (pid $PID)", or just "(pid $PID)" if we don't have a process name. If // (pid $PID)", or just "(pid $PID)" if we don't have a process name. If
// we're the main process, we let $PROCESS_NAME be "Main Process". // we're the main process, we let $PROCESS_NAME be "Main Process".
@ -678,7 +679,7 @@ class DumpReporterCallback MOZ_FINAL : public nsIMemoryReporterCallback
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
DumpReporterCallback(bool* aIsFirstPtr) : mIsFirstPtr(aIsFirstPtr) {} DumpReporterCallback() : mIsFirst(true) {}
NS_IMETHOD Callback(const nsACString &aProcess, const nsACString &aPath, NS_IMETHOD Callback(const nsACString &aProcess, const nsACString &aPath,
int32_t aKind, int32_t aUnits, int64_t aAmount, int32_t aKind, int32_t aUnits, int64_t aAmount,
@ -688,17 +689,12 @@ public:
nsCOMPtr<nsIGZFileWriter> writer = do_QueryInterface(aData); nsCOMPtr<nsIGZFileWriter> writer = do_QueryInterface(aData);
NS_ENSURE_TRUE(writer, NS_ERROR_FAILURE); NS_ENSURE_TRUE(writer, NS_ERROR_FAILURE);
// The |isFirst = false| assumes that at least one single reporter is return DumpReport(writer, &mIsFirst, aProcess, aPath, aKind, aUnits,
// present and so will have been processed in aAmount, aDescription);
// DumpProcessMemoryReportsToGZFileWriter() below.
bool isFirst = *mIsFirstPtr;
*mIsFirstPtr = false;
return DumpReport(writer, isFirst, aProcess, aPath, aKind, aUnits, aAmount,
aDescription);
} }
private: private:
bool* mIsFirstPtr; bool mIsFirst;
}; };
NS_IMPL_ISUPPORTS1(DumpReporterCallback, nsIMemoryReporterCallback) NS_IMPL_ISUPPORTS1(DumpReporterCallback, nsIMemoryReporterCallback)
@ -817,11 +813,10 @@ DumpProcessMemoryReportsToGZFileWriter(nsIGZFileWriter *aWriter)
DUMP(aWriter, " \"reports\": "); DUMP(aWriter, " \"reports\": ");
// Process reporters. // Process reporters.
bool isFirst = true;
bool more; bool more;
nsCOMPtr<nsISimpleEnumerator> e; nsCOMPtr<nsISimpleEnumerator> e;
mgr->EnumerateReporters(getter_AddRefs(e)); mgr->EnumerateReporters(getter_AddRefs(e));
nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback(&isFirst); nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback();
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) { while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r; nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r)); e->GetNext(getter_AddRefs(r));