22
edits
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
There will be a global <tt>Profiler</tt> object available to instantiate to begin profiling other objects. The <tt>Profiler</tt> object has the following methods: | There will be a global <tt>Profiler</tt> object available to instantiate to begin profiling other objects. The <tt>Profiler</tt> object has the following methods: | ||
* <tt> | * <tt>new Profiler()</tt> - constructor takes no arguments, creates an instance for the invoking context. | ||
* <tt> | * <tt>startProfiling : context → unit</tt> - Starts profiling the specified context. If the context is currently being profiled by another <tt>Profiler</tt> instance (including this one), then an error is thrown. | ||
* <tt>info : context → | * <tt>isProfiling : context → bool</tt> - Returns whether the specified context is being profiled or not by this instance. | ||
* <tt> | * <tt>event : object → unit</tt> - Records a profiling event for the current context. The event is an object which will eventually be returned in a <tt>Profiler.Stack</tt> object queued up in the <tt>events</tt> field. If the current context is not being profiled by this instance, then an error is thrown. | ||
* <tt>info : context → Profiler.Stack list</tt> - Fetches information about a context which is being profiled. Throws an error if the context provided isn't being profiled by this <tt>Profiler</tt> instance. | |||
* <tt>stopProfiling : context → Profiler.Stack list</tt> - Ceases profiling the specified context. Returns the same information that <tt>info</tt> returns. Throws an error if the context is not being profiled by this instance. | |||
Possibly have attributes or methods to enable/disable profiling specific attributes? (custom/memory/time/etc.) | |||
A <tt> | == The <tt>Profiler.Stack</tt> object == | ||
A <tt>Profiler.Stack</tt> object represents an event at a particular stack trace. A stack trace is defined by an ordered list of <tt><url, line></tt> pairs where the <tt>url</tt> is the source file of the function and <tt>line</tt> is the line number within the source file. The object would look similarly as follows: | |||
{ | { | ||
| Line 37: | Line 40: | ||
} | } | ||
The <tt>stack</tt> field is the actual stack trace this represents, and the first element is the function which triggered the events, and the subsequent elements are the callers of the previous element. The <tt>events</tt> field is a list of all events related to this stack trace. Events are added internally, but custom events can also be added via <tt> | The <tt>stack</tt> field is the actual stack trace this represents, and the first element is the function which triggered the events, and the subsequent elements are the callers of the previous element. The <tt>events</tt> field is a list of all events related to this stack trace. Events are added internally, but custom events can also be added via <tt>event</tt>. | ||
Possibly events would also be filtered out? This is more relevant to instrumented C++ functions, I would imagine that all JS events would be public to all <tt>Profiler</tt>s | Possibly events would also be filtered out? This is more relevant to instrumented C++ functions, I would imagine that all JS events would be public to all <tt>Profiler</tt>s | ||
== Use Cases == | == Use Cases == | ||
Here's some example use cases for when profiling is wanted and how they would use the API provided above. | Here's some example use cases for when profiling is wanted and how they would use the API provided above. | ||
=== Test Cases === | === Test Cases === | ||
The test suite would initially create a <tt>Profiler</tt> object and then start/stop profiling the current page on each call to <tt>startProfiling</tt>/<tt>stopProfiling</tt> and the information returned from <tt>stopProfiling</tt> would be what is displayed. | |||
=== Extension === | === Extension === | ||
Opened on a page and creates its own <tt>Profiler</tt> object. It then | Opened on a page and creates its own <tt>Profiler</tt> object. It then profiles the current page via <tt>startProfiling</tt> (probably a button to be hit). Some time later <tt>stopProfiling</tt> is used to get information about the run of profiling (again probably a button being hit) and then all of the information is sorted through and displayed in some fancy fashion. | ||
The page being profiled is unaware that it's being profiled, and there's nothing that it needs to do to help it along. If it so desires, it could conditionally call <tt>profilee.event()</tt> to learn some interesting information. | The page being profiled is unaware that it's being profiled, and there's nothing that it needs to do to help it along. If it so desires, it could conditionally call <tt>profilee.event()</tt> to learn some interesting information. | ||
= Implementation = | = Implementation = | ||
edits