chromium/third_party/google-closure-library/closure/goog/demos/tracer.html

<!DOCTYPE html>
<html>
<!--
Copyright The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>goog.debug.Tracer</title>
<script type="text/javascript" src="../base.js"></script>
<script type="text/javascript">
  goog.require('goog.debug.Trace');
</script>
<style class="text/css">
body {
  font: normal small arial,helvetica;
}


</style>
</head>
<body>

<div id="output" style="font-family:courier new,fixed">

</div>

<script type="text/javascript">
  function normalTracer() {
    goog.debug.Trace.initCurrentTrace(0);
    var tracer = goog.debug.Trace.startTracer('Outer Loop');
    var sum = 0;
    for (var i = 0; i < 15; i++) {
      sum = 0;
      var t2 = goog.debug.Trace.startTracer('Run ' + i);
      for (var j = 0; j < 50000; j++) {
        sum += j * i;
      }
      goog.debug.Trace.addComment('after');
      goog.debug.Trace.stopTracer(t2);
    }
    goog.debug.Trace.stopTracer(tracer);

    var s = goog.debug.Trace.toString();
    var outputElt = document.getElementById('output');
    outputElt.innerHTML = goog.string.whitespaceEscape(
        goog.string.htmlEscape(s));
  }

  function tooManyTracers() {
    goog.debug.Trace.initCurrentTrace(0);
    var tracer = goog.debug.Trace.startTracer('Outer Loop');
    var sum = 0;
    for (var i = 0; i < 1000; i++) {
      var t2 = goog.debug.Trace.startTracer('Run ' + i);
      goog.debug.Trace.stopTracer(t2);
    }
    goog.debug.Trace.stopTracer(tracer);

    var s = goog.debug.Trace.toString();
    var outputElt = document.getElementById('output');
    outputElt.innerHTML = goog.string.whitespaceEscape(
        goog.string.htmlEscape(s));
  }

  function unstoppedTracers() {
    goog.debug.Trace.initCurrentTrace(0);
    var tracer = goog.debug.Trace.startTracer('Outer Loop');
    var sum = 0;
    for (var i = 0; i < 10; i++) {
      var t2 = goog.debug.Trace.startTracer('Run ' + i);
      if (i != 5) {
        goog.debug.Trace.stopTracer(t2);
      }
    }
    goog.debug.Trace.stopTracer(tracer);

    var s = goog.debug.Trace.toString();
    var outputElt = document.getElementById('output');
    outputElt.innerHTML = goog.string.whitespaceEscape(
        goog.string.htmlEscape(s));
  }

  unstoppedTracers();

</script>



</body>
</html>