This directory contains android activities and host-side tests relating to libcore memory metrics.
apps
host
You can manually run this as follows:
make tradefed-all libcore-memory-metrics-tests LibcoreHeapDumper ahat tradefed.sh run commandAndExit template/local_min --template:map test=libcore-memory-metrics-tests
This installs and runs the LibcoreHeapDumpActivity on the device, pulls the heaps back to the host, analyses them, and derives metrics. You can see the metrics in the tradefed output.
This instrumentation dumps a heap, performs some configurable action (see the code for details), and then dumps another heap. You can run it manually as follows:
make LibcoreHeapDumper adb install -g -r ${ANDROID_PRODUCT_OUT}/testcases/LibcoreHeapDumper/arm64/LibcoreHeapDumper.apk
DEVICE_EXTERNAL_STORAGE=$(adb shell 'echo -n ${EXTERNAL_STORAGE}')
RELATIVE_DIR=dumps adb shell mkdir ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}
adb shell rm -r ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}/*
DUMPER_ACTION=NOOP adb shell am instrument -w -e dumpdir ${RELATIVE_DIR} -e action ${DUMPER_ACTION} libcore.heapdumper/.HeapDumpInstrumentation adb shell ls ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}
LOCAL_DIR=/tmp mkdir -p ${LOCAL_DIR}/${RELATIVE_DIR}
rm -r ${LOCAL_DIR}/${RELATIVE_DIR}/* adb pull ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR} ${LOCAL_DIR} ls ${LOCAL_DIR}/${RELATIVE_DIR}
make ahat
ahat ${LOCAL_DIR}/${RELATIVE_DIR}/before.hprof
ahat ${LOCAL_DIR}/${RELATIVE_DIR}/after.hprof --baseline ${LOCAL_DIR}/${RELATIVE_DIR}/before.hprof
rm -r ${LOCAL_DIR}/${RELATIVE_DIR} adb shell rm -r ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR} adb uninstall libcore.heapdumper
This instrumentation measures the PSS in kB, performs some configurable action (see the code for details), and then measures the PSS again. You can run it manually as follows:
make LibcoreHeapDumper adb install -g -r ${ANDROID_PRODUCT_OUT}/data/app/LibcoreHeapDumper/LibcoreHeapDumper.apk
DEVICE_EXTERNAL_STORAGE=$(adb shell 'echo -n ${EXTERNAL_STORAGE}')
RELATIVE_DIR=pss adb shell mkdir ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}
adb shell rm -r ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}/*
DUMPER_ACTION=NOOP adb shell am instrument -w -e dumpdir ${RELATIVE_DIR} -e action ${DUMPER_ACTION} libcore.heapdumper/.PssInstrumentation adb shell ls ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}
adb shell cat ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}/before.pss.txt adb shell cat ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR}/after.pss.txt
adb shell rm -r ${DEVICE_EXTERNAL_STORAGE}/${RELATIVE_DIR} adb uninstall libcore.heapdumper