зеркало из https://github.com/mozilla/gecko-dev.git
Bug 819801 - In DMD builds, check that SQLite's reporting of its total memory consumption are correct. r=asuth.
(NPOTB because it's DMD-only changes.)
This commit is contained in:
Родитель
0471905a26
Коммит
d43b81a00e
|
@ -60,6 +60,10 @@ namespace storage {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//// Memory Reporting
|
//// Memory Reporting
|
||||||
|
|
||||||
|
#ifdef MOZ_DMD
|
||||||
|
static mozilla::Atomic<size_t> gSqliteMemoryUsed;
|
||||||
|
#endif
|
||||||
|
|
||||||
static int64_t
|
static int64_t
|
||||||
StorageSQLiteDistinguishedAmount()
|
StorageSQLiteDistinguishedAmount()
|
||||||
{
|
{
|
||||||
|
@ -138,6 +142,13 @@ public:
|
||||||
SQLITE_DBSTATUS_SCHEMA_USED, &totalConnSize);
|
SQLITE_DBSTATUS_SCHEMA_USED, &totalConnSize);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MOZ_DMD
|
||||||
|
if (::sqlite3_memory_used() != int64_t(gSqliteMemoryUsed)) {
|
||||||
|
NS_WARNING("memory consumption reported by SQLite doesn't match "
|
||||||
|
"our measurements");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t other = ::sqlite3_memory_used() - totalConnSize;
|
int64_t other = ::sqlite3_memory_used() - totalConnSize;
|
||||||
|
@ -387,7 +398,10 @@ namespace {
|
||||||
// In other words, we are marking all sqlite heap blocks as reported even
|
// In other words, we are marking all sqlite heap blocks as reported even
|
||||||
// though we're not reporting them ourselves. Instead we're trusting that
|
// though we're not reporting them ourselves. Instead we're trusting that
|
||||||
// sqlite is fully and correctly accounting for all of its heap blocks via its
|
// sqlite is fully and correctly accounting for all of its heap blocks via its
|
||||||
// own memory accounting.
|
// own memory accounting. Well, we don't have to trust it entirely, because
|
||||||
|
// it's easy to keep track (while doing this DMD-specific marking) of exactly
|
||||||
|
// how much memory SQLite is using. And we can compare that against what
|
||||||
|
// SQLite reports it is using.
|
||||||
|
|
||||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_ON_ALLOC_FUN(SqliteMallocSizeOfOnAlloc)
|
NS_MEMORY_REPORTER_MALLOC_SIZEOF_ON_ALLOC_FUN(SqliteMallocSizeOfOnAlloc)
|
||||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_ON_FREE_FUN(SqliteMallocSizeOfOnFree)
|
NS_MEMORY_REPORTER_MALLOC_SIZEOF_ON_FREE_FUN(SqliteMallocSizeOfOnFree)
|
||||||
|
@ -398,7 +412,7 @@ static void *sqliteMemMalloc(int n)
|
||||||
{
|
{
|
||||||
void* p = ::moz_malloc(n);
|
void* p = ::moz_malloc(n);
|
||||||
#ifdef MOZ_DMD
|
#ifdef MOZ_DMD
|
||||||
SqliteMallocSizeOfOnAlloc(p);
|
gSqliteMemoryUsed += SqliteMallocSizeOfOnAlloc(p);
|
||||||
#endif
|
#endif
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -406,7 +420,7 @@ static void *sqliteMemMalloc(int n)
|
||||||
static void sqliteMemFree(void *p)
|
static void sqliteMemFree(void *p)
|
||||||
{
|
{
|
||||||
#ifdef MOZ_DMD
|
#ifdef MOZ_DMD
|
||||||
SqliteMallocSizeOfOnFree(p);
|
gSqliteMemoryUsed -= SqliteMallocSizeOfOnFree(p);
|
||||||
#endif
|
#endif
|
||||||
::moz_free(p);
|
::moz_free(p);
|
||||||
}
|
}
|
||||||
|
@ -414,13 +428,13 @@ static void sqliteMemFree(void *p)
|
||||||
static void *sqliteMemRealloc(void *p, int n)
|
static void *sqliteMemRealloc(void *p, int n)
|
||||||
{
|
{
|
||||||
#ifdef MOZ_DMD
|
#ifdef MOZ_DMD
|
||||||
SqliteMallocSizeOfOnFree(p);
|
gSqliteMemoryUsed -= SqliteMallocSizeOfOnFree(p);
|
||||||
void *pnew = ::moz_realloc(p, n);
|
void *pnew = ::moz_realloc(p, n);
|
||||||
if (pnew) {
|
if (pnew) {
|
||||||
SqliteMallocSizeOfOnAlloc(pnew);
|
gSqliteMemoryUsed += SqliteMallocSizeOfOnAlloc(pnew);
|
||||||
} else {
|
} else {
|
||||||
// realloc failed; undo the SqliteMallocSizeOfOnFree from above
|
// realloc failed; undo the SqliteMallocSizeOfOnFree from above
|
||||||
SqliteMallocSizeOfOnAlloc(p);
|
gSqliteMemoryUsed += SqliteMallocSizeOfOnAlloc(p);
|
||||||
}
|
}
|
||||||
return pnew;
|
return pnew;
|
||||||
#else
|
#else
|
||||||
|
|
Загрузка…
Ссылка в новой задаче