OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/system/handle_table.h" | 5 #include "mojo/edk/system/handle_table.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/trace_event/memory_dump_manager.h" | |
12 | |
11 namespace mojo { | 13 namespace mojo { |
12 namespace edk { | 14 namespace edk { |
13 | 15 |
14 HandleTable::HandleTable() {} | 16 namespace { |
15 | 17 |
16 HandleTable::~HandleTable() {} | 18 const char* GetNameForDispatcherType(Dispatcher::Type type) { |
19 switch (type) { | |
20 case Dispatcher::Type::UNKNOWN: | |
21 return "unknown"; | |
22 case Dispatcher::Type::MESSAGE_PIPE: | |
23 return "message_pipe"; | |
24 case Dispatcher::Type::DATA_PIPE_PRODUCER: | |
25 return "data_pipe_producer"; | |
26 case Dispatcher::Type::DATA_PIPE_CONSUMER: | |
27 return "data_pipe_consumer"; | |
28 case Dispatcher::Type::SHARED_BUFFER: | |
29 return "shared_buffer"; | |
30 case Dispatcher::Type::WATCHER: | |
31 return "watcher"; | |
32 case Dispatcher::Type::PLATFORM_HANDLE: | |
33 return "platform_handle"; | |
34 } | |
35 return "unknown"; | |
ssid
2017/06/07 00:30:28
Can you add NOTREACHED() here?
Creating 2 memory d
| |
36 } | |
37 | |
38 const char* kDumpProviderName = "MojoHandleTable"; | |
ssid
2017/06/07 00:30:28
remove this constant here and just inline. Will be
| |
39 | |
40 } // namespace | |
41 | |
42 HandleTable::HandleTable() { | |
43 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
44 this, kDumpProviderName, nullptr); | |
45 } | |
46 | |
47 HandleTable::~HandleTable() { | |
48 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
ssid
2017/06/07 00:30:28
Why are you registering the dump provider again. T
| |
49 this, kDumpProviderName, nullptr); | |
50 } | |
51 | |
52 base::Lock& HandleTable::GetLock() { | |
53 return lock_; | |
54 } | |
17 | 55 |
18 MojoHandle HandleTable::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { | 56 MojoHandle HandleTable::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { |
19 // Oops, we're out of handles. | 57 // Oops, we're out of handles. |
20 if (next_available_handle_ == MOJO_HANDLE_INVALID) | 58 if (next_available_handle_ == MOJO_HANDLE_INVALID) |
21 return MOJO_HANDLE_INVALID; | 59 return MOJO_HANDLE_INVALID; |
22 | 60 |
23 MojoHandle handle = next_available_handle_++; | 61 MojoHandle handle = next_available_handle_++; |
24 auto result = | 62 auto result = |
25 handles_.insert(std::make_pair(handle, Entry(std::move(dispatcher)))); | 63 handles_.insert(std::make_pair(handle, Entry(std::move(dispatcher)))); |
26 DCHECK(result.second); | 64 DCHECK(result.second); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 dispatcher.dispatcher->CancelTransit(); | 153 dispatcher.dispatcher->CancelTransit(); |
116 } | 154 } |
117 } | 155 } |
118 | 156 |
119 void HandleTable::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { | 157 void HandleTable::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { |
120 handles->clear(); | 158 handles->clear(); |
121 for (const auto& entry : handles_) | 159 for (const auto& entry : handles_) |
122 handles->push_back(entry.first); | 160 handles->push_back(entry.first); |
123 } | 161 } |
124 | 162 |
163 // MemoryDumpProvider implementation. | |
164 bool HandleTable::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
ssid
2017/06/07 00:30:28
Is it possible to add test for this?
If this is to
| |
165 base::trace_event::ProcessMemoryDump* pmd) { | |
166 // Create entries for all relevant dispatcher types to ensure they are present | |
167 // in the final dump. | |
168 std::map<Dispatcher::Type, int> handle_count; | |
169 handle_count[Dispatcher::Type::MESSAGE_PIPE]; | |
170 handle_count[Dispatcher::Type::DATA_PIPE_PRODUCER]; | |
171 handle_count[Dispatcher::Type::DATA_PIPE_CONSUMER]; | |
172 handle_count[Dispatcher::Type::SHARED_BUFFER]; | |
173 handle_count[Dispatcher::Type::WATCHER]; | |
174 handle_count[Dispatcher::Type::PLATFORM_HANDLE]; | |
ssid
2017/06/07 00:30:28
These lines are not needed.
Just doing ++handle_co
| |
175 | |
176 // Count the number of each dispatcher type. | |
177 { | |
178 base::AutoLock lock(GetLock()); | |
179 for (const auto& entry : handles_) { | |
180 ++handle_count[entry.second.dispatcher->GetType()]; | |
181 } | |
182 } | |
183 | |
184 base::trace_event::MemoryAllocatorDump* outer_dump = | |
185 pmd->CreateAllocatorDump("mojo"); | |
186 for (const auto& entry : handle_count) { | |
187 outer_dump->AddScalar(GetNameForDispatcherType(entry.first), | |
ssid
2017/06/07 00:30:28
This should be "mojo/unknown" and so on. Else no s
ssid
2017/06/07 00:31:16
just noticed that this is fixed. please ignore.
| |
188 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | |
189 entry.second); | |
190 } | |
191 | |
192 return true; | |
193 } | |
194 | |
125 HandleTable::Entry::Entry() {} | 195 HandleTable::Entry::Entry() {} |
126 | 196 |
127 HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) | 197 HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) |
128 : dispatcher(std::move(dispatcher)) {} | 198 : dispatcher(std::move(dispatcher)) {} |
129 | 199 |
130 HandleTable::Entry::Entry(const Entry& other) = default; | 200 HandleTable::Entry::Entry(const Entry& other) = default; |
131 | 201 |
132 HandleTable::Entry::~Entry() {} | 202 HandleTable::Entry::~Entry() {} |
133 | 203 |
134 } // namespace edk | 204 } // namespace edk |
135 } // namespace mojo | 205 } // namespace mojo |
OLD | NEW |