| OLD | NEW | 
|    1 // Copyright 2016 The Chromium Authors. All rights reserved. |    1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "components/leveldb/leveldb_database_impl.h" |    5 #include "components/leveldb/leveldb_database_impl.h" | 
|    6  |    6  | 
|    7 #include <inttypes.h> |    7 #include <inttypes.h> | 
|    8 #include <map> |    8 #include <map> | 
|    9 #include <string> |    9 #include <string> | 
|   10 #include <utility> |   10 #include <utility> | 
|   11  |   11  | 
|   12 #include "base/optional.h" |   12 #include "base/optional.h" | 
|   13 #include "base/rand_util.h" |   13 #include "base/rand_util.h" | 
|   14 #include "base/strings/string_number_conversions.h" |   14 #include "base/strings/string_number_conversions.h" | 
|   15 #include "base/strings/stringprintf.h" |   15 #include "base/strings/stringprintf.h" | 
|   16 #include "base/trace_event/memory_dump_manager.h" |   16 #include "base/trace_event/memory_dump_manager.h" | 
|   17 #include "components/leveldb/env_mojo.h" |   17 #include "components/leveldb/env_mojo.h" | 
|   18 #include "components/leveldb/public/cpp/util.h" |   18 #include "components/leveldb/public/cpp/util.h" | 
 |   19 #include "third_party/leveldatabase/env_chromium.h" | 
|   19 #include "third_party/leveldatabase/src/include/leveldb/db.h" |   20 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 
|   20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |   21 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 
|   21  |   22  | 
|   22 namespace leveldb { |   23 namespace leveldb { | 
|   23 namespace { |   24 namespace { | 
|   24  |   25  | 
|   25 template <typename FunctionType> |   26 template <typename FunctionType> | 
|   26 leveldb::Status ForEachWithPrefix(leveldb::DB* db, |   27 leveldb::Status ForEachWithPrefix(leveldb::DB* db, | 
|   27                                   const leveldb::Slice& key_prefix, |   28                                   const leveldb::Slice& key_prefix, | 
|   28                                   FunctionType function) { |   29                                   FunctionType function) { | 
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  301   mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |  302   mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 
|  302                  base::trace_event::MemoryAllocatorDump::kUnitsBytes, |  303                  base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 
|  303                  memory_usage); |  304                  memory_usage); | 
|  304   if (cache_) { |  305   if (cache_) { | 
|  305     auto* cache_mad = pmd->CreateAllocatorDump(name + "/block_cache"); |  306     auto* cache_mad = pmd->CreateAllocatorDump(name + "/block_cache"); | 
|  306     cache_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |  307     cache_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 
|  307                          base::trace_event::MemoryAllocatorDump::kUnitsBytes, |  308                          base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 
|  308                          cache_->TotalCharge()); |  309                          cache_->TotalCharge()); | 
|  309   } |  310   } | 
|  310  |  311  | 
|  311   const char* system_allocator_name = |  312   // All leveldb databases are already dumped by leveldb_env::DBTracker. Add | 
|  312       base::trace_event::MemoryDumpManager::GetInstance() |  313   // an edge to avoid double counting. | 
|  313           ->system_allocator_pool_name(); |  314   pmd->AddSuballocation(mad->guid(), | 
|  314   if (system_allocator_name) |  315                         leveldb_env::DBTracker::GetMemoryDumpName(db_.get())); | 
|  315     pmd->AddSuballocation(mad->guid(), system_allocator_name); |  | 
|  316  |  316  | 
|  317   if (memory_dump_id_) { |  317   if (memory_dump_id_) { | 
|  318     auto* global_dump = pmd->CreateSharedGlobalAllocatorDump(*memory_dump_id_); |  318     auto* global_dump = pmd->CreateSharedGlobalAllocatorDump(*memory_dump_id_); | 
|  319     pmd->AddOwnershipEdge(global_dump->guid(), mad->guid()); |  319     pmd->AddOwnershipEdge(global_dump->guid(), mad->guid()); | 
|  320     // Add size to global dump to propagate the size of the database to the |  320     // Add size to global dump to propagate the size of the database to the | 
|  321     // client's dump. |  321     // client's dump. | 
|  322     global_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |  322     global_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 
|  323                            base::trace_event::MemoryAllocatorDump::kUnitsBytes, |  323                            base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 
|  324                            memory_usage); |  324                            memory_usage); | 
|  325   } |  325   } | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  344     const leveldb::Slice& key_prefix, |  344     const leveldb::Slice& key_prefix, | 
|  345     leveldb::WriteBatch* batch) { |  345     leveldb::WriteBatch* batch) { | 
|  346   leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, |  346   leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, | 
|  347       [batch](const leveldb::Slice& key, const leveldb::Slice& value) { |  347       [batch](const leveldb::Slice& key, const leveldb::Slice& value) { | 
|  348         batch->Delete(key); |  348         batch->Delete(key); | 
|  349       }); |  349       }); | 
|  350   return status; |  350   return status; | 
|  351 } |  351 } | 
|  352  |  352  | 
|  353 }  // namespace leveldb |  353 }  // namespace leveldb | 
| OLD | NEW |