aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/tracer.html
blob: b145353417f44de44a31e8a95bb16164c2728fad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<!--
Copyright 2010 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>