Javascript Profiling: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 15: Line 15:
<dd>The constructor takes no arguments
<dd>The constructor takes no arguments


<dt>startProfiling(object)
<dt>startProfiling()
<dd>Starts profiling the specified object's global's scripts. If the object's global is currently being profiled this instance, then an error is thrown.
<dd>Ensures that profiling has started. If some other Profiler has started profiling, this is a no-op. If startProfiling() is invoked, an eventual stopProfiling() must be paired to cease profiling data collection.
<dt>isProfiling(object)
<dt>isProfiling()
<dd>Returns whether the specified object's global is being profiled or not by this instance.
<dd>Returns whether profiling is turned on by any Profiler objects
<dt>frame()
<dt>frame()
<dd>Fetch the current object instance representing the current stack trace of invocation for the invoking context's global. Properties can be added to this object and will be persisted across invocations of this method so long as each invocation has the same backtrace. If the invoking context's global is not being profiled by the <tt>Profiler</tt> instance, then an error is thrown
<dd>Fetch the current object instance representing the current stack trace of invocation for the invoking context's global. Properties can be added to this object and will be persisted across invocations of this method so long as each invocation has the same backtrace. If the invoking context's global is not being profiled by the <tt>Profiler</tt> instance, then an error is thrown
<dt>info(object)
<dt>info()
<dd>Returns all information profiled for the object's global given. The format of the information is described below
<dd>Returns all profile information for the past XXX seconds. Data is stored in a circular fashion, so only the most recent data will be available.
<dt>clearInfo(object)
<dt>clearInfo()
<dd>Removes all known frame instances for the given object's global. Throws an error if the global is not being profiled
<dd>Removes all information stored in profiling.
<dt>stopProfiling(object)
<dt>stopProfiling()
<dd>Ceases profiling the specified object's global. Throws an error if the global is not being profiled.
<dd>Ceases profiling. This must only be called if a pairing call to startProfiling() has been made.


</dl>
</dl>
Line 119: Line 119:
* Biased, operational callbacks are only invoked at particular points in the code, so true line-by-line sampling is impossible. It is possible with signal-based sampling, but that has a large number of other issues with it.
* Biased, operational callbacks are only invoked at particular points in the code, so true line-by-line sampling is impossible. It is possible with signal-based sampling, but that has a large number of other issues with it.
* Might still require some wonky code maybe? Not quite sure about this...
* Might still require some wonky code maybe? Not quite sure about this...
==== Pseudocode ====
def Profiler.startProfiling(object)             
  compartment = object.root.compartment         
  compartment.setOperationCallback(sample, FREQ)
  compartment.root_node = {}                   
                                                 
def Profiler.isProfiling(object) ...           
                                                 
def Profiler.stopProfling(object)               
  compartment = object.root.compartment         
  compartment.removeOperationCallback(sample)   
                                                 
def Profiler.frame(object)                     
  compartment = object.root.compartment         
  node = compartment.root_node                 
  for (frame in compartment.js_stack)           
    if (node[frame] == NULL)                   
      node[frame] = new node(parent=node)       
    node = node[frame.script]                   
  return node                                   
                                                 
def Profiler.info(object)                       
  return object.root.compartment.root_node     
                                                 
def Profiler.clearInfo(object)                 
  object.root.compartment.root_node.clear()     
                                                 
def Profiler.sample():                         
  compartment = this.upvalues.compartment       
  node = compartment.root_node                 
  for (frame in compartment.js_stack)           
    node2 = node[frame.str]                     
    if (node == NULL)                           
      node2 = new node(parent=node)             
      node[frame.str] = node2                   
    node = node2                               
    node.ticks++                               
    if (frame == compartment.js_stack.top)     
      node.self_ticks++                         


=== Choice ===
=== Choice ===
22

edits

Navigation menu