指定进程的DumpHeap使用

定义:com.android.server.am.ActivityManagerShellCommand#myRunDumpHeap

  int myRunDumpHeap(PrintWriter pw) throws RemoteException {
        final PrintWriter err = getErrPrintWriter();
        boolean managed = true;
        boolean mallocInfo = true;
        boolean runGc = true;

        String process = "com.example.test2";
        String heapFile = "/data/local/tmp/heapdump-" +process+ ".prof";

        pw.println("File: " + heapFile);
        pw.flush();

        File file = new File(heapFile);
        file.delete();
        ParcelFileDescriptor fd = openFileForSystem(heapFile, "w");
        if (fd == null) {
            return -1;
        }

        final CountDownLatch latch = new CountDownLatch(1);

        final RemoteCallback finishCallback = new RemoteCallback(new OnResultListener() {
            @Override
            public void onResult(Bundle result) {
                latch.countDown();
            }
        }, null);

        if (!mInterface.dumpHeap(process, UserHandle.USER_CURRENT, managed, mallocInfo, runGc, heapFile, fd,
                finishCallback)) {
            err.println("HEAP DUMP FAILED on process " + process);
            return -1;
        }
        pw.println("Waiting for dump to finish...");
        pw.flush();
        try {
            latch.await();
            pw.println("dump finished...");
        } catch (InterruptedException e) {
            err.println("Caught InterruptedException");
        }
        return 0;
    }

加入shell cmd 就可以使用如下命令 :

adb  shell  cmd   activity a0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值