Javascript Profiling: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 7: Line 7:
== The Profiler object ==
== The Profiler object ==


There will be a global <tt>Profiler</tt> object available to instantiate to begin profiling other runtimes. For each of the methods below, if an optional 'obj' parameter is taken, that is the specification of what runtime to modify profiling of. If the object is specified, then the object's runtime is used. Otherwise if no object is specified, the current runtime is used. The <tt>Profiler</tt> object has the following methods:
There will be a global <tt>Profiler</tt> object available to instantiate to begin profiling the runtime in which the profiler was created in. The <tt>Profiler</tt> object has the following methods:


<dl>
<dl>
Line 13: Line 13:
<dd>The constructor takes no arguments
<dd>The constructor takes no arguments


<dt>start([obj, [sample_rate, [max_samples]]])
<dt>start([sample_rate, [max_samples]])
<dd>Begins profiling. All arguments are optional. If no object is specified, then the current runtime of execution will be profile. Otherwise the specified object's runtime will be profiled. If the object's runtime (or the current runtime if obj isn't provided) is already being profiled by this Profiler instance, an error is thrown.
<dd>Begins profiling. All arguments are optional. If the runtime is already being profiled an error is thrown.


The sample rate is the time between samples of the call stack specified in microseconds (defaults to 1000 = 1ms). The sample rate is mostly a guideline as the platform being run might not guarantee the granularity of timing. Samples will not happen more frequently than the specified rate, but may occur more infrequently.
The sample rate is the time between samples of the call stack specified in microseconds (defaults to 1000 = 1ms). The sample rate is mostly a guideline as the platform being run might not guarantee the granularity of timing. Samples will not happen more frequently than the specified rate, but may occur more infrequently.
Line 21: Line 21:


If some other Profiler object is profiling the specified runtime, then an error is thrown if the sample rate or maximum sample count is different. Eventually a call to stopProfiling() must be paired with this call to cease data collection.
If some other Profiler object is profiling the specified runtime, then an error is thrown if the sample rate or maximum sample count is different. Eventually a call to stopProfiling() must be paired with this call to cease data collection.
<dt>isProfiling([obj])
<dt>isProfiling()
<dd>Returns whether profiling is turned on for the specified runtime
<dd>Returns whether profiling is turned on for the runtime
<dt>frame()
<dt>frame()
<dd>Fetches an object to represent the current stack trace to be later returned via results(). This object can have any properties attached to it and will persist across different invocations of frame() so long as the same backtrace is present each time. All information specified here will later be available via results() with the full backtrace listed. By default this returns an empty object with no properties. If the current runtime is not being profiled, then an error is thrown.
<dd>Fetches an object to represent the current stack trace to be later returned via results(). This object can have any properties attached to it and will persist across different invocations of frame() so long as the same backtrace is present each time. All information specified here will later be available via results() with the full backtrace listed. By default this returns an empty object with no properties. If the current runtime is not being profiled, then an error is thrown.
<dt>results([obj])
<dt>results()
<dd>Returns all profile information for the specified object's runtime. The data returned is all that is collected between the last invocation of reset() and all the profile data.
<dd>Returns all profile information for the runtime. The data returned is all that is collected between the last invocation of reset() and all the profile data.
<dt>reset([obj])
<dt>reset()
<dd>Resets all information known about the specified runtime. This includes samples and also frame() information. Throws an error if the runtime in question isn't being profiled.
<dd>Resets all information known about the runtime. This includes samples and also frame() information. Throws an error if the runtime in question isn't being profiled.
<dt>stop([obj])
<dt>stop()
<dd>Ceases profiling on the specified runtime. If the runtime in question isn't being profiled, an error is thrown.
<dd>Ceases profiling on the runtime. If the runtime in question isn't being profiled, an error is thrown.


</dl>
</dl>
22

edits

Navigation menu