| Index: base/trace_event/process_memory_totals_dump_provider.cc
|
| diff --git a/base/trace_event/process_memory_totals_dump_provider.cc b/base/trace_event/process_memory_totals_dump_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cda0ff113331ce6066a35bb40f21f20e9e96e999
|
| --- /dev/null
|
| +++ b/base/trace_event/process_memory_totals_dump_provider.cc
|
| @@ -0,0 +1,53 @@
|
| +// 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 "base/trace_event/process_memory_totals_dump_provider.h"
|
| +
|
| +#include "base/process/process_metrics.h"
|
| +#include "base/trace_event/process_memory_dump.h"
|
| +#include "base/trace_event/process_memory_totals.h"
|
| +
|
| +namespace base {
|
| +namespace trace_event {
|
| +
|
| +// static
|
| +uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0;
|
| +
|
| +namespace {
|
| +ProcessMetrics* CreateProcessMetricsForCurrentProcess() {
|
| +#if !defined(OS_MACOSX) || defined(OS_IOS)
|
| + return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle());
|
| +#else
|
| + return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL);
|
| +#endif
|
| +}
|
| +} // namespace
|
| +
|
| +// static
|
| +ProcessMemoryTotalsDumpProvider*
|
| +ProcessMemoryTotalsDumpProvider::GetInstance() {
|
| + return Singleton<
|
| + ProcessMemoryTotalsDumpProvider,
|
| + LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get();
|
| +}
|
| +
|
| +ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider()
|
| + : process_metrics_(CreateProcessMetricsForCurrentProcess()) {
|
| +}
|
| +
|
| +ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
|
| +}
|
| +
|
| +// Called at trace dump point time. Creates a snapshot the memory counters for
|
| +// the current process.
|
| +void ProcessMemoryTotalsDumpProvider::DumpInto(ProcessMemoryDump* pmd) {
|
| + const uint64 rss_bytes = rss_bytes_for_testing
|
| + ? rss_bytes_for_testing
|
| + : process_metrics_->GetWorkingSetSize();
|
| + pmd->process_totals()->set_resident_set_bytes(rss_bytes);
|
| + pmd->set_has_process_totals();
|
| +}
|
| +
|
| +} // namespace trace_event
|
| +} // namespace base
|
|
|