tracer.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.debug.Tracer</title>
  10. <script type="text/javascript" src="../base.js"></script>
  11. <script type="text/javascript">
  12. goog.require('goog.debug.Trace');
  13. </script>
  14. <style class="text/css">
  15. body {
  16. font: normal small arial,helvetica;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="output" style="font-family:courier new,fixed">
  22. </div>
  23. <script type="text/javascript">
  24. function normalTracer() {
  25. goog.debug.Trace.initCurrentTrace(0);
  26. var tracer = goog.debug.Trace.startTracer('Outer Loop');
  27. var sum = 0;
  28. for (var i = 0; i < 15; i++) {
  29. sum = 0;
  30. var t2 = goog.debug.Trace.startTracer('Run ' + i);
  31. for (var j = 0; j < 50000; j++) {
  32. sum += j * i;
  33. }
  34. goog.debug.Trace.addComment('after');
  35. goog.debug.Trace.stopTracer(t2);
  36. }
  37. goog.debug.Trace.stopTracer(tracer);
  38. var s = goog.debug.Trace.toString();
  39. var outputElt = document.getElementById('output');
  40. outputElt.innerHTML = goog.string.whitespaceEscape(
  41. goog.string.htmlEscape(s));
  42. }
  43. function tooManyTracers() {
  44. goog.debug.Trace.initCurrentTrace(0);
  45. var tracer = goog.debug.Trace.startTracer('Outer Loop');
  46. var sum = 0;
  47. for (var i = 0; i < 1000; i++) {
  48. var t2 = goog.debug.Trace.startTracer('Run ' + i);
  49. goog.debug.Trace.stopTracer(t2);
  50. }
  51. goog.debug.Trace.stopTracer(tracer);
  52. var s = goog.debug.Trace.toString();
  53. var outputElt = document.getElementById('output');
  54. outputElt.innerHTML = goog.string.whitespaceEscape(
  55. goog.string.htmlEscape(s));
  56. }
  57. function unstoppedTracers() {
  58. goog.debug.Trace.initCurrentTrace(0);
  59. var tracer = goog.debug.Trace.startTracer('Outer Loop');
  60. var sum = 0;
  61. for (var i = 0; i < 10; i++) {
  62. var t2 = goog.debug.Trace.startTracer('Run ' + i);
  63. if (i != 5) {
  64. goog.debug.Trace.stopTracer(t2);
  65. }
  66. }
  67. goog.debug.Trace.stopTracer(tracer);
  68. var s = goog.debug.Trace.toString();
  69. var outputElt = document.getElementById('output');
  70. outputElt.innerHTML = goog.string.whitespaceEscape(
  71. goog.string.htmlEscape(s));
  72. }
  73. unstoppedTracers();
  74. </script>
  75. </body>
  76. </html>