Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

YUI Library: ProfilerViewer Control 2008-02-19 v2.

5
Simple Use Case: Profiling an Object Key ProfilerViewer Configuration Options YAHOO.widget.
Field Type Description
ProfilerViewer Properties
//assuming you have an object with functions called
“myObject”: base string Path to your YUI base directory, to be used by YUI STRINGS static member containing
strings used in the UI; see API docs
YAHOO.tool.Profiler.registerObject("myObject", Loader in pulling in dependencies on-demand. for the format of this object and
myObject); //see Profiler docs for more on how Default: YUI files will be served from examples for how to use this object to
//to set up your code profiles. yui.yahooapis.com. internationalize your ProfilerViewer
console.
var pv = new YAHOO.widget.ProfilerViewer(“myEl”); filter function The filter used by ProfilerViewer in determining which
profilerd functions to show in the display. See
This code tells the Profiler to profile myObject and tells ProfilerViewer to
Solutions below for more. YAHOO.widget.
create a viewer display in the DOM element whose id is myEl. ProfilerViewer Methods
maxChart string The maximum number of functions to profile in the
ProfilerViewer will show all profiled functions; use the filter attribute to
Functions Chart display. Default: 6. getBodyEl() returns the element
limit a viewer instance to a subset of profiled functions. Upon
showChart boolean Determines whether or not the Chart Control should containing the console body (chart
instantiation, the ProfilerViewer launcher is rendered: and table)
be used to visualize profiling data. Default: true.
getChart() returns the Chart Control
sortedBy object {key: string, dir: string} The default sort instance (if present)
column and direction for data in the DataTable. Valid getChartEl() returns the element
Once the View Profiler Data button is clicked, ProflierViewer will load the keys are: fn, calls, avg, min, max, total, pct. Valid dir containing the Chart Control and
legend
DataTable and Charts controls and display the viewing console. A values are: YAHOO.widget.DataTable.CLASS_ASC
getDataTable() returns the DataTable
ProfilerViewer console with default options will look like this: and YAHOO.widget.DataTable.CLASS_DESC. Control instance
swfUrl string Relative path or url to the YUI Charts Control .swf file. getHeadEl() returns the element
Defaults to current version hosted on containing console header and
buttons
yui.yahooapis.com. getTableEl() returns the element
tableHeight string Height of the DataTable portion of the console. containing DataTable’s DOM
Default: “15em”. structure.
visible boolean If true, the ProfilerViewer Console will render refreshData() programmatically
refreshes the data in the console
immediately upon instantiation. Otherwise, just the
launcher will render initially. Default: false.
Configuration options should be set in the second argument of the constructor: Dependencies
var pv = new YAHOO.widget.ProfilerViewer(“myEl”, {visible:true});.
The ProfilerViewer Control
Key Interesting Moments in ProfilerViewer requires the YUI Loader
(which includes the Yahoo
Event Description/Fields: Global Object and the Get
renderEvent Event fires when the viewer canvas first renders. No Utiltiy), Dom Collection,
arguments passed. Event Utility, Profiler, and
refreshDataEvent Event fires when a data refresh is requested through the UI Element Utility. (The
or programmatically. DataTable Control and
sortedByChange Event fires when the DataTable is resorted. Argument: Charts Control are brought
{newValue: new value, oldValue: old value}. in dynamically by YUI
visibleChange Event fires when the viewer console is shown/hidden. Loader when the
Argument: {newValue: new value, oldValue: old value} ProfilerViewer UI is first
made visible.)
Constructor: YAHOO.widget.ProfilerViewer Subscribe: pv.subscribe(“visibleChange”, function(o){});.

YAHOO.widget.ProfilerViewer([str | obj container, obj Solutions:


configuration])
Configure ProfilerViewer to not use the Charts Control:
Arguments:
(1) Container: (Optional) A reference to a DOM element (by ID or direct var pv = new YAHOO.widget.ProfilerViewer(“myEl”,
reference) that will contain the ProfilerViewer display. For best showChart: false);
results, us an element with at least 750px of viewable width. If no Use a filter function to only display profiling data for functions that have been
element is passed, a new element will be created as the first child of called at least once:
the <body> element.
(2) Configuration: (Optional) An optional object containing your desired var pv = new YAHOO.widget.ProfilerViewer(“myEl”,
configuration options. See Configuration Options section for details. filter: function(o) {return o.calls > 0;}
);

You might also like