40 Log::Log(Logger* logger)
43 ll_output_handle_(
NULL),
45 message_buffer_(
NULL),
50 static void AddIsolateIdIfNeeded(StringStream* stream) {
51 Isolate* isolate = Isolate::Current();
52 if (isolate->IsDefaultIsolate())
return;
53 stream->Add(
"isolate-%p-", isolate);
63 FLAG_log_runtime =
true;
67 FLAG_log_suspect =
true;
68 FLAG_log_handles =
true;
69 FLAG_log_regexp =
true;
73 if (FLAG_prof) FLAG_log_code =
true;
77 FLAG_log_code =
false;
78 FLAG_prof_auto =
false;
81 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api
82 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
83 || FLAG_log_regexp || FLAG_log_state_changes || FLAG_ll_prof;
87 if (strcmp(FLAG_logfile,
"-") == 0) {
92 if (strchr(FLAG_logfile,
'%') !=
NULL ||
93 !Isolate::Current()->IsDefaultIsolate()) {
98 AddIsolateIdIfNeeded(&stream);
99 for (
const char* p = FLAG_logfile; *p; p++) {
131 OpenFile(FLAG_logfile);
138 void Log::OpenStdout() {
140 output_handle_ = stdout;
144 void Log::OpenTemporaryFile() {
151 static const char kLowLevelLogExt[] =
".ll";
155 static const int kLowLevelLogBufferSize = 2 *
MB;
158 void Log::OpenFile(
const char* name) {
163 size_t len = strlen(name);
164 ScopedVector<char> ll_name(static_cast<int>(len +
sizeof(kLowLevelLogExt)));
165 memcpy(ll_name.start(), name, len);
166 memcpy(ll_name.start() + len, kLowLevelLogExt,
sizeof(kLowLevelLogExt));
168 setvbuf(ll_output_handle_,
NULL, _IOFBF, kLowLevelLogBufferSize);
175 if (output_handle_ !=
NULL) {
177 fclose(output_handle_);
179 result = output_handle_;
182 output_handle_ =
NULL;
183 if (ll_output_handle_ !=
NULL) fclose(ll_output_handle_);
184 ll_output_handle_ =
NULL;
187 message_buffer_ =
NULL;
197 LogMessageBuilder::LogMessageBuilder(
Logger* logger)
198 : log_(logger->log_),
205 void LogMessageBuilder::Append(
const char* format, ...) {
206 Vector<char> buf(log_->message_buffer_ + pos_,
209 va_start(args, format);
210 AppendVA(format, args);
216 void LogMessageBuilder::AppendVA(
const char* format, va_list args) {
217 Vector<char> buf(log_->message_buffer_ + pos_,
231 void LogMessageBuilder::Append(
const char c) {
233 log_->message_buffer_[pos_++] = c;
239 void LogMessageBuilder::Append(String* str) {
240 AssertNoAllocation no_heap_allocation;
241 int length = str->length();
242 for (
int i = 0; i < length; i++) {
243 Append(static_cast<char>(str->Get(i)));
248 void LogMessageBuilder::AppendAddress(
Address addr) {
253 void LogMessageBuilder::AppendDetailed(String* str,
bool show_impl_info) {
254 if (str ==
NULL)
return;
255 AssertNoAllocation no_heap_allocation;
256 int len = str->length();
259 if (show_impl_info) {
260 Append(str->IsAsciiRepresentation() ?
'a' :
'2');
261 if (StringShape(str).IsExternal())
263 if (StringShape(str).IsSymbol())
265 Append(
":%i:", str->length());
267 for (
int i = 0; i < len; i++) {
268 uc32 c = str->Get(i);
270 Append(
"\\u%04x", c);
271 }
else if (c < 32 || c > 126) {
272 Append(
"\\x%02x", c);
273 }
else if (c ==
',') {
275 }
else if (c ==
'\\') {
277 }
else if (c ==
'\"') {
286 void LogMessageBuilder::AppendStringPart(
const char* str,
int len) {
290 if (len == 0)
return;
292 Vector<char> buf(log_->message_buffer_ + pos_,
300 void LogMessageBuilder::WriteToLogFile() {
302 const int written = log_->WriteToFile(log_->message_buffer_, pos_);
303 if (written != pos_) {
305 log_->logger_->LogFailure();
static int VSNPrintF(Vector< char > str, const char *format, va_list args)
static const char *const kLogToTemporaryFile
static FILE * OpenTemporaryFile()
#define ASSERT(condition)
void Add(Vector< const char > format, Vector< FmtElm > elms)
static FILE * FOpen(const char *path, const char *mode)
static const int kMessageBufferSize
static Mutex * CreateMutex()
static double TimeCurrentMillis()
activate correct semantics for inheriting readonliness false
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
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
SmartArrayPointer< const char > ToCString() const
void DeleteArray(T *array)
static const char *const LogFileOpenMode