How to Measure and Analyze Startup Performance
Suresh Duddi <dp@netscape.com>
Cathleen Wang <cathleen@netscape.com >
Simon Fraser <sfraser@netscape.com >
Performance timeline
Timeline is a linear growing timestamp on when what is happening starting from the launch. It also enables code that can be used to time individual functions or bodies of code.- Build setting
Windows: set MOZ_TIMELINE=1
[default for DEBUG builds]Unix: ac_add_options --enable-timeline
Mac: put ' options timeline 1
' in your build prefs file - Rebuild
- Runtime setting: to turn ON timeline data output
Windows: set NS_TIMELINE_ENABLE=1
Unix: setenv NS_TIMELINE_ENABLE 1
Mac: set environment variables as described here - Runtime setting: to log all timeline output to file instead
of console
Windows: set NS_TIMELINE_LOG_FILE=filename
Unix: setenv NS_TIMELINE_LOG_FILE=filename
Mac: set environment variables as described here
#include "nsITimelineService.h"
nsresult myfunc(char * args)
{
NS_TIMELINE_START_TIMER("myfunc
timer")
... body of function or code to be timed
NS_TIMELINE_STOP_TIMER("myfunc
timer");
// Print timing results
NS_TIMELINE_MARK_TIMER("myfunc
timer");
return NS_OK;
}
This will print to console or file selected
via NS_TIMELINE_LOG_FILE. You should have enabled timeline in your build to
have these do anything. On release builds these defines will be nooped. So
you could chceckin these too into the tree. If the function is called multiple times and only the cumulative time is interesting, move
NS_TIMELINE_MARK_TIMER("myfunctimer")
to outside the function to a suitable point. These timers are stored
by a nsITimerService and are accessible from anywhere in the code until
XPCOM shutdown. It is highly recommended for all developers to enable timeline. These defines do the right thing on all platforms - take care of using high res timers, prevent getting caught by clock skews. So use these rather than rolling your own.
Startup Performance Measurement
Always follow these precautions when doing startup measurementMethod 1 : Recommended for developers
If you enabled timeline, then- Create
quit.html as
<html>
<body onLoad="window.close();">
</body>
</html> - Create a default profile say "Default User"
./mozilla -P 'Default User' file:///c:/tmp/quit.html > out 2>&1 (windows)
./mozilla -P "Default User" file:///usr/tmp/quit.html >& out (unix csh/tcsh)- Look for timing of main1 in the output. That is roughtly the
startuptime. Ignore first run and take average of 3 runs.
cvs co
mozilla/tools/performance/startup
cd mozilla/tools/performance/startup
perl measure-simple.pl ../../../dist/bin/mozilla
Method 2 : QA and tinderbox do this
cvs co mozilla/tools/performance/startup
cd mozilla/tools/performance/startup
startup-unix.pl ../../../dist/bin/mozilla -P "Default User"
(unix/win)
??? (mac)
Startup Performance Analysis
You could use many tools to analyze what is happening in startup.- Windows - Quantify, VTune
- Unix - Jprof, trace-malloc
- Mac - ???
Last Modified: Oct 12 2001