Index: mojo/edk/system/handle_table.cc |
diff --git a/mojo/edk/system/handle_table.cc b/mojo/edk/system/handle_table.cc |
index b570793dbe0f4286dc204f76402fa29665c40b91..03b6d0b0b527ec591e5693304b72d2b4a641f05b 100644 |
--- a/mojo/edk/system/handle_table.cc |
+++ b/mojo/edk/system/handle_table.cc |
@@ -8,12 +8,50 @@ |
#include <limits> |
+#include "base/trace_event/memory_dump_manager.h" |
+ |
namespace mojo { |
namespace edk { |
-HandleTable::HandleTable() {} |
+namespace { |
+ |
+const char* GetNameForDispatcherType(Dispatcher::Type type) { |
+ switch (type) { |
+ case Dispatcher::Type::UNKNOWN: |
+ return "unknown"; |
+ case Dispatcher::Type::MESSAGE_PIPE: |
+ return "message_pipe"; |
+ case Dispatcher::Type::DATA_PIPE_PRODUCER: |
+ return "data_pipe_producer"; |
+ case Dispatcher::Type::DATA_PIPE_CONSUMER: |
+ return "data_pipe_consumer"; |
+ case Dispatcher::Type::SHARED_BUFFER: |
+ return "shared_buffer"; |
+ case Dispatcher::Type::WATCHER: |
+ return "watcher"; |
+ case Dispatcher::Type::PLATFORM_HANDLE: |
+ return "platform_handle"; |
+ } |
+ return "unknown"; |
ssid
2017/06/07 00:30:28
Can you add NOTREACHED() here?
Creating 2 memory d
|
+} |
-HandleTable::~HandleTable() {} |
+const char* kDumpProviderName = "MojoHandleTable"; |
ssid
2017/06/07 00:30:28
remove this constant here and just inline. Will be
|
+ |
+} // namespace |
+ |
+HandleTable::HandleTable() { |
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
+ this, kDumpProviderName, nullptr); |
+} |
+ |
+HandleTable::~HandleTable() { |
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
ssid
2017/06/07 00:30:28
Why are you registering the dump provider again. T
|
+ this, kDumpProviderName, nullptr); |
+} |
+ |
+base::Lock& HandleTable::GetLock() { |
+ return lock_; |
+} |
MojoHandle HandleTable::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { |
// Oops, we're out of handles. |
@@ -122,6 +160,38 @@ void HandleTable::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { |
handles->push_back(entry.first); |
} |
+// MemoryDumpProvider implementation. |
+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
|
+ base::trace_event::ProcessMemoryDump* pmd) { |
+ // Create entries for all relevant dispatcher types to ensure they are present |
+ // in the final dump. |
+ std::map<Dispatcher::Type, int> handle_count; |
+ handle_count[Dispatcher::Type::MESSAGE_PIPE]; |
+ handle_count[Dispatcher::Type::DATA_PIPE_PRODUCER]; |
+ handle_count[Dispatcher::Type::DATA_PIPE_CONSUMER]; |
+ handle_count[Dispatcher::Type::SHARED_BUFFER]; |
+ handle_count[Dispatcher::Type::WATCHER]; |
+ handle_count[Dispatcher::Type::PLATFORM_HANDLE]; |
ssid
2017/06/07 00:30:28
These lines are not needed.
Just doing ++handle_co
|
+ |
+ // Count the number of each dispatcher type. |
+ { |
+ base::AutoLock lock(GetLock()); |
+ for (const auto& entry : handles_) { |
+ ++handle_count[entry.second.dispatcher->GetType()]; |
+ } |
+ } |
+ |
+ base::trace_event::MemoryAllocatorDump* outer_dump = |
+ pmd->CreateAllocatorDump("mojo"); |
+ for (const auto& entry : handle_count) { |
+ 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.
|
+ base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
+ entry.second); |
+ } |
+ |
+ return true; |
+} |
+ |
HandleTable::Entry::Entry() {} |
HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) |