Home | History | Annotate | Download | only in trace_event
      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
      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
     14 JavaHeapDumpProvider* JavaHeapDumpProvider::GetInstance() {
     15   return Singleton<JavaHeapDumpProvider,
     16                    LeakySingletonTraits<JavaHeapDumpProvider>>::get();
     17 }
     18 
     19 JavaHeapDumpProvider::JavaHeapDumpProvider() {
     20 }
     21 
     22 JavaHeapDumpProvider::~JavaHeapDumpProvider() {
     23 }
     24 
     25 // Called at trace dump point time. Creates a snapshot with the memory counters
     26 // for the current process.
     27 bool JavaHeapDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
     28                                         ProcessMemoryDump* pmd) {
     29   // These numbers come from java.lang.Runtime stats.
     30   long total_heap_size = 0;
     31   long free_heap_size = 0;
     32   android::JavaRuntime::GetMemoryUsage(&total_heap_size, &free_heap_size);
     33 
     34   MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("java_heap");
     35   outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
     36                         MemoryAllocatorDump::kUnitsBytes, total_heap_size);
     37 
     38   MemoryAllocatorDump* inner_dump =
     39       pmd->CreateAllocatorDump("java_heap/allocated_objects");
     40   inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
     41                         MemoryAllocatorDump::kUnitsBytes,
     42                         total_heap_size - free_heap_size);
     43   return true;
     44 }
     45 
     46 }  // namespace trace_event
     47 }  // namespace base
     48