Main Page

Profiling

Adding a watch adds a variable into the Watches view. The Watches view behaves in the exact same way
as the Local Variables view, displaying the value of each variable when available and enumerating all
properties of each object.
Profiling
One of the unique features of Venkman is its profiling capability. If you turn on profiling, Venkman
begins keeping track of each function, how many times it’s called, and how long each call takes.
You can turn profiling on and off by clicking the Profile button on the toolbar. A green checkmark
appears on the Profile button when Venkman is profiling; no checkmark appears when it is not profiling.
After Venkman is in profiling mode, run your script. When you are satisfied with your tests, select
Profile
?
Save Profile Data As. You are presented with a Save File dialog where you can save the profile
data to view later.
By default, the dialog suggests you save the file in HTML format. This is a bug; you should save the file
as plain text.
When you profile your script, each function gets a section in the file that looks like this:
<file:/C:/Chapter%2014/Examples/ThrowExample.htm>
ThrowExample.htm: 1000 - 5000 milliseconds
Function Name: addTwoNumbers (Lines 5 - 10)
Total Calls: 1 (max recurse 0)
Total Time: 4696.75 (min/max/avg 4696.75/4696.75/4696.75)
Each section begins with the location of the file containing the function and is followed by each function
contained in the file. Each function is displayed with the following:
?
The lines it appears on
?
The total number of calls to the function and the maximum recursion level reached (identified
by
max recurse
)
?
The total amount of time (in milliseconds) it took to run the function along with the minimum
time for a call, the maximum time for a call, and the average time for a call
This information is incredibly useful for detecting bottlenecks in your code.
Unfortunately, the profile data includes data about the browser and debugger itself, so you need to read
through it all to get to the information you want.
Watches in Venkman are tied to variable names, not directly to variables, so if you
have two variables with the same name in different scopes, both of their values are
displayed in the Watches view when appropriate.
442
Chapter 14
17_579088 ch14.qxd 3/28/05 11:41 AM Page 442


JavaScript EditorFree JavaScript Editor     Ajax Editor


©