Skip to content

Instantly share code, notes, and snippets.

@EricRahm
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricRahm/a5b96df4583a163bf809 to your computer and use it in GitHub Desktop.
Save EricRahm/a5b96df4583a163bf809 to your computer and use it in GitHub Desktop.
On device memory profiling

Figuring out available memory on a device

adb shell cat /proc/meminfo

  • MemTotal tells you how much device memory is available outside of drivers/kernel.
  • MemFree tells you how much memory is currently available, checking this after booting should give you a rough guesstimate of what our max is.

To simulate what would happen in a low-memory situation you can adb shell kill <pid> each b2g process but b2g, (Nuwa), Homescreen (use b2g-ps to get a b2g process listing). Unfortunately Homescreen just comes back (it can be LMK'd though, so add it's USS to the MemFree total to get a better idea of an ideal MemFree value).

Get an overview of b2g application memory usage

adb shell b2g-procrank

Note there are quite a few apps, some of which can get nuked when we need more memory (Homescreen, keyboard, preallocated, usage, etc). The most useful field for your app is probably USS.

Getting a breakdown of memory usage in-app

Use the get_about_memory.py script from the mozilla-b2g/B2G repo.

Example:

git clone https://github.com/mozilla-b2g/B2G.git
cd B2G
tools/get_about_memory.py --minimize

This will write a set of files to about-memory-N. Load the URL it spits out in Firefox to view the memory report.

Measuring on desktop

  1. Start with a clean profile only used for testing j2me.js. You probably want to disable e10s.
  2. Open your j2me.js app and about:memory
  3. Use the app
  4. Measure memory in about:memory
  5. click 'Minimize memory usage' - this will trigger a few rounds of gc/cc
  6. click 'Measure' to get a snapshot of memory usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment