mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
[Not part of build] Added traceCollection, getServices methods.
This commit is contained in:
parent
93854b043f
commit
40fafcfe3c
@ -22,6 +22,8 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsICollection;
|
||||
|
||||
/**
|
||||
* Controls the leak detector.
|
||||
*/
|
||||
@ -29,5 +31,7 @@
|
||||
interface nsILeakDetector : nsISupports {
|
||||
void dumpLeaks();
|
||||
void traceObject(in nsISupports object, in PRBool verbose);
|
||||
void traceCollection(in nsICollection objects, in PRBool verbose);
|
||||
void markObject(in nsISupports object, in PRBool marked);
|
||||
nsISupports getServices();
|
||||
};
|
||||
|
@ -25,8 +25,10 @@
|
||||
#include "nsLeakDetector.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsILeakDetector.h"
|
||||
#include "nsICollection.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
@ -107,12 +109,52 @@ NS_METHOD nsLeakDetector::TraceObject(nsISupports* object, PRBool verbose)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD nsLeakDetector::TraceCollection(nsICollection* objects, PRBool verbose)
|
||||
{
|
||||
PRUint32 count;
|
||||
if (NS_FAILED(objects->Count(&count)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISupports>* elements = new nsCOMPtr<nsISupports>[count];
|
||||
if (elements == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
for (PRUint32 i = 0; i < count; ++i)
|
||||
objects->GetElementAt(i, getter_AddRefs(elements[i]));
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
FILE* trace = openTraceFile();
|
||||
if (trace != NULL) {
|
||||
FILE* old_stderr = GC_stderr;
|
||||
GC_stderr = trace;
|
||||
GC_trace_object(elements, (verbose ? 1 : 0));
|
||||
GC_stderr = old_stderr;
|
||||
fclose(trace);
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
delete[] elements;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD nsLeakDetector::MarkObject(nsISupports* object, PRBool marked)
|
||||
{
|
||||
GC_mark_object(object, (marked ? 1 : 0));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsLeakDetector::GetServices(nsISupports* *result)
|
||||
{
|
||||
nsIServiceManager* serviceManager = nsnull;
|
||||
nsresult rv = nsServiceManager::GetGlobalServiceManager(&serviceManager);
|
||||
if (rv == NS_OK) {
|
||||
*result = serviceManager;
|
||||
NS_ADDREF(*result);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#define NS_CLEAKDETECTOR_CID_STR "bb1ba360-1dd1-11b2-b30e-aa2314429f54"
|
||||
#define NS_CLEAKDETECTOR_CID {0xbb1ba360, 0x1dd1, 0x11b2, {0xb3, 0x0e, 0xaa, 0x23, 0x14, 0x42, 0x9f, 0x54}}
|
||||
#define NS_CLEAKDETECTOR_CONTRACTID "@mozilla.org/xpcom/leakdetector;1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user