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 #include "base/trace_event/trace_event_argument.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 namespace trace_event { | 15 namespace trace_event { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | |
18 MemoryDumpManager* g_instance_for_testing = nullptr; | 19 MemoryDumpManager* g_instance_for_testing = nullptr; |
20 const int kTraceEventNumArgs = 1; | |
21 const char* kTraceEventArgNames[] = {"dumps"}; | |
22 const unsigned char kTraceEventArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; | |
23 uint64 g_next_guid = 0; | |
24 | |
25 const char* DumpPointTypeToString(const DumpPointType& type) { | |
26 switch (type) { | |
27 case DumpPointType::TASK_BEGIN: | |
28 return "TASK_BEGIN"; | |
29 case DumpPointType::TASK_END: | |
30 return "TASK_END"; | |
31 case DumpPointType::PERIODIC_INTERVAL: | |
32 return "PERIODIC_INTERVAL"; | |
33 case DumpPointType::EXPLICITLY_TRIGGERED: | |
34 return "EXPLICITLY_TRIGGERED"; | |
35 } | |
36 NOTREACHED(); | |
37 return "UNKNOWN"; | |
38 } | |
19 } | 39 } |
20 | 40 |
21 // TODO(primiano): this should be smarter and should do something similar to | 41 // TODO(primiano): this should be smarter and should do something similar to |
22 // trace event synthetic delays. | 42 // trace event synthetic delays. |
23 const char MemoryDumpManager::kTraceCategory[] = | 43 const char MemoryDumpManager::kTraceCategory[] = |
24 TRACE_DISABLED_BY_DEFAULT("memory-dumps"); | 44 TRACE_DISABLED_BY_DEFAULT("memory-dumps"); |
25 | 45 |
26 // static | 46 // static |
27 MemoryDumpManager* MemoryDumpManager::GetInstance() { | 47 MemoryDumpManager* MemoryDumpManager::GetInstance() { |
28 if (g_instance_for_testing) | 48 if (g_instance_for_testing) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 if (it != dump_providers_enabled_.end()) | 95 if (it != dump_providers_enabled_.end()) |
76 dump_providers_enabled_.erase(it); | 96 dump_providers_enabled_.erase(it); |
77 } | 97 } |
78 | 98 |
79 void MemoryDumpManager::RequestDumpPoint(DumpPointType type) { | 99 void MemoryDumpManager::RequestDumpPoint(DumpPointType type) { |
80 // TODO(primiano): this will have more logic, IPC broadcast & co. | 100 // TODO(primiano): this will have more logic, IPC broadcast & co. |
81 // Bail out immediately if tracing is not enabled at all. | 101 // Bail out immediately if tracing is not enabled at all. |
82 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) | 102 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) |
83 return; | 103 return; |
84 | 104 |
85 CreateLocalDumpPoint(); | 105 CreateLocalDumpPoint(type); |
86 } | 106 } |
87 | 107 |
88 void MemoryDumpManager::BroadcastDumpRequest() { | 108 void MemoryDumpManager::BroadcastDumpRequest() { |
89 NOTREACHED(); // TODO(primiano): implement IPC synchronization. | 109 NOTREACHED(); // TODO(primiano): implement IPC synchronization. |
90 } | 110 } |
91 | 111 |
92 // Creates a dump point for the current process and appends it to the trace. | 112 // Creates a dump point for the current process and appends it to the trace. |
93 void MemoryDumpManager::CreateLocalDumpPoint() { | 113 void MemoryDumpManager::CreateLocalDumpPoint(DumpPointType type) { |
94 AutoLock lock(lock_); | 114 AutoLock lock(lock_); |
95 bool did_any_provider_dump = false; | 115 bool did_any_provider_dump = false; |
96 scoped_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump()); | 116 scoped_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump()); |
97 | 117 |
98 for (auto it = dump_providers_enabled_.begin(); | 118 for (auto it = dump_providers_enabled_.begin(); |
99 it != dump_providers_enabled_.end();) { | 119 it != dump_providers_enabled_.end();) { |
100 MemoryDumpProvider* dump_provider = *it; | 120 MemoryDumpProvider* dump_provider = *it; |
101 if (!dump_provider->DumpInto(pmd.get())) { | 121 if (!dump_provider->DumpInto(pmd.get())) { |
picksi
2015/02/26 17:58:04
Not part of this CL, but it would read easier if y
Primiano Tucci (use gerrit)
2015/03/01 11:32:28
Makes sense. Done
| |
102 LOG(ERROR) << "The memory dumper " << dump_provider->GetFriendlyName() | 122 LOG(ERROR) << "The memory dumper " << dump_provider->GetFriendlyName() |
103 << " failed, possibly due to sandboxing (crbug.com/461788), " | 123 << " failed, possibly due to sandboxing (crbug.com/461788), " |
104 "disabling it for current process. Try restarting chrome " | 124 "disabling it for current process. Try restarting chrome " |
105 "with the --no-sandbox switch."; | 125 "with the --no-sandbox switch."; |
106 it = dump_providers_enabled_.erase(it); | 126 it = dump_providers_enabled_.erase(it); |
107 } else { | 127 } else { |
108 did_any_provider_dump = true; | 128 did_any_provider_dump = true; |
109 ++it; | 129 ++it; |
110 } | 130 } |
111 } | 131 } |
112 | 132 |
113 // Don't create a dump point if all the dumpers failed. | 133 // Don't create a dump point if all the dumpers failed. |
114 if (!did_any_provider_dump) | 134 if (!did_any_provider_dump) |
115 return; | 135 return; |
116 | 136 |
picksi
2015/02/26 17:58:04
[Without thinking too deeply about this...] Does t
Primiano Tucci (use gerrit)
2015/03/01 11:32:28
Done. Turns out I needed to change the g_next_guid
| |
117 scoped_refptr<TracedValue> value(new TracedValue()); | 137 scoped_refptr<ConvertableToTraceFormat> event_value(new TracedValue()); |
118 pmd->AsValueInto(value.get()); | 138 pmd->AsValueInto(static_cast<TracedValue*>(event_value.get())); |
119 // TODO(primiano): add the dump point to the trace at this point. | 139 const char* const event_name = DumpPointTypeToString(type); |
140 const uint64 event_guid = ++g_next_guid; | |
nduca
2015/02/26 17:26:29
i think you need TRACE_ID_DONT_MANGLE -- see trace
Primiano Tucci (use gerrit)
2015/03/01 11:32:28
Right.
FTR: the rationale here is that we don't wa
| |
141 | |
142 TRACE_EVENT_API_ADD_TRACE_EVENT( | |
dsinclair
2015/02/26 17:54:54
I'm not sure if want to leak this out of trace_eve
Primiano Tucci (use gerrit)
2015/03/01 11:32:28
Oh, I though that was meant to be part of the publ
| |
143 TRACE_EVENT_PHASE_MEMORY_DUMP, | |
144 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, event_guid, | |
145 kTraceEventNumArgs, kTraceEventArgNames, kTraceEventArgTypes, NULL, | |
picksi
2015/02/26 17:58:04
It would make this code clearer if the NULL was a
Primiano Tucci (use gerrit)
2015/03/01 11:32:28
Makes sense making it explicit. IIRC in chromium w
| |
146 &event_value, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_MANGLE_ID); | |
120 } | 147 } |
121 | 148 |
122 void MemoryDumpManager::OnTraceLogEnabled() { | 149 void MemoryDumpManager::OnTraceLogEnabled() { |
123 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter | 150 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter |
124 // to figure out (and cache) which dumpers should be enabled or not. | 151 // to figure out (and cache) which dumpers should be enabled or not. |
125 // For the moment piggy back everything on the generic "memory" category. | 152 // For the moment piggy back everything on the generic "memory" category. |
126 bool enabled; | 153 bool enabled; |
127 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | 154 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); |
128 | 155 |
129 AutoLock lock(lock_); | 156 AutoLock lock(lock_); |
130 if (enabled) { | 157 if (enabled) { |
131 dump_providers_enabled_.assign(dump_providers_registered_.begin(), | 158 dump_providers_enabled_.assign(dump_providers_registered_.begin(), |
132 dump_providers_registered_.end()); | 159 dump_providers_registered_.end()); |
133 } else { | 160 } else { |
134 dump_providers_enabled_.clear(); | 161 dump_providers_enabled_.clear(); |
135 } | 162 } |
136 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 163 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
137 } | 164 } |
138 | 165 |
139 void MemoryDumpManager::OnTraceLogDisabled() { | 166 void MemoryDumpManager::OnTraceLogDisabled() { |
140 AutoLock lock(lock_); | 167 AutoLock lock(lock_); |
141 dump_providers_enabled_.clear(); | 168 dump_providers_enabled_.clear(); |
142 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 169 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
143 } | 170 } |
144 | 171 |
145 } // namespace trace_event | 172 } // namespace trace_event |
146 } // namespace base | 173 } // namespace base |
OLD | NEW |