Zelimir Fedoran
email zelimir.fedoran@gmail.com

Profiling on the Xbox 360

Posted on
November 26th, 2010
Tags
, ,

When confronted with a new problem I like to brainstorm possible solutions on paper. Doing this allows me to find other problems that I may otherwise miss. Also, it is a good way to figure out how much processing time a solution may eat up.

However, sometimes it is difficult to tell which solution is best. When this happens, I code up a simplified version of the solution to test how it performs. This is usually enough to make a decision. But there are some problems. How do you profile the CPU on the Xbox 360? There are no tools which allow you to do this. Also, what if the solution is multi-threaded?

Profiling with Stopwatch

One way to profile XNA games on the Xbox 360 is to use the Stopwatch class to measure how long something takes to execute. But having stopwatches all over the place can become confusing and cluttered. Even if you implement a simple profiler using Stopwatch, like Shawn Hargreaves did, you still have to look at the numbers to determine if the solution is good. This can be confusing and hard to do if there is a lot of action.

Visualizing the Stopwatch

While working on Aqua, I spent a lot of time looking at the developer diaries for Killzone 2. I really like the way they display the PS3 spu usage through bars on a timeline. So, I decided to create my profiling tool based on the Killzone 2 profiler. The first screenshot is from Killzone 2 and the others are from my Orion project.

Killzone 2 ProfilerOrion ProfilerOrion Profiler

Using the Profiler

Using the profiler is really easy and you don’t even need to create a variable thanks to the IDisposable interface. I could have used reflection to get the name of the current method but I like having control over what shows up on the screen. If you would like the source code to the profiler send me an email.

using (new ProfileMarker("the name of this marker", Color.Yellow))
{
     //... code to profile
}