Profiling Tutorial

Profiling B2G drawing

Start by familaring yourself with the b2g subsection of the MDN Profiler Page.

Build with the following patch OR with enable-profiling:

diff --git a/tools/profiler/platform.cpp b/tools/profiler/platform.cpp
index ca656a5..f8428f5 100644
--- a/tools/profiler/platform.cpp
+++ b/tools/profiler/platform.cpp
@@ -724,7 +724,7 @@ bool mozilla_sampler_register_thread(const char* aName, void* stackTop)
   // is to build with profiling OR have the profiler
   // running on startup.
   if (!profiler_is_active()) {
-    return false;
+    //return false;

With Off-Main-Thread-Compositing (OMTCompositing) drawing will happens on two threads (1) The content thread (2) The compositor thread. To capture a useful profile you will want collect a profile with at least these two threads. For example to profile scrolling in a particular app like Settings, Homescreen you will want to profile the main thread of these processes. The compositor lives in the b2g process. Thus use the following command line:

./ start -p b2g -t Compositor

Note that some root drawing happens in the b2g main thread like the status bar, background (Not the homescreen icons), lock screen. For this you will want to use this command:

./ start -p b2g -t GeckoMain,Compositor

Finally capture the combined profile using:

./ capture

and open it from cleopatra:

Open in Cleopatra

How to read a profile using Cleopatra

Zooming in to a subrange

Highlight a range in the timeline and select the breadcrumb that appears near the top left.

Select a sample at a particular time

Click on a sample in the timeline at a particular point to highligh that sample in the tree view

With the treeview selected you may use the arrow keys to navigate the tree view efficiently. Keep an eye on the timeline as the green region will shift indicating when you selection happen.

Understanding the timeline

The timeline will show unselected samples in black or and selected samples in green. The timeline x axis is time and the y axis is stack depth *not cpu usage*! Using the timeline to understand how your select samples occured in time is very important. Blocky green

Filtering by name

Select the filter box in the middle left and type in a case insensitive search like 'reflow'.

Share a profile

Click the share button in the bottom left to upload the profile a *public* cloud storage. This will returns a URL that you can share on bugzilla & irc. This is useful if you need help from others to understand the performance profile.