OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/trace_event/memory_dump_provider.h" | 10 #include "base/trace_event/memory_dump_provider.h" |
11 #include "base/trace_event/process_memory_dump.h" | 11 #include "base/trace_event/process_memory_dump.h" |
12 #include "base/trace_event/trace_event_argument.h" | |
12 | 13 |
13 // TODO(primiano): in a separate CL rename DeleteTraceLogForTesting into | 14 // TODO(primiano): in a separate CL rename DeleteTraceLogForTesting into |
14 // something like base::internal::TeardownSingletonForTesting so we don't have | 15 // something like base::internal::TeardownSingletonForTesting so we don't have |
15 // to add a new friend to singleton each time. | 16 // to add a new friend to singleton each time. |
16 class DeleteTraceLogForTesting { | 17 class DeleteTraceLogForTesting { |
17 public: | 18 public: |
18 static void Delete() { | 19 static void Delete() { |
19 Singleton< | 20 Singleton< |
20 base::trace_event::MemoryDumpManager, | 21 base::trace_event::MemoryDumpManager, |
21 LeakySingletonTraits<base::trace_event::MemoryDumpManager>>::OnExit(0); | 22 LeakySingletonTraits<base::trace_event::MemoryDumpManager>>::OnExit(0); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 void MemoryDumpManager::BroadcastDumpRequest() { | 93 void MemoryDumpManager::BroadcastDumpRequest() { |
93 NOTREACHED(); // TODO(primiano): implement IPC synchronization. | 94 NOTREACHED(); // TODO(primiano): implement IPC synchronization. |
94 } | 95 } |
95 | 96 |
96 // Creates a dump point for the current process and appends it to the trace. | 97 // Creates a dump point for the current process and appends it to the trace. |
97 void MemoryDumpManager::CreateLocalDumpPoint() { | 98 void MemoryDumpManager::CreateLocalDumpPoint() { |
98 AutoLock lock(lock_); | 99 AutoLock lock(lock_); |
99 // TRACE_EVENT_* macros don't induce scoped_refptr type inference, hence we | 100 // TRACE_EVENT_* macros don't induce scoped_refptr type inference, hence we |
100 // need the base ConvertableToTraceFormat and the upcast below. The | 101 // need the base ConvertableToTraceFormat and the upcast below. The |
101 // alternative would be unnecessarily expensive (double Acquire/Release). | 102 // alternative would be unnecessarily expensive (double Acquire/Release). |
102 scoped_refptr<ConvertableToTraceFormat> pmd(new ProcessMemoryDump()); | 103 scoped_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump()); |
Sami
2015/02/19 12:07:05
Is this cast trickery now obsolete?
Primiano Tucci (use gerrit)
2015/02/19 12:18:12
Oh right (FTR: skyostil@ was referring to line 106
Sami
2015/02/19 16:16:36
Right, and also to the comment above this line :)
| |
103 | 104 |
104 for (MemoryDumpProvider* dump_provider : dump_providers_enabled_) { | 105 for (MemoryDumpProvider* dump_provider : dump_providers_enabled_) { |
105 dump_provider->DumpInto(static_cast<ProcessMemoryDump*>(pmd.get())); | 106 dump_provider->DumpInto(static_cast<ProcessMemoryDump*>(pmd.get())); |
106 } | 107 } |
107 | 108 |
109 scoped_refptr<TracedValue> value(new TracedValue()); | |
110 pmd->AsValueInto(value.get()); | |
108 // TODO(primiano): add the dump point to the trace at this point. | 111 // TODO(primiano): add the dump point to the trace at this point. |
109 } | 112 } |
110 | 113 |
111 void MemoryDumpManager::OnTraceLogEnabled() { | 114 void MemoryDumpManager::OnTraceLogEnabled() { |
112 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter | 115 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter |
113 // to figure out (and cache) which dumpers should be enabled or not. | 116 // to figure out (and cache) which dumpers should be enabled or not. |
114 // For the moment piggy back everything on the generic "memory" category. | 117 // For the moment piggy back everything on the generic "memory" category. |
115 bool enabled; | 118 bool enabled; |
116 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | 119 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); |
117 | 120 |
118 AutoLock lock(lock_); | 121 AutoLock lock(lock_); |
119 if (enabled) { | 122 if (enabled) { |
120 dump_providers_enabled_.assign(dump_providers_registered_.begin(), | 123 dump_providers_enabled_.assign(dump_providers_registered_.begin(), |
121 dump_providers_registered_.end()); | 124 dump_providers_registered_.end()); |
122 } else { | 125 } else { |
123 dump_providers_enabled_.clear(); | 126 dump_providers_enabled_.clear(); |
124 } | 127 } |
125 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 128 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
126 } | 129 } |
127 | 130 |
128 void MemoryDumpManager::OnTraceLogDisabled() { | 131 void MemoryDumpManager::OnTraceLogDisabled() { |
129 AutoLock lock(lock_); | 132 AutoLock lock(lock_); |
130 dump_providers_enabled_.clear(); | 133 dump_providers_enabled_.clear(); |
131 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 134 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
132 } | 135 } |
133 | 136 |
134 } // namespace trace_event | 137 } // namespace trace_event |
135 } // namespace base | 138 } // namespace base |
OLD | NEW |