forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tracing] Add sqlite memory statistics to tracing.
The process-wide memory usage statistics of sqlite library is added to chrome://tracing. The memory usage of sqlite library is mainly through sqlite_malloc. The total usage of the process is recorded by sqlite3_memory_used() api. This CL also adds per-connection memory usage to tracing. Each connection uses memory for cache, schema and statement, and these usages are recorded. sqlit3_malloc uses malloc internally to allocate memory. So, thie memory is traced as sub-allocation from system_allocator(malloc). This CL lets us keep track of sqlite memory usage in chrome telemetry. BUG=466141 Review URL: https://codereview.chromium.org/1327063002 Cr-Commit-Position: refs/heads/master@{#353549}
- Loading branch information
1 parent
55e0b36
commit 9f8022f
Showing
9 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "sql/sql_memory_dump_provider.h" | ||
|
||
#include "base/trace_event/memory_dump_manager.h" | ||
#include "base/trace_event/process_memory_dump.h" | ||
#include "third_party/sqlite/sqlite3.h" | ||
|
||
namespace sql { | ||
|
||
// static | ||
SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() { | ||
return base::Singleton< | ||
SqlMemoryDumpProvider, | ||
base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get(); | ||
} | ||
|
||
SqlMemoryDumpProvider::SqlMemoryDumpProvider() {} | ||
|
||
SqlMemoryDumpProvider::~SqlMemoryDumpProvider() {} | ||
|
||
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 */); | ||
if (status != SQLITE_OK) | ||
return false; | ||
|
||
base::trace_event::MemoryAllocatorDump* dump = | ||
pmd->CreateAllocatorDump("sqlite"); | ||
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | ||
base::trace_event::MemoryAllocatorDump::kUnitsBytes, | ||
memory_used); | ||
dump->AddScalar("malloc_high_wmark_size", | ||
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 */); | ||
if (status == SQLITE_OK) { | ||
dump->AddScalar("malloc_count", | ||
base::trace_event::MemoryAllocatorDump::kUnitsObjects, | ||
malloc_count); | ||
} | ||
|
||
const char* system_allocator_name = | ||
base::trace_event::MemoryDumpManager::GetInstance() | ||
->system_allocator_pool_name(); | ||
if (system_allocator_name) { | ||
pmd->AddSuballocation(dump->guid(), system_allocator_name); | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SQL_PROCESS_MEMORY_DUMP_PROVIDER_H | ||
#define SQL_PROCESS_MEMORY_DUMP_PROVIDER_H | ||
|
||
#include "base/memory/singleton.h" | ||
#include "base/trace_event/memory_dump_provider.h" | ||
#include "sql/sql_export.h" | ||
|
||
namespace sql { | ||
|
||
// Adds process-wide memory usage statistics about sqlite to chrome://tracing. | ||
// sql::Connection::OnMemoryDump adds per-connection memory statistics. | ||
class SQL_EXPORT SqlMemoryDumpProvider | ||
: public base::trace_event::MemoryDumpProvider { | ||
public: | ||
static SqlMemoryDumpProvider* GetInstance(); | ||
|
||
// MemoryDumpProvider implementation. | ||
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | ||
base::trace_event::ProcessMemoryDump* pmd) override; | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<SqlMemoryDumpProvider>; | ||
|
||
SqlMemoryDumpProvider(); | ||
~SqlMemoryDumpProvider() override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(SqlMemoryDumpProvider); | ||
}; | ||
|
||
} // namespace sql | ||
|
||
#endif // SQL_PROCESS_MEMORY_DUMP_PROVIDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "sql/sql_memory_dump_provider.h" | ||
|
||
#include "base/trace_event/process_memory_dump.h" | ||
#include "sql/test/sql_test_base.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace { | ||
using SQLMemoryDumpProviderTest = sql::SQLTestBase; | ||
} | ||
|
||
TEST_F(SQLMemoryDumpProviderTest, OnMemoryDump) { | ||
base::trace_event::ProcessMemoryDump pmd(nullptr); | ||
base::trace_event::MemoryDumpArgs args = { | ||
base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | ||
ASSERT_TRUE( | ||
sql::SqlMemoryDumpProvider::GetInstance()->OnMemoryDump(args, &pmd)); | ||
ASSERT_TRUE(pmd.GetAllocatorDump("sqlite")); | ||
} |