summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorprimiano <primiano@chromium.org>2015-04-20 23:09:08 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-21 06:09:12 +0000
commit2de25ee6691cef57d0f30e75aa4f88b84a34c040 (patch)
treef6ca11e2db88ab864d3d8f0f3976ad21b02b7017 /base
parent8d0d95b2eb92660b18b9804f3897c5fe74326006 (diff)
downloadchromium_src-2de25ee6691cef57d0f30e75aa4f88b84a34c040.zip
chromium_src-2de25ee6691cef57d0f30e75aa4f88b84a34c040.tar.gz
chromium_src-2de25ee6691cef57d0f30e75aa4f88b84a34c040.tar.bz2
[tracing] Introduce MemoryDumpSessionState
MemoryDumpSessionState is a container class to hold objects that need to be shared between all the ProcessMemoryDumps for all the lifetime of a tracing session. A concrete use case is going to be represented by the dictionary of allocator attributes types, that will be dumped once by the MemoryDumpProviders into the MemoryDumpSessionState when the trace starts and will be accessed when generating the final trace data. BUG=466141 Review URL: https://codereview.chromium.org/1093953002 Cr-Commit-Position: refs/heads/master@{#325987}
Diffstat (limited to 'base')
-rw-r--r--base/trace_event/BUILD.gn2
-rw-r--r--base/trace_event/memory_allocator_dump_unittest.cc5
-rw-r--r--base/trace_event/memory_dump_manager.cc17
-rw-r--r--base/trace_event/memory_dump_manager.h11
-rw-r--r--base/trace_event/memory_dump_session_state.cc17
-rw-r--r--base/trace_event/memory_dump_session_state.h31
-rw-r--r--base/trace_event/process_memory_dump.cc7
-rw-r--r--base/trace_event/process_memory_dump.h14
-rw-r--r--base/trace_event/process_memory_maps_dump_provider_unittest.cc6
-rw-r--r--base/trace_event/process_memory_totals_dump_provider_unittest.cc4
-rw-r--r--base/trace_event/trace_event.gypi2
11 files changed, 98 insertions, 18 deletions
diff --git a/base/trace_event/BUILD.gn b/base/trace_event/BUILD.gn
index 89364b2..8512521 100644
--- a/base/trace_event/BUILD.gn
+++ b/base/trace_event/BUILD.gn
@@ -14,6 +14,8 @@ source_set("trace_event") {
"memory_dump_provider.cc",
"memory_dump_provider.h",
"memory_dump_request_args.h",
+ "memory_dump_session_state.cc",
+ "memory_dump_session_state.h",
"process_memory_dump.cc",
"process_memory_dump.h",
"process_memory_maps.cc",
diff --git a/base/trace_event/memory_allocator_dump_unittest.cc b/base/trace_event/memory_allocator_dump_unittest.cc
index 8c14560..a0b56f5 100644
--- a/base/trace_event/memory_allocator_dump_unittest.cc
+++ b/base/trace_event/memory_allocator_dump_unittest.cc
@@ -5,6 +5,7 @@
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_provider.h"
+#include "base/trace_event/memory_dump_session_state.h"
#include "base/trace_event/process_memory_dump.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -45,7 +46,7 @@ class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
FakeMemoryAllocatorDumpProvider fmadp;
- ProcessMemoryDump pmd;
+ ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
fmadp.DumpInto(&pmd);
@@ -84,7 +85,7 @@ TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
#if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
FakeMemoryAllocatorDumpProvider fmadp;
- ProcessMemoryDump pmd;
+ ProcessMemoryDump pmd(nullptr /* session_state */);
pmd.CreateAllocatorDump("dump_1");
pmd.CreateAllocatorDump("dump_2");
ASSERT_DEATH(pmd.CreateAllocatorDump("dump_1"), "");
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index dd6164b..c593b80 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -9,6 +9,7 @@
#include "base/atomic_sequence_num.h"
#include "base/compiler_specific.h"
#include "base/trace_event/memory_dump_provider.h"
+#include "base/trace_event/memory_dump_session_state.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event_argument.h"
@@ -49,9 +50,12 @@ const char* MemoryDumpTypeToString(const MemoryDumpType& dump_type) {
class ProcessMemoryDumpHolder
: public RefCountedThreadSafe<ProcessMemoryDumpHolder> {
public:
- ProcessMemoryDumpHolder(MemoryDumpRequestArgs req_args,
- MemoryDumpCallback callback)
- : req_args(req_args),
+ ProcessMemoryDumpHolder(
+ MemoryDumpRequestArgs req_args,
+ const scoped_refptr<MemoryDumpSessionState>& session_state,
+ MemoryDumpCallback callback)
+ : process_memory_dump(session_state),
+ req_args(req_args),
callback(callback),
task_runner(MessageLoop::current()->task_runner()),
num_pending_async_requests(0) {}
@@ -207,7 +211,7 @@ void MemoryDumpManager::RequestGlobalDump(MemoryDumpType dump_type) {
void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args,
const MemoryDumpCallback& callback) {
scoped_refptr<ProcessMemoryDumpHolder> pmd_holder(
- new ProcessMemoryDumpHolder(args, callback));
+ new ProcessMemoryDumpHolder(args, session_state_, callback));
ProcessMemoryDump* pmd = &pmd_holder->process_memory_dump;
bool did_any_provider_dump = false;
@@ -305,10 +309,10 @@ void MemoryDumpManager::OnTraceLogEnabled() {
TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled);
AutoLock lock(lock_);
+ dump_providers_enabled_.clear();
if (enabled) {
+ session_state_ = new MemoryDumpSessionState();
dump_providers_enabled_ = dump_providers_registered_;
- } else {
- dump_providers_enabled_.clear();
}
subtle::NoBarrier_Store(&memory_tracing_enabled_, 1);
}
@@ -317,6 +321,7 @@ void MemoryDumpManager::OnTraceLogDisabled() {
AutoLock lock(lock_);
dump_providers_enabled_.clear();
subtle::NoBarrier_Store(&memory_tracing_enabled_, 0);
+ session_state_ = nullptr;
}
} // namespace trace_event
diff --git a/base/trace_event/memory_dump_manager.h b/base/trace_event/memory_dump_manager.h
index a311d7c..6fc2341 100644
--- a/base/trace_event/memory_dump_manager.h
+++ b/base/trace_event/memory_dump_manager.h
@@ -25,6 +25,7 @@ class ProcessMemoryDumpHolder;
class MemoryDumpManagerDelegate;
class MemoryDumpProvider;
class ProcessMemoryDump;
+class MemoryDumpSessionState;
// This is the interface exposed to the rest of the codebase to deal with
// memory tracing. The main entry point for clients is represented by
@@ -69,6 +70,13 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
return dump_provider_currently_active_;
}
+ // Returns the MemoryDumpSessionState object, which is shared by all the
+ // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing
+ // session lifetime.
+ const scoped_refptr<MemoryDumpSessionState>& session_state() const {
+ return session_state_;
+ }
+
private:
friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance.
friend struct DefaultSingletonTraits<MemoryDumpManager>;
@@ -99,6 +107,9 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
// TODO(primiano): this is required only until crbug.com/466121 gets fixed.
MemoryDumpProvider* dump_provider_currently_active_; // Not owned.
+ // Shared among all the PMDs to keep state scoped to the tracing session.
+ scoped_refptr<MemoryDumpSessionState> session_state_;
+
MemoryDumpManagerDelegate* delegate_; // Not owned.
// Protects from concurrent accesses to the |dump_providers_*| and |delegate_|
diff --git a/base/trace_event/memory_dump_session_state.cc b/base/trace_event/memory_dump_session_state.cc
new file mode 100644
index 0000000..433ac14
--- /dev/null
+++ b/base/trace_event/memory_dump_session_state.cc
@@ -0,0 +1,17 @@
+// 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/memory_dump_session_state.h"
+
+namespace base {
+namespace trace_event {
+
+MemoryDumpSessionState::MemoryDumpSessionState() {
+}
+
+MemoryDumpSessionState::~MemoryDumpSessionState() {
+}
+
+} // namespace trace_event
+} // namespace base
diff --git a/base/trace_event/memory_dump_session_state.h b/base/trace_event/memory_dump_session_state.h
new file mode 100644
index 0000000..0e5e24e
--- /dev/null
+++ b/base/trace_event/memory_dump_session_state.h
@@ -0,0 +1,31 @@
+// 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 BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
+#define BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
+
+#include <string>
+
+#include "base/base_export.h"
+#include "base/memory/ref_counted.h"
+#include "base/trace_event/memory_allocator_attributes_type_info.h"
+
+namespace base {
+namespace trace_event {
+
+class BASE_EXPORT MemoryDumpSessionState
+ : public RefCountedThreadSafe<MemoryDumpSessionState> {
+ public:
+ MemoryDumpSessionState();
+ MemoryAllocatorAttributesTypeInfo allocators_attributes_types;
+
+ private:
+ friend class RefCountedThreadSafe<MemoryDumpSessionState>;
+ ~MemoryDumpSessionState();
+};
+
+} // namespace trace_event
+} // namespace base
+
+#endif // BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
diff --git a/base/trace_event/process_memory_dump.cc b/base/trace_event/process_memory_dump.cc
index bbca36c..d646ef3 100644
--- a/base/trace_event/process_memory_dump.cc
+++ b/base/trace_event/process_memory_dump.cc
@@ -10,8 +10,11 @@
namespace base {
namespace trace_event {
-ProcessMemoryDump::ProcessMemoryDump()
- : has_process_totals_(false), has_process_mmaps_(false) {
+ProcessMemoryDump::ProcessMemoryDump(
+ const scoped_refptr<MemoryDumpSessionState>& session_state)
+ : has_process_totals_(false),
+ has_process_mmaps_(false),
+ session_state_(session_state) {
}
ProcessMemoryDump::~ProcessMemoryDump() {
diff --git a/base/trace_event/process_memory_dump.h b/base/trace_event/process_memory_dump.h
index b59ae67..3d66f78 100644
--- a/base/trace_event/process_memory_dump.h
+++ b/base/trace_event/process_memory_dump.h
@@ -8,8 +8,10 @@
#include "base/base_export.h"
#include "base/containers/hash_tables.h"
#include "base/containers/small_map.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/trace_event/memory_allocator_dump.h"
+#include "base/trace_event/memory_dump_session_state.h"
#include "base/trace_event/process_memory_maps.h"
#include "base/trace_event/process_memory_totals.h"
@@ -18,6 +20,7 @@ namespace trace_event {
class ConvertableToTraceFormat;
class MemoryDumpManager;
+class MemoryDumpSessionState;
// ProcessMemoryDump is as a strongly typed container which enforces the data
// model for each memory dump and holds the dumps produced by the
@@ -30,7 +33,7 @@ class BASE_EXPORT ProcessMemoryDump {
using AllocatorDumpsMap =
SmallMap<hash_map<std::string, MemoryAllocatorDump*>>;
- ProcessMemoryDump();
+ ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state);
~ProcessMemoryDump();
// Called at trace generation time to populate the TracedValue.
@@ -59,6 +62,10 @@ class BASE_EXPORT ProcessMemoryDump {
// Returns the map of the MemoryAllocatorDumps added to this dump.
const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; }
+ const scoped_refptr<MemoryDumpSessionState>& session_state() const {
+ return session_state_;
+ }
+
private:
ProcessMemoryTotals process_totals_;
bool has_process_totals_;
@@ -66,13 +73,14 @@ class BASE_EXPORT ProcessMemoryDump {
ProcessMemoryMaps process_mmaps_;
bool has_process_mmaps_;
- // A maps of "allocator_name" -> MemoryAllocatorDump populated by
- // allocator dump providers.
AllocatorDumpsMap allocator_dumps_;
// ProcessMemoryDump handles the memory ownership of all its belongings.
ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_;
+ // State shared among all PMDs instances created in a given trace session.
+ scoped_refptr<MemoryDumpSessionState> session_state_;
+
DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump);
};
diff --git a/base/trace_event/process_memory_maps_dump_provider_unittest.cc b/base/trace_event/process_memory_maps_dump_provider_unittest.cc
index 0bf81ac..2ce2504 100644
--- a/base/trace_event/process_memory_maps_dump_provider_unittest.cc
+++ b/base/trace_event/process_memory_maps_dump_provider_unittest.cc
@@ -114,7 +114,7 @@ TEST(ProcessMemoryMapsDumpProviderTest, ParseProcSmaps) {
auto pmmdp = ProcessMemoryMapsDumpProvider::GetInstance();
// Emulate a non-existent /proc/self/smaps.
- ProcessMemoryDump pmd_invalid;
+ ProcessMemoryDump pmd_invalid(nullptr /* session_state */);
std::ifstream non_existent_file("/tmp/does-not-exist");
ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = &non_existent_file;
CHECK_EQ(false, non_existent_file.good());
@@ -129,7 +129,7 @@ TEST(ProcessMemoryMapsDumpProviderTest, ParseProcSmaps) {
ASSERT_FALSE(pmd_invalid.has_process_mmaps());
// Parse the 1st smaps file.
- ProcessMemoryDump pmd_1;
+ ProcessMemoryDump pmd_1(nullptr /* session_state */);
std::istringstream test_smaps_1(kTestSmaps1);
ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = &test_smaps_1;
pmmdp->DumpInto(&pmd_1);
@@ -154,7 +154,7 @@ TEST(ProcessMemoryMapsDumpProviderTest, ParseProcSmaps) {
EXPECT_EQ((60 + 8) * 1024UL, regions_1[1].byte_stats_private_resident);
// Parse the 2nd smaps file.
- ProcessMemoryDump pmd_2;
+ ProcessMemoryDump pmd_2(nullptr /* session_state */);
std::istringstream test_smaps_2(kTestSmaps2);
ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = &test_smaps_2;
pmmdp->DumpInto(&pmd_2);
diff --git a/base/trace_event/process_memory_totals_dump_provider_unittest.cc b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
index 372db63..ffaf177 100644
--- a/base/trace_event/process_memory_totals_dump_provider_unittest.cc
+++ b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
@@ -13,8 +13,8 @@ namespace trace_event {
TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) {
auto pmtdp = ProcessMemoryTotalsDumpProvider::GetInstance();
- scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump());
- scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump());
+ scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump(nullptr));
+ scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump(nullptr));
ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 1024;
pmtdp->DumpInto(pmd_before.get());
diff --git a/base/trace_event/trace_event.gypi b/base/trace_event/trace_event.gypi
index c3ddbfc..5279437 100644
--- a/base/trace_event/trace_event.gypi
+++ b/base/trace_event/trace_event.gypi
@@ -14,6 +14,8 @@
'trace_event/memory_dump_provider.cc',
'trace_event/memory_dump_provider.h',
'trace_event/memory_dump_request_args.h',
+ 'trace_event/memory_dump_session_state.cc',
+ 'trace_event/memory_dump_session_state.h',
'trace_event/process_memory_dump.cc',
'trace_event/process_memory_dump.h',
'trace_event/process_memory_maps.cc',