v8  3.25.30(node0.11.13)
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(const char* log_file_name);
43 
44  // Disables logging, but preserves acquired resources.
45  void stop() { is_stopped_ = true; }
46 
47  static bool InitLogAtStart() {
48  return FLAG_log || FLAG_log_runtime || FLAG_log_api
49  || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
50  || FLAG_log_regexp || FLAG_ll_prof || FLAG_perf_basic_prof
51  || FLAG_perf_jit_prof || FLAG_log_internal_timer_events;
52  }
53 
54  // Frees all resources acquired in Initialize and Open... functions.
55  // When a temporary file is used for the log, returns its stream descriptor,
56  // leaving the file open.
57  FILE* Close();
58 
59  // Returns whether logging is enabled.
60  bool IsEnabled() {
61  return !is_stopped_ && output_handle_ != NULL;
62  }
63 
64  // Size of buffer used for formatting log messages.
65  static const int kMessageBufferSize = 2048;
66 
67  // This mode is only used in tests, as temporary files are automatically
68  // deleted on close and thus can't be accessed afterwards.
69  static const char* const kLogToTemporaryFile;
70  static const char* const kLogToConsole;
71 
72  // Utility class for formatting log messages. It fills the message into the
73  // static buffer in Log.
74  class MessageBuilder BASE_EMBEDDED {
75  public:
76  // Create a message builder starting from position 0.
77  // This acquires the mutex in the log as well.
78  explicit MessageBuilder(Log* log);
80 
81  // Append string data to the log message.
82  void Append(const char* format, ...);
83 
84  // Append string data to the log message.
85  void AppendVA(const char* format, va_list args);
86 
87  // Append a character to the log message.
88  void Append(const char c);
89 
90  // Append double quoted string to the log message.
91  void AppendDoubleQuotedString(const char* string);
92 
93  // Append a heap string.
94  void Append(String* str);
95 
96  // Appends an address.
97  void AppendAddress(Address addr);
98 
99  void AppendSymbolName(Symbol* symbol);
100 
101  void AppendDetailed(String* str, bool show_impl_info);
102 
103  // Append a portion of a string.
104  void AppendStringPart(const char* str, int len);
105 
106  // Write the log message to the log file currently opened.
107  void WriteToLogFile();
108 
109  private:
110  Log* log_;
111  LockGuard<Mutex> lock_guard_;
112  int pos_;
113  };
114 
115  private:
116  explicit Log(Logger* logger);
117 
118  // Opens stdout for logging.
119  void OpenStdout();
120 
121  // Opens file for logging.
122  void OpenFile(const char* name);
123 
124  // Opens a temporary file for logging.
125  void OpenTemporaryFile();
126 
127  // Implementation of writing to a log file.
128  int WriteToFile(const char* msg, int length) {
129  ASSERT(output_handle_ != NULL);
130  size_t rv = fwrite(msg, 1, length, output_handle_);
131  ASSERT(static_cast<size_t>(length) == rv);
132  USE(rv);
133  fflush(output_handle_);
134  return length;
135  }
136 
137  // Whether logging is stopped (e.g. due to insufficient resources).
138  bool is_stopped_;
139 
140  // When logging is active output_handle_ is used to store a pointer to log
141  // destination. mutex_ should be acquired before using output_handle_.
142  FILE* output_handle_;
143 
144  // mutex_ is a Mutex used for enforcing exclusive
145  // access to the formatting buffer and the log file or log memory buffer.
146  Mutex mutex_;
147 
148  // Buffer used for formatting log messages. This is a singleton buffer and
149  // mutex_ should be acquired before using it.
150  char* message_buffer_;
151 
152  Logger* logger_;
153 
154  friend class Logger;
155 };
156 
157 
158 } } // namespace v8::internal
159 
160 #endif // V8_LOG_UTILS_H_
byte * Address
Definition: globals.h:186
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
static const char *const kLogToConsole
Definition: log-utils.h:70
static const char *const kLogToTemporaryFile
Definition: log-utils.h:69
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including on console Map counters to a file Enable debugger compile events enable GDBJIT enable GDBJIT interface for all code objects dump only objects containing this substring stress the GC compactor to flush out pretty print source code print source AST function name where to insert a breakpoint print scopes for builtins trace contexts operations print stuff during garbage collection report code statistics after GC report handles after GC trace cache state transitions print interface inference details prints when objects are turned into dictionaries report heap spill statistics along with trace isolate state changes trace regexp bytecode execution Minimal Log all events to the log file Log API events to the log file Log heap samples on garbage collection for the hp2ps tool log positions Log suspect operations Used with turns on browser compatible mode for profiling v8 log
Definition: flags.cc:806
static bool InitLogAtStart()
Definition: log-utils.h:47
#define ASSERT(condition)
Definition: checks.h:329
FILE * Close()
Definition: log-utils.cc:98
static const int kMessageBufferSize
Definition: log-utils.h:65
bool IsEnabled()
Definition: log-utils.h:60
void USE(T)
Definition: globals.h:341
friend class Logger
Definition: log-utils.h:154
void Initialize(const char *log_file_name)
Definition: log-utils.cc:49
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505