Skip to content

Commit

Permalink
[tracing] Remove MemoryAllocatorDump::process_memory_dump
Browse files Browse the repository at this point in the history
This function should not be exist as it is casusing misleading use of
this function. The MAD is passed around to objects to dump memory
instead of PMD being passed around like the case of Sync. The
ReportMemoryUsage method should not be changing the PMD object when it
is passed only MAD.

BUG=

Review-Url: https://codereview.chromium.org/2545173002
Cr-Commit-Position: refs/heads/master@{#437328}
  • Loading branch information
ssiddhartha authored and Commit bot committed Dec 8, 2016
1 parent db7c3b1 commit 1f4e536
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
5 changes: 0 additions & 5 deletions base/trace_event/memory_allocator_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class BASE_EXPORT MemoryAllocatorDump {
// Called at trace generation time to populate the TracedValue.
void AsValueInto(TracedValue* value) const;

// Get the ProcessMemoryDump instance that owns this.
ProcessMemoryDump* process_memory_dump() const {
return process_memory_dump_;
}

// Use enum Flags to set values.
void set_flags(int flags) { flags_ |= flags; }
void clear_flags(int flags) { flags_ &= ~flags; }
Expand Down
3 changes: 1 addition & 2 deletions components/sync/syncable/directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,7 @@ void Directory::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) {
if (store_) {
std::string dump_name =
base::StringPrintf("%s/store", dump_name_base.c_str());
auto* dump = pmd->CreateAllocatorDump(dump_name);
store_->ReportMemoryUsage(dump);
store_->ReportMemoryUsage(pmd, dump_name);
}
}

Expand Down
5 changes: 3 additions & 2 deletions components/sync/syncable/directory_backing_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1718,8 +1718,9 @@ bool DirectoryBackingStore::GetDatabasePageSize(int* page_size) {
}

bool DirectoryBackingStore::ReportMemoryUsage(
base::trace_event::MemoryAllocatorDump* mad) {
return db_ && db_->ReportMemoryUsage(mad);
base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name) {
return db_ && db_->ReportMemoryUsage(pmd, dump_name);
}

bool DirectoryBackingStore::UpdatePageSizeIfNecessary() {
Expand Down
5 changes: 3 additions & 2 deletions components/sync/syncable/directory_backing_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace base {
namespace trace_event {
class MemoryAllocatorDump;
class ProcessMemoryDump;
}
}

Expand Down Expand Up @@ -104,7 +104,8 @@ class DirectoryBackingStore : public base::NonThreadSafe {
// Returns true on success, false on error.
bool GetDatabasePageSize(int* page_size);

bool ReportMemoryUsage(base::trace_event::MemoryAllocatorDump* mad);
bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name);

protected:
// For test classes.
Expand Down
6 changes: 3 additions & 3 deletions sql/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2044,10 +2044,10 @@ bool Connection::IntegrityCheckHelper(
return ret;
}

bool Connection::ReportMemoryUsage(
base::trace_event::MemoryAllocatorDump* mad) {
bool Connection::ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name) {
return memory_dump_provider_ &&
memory_dump_provider_->ReportMemoryUsage(mad);
memory_dump_provider_->ReportMemoryUsage(pmd, dump_name);
}

base::TimeTicks TimeSource::Now() {
Expand Down
7 changes: 4 additions & 3 deletions sql/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace base {
class FilePath;
class HistogramBase;
namespace trace_event {
class MemoryAllocatorDump;
class ProcessMemoryDump;
}
}

Expand Down Expand Up @@ -254,8 +254,9 @@ class SQL_EXPORT Connection {
// get diagnostic information about the database.
std::string GetDiagnosticInfo(int extended_error, Statement* statement);

// Reports memory usage into provided memory dump.
bool ReportMemoryUsage(base::trace_event::MemoryAllocatorDump* mad);
// Reports memory usage into provided memory dump with the given name.
bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name);

// Initialization ------------------------------------------------------------

Expand Down
9 changes: 5 additions & 4 deletions sql/connection_memory_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ bool ConnectionMemoryDumpProvider::OnMemoryDump(
}

bool ConnectionMemoryDumpProvider::ReportMemoryUsage(
base::trace_event::MemoryAllocatorDump* mad) {
base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name) {
int cache_size = 0;
int schema_size = 0;
int statement_size = 0;
if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) {
if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size))
return false;
}

auto* mad = pmd->CreateAllocatorDump(dump_name);
mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
cache_size + schema_size + statement_size);
mad->process_memory_dump()->AddSuballocation(mad->guid(), FormatDumpName());
pmd->AddSuballocation(mad->guid(), FormatDumpName());

return true;
}
Expand Down
12 changes: 9 additions & 3 deletions sql/connection_memory_dump_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@

#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_provider.h"

struct sqlite3;

namespace base {
namespace trace_event {
class ProcessMemoryDump;
}
}

namespace sql {

class ConnectionMemoryDumpProvider
Expand All @@ -29,9 +34,10 @@ class ConnectionMemoryDumpProvider
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) override;

// Reports memory usage into provided memory dump.
// Reports memory usage into provided memory dump with the given |dump_name|.
// Called by sql::Connection when its owner asks it to report memory usage.
bool ReportMemoryUsage(base::trace_event::MemoryAllocatorDump* mad);
bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
const std::string& dump_name);

private:
bool GetDbMemoryUsage(int* cache_size,
Expand Down

0 comments on commit 1f4e536

Please sign in to comment.