When reporting a performance problem with Firefox, or when experiencing instances of Firefox stuttering or otherwise being unresponsive to input, obtaining a snapshot of what's going on during that period is extremely helpful for developers. This page will walk you through using the freely available AMD CodeAnalyst tool to create such a snapshot.
You can also work around the problem by manually starting and stopping the service that CodeAnalyst uses for data collection: first, after installation open up the service manager, and change
CALoadServiceto be Manual start only. Then, before profiling, start the service ('
sc start CALoadService' on the command line) and stop after profiling ('
sc stop CALoadService'. Don't let your computer idle to a point where the screensaver/monitor blanking/etc. kicks in.
Download and Install AMD CodeAnalyst
Download AMD CodeAnalyst for Windows from AMD's Developer site. (You may need to create an account.) Make sure you download the latest version, which at the time of this writing is 2.94. The download site is a little unclear, often offering links to multiple versions.
The installer will ask that you restart, but I've found that in most cases that's not necessary. You can begin profiling without restarting, though if you experience problems, you may want to try restarting just in case.
Start a Profiling Run
Start CodeAnalyst by double-clicking its icon. You'll see the following:
Select Express Profile.
You'll be presented with the following:
Leave everything at the defaults, and click OK.
As soon as you click OK, profiling starts, and will run for about 30 seconds.
Set up the Mozilla Symbol Server
After the first profiling run finishes, you'll see the following:
Before we can extract useful data, we'll need to set up access to the Mozilla Symbol Server.
From the Tools menu, select CodeAnalyst Options. In the options dialog, select the Directories tab.
- Check Use Symbol Servers
- Enter a directory for the Download directory; something like C:\SymCache works. This is a location where symbol data will be downloaded and cached to.
- The Microsoft symbol location should already be in the list of symbol sources, so all you need to do is add the Mozilla server. Click New.
- Enter http://symbols.mozilla.org/firefox
Your options dialog should look like this:
Click OK. Symbols are available for all released versions of Firefox, as well as for the last 30 days' worth of nightly builds.
Examining Profiling Data
You're now ready to examine the data that you captured! The results window will have a few tabs in it; select Processes. You'll see a list of all the processes that were running while the sample was captured, along with the percentage of samples that happened within them:
In this case, Firefox was using 42% of the system time. That's a good percentage; the higher you see firefox in the list, the easier it is to track down the problem, because it means that more data was captured. Now we want to drill in to firefox.exe, so double click firefox.exe. You'll see a module view of the Firefox process:
In the above example, most of the time is spent inside xul.dll, so let's focus on that. Double click xul.dll.
CodeAnalyst will spend some time downloading symbols if it hasn't done so before, and eventually you'll see the following view:
If, in the previous step, the time was split between multiple modules, you should repeat the above for each module of interest (for example, for xul.dll and js3250.dll.
What To Do With The Data
At this point, you have information that's very useful when filing a bug report regarding performance in bugzilla.mozilla.org. The easiest way to get data into a bug report is to select the top ten symbols or so, right click, and select Copy selection to buffer. You can then paste the result directly into a bug report. Or, select Export data to file and attach the file to the bug.
Filing a peformance-related bug with the profile information attached lets developers immediately have an area that they can look at, especially for intermittent or hard-to-reproduce problems.
Capturing Another Sample
If the problem you are trying to analyze is intermittent, it's helpful to leave the CodeAnalyst window open. When it appears, just hit the green Start button in the window to start profiling, and when the slowness/lockup stops, hit the stop button. That will give you a new session with just that information. It can be difficult to do this for short problems, and might take a few tries to get a useful profiling sample.
CodeAnalyst includes command line tools for driving profiling. Details about various options can be found in the online help, but here's a quick overview:
caprofile /s /t 500 /o profile /l js.exe -j -f test.js
Start profiling right away, capture a sample every 500 microseconds, place the output in a file starting with 'profile', and execute "js.exe -j -f test.js". If you're doing this in a msys shell, remember that you need to use double-slashes for the options, e.g. "caprofile //s //t 500". Also, you may need to give the full path to the executable.
After capturing a profile, you need to run it through cadataanalyze to get it to a point where you can view it. If you have a CodeAnalyst workspace named "Profiling.caw", you can process the data and add it to that workspace:
cadataanalyze /i profile /o profile /a Profiling.caw
This will create profile.tbp.dir. If Profiling.caw isn't in the current directory, you may need to move profile.tbp.dir to the same directory in order for the GUI to find it. You can also skip the /a step, and use careport to view results (note: careport will show each separate VMA underneath the actual function which groups them; this can be annoying noise, but it can also be helpful to see exactly where inside a function a program is spending time. The GUI is generally much easier to use to view results.)
% careport //i profiling.tbp.dir/profiling.tbp //m 'c:\proj\js\js.exe' | grep -v '^ ' | tail -20
0x144ff30 777.00 0.29 TypedArrayTemplate<float>::obj_getProperty
0x14267c0 944.00 0.35 JSDOUBLE_IS_INT
0x13c71f0 1081.00 0.40 js_NewDoubleInRootedValue
0x142ac60 2112.00 0.79 JSDOUBLE_IS_INT
0x142d030 23849.00 8.87 js_Interpret
CodeAnalyst for Windows:
careport control utility, version 220.127.116.11