Bug 731923 - Convert the N "gfx-surface" memory reporters to a single multi-reporter. r=jlebar.

--HG--
extra : rebase_source : 176ed4f7e417b3f8fc4247b8f976ab6c47dc565f
This commit is contained in:
Nicholas Nethercote 2012-03-18 14:59:17 -07:00
Родитель c12d7213d5
Коммит 25c0ac4496
1 изменённых файлов: 38 добавлений и 52 удалений

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

@ -555,7 +555,7 @@ static const char *sDefaultSurfaceDescription =
"Memory used by gfx surface of the given type.";
struct SurfaceMemoryReporterAttrs {
const char *name;
const char *path;
const char *description;
};
@ -600,74 +600,59 @@ PR_STATIC_ASSERT(PRUint32(CAIRO_SURFACE_TYPE_D2D) ==
PR_STATIC_ASSERT(PRUint32(CAIRO_SURFACE_TYPE_SKIA) ==
PRUint32(gfxASurface::SurfaceTypeSkia));
static const char *
SurfaceMemoryReporterPathForType(gfxASurface::gfxSurfaceType aType)
{
if (aType < 0 ||
aType >= gfxASurface::SurfaceTypeMax)
return "gfx-surface-unknown";
return sSurfaceMemoryReporterAttrs[aType].name;
}
static const char *
SurfaceMemoryReporterDescriptionForType(gfxASurface::gfxSurfaceType aType)
{
if (aType >= 0 && aType < gfxASurface::SurfaceTypeMax &&
sSurfaceMemoryReporterAttrs[aType].description)
return sSurfaceMemoryReporterAttrs[aType].description;
return sDefaultSurfaceDescription;
}
/* Surface size memory reporting */
static nsIMemoryReporter *gSurfaceMemoryReporters[gfxASurface::SurfaceTypeMax] = { 0 };
static PRInt64 gSurfaceMemoryUsed[gfxASurface::SurfaceTypeMax] = { 0 };
class SurfaceMemoryReporter :
public nsIMemoryReporter
public nsIMemoryMultiReporter
{
public:
SurfaceMemoryReporter(gfxASurface::gfxSurfaceType aType)
: mType(aType)
SurfaceMemoryReporter()
{ }
NS_DECL_ISUPPORTS
NS_IMETHOD GetProcess(nsACString &process) {
process.Truncate();
NS_IMETHOD GetName(nsACString &name)
{
name.AssignLiteral("gfx-surface");
return NS_OK;
}
NS_IMETHOD GetPath(nsACString &path) {
path.Assign(SurfaceMemoryReporterPathForType(mType));
NS_IMETHOD CollectReports(nsIMemoryMultiReporterCallback *aCb,
nsISupports *aClosure)
{
size_t len = NS_ARRAY_LENGTH(sSurfaceMemoryReporterAttrs);
for (size_t i = 0; i < len; i++) {
PRInt64 amount = gSurfaceMemoryUsed[i];
if (amount != 0) {
const char *path = sSurfaceMemoryReporterAttrs[i].path;
const char *desc = sSurfaceMemoryReporterAttrs[i].description;
if (!desc) {
desc = sDefaultSurfaceDescription;
}
nsresult rv = aCb->Callback(EmptyCString(), nsCString(path),
nsIMemoryReporter::KIND_OTHER,
nsIMemoryReporter::UNITS_BYTES,
gSurfaceMemoryUsed[i],
nsCString(desc), aClosure);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
NS_IMETHOD GetKind(PRInt32 *kind) {
*kind = KIND_OTHER;
NS_IMETHOD GetExplicitNonHeap(PRInt64 *n)
{
*n = 0; // this reporter makes neither "explicit" non NONHEAP reports
return NS_OK;
}
NS_IMETHOD GetUnits(PRInt32 *units) {
*units = UNITS_BYTES;
return NS_OK;
}
NS_IMETHOD GetAmount(PRInt64 *amount) {
*amount = gSurfaceMemoryUsed[mType];
return NS_OK;
}
NS_IMETHOD GetDescription(nsACString &desc) {
desc.Assign(SurfaceMemoryReporterDescriptionForType(mType));
return NS_OK;
}
gfxASurface::gfxSurfaceType mType;
};
NS_IMPL_ISUPPORTS1(SurfaceMemoryReporter, nsIMemoryReporter)
NS_IMPL_ISUPPORTS1(SurfaceMemoryReporter, nsIMemoryMultiReporter)
void
gfxASurface::RecordMemoryUsedForSurfaceType(gfxASurface::gfxSurfaceType aType,
@ -678,9 +663,10 @@ gfxASurface::RecordMemoryUsedForSurfaceType(gfxASurface::gfxSurfaceType aType,
return;
}
if (gSurfaceMemoryReporters[aType] == 0) {
gSurfaceMemoryReporters[aType] = new SurfaceMemoryReporter(aType);
NS_RegisterMemoryReporter(gSurfaceMemoryReporters[aType]);
static bool registered = false;
if (!registered) {
NS_RegisterMemoryMultiReporter(new SurfaceMemoryReporter());
registered = true;
}
gSurfaceMemoryUsed[aType] += aBytes;