Skip to content

Commit

Permalink
sql: Use 64-bit integers to collect SQLite memory usage.
Browse files Browse the repository at this point in the history
The MemoryDumpProvider API uses 64-bit integers. For consistency, use
SQLite's 64-bit API (sqlite_status64) to obtain memory usage statistics
from SQLite.

This CL also documents the SQLite build configuration setting assumed by
the memory usage reporting code. The value needed by the memory
reporting code is (currently) the default. However, the SQLite
docs [1] recommend a different value, so documenting our needs makes it
less likely that we'll accidentally end up with an incorrect
configuration.

Change-Id: I15217e11bce8d167dce65db345ddf78d21148144
Reviewed-on: https://chromium-review.googlesource.com/1146293
Reviewed-by: Chris Mumford <cmumford@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577260}
  • Loading branch information
pwnall authored and Commit Bot committed Jul 23, 2018
1 parent 1490393 commit ccc7647
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sql/sql_memory_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ SqlMemoryDumpProvider::~SqlMemoryDumpProvider() = default;
bool SqlMemoryDumpProvider::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
int memory_used = 0;
int memory_high_water = 0;
int status = sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memory_used,
&memory_high_water, 1 /*resetFlag */);
sqlite3_int64 memory_used = 0;
sqlite3_int64 memory_high_water = 0;
int status = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &memory_used,
&memory_high_water, /* resetFlag= */ 1);
if (status != SQLITE_OK)
return false;

Expand All @@ -40,10 +40,10 @@ bool SqlMemoryDumpProvider::OnMemoryDump(
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
memory_high_water);

int dummy_high_water = -1;
int malloc_count = -1;
status = sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &malloc_count,
&dummy_high_water, 0 /* resetFlag */);
sqlite3_int64 dummy_high_water = -1;
sqlite3_int64 malloc_count = -1;
status = sqlite3_status64(SQLITE_STATUS_MALLOC_COUNT, &malloc_count,
&dummy_high_water, /* resetFlag= */ 0);
if (status == SQLITE_OK) {
dump->AddScalar("malloc_count",
base::trace_event::MemoryAllocatorDump::kUnitsObjects,
Expand Down
7 changes: 7 additions & 0 deletions third_party/sqlite/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ config("chromium_sqlite3_compile_options") {
# TODO(pwnall): Upstream the ability to use this define.
"SQLITE_MMAP_READ_ONLY=1",

# Needed by the SQL MemoryDumpProvider.
#
# Setting this to 1 is needed to collect the information reported by
# sqlite3_status64(SQLITE_STATUS_MEMORY_USED). Without this setting, the API
# still exists, but does not work as promised.
"SQLITE_DEFAULT_MEMSTATUS=1",

# By default SQLite pre-allocates 100 pages of pcache data, which will not
# be released until the handle is closed. This is contrary to Chromium's
# memory-usage goals.
Expand Down

0 comments on commit ccc7647

Please sign in to comment.