[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / sql / sql_memory_dump_provider.cc
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sql/sql_memory_dump_provider.h"
6
7 #include "base/trace_event/memory_dump_manager.h"
8 #include "base/trace_event/process_memory_dump.h"
9 #include "sql/sqlite_result_code.h"
10 #include "sql/sqlite_result_code_values.h"
11 #include "third_party/sqlite/sqlite3.h"
12
13 namespace sql {
14
15 // static
16 SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() {
17   return base::Singleton<
18       SqlMemoryDumpProvider,
19       base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get();
20 }
21
22 SqlMemoryDumpProvider::SqlMemoryDumpProvider() = default;
23
24 SqlMemoryDumpProvider::~SqlMemoryDumpProvider() = default;
25
26 bool SqlMemoryDumpProvider::OnMemoryDump(
27     const base::trace_event::MemoryDumpArgs& args,
28     base::trace_event::ProcessMemoryDump* pmd) {
29   sqlite3_int64 memory_used = 0;
30   sqlite3_int64 memory_high_water = 0;
31   auto sqlite_result_code = ToSqliteResultCode(sqlite3_status64(
32       SQLITE_STATUS_MEMORY_USED, &memory_used, &memory_high_water,
33       /*resetFlag=*/1));
34   DCHECK_EQ(sqlite_result_code, SqliteResultCode::kOk)
35       << "sqlite3_status64(SQLITE_STATUS_MEMORY_USED) failed";
36
37   base::trace_event::MemoryAllocatorDump* dump =
38       pmd->CreateAllocatorDump("sqlite");
39   dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
40                   base::trace_event::MemoryAllocatorDump::kUnitsBytes,
41                   memory_used);
42   dump->AddScalar("malloc_high_wmark_size",
43                   base::trace_event::MemoryAllocatorDump::kUnitsBytes,
44                   memory_high_water);
45
46   sqlite3_int64 dummy_high_water = -1;
47   sqlite3_int64 malloc_count = -1;
48   sqlite_result_code = ToSqliteResultCode(sqlite3_status64(
49       SQLITE_STATUS_MALLOC_COUNT, &malloc_count, &dummy_high_water,
50       /*resetFlag=*/0));
51   DCHECK_EQ(sqlite_result_code, SqliteResultCode::kOk)
52       << "sqlite3_status64(SQLITE_STATUS_MALLOC_COUNT) failed";
53   dump->AddScalar("malloc_count",
54                   base::trace_event::MemoryAllocatorDump::kUnitsObjects,
55                   malloc_count);
56
57   const char* system_allocator_name =
58       base::trace_event::MemoryDumpManager::GetInstance()
59           ->system_allocator_pool_name();
60   if (system_allocator_name) {
61     pmd->AddSuballocation(dump->guid(), system_allocator_name);
62   }
63   return true;
64 }
65
66 }  // namespace sql