Firefox OS/Performance/Profiling: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
m (Lakrits moved page FirefoxOS/Performance/Profiling to Firefox OS/Performance/Profiling: The official spelling of "Firefox OS" leaves a space between the two parts of the name. It's easier to find a page if the spelling of its name is consistent...)
 
(21 intermediate revisions by 12 users not shown)
Line 1: Line 1:
= Profiling with oprofile =
= Profiling with the gecko profiler =
OProfile is a system-wide profiler for Linux systems. The detail description about OProfile please refer to below url<br>
http://oprofile.sourceforge.net/news/


OProfile consists of three portions, linux kernel driver, userspace applications and collected profiling samplings.<br>
Good at: Native stacks (with runtime options) + javascript profiling, low overhead sampling, familiar for gecko developers


== Prepare the Linux Kernel ==
See [https://developer.mozilla.org/en-US/docs/Performance/Profiling_with_the_Built-in_Profiler#Profiling_Boot_to_Gecko_%28with_a_real_device%29 these instructions]. Patches are in-flight to get native stacks in profiles, but that's not in default configurations yet.
Please make sure you have turned on below features in kerenl configuration file. The kerenl configuration file will be .config in your linux kernel directory normally. You need to recompile linux kernel after turn on OProfile feature.


<pre>
= Profiling with systrace =
CONFIG_PROFILING=y
Good at: Shows process preemption, shows all calls to instrumented functions, Familiar for android developers
CONFIG_OPROFILE=y
CONFIG_HAVE_OPROFILE=y
</pre>


== userspace applications ==
Bad at: Requires configure option, higher overhead
Userspace applications of OProfile includes opcontrol and oprofiled. You can find source code of OProfile in glue/gonk/external/oprofile.<br>


== host application ==
*Download android sdk to get systrace tool:
use host utility opreport to analysis profiling samples<br>
**[http://developer.android.com/sdk/index.html 1. download link]
you can need to install it in your host system.  
**2. the systrace.py tool is at path-to-android-sdk/tools/systrace
<pre>
sudo apt-get install oprofile
</pre>


== Five Steps to profile your target device ==
*Enable systrace in B2G:
To make it easier to use OProfile on B2G project, several Makefile targets have been written.
**Build with '--enable-systrace' config or just uncomment the MOZ_USE_SYSTRACE define in gecko/tools/profiler/GeckoProfilerImpl.h like:
<pre>
make op_setup        # start up oprofile
make op_start        # start profiling
make op_status      # check status
make op_stop        # stop profiling
make op_pull        # pull profile data from phone
make op_show        # save profiling result in oprofile/oprofile.log
</pre>
===make op_setup===
prepare opsetup script file and push it to target device. <br>
opsetup script will wake up oprofiled and setup trigger event.<br>
The snapshot of opsetup is listed below<br>
<pre>
<pre>
opcontrol --setup<br>
#define MOZ_USE_SYSTRACE
opcontrol --vmlinux=/home/vincent/project/B2G_20120217/boot/kernel-android-galaxy-s2/vmlinux --kernel-range=0xc059c000, 0xc0c06000 --event=CPU_CYCLES<br>
#ifdef MOZ_USE_SYSTRACE
# define ATRACE_TAG ATRACE_TAG_ALWAYS
// We need HAVE_ANDROID_OS to be defined for Trace.h.
// If its not set we will set it temporary and remove it.
# ifndef HAVE_ANDROID_OS
#  define HAVE_ANDROID_OS
#  define REMOVE_HAVE_ANDROID_OS
# endif
</pre>
</pre>


===make op_start===
*How to use systrace:
We use "adb shell opcontrol --start" to start profiling and collect samples in target device<br>
**[http://developer.android.com/tools/help/systrace.html systrace.py document]
===make op_status===
**./systrace.py --time=10 -o mynewtrace.html sched
We use "adb shell opcontrol --status" to check profiling status<br>
<pre>
Driver directory: /dev/oprofile
Session directory: /data/oprofile
Counter 0:
    name: CPU_CYCLES
    count: 150000
Counter 1 disabled
Counter 2 disabled
Counter 3 disabled
Counter 4 disabled
oprofiled pid: 3074
profiler is running
      5621 samples received
          0 samples lost overflow
</pre>
===make op_stop===
we use "adb shell opcontrol --stop" to stop profiling<br>
===make op_pull===
pull profiling samples from target device to host PC and copy the related binary files to correlate symbols and memory address
===make op_show===
use opreport to analysis profiling samples<br>
use sudo apt-get install oprofile to install it in your host system
<pre>
CPU: ARM Cortex-A9, speed 0 MHz (estimated)
Counted CPU_CYCLES events (Number of CPU cycles) with a unit mask of 0x00 (No unit mask) count 150000
samples  %        image name              app name                symbol name
5438      9.9701  libmozglue.so            libmozglue.so            __aeabi_idiv
2811      5.1537  libGLESv2_mali.so        libGLESv2_mali.so        /system/lib/egl/libGLESv2_mali.so
2348      4.3049  libc.so                  libc.so                  __aeabi_idiv
2083      3.8190  libxul.so                libxul.so                pixman_composite_over_8888_8_8888_asm_neon
1556      2.8528  libxul.so                libxul.so                pixman_composite_over_8888_8888_asm_neon
1337      2.4513  libxul.so                libxul.so                pixman_scaled_bilinear_scanline_8888_8888_OVER_asm_neon
594      1.0890  libc.so                  libc.so                  timesub
578      1.0597  libxul.so                libxul.so                __aeabi_l2f
547      1.0029  libmozglue.so            libmozglue.so            __aeabi_uidiv
421      0.7719  libc.so                  libc.so                  localsub
383      0.7022  libc.so                  libc.so                  memset
357      0.6545  libxul.so                libxul.so                pixman_composite_over_n_8888_asm_neon
341      0.6252  libxul.so                libxul.so                pixman_composite_over_n_8_8888_asm_neon
308      0.5647  libxul.so                libxul.so                pixman_composite_src_8888_8888_asm_neon
304      0.5574  libm.so                  libm.so                  floor
211      0.3869  libc.so                  libc.so                  __findenv
208      0.3814  libc.so                  libc.so                  pthread_mutex_lock
201      0.3685  libmozglue.so            libmozglue.so            arena_malloc
193      0.3538  libmozglue.so            libmozglue.so            arena_dalloc
180      0.3300  libm.so                  libm.so                  fmod
177      0.3245  libxul.so                libxul.so                nsIFrame::FinishAndStoreOverflow(nsOverflowAreas&, nsSize)
176      0.3227  libc.so                  libc.so                  __system_property_find
174      0.3190  libxul.so                libxul.so                gfx3DMatrix::Transform3D(gfxPoint3D const&) const
171      0.3135  libxul.so                libxul.so                pixman_composite_src_n_8888_asm_neon
162      0.2970  libc.so                  libc.so                  time2sub.clone.2
161      0.2952  libxul.so                libxul.so                PL_DHashTableOperate
</pre>


= Profiling with perf =
Note: Gecko code is tagged as ATRACE_TAG_ALWAYS, so we don't set the category type.
The perf utility is a performance analysis tools for Linux.<br>Please read about [[B2G/Profiling/perf|profiling B2G with perf]].

Latest revision as of 13:59, 1 February 2015

Profiling with the gecko profiler

Good at: Native stacks (with runtime options) + javascript profiling, low overhead sampling, familiar for gecko developers

See these instructions. Patches are in-flight to get native stacks in profiles, but that's not in default configurations yet.

Profiling with systrace

Good at: Shows process preemption, shows all calls to instrumented functions, Familiar for android developers

Bad at: Requires configure option, higher overhead

  • Download android sdk to get systrace tool:
    • 1. download link
    • 2. the systrace.py tool is at path-to-android-sdk/tools/systrace
  • Enable systrace in B2G:
    • Build with '--enable-systrace' config or just uncomment the MOZ_USE_SYSTRACE define in gecko/tools/profiler/GeckoProfilerImpl.h like:
#define MOZ_USE_SYSTRACE
#ifdef MOZ_USE_SYSTRACE
# define ATRACE_TAG ATRACE_TAG_ALWAYS
// We need HAVE_ANDROID_OS to be defined for Trace.h.
// If its not set we will set it temporary and remove it.
# ifndef HAVE_ANDROID_OS
#   define HAVE_ANDROID_OS
#   define REMOVE_HAVE_ANDROID_OS
# endif

Note: Gecko code is tagged as ATRACE_TAG_ALWAYS, so we don't set the category type.