Profiling with AMD CodeAnalyst

  • Revision slug: Profiling_with_AMD_CodeAnalyst
  • Revision title: Profiling with AMD CodeAnalyst
  • Revision id: 111492
  • Created:
  • Creator: VladVukicevic
  • Is current revision? No
  • Comment 46 words added

Revision Content

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.

This page applies to Windows only, because of the dependency on obtaining symbols from the Mozilla Symbol Server.  On MacOS X, a special Shark-enabled build can be used which has symbol information already built in.  On Linux, a custom build would be required.
If you are on a 64-bit version of Windows, AMD CodeAnalyst has some known problems that may cause blue screen crashes when your computer idles, especially on non-AMD CPUs.  You may want to avoid using CodeAnalyst until the problem is resolved.

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:

codeanalyst1.PNG

Select Express Profile.

You'll be presented with the following:

codeanalyst2.PNG

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:

codeanalyst4.PNG

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:

codeanalyst5.PNG

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:

codeanalyst6.PNG

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:

codeanalyst7.PNG

There are two main modules that are relevant for Firefox -- xul.dll and js3250.dll.  The vast majority of what Firefox does is part of xul.dll; everything except JavaScript execution, which is part of js3250.dll.  There are a few other miscellaneous modules also part of Firefox (such as mozcrt19.dll, nspr4.dll, etc.), but you should rarely see them show up high in profiles.

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:

codeanalyst8.PNG

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.

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.

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.

Revision Source

<p>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.</p>
<div class="note"><strong>This page applies to Windows only</strong>, because of the dependency on obtaining symbols from the <a class="internal" href="/en/Using_the_Mozilla_symbol_server" title="en/Using the Mozilla symbol server">Mozilla Symbol Server</a>.  On MacOS X, a special Shark-enabled build can be used which has symbol information already built in.  On Linux, a custom build would be required.</div>
<div class="warning"><strong>If you are on a 64-bit version of Windows</strong>, AMD CodeAnalyst has some known problems that may cause blue screen crashes when your computer idles, especially on non-AMD CPUs.  You may want to avoid using CodeAnalyst until the problem is resolved.</div>
<h3>Download and Install AMD CodeAnalyst</h3>
<p>Download <a class="external" href="http://developer.amd.com/cpu/CodeAnalyst/codeanalystwindows/Pages/default.aspx" title="http://developer.amd.com/cpu/CodeAnalyst/codeanalystwindows/Pages/default.aspx">AMD CodeAnalyst for Windows </a> from AMD's Developer site.  (You may need to create an account.)  <strong>Make sure you download the latest version, which at the time of this writing is 2.94.</strong>  The download site is a little unclear, often offering links to multiple versions.</p>
<p>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.</p>
<h3>Start a Profiling Run</h3>
<p>Start CodeAnalyst by double-clicking its icon.  You'll see the following:</p>
<p><img alt="codeanalyst1.PNG" class="internal default" src="/@api/deki/files/3781/=codeanalyst1.PNG" style="width: 454px; height: 353px;"></p>
<p>Select <strong>Express Profile</strong>.</p>
<p>You'll be presented with the following:</p>
<p><img alt="codeanalyst2.PNG" class="internal default" src="/@api/deki/files/3782/=codeanalyst2.PNG" style="width: 529px; height: 337px;"></p>
<p>Leave everything at the defaults, and click OK.</p>
<p>As soon as you click OK, profiling starts, and will run for about 30 seconds.</p>
<h3>Set up the Mozilla Symbol Server</h3>
<p>After the first profiling run finishes, you'll see the following:</p>
<p><img alt="codeanalyst4.PNG" class="internal default" src="/@api/deki/files/3783/=codeanalyst4.PNG" style="width: 918px; height: 542px;"></p>
<p>Before we can extract useful data, we'll need to set up access to the Mozilla Symbol Server.</p>
<p>From the <strong>Tools</strong> menu, select <strong>CodeAnalyst Options</strong>.  In the options dialog, select the <strong>Directories</strong> tab.</p>
<ul> <li>Check <strong>Use Symbol Servers</strong></li> <li>Enter a directory for the <strong>Download directory</strong>; something like <strong>C:\SymCache</strong> works.  This is a location where symbol data will be downloaded and cached to.</li> <li>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 <strong>New</strong>.</li> <li>Enter <strong><a class=" external" href="http://symbols.mozilla.org/firefox" rel="freelink">http://symbols.mozilla.org/firefox</a></strong></li>
</ul>
<p>Your options dialog should look like this:</p>
<p><img alt="codeanalyst5.PNG" class="internal default" src="/@api/deki/files/3784/=codeanalyst5.PNG" style="width: 445px; height: 621px;"></p>
<p>Click OK.  Symbols are available for all released versions of Firefox, as well as for the last 30 days' worth of nightly builds.</p>
<h3>Examining Profiling Data</h3>
<p>You're now ready to examine the data that you captured!  The results window will have a few tabs in it; select <strong>Processes</strong>.  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:</p>
<p><img alt="codeanalyst6.PNG" class="internal default" src="/@api/deki/files/3785/=codeanalyst6.PNG" style="width: 918px; height: 569px;"></p>
<p>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 <strong>double click firefox.exe</strong>.  You'll see a module view of the Firefox process:</p>
<p><img alt="codeanalyst7.PNG" class="internal default" src="/@api/deki/files/3786/=codeanalyst7.PNG" style="width: 918px; height: 569px;"></p>
<p>There are two main modules that are relevant for Firefox -- xul.dll and js3250.dll.  The vast majority of what Firefox does is part of xul.dll; everything except JavaScript execution, which is part of js3250.dll.  There are a few other miscellaneous modules also part of Firefox (such as mozcrt19.dll, nspr4.dll, etc.), but you should rarely see them show up high in profiles.</p>
<p>In the above example, most of the time is spent inside xul.dll, so let's focus on that.  <strong>Double click xul.dll</strong>.</p>
<p>CodeAnalyst will spend some time downloading symbols if it hasn't done so before, and eventually you'll see the following view:</p>
<p><img alt="codeanalyst8.PNG" class="internal default" src="/@api/deki/files/3787/=codeanalyst8.PNG" style="width: 918px; height: 569px;"></p>
<p>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.</p>
<h3>Capturing Another Sample</h3>
<p>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.</p>
<h3>What To Do With The Data</h3>
<p>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 <strong>Copy selection to buffer</strong>.  You can then paste the result directly into a bug report.  Or, select <strong>Export data to file</strong> and attach the file to the bug.</p>
<p>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.</p>
Revert to this revision