1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/trace_event/java_heap_dump_provider_android.h" 6 7 #include "base/android/java_runtime.h" 8 #include "base/trace_event/process_memory_dump.h" 9 10 namespace base { 11 namespace trace_event { 12 13 // static GetInstance()14JavaHeapDumpProvider* JavaHeapDumpProvider::GetInstance() { 15 return Singleton<JavaHeapDumpProvider, 16 LeakySingletonTraits<JavaHeapDumpProvider>>::get(); 17 } 18 19 // Called at trace dump point time. Creates a snapshot with the memory counters 20 // for the current process. OnMemoryDump(const MemoryDumpArgs & args,ProcessMemoryDump * pmd)21bool JavaHeapDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, 22 ProcessMemoryDump* pmd) { 23 // These numbers come from java.lang.Runtime stats. 24 uint64_t total_heap_size = 0; 25 uint64_t free_heap_size = 0; 26 android::JavaRuntime::GetMemoryUsage(&total_heap_size, &free_heap_size); 27 28 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("java_heap"); 29 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, 30 MemoryAllocatorDump::kUnitsBytes, total_heap_size); 31 32 MemoryAllocatorDump* inner_dump = 33 pmd->CreateAllocatorDump("java_heap/allocated_objects"); 34 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, 35 MemoryAllocatorDump::kUnitsBytes, 36 total_heap_size - free_heap_size); 37 return true; 38 } 39 40 } // namespace trace_event 41 } // namespace base 42