GithubHelp home page GithubHelp logo

srikanth007m / android-memory-analyzer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linzj/android-memory-analyzer

0.0 2.0 0.0 292 KB

An memory analyzer targeted android native heap

Python 16.84% Makefile 0.77% Shell 0.03% C++ 12.08% C 70.27%

android-memory-analyzer's Introduction

Android Memory Analyzer

Breifing

This is a memory analyzer targeting android os, but it is portable to any linux system, or even a Windows system. It is used to analyze native heap usage, native heap leaking.

Usage

We first compile a shared library targeted to our android machine. Current version has support x86/arm android machine. The compile step is simple. Just press ndk-build. Now we have a share library in libs/$TARGET_ARCH/libmemanaly.so. We push it into /data/local/tmp like this:

    adb push libs/\$TARGET_ARCH/libmemanaly.so /data/local/tmp/

Then we need to push the wrapper too.

adb push mywrapper.sh /data/local/tmp/

We set the mode of our wrapper.

adb shell chmod 755 /data/local/tmp/mywrapper.sh

Set the property of the machine, to tell Android start our application with this wrapper. Note our machine must have been rooted.

adb shell su -c "setprop wrap.<our application package name> /data/local/tmp/mywrapper.sh"

Note here our application package name has a length limit to 31 characters. If you have such a long package name ( normally a service of yours), just truncate it to 31 characters. Start our application. Let's rock for a while.

Now we are ready to pull the heap snapshot to our PC. Let's do this. Here I assume you are using a Linux OS, with all GNU tools. First we forward the port from the android machine to our PC.

    adb forward tcp:3244 tcp:3244

If you don't care about the leaking, you may do this

    adb forward tcp:3255 tcp:3255

3255 port transfers simpler data, but not suitable for analyzing leaking. We use nc utility to transfer the snapshot back.

    nc localhost 3244 >/tmp/snapshot

then we can do the analyze:

    python analyze.py -b /tmp/snapshot >/tmp/result

This command give the heap usage, the allocation elements is sorted descending. We usually care the top ten element, which would solve most bugs. And this command:

    python analyze.py -m /tmp/snapshot

Using mark and sweep algorithm to filter out the leaking. The result is stored at /tmp/analyze_zero.

All this reports have elements with backtracing information. But we have no idea what these backtracing information means, for they are all numbers. We filter our resulted report like this, make it readable:

    cat <resulted report> | python AddressFilter.py <maps file> <paths to your symbol files>

The maps file must read from your application process THE SAME PROCESS AS YOU GET THE SNAPSHOT . We get it lke this:

    adb shell su -c "cat /proc/<pid>/maps" >maps

Just Enjoy It.

android-memory-analyzer's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.