LCOV - code coverage report
Current view: directory - js/src/methodjit - Logging.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 57 14 24.6 %
Date: 2012-06-02 Functions: 5 3 60.0 %

       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                 : 
      41                 : #include <stdlib.h>
      42                 : #include <stdio.h>
      43                 : #include <stdarg.h>
      44                 : #include <string.h>
      45                 : #include "jsutil.h"
      46                 : #include "MethodJIT.h"
      47                 : #include "Logging.h"
      48                 : 
      49                 : #include "jsobjinlines.h"
      50                 : 
      51                 : #if defined(JS_METHODJIT_SPEW)
      52                 : 
      53                 : static bool LoggingChecked = false;
      54                 : static uint32_t LoggingBits = 0;
      55                 : 
      56                 : static const char *ChannelNames[] =
      57                 : {
      58                 : #define _(name) #name,
      59                 :     JSPEW_CHAN_MAP(_)
      60                 : #undef  _
      61                 : };
      62                 : 
      63                 : void
      64         5460398 : js::JMCheckLogging()
      65                 : {
      66                 :     /* Not MT safe; races on Logging{Checked,Bits}. */
      67         5460398 :     if (LoggingChecked)
      68         5440587 :         return;
      69           19811 :     LoggingChecked = true;
      70           19811 :     const char *env = getenv("JMFLAGS");
      71           19811 :     if (!env)
      72           19811 :         return;
      73               0 :     if (strstr(env, "help")) {
      74               0 :         fflush(NULL);
      75                 :         printf(
      76                 :             "\n"
      77                 :             "usage: JMFLAGS=option,option,option,... where options can be:\n"
      78                 :             "\n"
      79                 :             "  help          show this message\n"
      80                 :             "  abort/aborts  ???\n"
      81                 :             "  scripts       ???\n"
      82                 :             "  profile       ???\n"
      83                 : #ifdef DEBUG
      84                 :             "  pcprofile     Runtime hit counts of every JS opcode executed\n"
      85                 :             "  jsops         JS opcodes\n"
      86                 : #endif
      87                 :             "  insns         JS opcodes and generated insns\n"
      88                 :             "  vmframe       VMFrame contents\n"
      89                 :             "  pics          PIC patching activity\n"
      90                 :             "  slowcalls     Calls to slow path functions\n"
      91                 :             "  analysis      LICM and other analysis behavior\n"
      92                 :             "  regalloc      Register allocation behavior\n"
      93                 :             "  inlin         Call inlining behavior\n"
      94                 :             "  recompile     Dynamic recompilations\n"
      95                 :             "  full          everything not affecting codegen\n"
      96                 :             "\n"
      97               0 :         );
      98               0 :         exit(0);
      99                 :         /*NOTREACHED*/
     100                 :     }
     101               0 :     if (strstr(env, "abort") || strstr(env, "aborts"))
     102               0 :         LoggingBits |= (1 << uint32_t(JSpew_Abort));
     103               0 :     if (strstr(env, "scripts"))
     104               0 :         LoggingBits |= (1 << uint32_t(JSpew_Scripts));
     105               0 :     if (strstr(env, "profile"))
     106               0 :         LoggingBits |= (1 << uint32_t(JSpew_Prof));
     107                 : #ifdef DEBUG
     108               0 :     if (strstr(env, "jsops"))
     109               0 :         LoggingBits |= (1 << uint32_t(JSpew_JSOps));
     110                 : #endif
     111               0 :     if (strstr(env, "insns"))
     112               0 :         LoggingBits |= (1 << uint32_t(JSpew_Insns) | (1 << uint32_t(JSpew_JSOps)));
     113               0 :     if (strstr(env, "vmframe"))
     114               0 :         LoggingBits |= (1 << uint32_t(JSpew_VMFrame));
     115               0 :     if (strstr(env, "pics"))
     116               0 :         LoggingBits |= (1 << uint32_t(JSpew_PICs));
     117               0 :     if (strstr(env, "slowcalls"))
     118               0 :         LoggingBits |= (1 << uint32_t(JSpew_SlowCalls));
     119               0 :     if (strstr(env, "analysis"))
     120               0 :         LoggingBits |= (1 << uint32_t(JSpew_Analysis));
     121               0 :     if (strstr(env, "regalloc"))
     122               0 :         LoggingBits |= (1 << uint32_t(JSpew_Regalloc));
     123               0 :     if (strstr(env, "recompile"))
     124               0 :         LoggingBits |= (1 << uint32_t(JSpew_Recompile));
     125               0 :     if (strstr(env, "inlin"))
     126               0 :         LoggingBits |= (1 << uint32_t(JSpew_Inlining));
     127               0 :     if (strstr(env, "full"))
     128               0 :         LoggingBits |= 0xFFFFFFFF;
     129                 : }
     130                 : 
     131               0 : js::ConditionalLog::ConditionalLog(bool logging)
     132               0 :     : oldBits(LoggingBits), logging(logging)
     133                 : {
     134               0 :     if (logging)
     135               0 :         LoggingBits = 0xFFFFFFFF;
     136               0 : }
     137                 : 
     138               0 : js::ConditionalLog::~ConditionalLog() {
     139               0 :     if (logging)
     140               0 :         LoggingBits = oldBits;
     141               0 : }
     142                 : 
     143                 : bool
     144         9119247 : js::IsJaegerSpewChannelActive(JaegerSpewChannel channel)
     145                 : {
     146         9119247 :     JS_ASSERT(LoggingChecked);
     147         9119247 :     return !!(LoggingBits & (1 << uint32_t(channel)));
     148                 : }
     149                 : 
     150                 : void
     151       270029038 : js::JaegerSpew(JaegerSpewChannel channel, const char *fmt, ...)
     152                 : {
     153       270029038 :     JS_ASSERT(LoggingChecked);
     154                 : 
     155       270029038 :     if (!(LoggingBits & (1 << uint32_t(channel))))
     156       270029038 :         return;
     157                 : 
     158               0 :     fprintf(stderr, "[jaeger] %-7s  ", ChannelNames[channel]);
     159                 : 
     160                 :     va_list ap;
     161               0 :     va_start(ap, fmt);
     162               0 :     vfprintf(stderr, fmt, ap);
     163               0 :     va_end(ap);
     164                 : 
     165                 :     /* fprintf(stdout, "\n"); */
     166                 : }
     167                 : 
     168                 : #endif
     169                 : 

Generated by: LCOV version 1.7