389
9.8.1.1. Measuring Execution Times Hierarchically
If we measure the execution time of a single function, the time we measure
includes the execution time of any the child functions called and all of their
grandchildren, great grandchildren, and so on as well. To properly interpret
any profi ling data we might collect, we must be sure to take the function call
hierarchy into account.
Many commercial profi lers can automatically instrument every single
function in your program. This permits them to measure both the inclusive
and exclusive execution times of every function that is called during a profi l-
ing session. As the name implies, inclusive times measure the execution time
of the function including all of its children, while exclusive times measure
only the time spent in the function itself. (The exclusive time of a function
can be calculated by subtracting the inclusive times of all its immediate chil-
dren from the inclusive time of the function in question.) In addition, some
profi lers record how many times each function is called. This is an impor-
tant piece of information to have when optimizing a program, because it al-
lows you to diff erentiate between functions that eat up a lot of time internally
and functions that eat up time because they are called a very large number of
times.
In contrast, in-game profi ling tools are not so sophisticated and usually
rely on manual instrumentation of the code. If our game engine’s main loop
is structured simply enough, we may be able to obtain valid data at a coarse
level without thinking much about the function call hierarchy. For example, a
typical game loop might look roughly like this:
while (!quitGame)
{
PollJoypad();
UpdateGameObjects();
UpdateAllAnimations();
PostProcessJoints();
DetectCollisions();
RunPhysics();
GenerateFinalAnimationPoses();
UpdateCameras();
RenderScene();
UpdateAudio();
}
We could profi le this game at a very coarse level by measuring the execution
times of each major phase of the game loop:
while (!quitGame)
{
9.8. In-Game Profi ling