v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log-utils.h
Go to the documentation of this file.
1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_LOG_UTILS_H_
29 #define V8_LOG_UTILS_H_
30 
31 #include "allocation.h"
32 
33 namespace v8 {
34 namespace internal {
35 
36 class Logger;
37 
38 // Functions and data for performing output of log messages.
39 class Log {
40  public:
41  // Performs process-wide initialization.
42  void Initialize();
43 
44  // Disables logging, but preserves acquired resources.
45  void stop() { is_stopped_ = true; }
46 
47  // Frees all resources acquired in Initialize and Open... functions.
48  // When a temporary file is used for the log, returns its stream descriptor,
49  // leaving the file open.
50  FILE* Close();
51 
52  // Returns whether logging is enabled.
53  bool IsEnabled() {
54  return !is_stopped_ && output_handle_ != NULL;
55  }
56 
57  // Size of buffer used for formatting log messages.
58  static const int kMessageBufferSize = 2048;
59 
60  // This mode is only used in tests, as temporary files are automatically
61  // deleted on close and thus can't be accessed afterwards.
62  static const char* const kLogToTemporaryFile;
63 
64  private:
65  explicit Log(Logger* logger);
66 
67  // Opens stdout for logging.
68  void OpenStdout();
69 
70  // Opens file for logging.
71  void OpenFile(const char* name);
72 
73  // Opens a temporary file for logging.
74  void OpenTemporaryFile();
75 
76  // Implementation of writing to a log file.
77  int WriteToFile(const char* msg, int length) {
78  ASSERT(output_handle_ != NULL);
79  size_t rv = fwrite(msg, 1, length, output_handle_);
80  ASSERT(static_cast<size_t>(length) == rv);
81  USE(rv);
82  fflush(output_handle_);
83  return length;
84  }
85 
86  // Whether logging is stopped (e.g. due to insufficient resources).
87  bool is_stopped_;
88 
89  // When logging is active output_handle_ is used to store a pointer to log
90  // destination. mutex_ should be acquired before using output_handle_.
91  FILE* output_handle_;
92 
93  // Used when low-level profiling is active.
94  FILE* ll_output_handle_;
95 
96  // mutex_ is a Mutex used for enforcing exclusive
97  // access to the formatting buffer and the log file or log memory buffer.
98  Mutex* mutex_;
99 
100  // Buffer used for formatting log messages. This is a singleton buffer and
101  // mutex_ should be acquired before using it.
102  char* message_buffer_;
103 
104  Logger* logger_;
105 
106  friend class Logger;
107  friend class LogMessageBuilder;
108 };
109 
110 
111 // Utility class for formatting log messages. It fills the message into the
112 // static buffer in Log.
113 class LogMessageBuilder BASE_EMBEDDED {
114  public:
115  // Create a message builder starting from position 0. This acquires the mutex
116  // in the log as well.
117  explicit LogMessageBuilder(Logger* logger);
119 
120  // Append string data to the log message.
121  void Append(const char* format, ...);
122 
123  // Append string data to the log message.
124  void AppendVA(const char* format, va_list args);
125 
126  // Append a character to the log message.
127  void Append(const char c);
128 
129  // Append a heap string.
130  void Append(String* str);
131 
132  // Appends an address.
133  void AppendAddress(Address addr);
134 
135  void AppendDetailed(String* str, bool show_impl_info);
136 
137  // Append a portion of a string.
138  void AppendStringPart(const char* str, int len);
139 
140  // Write the log message to the log file currently opened.
141  void WriteToLogFile();
142 
143  private:
144  Log* log_;
145  ScopedLock sl;
146  int pos_;
147 };
148 
149 } } // namespace v8::internal
150 
151 #endif // V8_LOG_UTILS_H_
byte * Address
Definition: globals.h:157
static const char *const kLogToTemporaryFile
Definition: log-utils.h:62
#define ASSERT(condition)
Definition: checks.h:270
static const int kMessageBufferSize
Definition: log-utils.h:58
bool IsEnabled()
Definition: log-utils.h:53
friend class LogMessageBuilder
Definition: log-utils.h:107
void USE(T)
Definition: globals.h:289
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Definition: flags.cc:301