mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
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:
parent
4ff2db0e59
commit
eba1059de2
@ -610,12 +610,10 @@ namespace mozilla {
|
||||
} while (0)
|
||||
|
||||
static nsresult
|
||||
DumpReport(nsIGZFileWriter *aWriter, bool aIsFirst,
|
||||
DumpReport(nsIGZFileWriter *aWriter, bool *aIsFirstPtr,
|
||||
const nsACString &aProcess, const nsACString &aPath, int32_t aKind,
|
||||
int32_t aUnits, int64_t aAmount, const nsACString &aDescription)
|
||||
{
|
||||
DUMP(aWriter, aIsFirst ? "[" : ",");
|
||||
|
||||
// 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
|
||||
// to a "child-memory-reporter-request" event; ignore such reports.
|
||||
@ -623,6 +621,9 @@ DumpReport(nsIGZFileWriter *aWriter, bool aIsFirst,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DUMP(aWriter, *aIsFirstPtr ? "[" : ",");
|
||||
*aIsFirstPtr = false;
|
||||
|
||||
// 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
|
||||
// we're the main process, we let $PROCESS_NAME be "Main Process".
|
||||
@ -678,7 +679,7 @@ class DumpReporterCallback MOZ_FINAL : public nsIMemoryReporterCallback
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
DumpReporterCallback(bool* aIsFirstPtr) : mIsFirstPtr(aIsFirstPtr) {}
|
||||
DumpReporterCallback() : mIsFirst(true) {}
|
||||
|
||||
NS_IMETHOD Callback(const nsACString &aProcess, const nsACString &aPath,
|
||||
int32_t aKind, int32_t aUnits, int64_t aAmount,
|
||||
@ -688,17 +689,12 @@ public:
|
||||
nsCOMPtr<nsIGZFileWriter> writer = do_QueryInterface(aData);
|
||||
NS_ENSURE_TRUE(writer, NS_ERROR_FAILURE);
|
||||
|
||||
// The |isFirst = false| assumes that at least one single reporter is
|
||||
// present and so will have been processed in
|
||||
// DumpProcessMemoryReportsToGZFileWriter() below.
|
||||
bool isFirst = *mIsFirstPtr;
|
||||
*mIsFirstPtr = false;
|
||||
return DumpReport(writer, isFirst, aProcess, aPath, aKind, aUnits, aAmount,
|
||||
aDescription);
|
||||
return DumpReport(writer, &mIsFirst, aProcess, aPath, aKind, aUnits,
|
||||
aAmount, aDescription);
|
||||
}
|
||||
|
||||
private:
|
||||
bool* mIsFirstPtr;
|
||||
bool mIsFirst;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(DumpReporterCallback, nsIMemoryReporterCallback)
|
||||
@ -817,11 +813,10 @@ DumpProcessMemoryReportsToGZFileWriter(nsIGZFileWriter *aWriter)
|
||||
DUMP(aWriter, " \"reports\": ");
|
||||
|
||||
// Process reporters.
|
||||
bool isFirst = true;
|
||||
bool more;
|
||||
nsCOMPtr<nsISimpleEnumerator> e;
|
||||
mgr->EnumerateReporters(getter_AddRefs(e));
|
||||
nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback(&isFirst);
|
||||
nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback();
|
||||
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
|
||||
nsCOMPtr<nsIMemoryReporter> r;
|
||||
e->GetNext(getter_AddRefs(r));
|
||||
|
Loading…
Reference in New Issue
Block a user