Index: base/trace_event/memory_dump_manager.cc |
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc |
index 18b255ab8b1db1303f3ee4567f309f819622e11b..4ca61be64387d14641de282682b15eebaa20e997 100644 |
--- a/base/trace_event/memory_dump_manager.cc |
+++ b/base/trace_event/memory_dump_manager.cc |
@@ -94,33 +94,6 @@ void OnGlobalDumpDone(MemoryDumpCallback wrapped_callback, |
} |
} |
-// Proxy class which wraps a ConvertableToTraceFormat owned by the |
-// |session_state| into a proxy object that can be added to the trace event log. |
-// This is to solve the problem that the MemoryDumpSessionState is refcounted |
-// but the tracing subsystem wants a std::unique_ptr<ConvertableToTraceFormat>. |
-template <typename T> |
-struct SessionStateConvertableProxy : public ConvertableToTraceFormat { |
- using GetterFunctPtr = T* (MemoryDumpSessionState::*)() const; |
- |
- SessionStateConvertableProxy( |
- scoped_refptr<MemoryDumpSessionState> session_state, |
- GetterFunctPtr getter_function) |
- : session_state(session_state), getter_function(getter_function) {} |
- |
- void AppendAsTraceFormat(std::string* out) const override { |
- return (session_state.get()->*getter_function)()->AppendAsTraceFormat(out); |
- } |
- |
- void EstimateTraceMemoryOverhead( |
- TraceEventMemoryOverhead* overhead) override { |
- return (session_state.get()->*getter_function)() |
- ->EstimateTraceMemoryOverhead(overhead); |
- } |
- |
- scoped_refptr<MemoryDumpSessionState> session_state; |
- GetterFunctPtr const getter_function; |
-}; |
- |
} // namespace |
// static |
@@ -734,6 +707,55 @@ void MemoryDumpManager::FinalizeDumpAndAddToTrace( |
TRACE_EVENT_FLAG_HAS_ID); |
} |
+ const size_t kHeapDumpNumArgs = 1; |
+ const char* kHeapDumpArgNames[] = {"data"}; |
+ const unsigned char kHeapDumpArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; |
+ for (const auto& kv : pmd_async_state->process_dumps) { |
+ ProcessId pid = kv.first; |
+ ProcessMemoryDump* process_memory_dump = kv.second.get(); |
+ if (pid != kNullProcessId) { |
+ // We expect heap dumps only from the current process. |
+ DCHECK(process_memory_dump->heap_dumps().empty()); |
+ continue; |
+ } |
+ |
+ auto heap_dump_value = MakeUnique<TracedValue>(); |
+ |
+ // Add version specifying format of the data below. |
+ heap_dump_value->SetInteger("version", 1); |
Primiano Tucci (use gerrit)
2017/02/17 17:07:05
I think that historically we avoided any sort of v
DmitrySkiba
2017/02/23 07:17:19
My position is exactly the opposite - versioning i
hjd
2017/02/23 12:33:27
I was motivated to ask Dmitry to add the version k
|
+ |
+ // Add "malloc", "blink_gc", etc. nodes, each containing a dump. |
+ for (const auto& name_and_dump : process_memory_dump->heap_dumps()) { |
+ heap_dump_value->SetValueWithCopiedName(name_and_dump.first.c_str(), |
+ *name_and_dump.second); |
+ } |
+ |
+ // Add "maps" node. |
+ if (auto* session_state = pmd_async_state->session_state.get()) { |
+ heap_dump_value->BeginDictionary("maps"); |
+ if (auto* deduplicator = session_state->type_name_deduplicator()) { |
+ heap_dump_value->BeginArray("types"); |
+ deduplicator->AppendIncrementally(&*heap_dump_value); |
+ heap_dump_value->EndArray(); |
+ } |
+ if (auto* deduplicator = session_state->stack_frame_deduplicator()) { |
+ heap_dump_value->BeginArray("nodes"); |
+ deduplicator->AppendIncrementally(&*heap_dump_value); |
+ heap_dump_value->EndArray(); |
+ } |
+ heap_dump_value->EndDictionary(); |
+ } |
+ |
+ std::unique_ptr<ConvertableToTraceFormat> values[kHeapDumpNumArgs] = { |
+ std::move(heap_dump_value)}; |
+ TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( |
+ TRACE_EVENT_PHASE_SAMPLE, |
+ TraceLog::GetCategoryGroupEnabled(kTraceCategory), "heap_profile", |
Primiano Tucci (use gerrit)
2017/02/17 17:07:05
this is the only thing where I'm not fully sure. W
DmitrySkiba
2017/02/23 07:17:19
I think we discussed this exact concern several ti
hjd
2017/02/23 12:33:27
As I mentioned before if we eventually want to sha
|
+ trace_event_internal::kGlobalScope, dump_guid, pid, kHeapDumpNumArgs, |
+ kHeapDumpArgNames, kHeapDumpArgTypes, nullptr /* arg_values */, values, |
+ TRACE_EVENT_FLAG_HAS_ID); |
+ } |
+ |
bool tracing_still_enabled; |
TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); |
if (!tracing_still_enabled) { |
@@ -783,18 +805,6 @@ void MemoryDumpManager::OnTraceLogEnabled() { |
session_state->SetTypeNameDeduplicator( |
WrapUnique(new TypeNameDeduplicator)); |
- |
- TRACE_EVENT_API_ADD_METADATA_EVENT( |
- TraceLog::GetCategoryGroupEnabled("__metadata"), "stackFrames", |
- "stackFrames", |
- MakeUnique<SessionStateConvertableProxy<StackFrameDeduplicator>>( |
- session_state, &MemoryDumpSessionState::stack_frame_deduplicator)); |
- |
- TRACE_EVENT_API_ADD_METADATA_EVENT( |
- TraceLog::GetCategoryGroupEnabled("__metadata"), "typeNames", |
- "typeNames", |
- MakeUnique<SessionStateConvertableProxy<TypeNameDeduplicator>>( |
- session_state, &MemoryDumpSessionState::type_name_deduplicator)); |
} |
{ |