/js/src/methodjit/Logging.h

http://github.com/zpao/v8monkey · C Header · 132 lines · 69 code · 24 blank · 39 comment · 2 complexity · b0cdc6a162c4b52da37cbd9a82f5d9b4 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=4 sw=4 et tw=99:
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
  18. * May 28, 2008.
  19. *
  20. * The Initial Developer of the Original Code is
  21. * Brendan Eich <brendan@mozilla.org>
  22. *
  23. * Contributor(s):
  24. * David Anderson <danderson@mozilla.com>
  25. * Julian Seward <jseward@acm.org>
  26. *
  27. * Alternatively, the contents of this file may be used under the terms of
  28. * either of the GNU General Public License Version 2 or later (the "GPL"),
  29. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30. * in which case the provisions of the GPL or the LGPL are applicable instead
  31. * of those above. If you wish to allow use of your version of this file only
  32. * under the terms of either the GPL or the LGPL, and not to allow others to
  33. * use your version of this file under the terms of the MPL, indicate your
  34. * decision by deleting the provisions above and replace them with the notice
  35. * and other provisions required by the GPL or the LGPL. If you do not delete
  36. * the provisions above, a recipient may use your version of this file under
  37. * the terms of any one of the MPL, the GPL or the LGPL.
  38. *
  39. * ***** END LICENSE BLOCK ***** */
  40. #if !defined jsjaeger_logging_h__
  41. #define jsjaeger_logging_h__
  42. #include "assembler/wtf/Platform.h"
  43. #include "prmjtime.h"
  44. #if defined(JS_METHODJIT) || ENABLE_YARR_JIT
  45. namespace js {
  46. #define JSPEW_CHAN_MAP(_) \
  47. _(Abort) \
  48. _(Scripts) \
  49. _(Prof) \
  50. _(JSOps) \
  51. _(Insns) \
  52. _(VMFrame) \
  53. _(PICs) \
  54. _(SlowCalls) \
  55. _(Analysis) \
  56. _(Regalloc) \
  57. _(Inlining) \
  58. _(Recompile)
  59. enum JaegerSpewChannel {
  60. #define _(name) JSpew_##name,
  61. JSPEW_CHAN_MAP(_)
  62. #undef _
  63. JSpew_Terminator
  64. };
  65. #if defined(DEBUG) && !defined(JS_METHODJIT_SPEW)
  66. # define JS_METHODJIT_SPEW
  67. #endif
  68. #if defined(JS_METHODJIT_SPEW)
  69. void JMCheckLogging();
  70. struct ConditionalLog {
  71. uint32_t oldBits;
  72. bool logging;
  73. ConditionalLog(bool logging);
  74. ~ConditionalLog();
  75. };
  76. bool IsJaegerSpewChannelActive(JaegerSpewChannel channel);
  77. #ifdef __GNUC__
  78. void JaegerSpew(JaegerSpewChannel channel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
  79. #else
  80. void JaegerSpew(JaegerSpewChannel channel, const char *fmt, ...);
  81. #endif
  82. struct Profiler {
  83. int64_t t_start;
  84. int64_t t_stop;
  85. static inline int64_t now() {
  86. return PRMJ_Now();
  87. }
  88. inline void start() {
  89. t_start = now();
  90. }
  91. inline void stop() {
  92. t_stop = now();
  93. }
  94. inline uint32_t time_ms() {
  95. return uint32_t((t_stop - t_start) / PRMJ_USEC_PER_MSEC);
  96. }
  97. inline uint32_t time_us() {
  98. return uint32_t(t_stop - t_start);
  99. }
  100. };
  101. #else
  102. static inline void JaegerSpew(JaegerSpewChannel channel, const char *fmt, ...)
  103. {
  104. }
  105. #endif
  106. }
  107. #endif
  108. #endif