1 // Copyright 2019 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 package org.chromium.base.memory; 6 7 import android.os.Debug; 8 9 import org.jni_zero.CalledByNative; 10 11 import org.chromium.base.Log; 12 13 import java.io.IOException; 14 15 /** Enables the generation of hprof files from heap dumps. */ 16 public final class JavaHeapDumpGenerator { 17 private static final String TAG = "JavaHprofGenerator"; 18 JavaHeapDumpGenerator()19 private JavaHeapDumpGenerator() {} 20 21 /** 22 * Generates an hprof file at the given filePath. 23 * @param filePath 24 * @return whether or not the hprof file was properly generated. 25 */ 26 @CalledByNative generateHprof(String filePath)27 public static boolean generateHprof(String filePath) { 28 try { 29 Debug.dumpHprofData(filePath); 30 } catch (IOException e) { 31 Log.i(TAG, "Error writing to file " + filePath + ". Error: " + e.getMessage()); 32 return false; 33 } 34 return true; 35 } 36 } 37