Yahoo! Developer Network Home - Help

YUI Library Examples: Profiler (beta): Object Profiling Example

Profiler (beta): Object Profiling Example

This example shows using the Profiler on all methods in an object. It uses the YAHOO.util.Dom object as the object to be profiled.

Note:

Keep an eye on the Logger console at right to see the profiling information being reported.

div class="bar"
div class="bar-baz"
div class="bar "
div class=" bar "
div class=" bar baz"
div class=" bar2 baz"
div class="foo"
div class="foo" id="bar"
div class="foo bar baz"

p class="bar"

Object Profiling Example

To illustrate using the Profiler on objects, the YAHOO.util.Dom object is registered for profiling. This means that all of the methods on the object are being profiled. The two methods being called explicity are getElementsByClassName() and addClass(), although the Profiler will show that these methods use other methods on YAHOO.util.Dom. To illustrate their use, a number of demo elements are added to the markup:

The button is used to run the example. The function being called when the button is clicked is assigned using the YUI Event Utility's on() method:

The function begins be registering YAHOO.util.Dom with the Profiler. Note that since this object exists in the global scope, only one argument is necessary for registerObject(). Then, the getElementsByClassName() and addClass() methods are called. After that, the full report is returned and the object is unregistered. The last step is to output all of the information that was collected. Even though there's only two methods called explicitly in this example, the profiled data indicates that several other methods on YAHOO.util.Dom were called internally to accomplish the tasks.

YUI Logger Output:

More Profiler (beta) Resources:

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings