OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 #ifdef ENABLE_LOGGING_AND_PROFILING | 262 #ifdef ENABLE_LOGGING_AND_PROFILING |
263 // Utility class for formatting log messages. It fills the message into the | 263 // Utility class for formatting log messages. It fills the message into the |
264 // static buffer in Logger. | 264 // static buffer in Logger. |
265 class LogMessageBuilder BASE_EMBEDDED { | 265 class LogMessageBuilder BASE_EMBEDDED { |
266 public: | 266 public: |
267 explicit LogMessageBuilder(); | 267 explicit LogMessageBuilder(); |
268 ~LogMessageBuilder() { } | 268 ~LogMessageBuilder() { } |
269 | 269 |
270 void Append(const char* format, ...); | 270 void Append(const char* format, ...); |
| 271 void Append(const char* format, va_list args); |
271 void Append(const char c); | 272 void Append(const char c); |
| 273 void Append(String *str); |
| 274 void AppendDetailed(String* str, bool show_impl_info); |
272 | 275 |
273 void WriteToLogFile(); | 276 void WriteToLogFile(); |
274 | 277 |
275 private: | 278 private: |
276 ScopedLock sl; | 279 ScopedLock sl; |
277 int pos_; | 280 int pos_; |
278 }; | 281 }; |
279 | 282 |
280 | 283 |
281 // Create a message builder starting from position 0. This acquires the mutex | 284 // Create a message builder starting from position 0. This acquires the mutex |
282 // in the logger as well. | 285 // in the logger as well. |
283 LogMessageBuilder::LogMessageBuilder(): pos_(0), sl(Logger::mutex_) { | 286 LogMessageBuilder::LogMessageBuilder(): pos_(0), sl(Logger::mutex_) { |
284 ASSERT(Logger::message_buffer_ != NULL); | 287 ASSERT(Logger::message_buffer_ != NULL); |
285 } | 288 } |
286 | 289 |
287 | 290 |
288 // Append string data to the log message. | 291 // Append string data to the log message. |
289 void LogMessageBuilder::Append(const char* format, ...) { | 292 void LogMessageBuilder::Append(const char* format, ...) { |
290 Vector<char> buf(Logger::message_buffer_ + pos_, | 293 Vector<char> buf(Logger::message_buffer_ + pos_, |
291 Logger::kMessageBufferSize - pos_); | 294 Logger::kMessageBufferSize - pos_); |
292 va_list args; | 295 va_list args; |
293 va_start(args, format); | 296 va_start(args, format); |
| 297 Append(format, args); |
| 298 va_end(args); |
| 299 ASSERT(pos_ <= Logger::kMessageBufferSize); |
| 300 } |
| 301 |
| 302 |
| 303 // Append string data to the log message. |
| 304 void LogMessageBuilder::Append(const char* format, va_list args) { |
| 305 Vector<char> buf(Logger::message_buffer_ + pos_, |
| 306 Logger::kMessageBufferSize - pos_); |
294 int result = v8::internal::OS::VSNPrintF(buf, format, args); | 307 int result = v8::internal::OS::VSNPrintF(buf, format, args); |
295 va_end(args); | |
296 | 308 |
297 // Result is -1 if output was truncated. | 309 // Result is -1 if output was truncated. |
298 if (result >= 0) { | 310 if (result >= 0) { |
299 pos_ += result; | 311 pos_ += result; |
300 } else { | 312 } else { |
301 pos_ = Logger::kMessageBufferSize; | 313 pos_ = Logger::kMessageBufferSize; |
302 } | 314 } |
303 ASSERT(pos_ <= Logger::kMessageBufferSize); | 315 ASSERT(pos_ <= Logger::kMessageBufferSize); |
304 } | 316 } |
305 | 317 |
306 | 318 |
307 // Append a character to the log message. | 319 // Append a character to the log message. |
308 void LogMessageBuilder::Append(const char c) { | 320 void LogMessageBuilder::Append(const char c) { |
309 if (pos_ < Logger::kMessageBufferSize) { | 321 if (pos_ < Logger::kMessageBufferSize) { |
310 Logger::message_buffer_[pos_++] = c; | 322 Logger::message_buffer_[pos_++] = c; |
311 } | 323 } |
312 ASSERT(pos_ <= Logger::kMessageBufferSize); | 324 ASSERT(pos_ <= Logger::kMessageBufferSize); |
313 } | 325 } |
314 | 326 |
315 | 327 |
| 328 // Append a heap string. |
| 329 void LogMessageBuilder::Append(String* str) { |
| 330 AssertNoAllocation no_heap_allocation; // Ensure string stay valid. |
| 331 StringShape shape(str); |
| 332 int length = str->length(shape); |
| 333 for (int i = 0; i < length; i++) { |
| 334 Append(static_cast<char>(str->Get(shape, i))); |
| 335 } |
| 336 } |
| 337 |
| 338 void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) { |
| 339 AssertNoAllocation no_heap_allocation; // Ensure string stay valid. |
| 340 StringShape shape(str); |
| 341 int len = str->length(shape); |
| 342 if (len > 0x1000) |
| 343 len = 0x1000; |
| 344 if (show_impl_info) { |
| 345 Append(shape.IsAsciiRepresentation() ? 'a' : '2'); |
| 346 if (shape.IsExternal()) |
| 347 Append('e'); |
| 348 if (shape.IsSymbol()) |
| 349 Append('#'); |
| 350 Append(":%i:", str->length()); |
| 351 } |
| 352 for (int i = 0; i < len; i++) { |
| 353 uc32 c = str->Get(shape, i); |
| 354 if (c > 0xff) { |
| 355 Append("\\u%04x", c); |
| 356 } else if (c < 32 || c > 126) { |
| 357 Append("\\x%02x", c); |
| 358 } else if (c == ',') { |
| 359 Append("\\,"); |
| 360 } else if (c == '\\') { |
| 361 Append("\\\\"); |
| 362 } else { |
| 363 Append("%lc", c); |
| 364 } |
| 365 } |
| 366 } |
| 367 |
316 // Write the log message to the log file currently opened. | 368 // Write the log message to the log file currently opened. |
317 void LogMessageBuilder::WriteToLogFile() { | 369 void LogMessageBuilder::WriteToLogFile() { |
318 ASSERT(pos_ <= Logger::kMessageBufferSize); | 370 ASSERT(pos_ <= Logger::kMessageBufferSize); |
319 fwrite(Logger::message_buffer_, 1, pos_, Logger::logfile_); | 371 fwrite(Logger::message_buffer_, 1, pos_, Logger::logfile_); |
320 } | 372 } |
321 #endif | 373 #endif |
322 | 374 |
323 | 375 |
324 // | 376 // |
325 // Logger class implementation. | 377 // Logger class implementation. |
326 // | 378 // |
327 Ticker* Logger::ticker_ = NULL; | 379 Ticker* Logger::ticker_ = NULL; |
328 char* Logger::message_buffer_ = NULL; | 380 char* Logger::message_buffer_ = NULL; |
329 FILE* Logger::logfile_ = NULL; | 381 FILE* Logger::logfile_ = NULL; |
330 Profiler* Logger::profiler_ = NULL; | 382 Profiler* Logger::profiler_ = NULL; |
331 Mutex* Logger::mutex_ = NULL; | 383 Mutex* Logger::mutex_ = NULL; |
332 VMState* Logger::current_state_ = NULL; | 384 VMState* Logger::current_state_ = NULL; |
333 SlidingStateWindow* Logger::sliding_state_window_ = NULL; | 385 SlidingStateWindow* Logger::sliding_state_window_ = NULL; |
334 | 386 |
335 #endif // ENABLE_LOGGING_AND_PROFILING | 387 #endif // ENABLE_LOGGING_AND_PROFILING |
336 | 388 |
337 | 389 |
338 void Logger::Preamble(const char* content) { | 390 void Logger::Preamble(const char* content) { |
339 #ifdef ENABLE_LOGGING_AND_PROFILING | 391 #ifdef ENABLE_LOGGING_AND_PROFILING |
340 if (logfile_ == NULL || !FLAG_log_code) return; | 392 if (logfile_ == NULL || !FLAG_log_code) return; |
341 ScopedLock sl(mutex_); | 393 LogMessageBuilder msg; |
342 fprintf(logfile_, "%s", content); | 394 msg.Append("%s", content); |
| 395 msg.WriteToLogFile(); |
343 #endif | 396 #endif |
344 } | 397 } |
345 | 398 |
346 | 399 |
347 void Logger::StringEvent(const char* name, const char* value) { | 400 void Logger::StringEvent(const char* name, const char* value) { |
348 #ifdef ENABLE_LOGGING_AND_PROFILING | 401 #ifdef ENABLE_LOGGING_AND_PROFILING |
349 if (FLAG_log) UncheckedStringEvent(name, value); | 402 if (FLAG_log) UncheckedStringEvent(name, value); |
350 #endif | 403 #endif |
351 } | 404 } |
352 | 405 |
353 | 406 |
354 #ifdef ENABLE_LOGGING_AND_PROFILING | 407 #ifdef ENABLE_LOGGING_AND_PROFILING |
355 void Logger::UncheckedStringEvent(const char* name, const char* value) { | 408 void Logger::UncheckedStringEvent(const char* name, const char* value) { |
356 if (logfile_ == NULL) return; | 409 if (logfile_ == NULL) return; |
357 ScopedLock sl(mutex_); | 410 LogMessageBuilder msg; |
358 fprintf(logfile_, "%s,\"%s\"\n", name, value); | 411 msg.Append("%s,\"%s\"\n", name, value); |
| 412 msg.WriteToLogFile(); |
359 } | 413 } |
360 #endif | 414 #endif |
361 | 415 |
362 | 416 |
363 void Logger::IntEvent(const char* name, int value) { | 417 void Logger::IntEvent(const char* name, int value) { |
364 #ifdef ENABLE_LOGGING_AND_PROFILING | 418 #ifdef ENABLE_LOGGING_AND_PROFILING |
365 if (logfile_ == NULL || !FLAG_log) return; | 419 if (logfile_ == NULL || !FLAG_log) return; |
366 ScopedLock sl(mutex_); | 420 LogMessageBuilder msg; |
367 fprintf(logfile_, "%s,%d\n", name, value); | 421 msg.Append("%s,%d\n", name, value); |
| 422 msg.WriteToLogFile(); |
368 #endif | 423 #endif |
369 } | 424 } |
370 | 425 |
371 | 426 |
372 void Logger::HandleEvent(const char* name, Object** location) { | 427 void Logger::HandleEvent(const char* name, Object** location) { |
373 #ifdef ENABLE_LOGGING_AND_PROFILING | 428 #ifdef ENABLE_LOGGING_AND_PROFILING |
374 if (logfile_ == NULL || !FLAG_log_handles) return; | 429 if (logfile_ == NULL || !FLAG_log_handles) return; |
375 ScopedLock sl(mutex_); | 430 LogMessageBuilder msg; |
376 fprintf(logfile_, "%s,0x%x\n", name, | 431 msg.Append("%s,0x%x\n", name, |
377 reinterpret_cast<unsigned int>(location)); | 432 reinterpret_cast<unsigned int>(location)); |
| 433 msg.WriteToLogFile(); |
378 #endif | 434 #endif |
379 } | 435 } |
380 | 436 |
381 | 437 |
382 #ifdef ENABLE_LOGGING_AND_PROFILING | 438 #ifdef ENABLE_LOGGING_AND_PROFILING |
383 // ApiEvent is private so all the calls come from the Logger class. It is the | 439 // ApiEvent is private so all the calls come from the Logger class. It is the |
384 // caller's responsibility to ensure that logfile_ is not NULL and that | 440 // caller's responsibility to ensure that logfile_ is not NULL and that |
385 // FLAG_log_api is true. | 441 // FLAG_log_api is true. |
386 void Logger::ApiEvent(const char* format, ...) { | 442 void Logger::ApiEvent(const char* format, ...) { |
387 ASSERT(logfile_ != NULL && FLAG_log_api); | 443 ASSERT(logfile_ != NULL && FLAG_log_api); |
388 ScopedLock sl(mutex_); | 444 LogMessageBuilder msg; |
389 va_list ap; | 445 va_list ap; |
390 va_start(ap, format); | 446 va_start(ap, format); |
391 vfprintf(logfile_, format, ap); | 447 msg.Append(format, ap); |
| 448 va_end(ap); |
| 449 msg.WriteToLogFile(); |
392 } | 450 } |
393 #endif | 451 #endif |
394 | 452 |
395 | 453 |
396 void Logger::ApiNamedSecurityCheck(Object* key) { | 454 void Logger::ApiNamedSecurityCheck(Object* key) { |
397 #ifdef ENABLE_LOGGING_AND_PROFILING | 455 #ifdef ENABLE_LOGGING_AND_PROFILING |
398 if (logfile_ == NULL || !FLAG_log_api) return; | 456 if (logfile_ == NULL || !FLAG_log_api) return; |
399 if (key->IsString()) { | 457 if (key->IsString()) { |
400 SmartPointer<char> str = | 458 SmartPointer<char> str = |
401 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 459 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
402 ApiEvent("api,check-security,\"%s\"\n", *str); | 460 ApiEvent("api,check-security,\"%s\"\n", *str); |
403 } else if (key->IsUndefined()) { | 461 } else if (key->IsUndefined()) { |
404 ApiEvent("api,check-security,undefined\n"); | 462 ApiEvent("api,check-security,undefined\n"); |
405 } else { | 463 } else { |
406 ApiEvent("api,check-security,['no-name']\n"); | 464 ApiEvent("api,check-security,['no-name']\n"); |
407 } | 465 } |
408 #endif | 466 #endif |
409 } | 467 } |
410 | 468 |
411 | 469 |
412 void Logger::SharedLibraryEvent(const char* library_path, | 470 void Logger::SharedLibraryEvent(const char* library_path, |
413 unsigned start, | 471 unsigned start, |
414 unsigned end) { | 472 unsigned end) { |
415 #ifdef ENABLE_LOGGING_AND_PROFILING | 473 #ifdef ENABLE_LOGGING_AND_PROFILING |
416 if (logfile_ == NULL || !FLAG_prof) return; | 474 if (logfile_ == NULL || !FLAG_prof) return; |
417 ScopedLock sl(mutex_); | 475 LogMessageBuilder msg; |
418 fprintf(logfile_, "shared-library,\"%s\",0x%08x,0x%08x\n", library_path, | 476 msg.Append("shared-library,\"%s\",0x%08x,0x%08x\n", library_path, |
419 start, end); | 477 start, end); |
| 478 msg.WriteToLogFile(); |
420 #endif | 479 #endif |
421 } | 480 } |
422 | 481 |
423 | 482 |
424 void Logger::SharedLibraryEvent(const wchar_t* library_path, | 483 void Logger::SharedLibraryEvent(const wchar_t* library_path, |
425 unsigned start, | 484 unsigned start, |
426 unsigned end) { | 485 unsigned end) { |
427 #ifdef ENABLE_LOGGING_AND_PROFILING | 486 #ifdef ENABLE_LOGGING_AND_PROFILING |
428 if (logfile_ == NULL || !FLAG_prof) return; | 487 if (logfile_ == NULL || !FLAG_prof) return; |
429 ScopedLock sl(mutex_); | 488 LogMessageBuilder msg; |
430 fprintf(logfile_, "shared-library,\"%ls\",0x%08x,0x%08x\n", library_path, | 489 msg.Append("shared-library,\"%ls\",0x%08x,0x%08x\n", library_path, |
431 start, end); | 490 start, end); |
| 491 msg.WriteToLogFile(); |
432 #endif | 492 #endif |
433 } | 493 } |
434 | 494 |
435 | 495 |
436 #ifdef ENABLE_LOGGING_AND_PROFILING | 496 #ifdef ENABLE_LOGGING_AND_PROFILING |
437 void Logger::LogString(Handle<String> str, bool show_impl_info) { | |
438 StringShape shape(*str); | |
439 int len = str->length(shape); | |
440 if (len > 0x1000) | |
441 len = 0x1000; | |
442 if (show_impl_info) { | |
443 fputc(shape.IsAsciiRepresentation() ? 'a' : '2', logfile_); | |
444 if (shape.IsExternal()) | |
445 fputc('e', logfile_); | |
446 if (shape.IsSymbol()) | |
447 fputc('#', logfile_); | |
448 fprintf(logfile_, ":%i:", str->length()); | |
449 } | |
450 for (int i = 0; i < len; i++) { | |
451 uc32 c = str->Get(shape, i); | |
452 if (c > 0xff) { | |
453 fprintf(logfile_, "\\u%04x", c); | |
454 } else if (c < 32 || c > 126) { | |
455 fprintf(logfile_, "\\x%02x", c); | |
456 } else if (c == ',') { | |
457 fprintf(logfile_, "\\,"); | |
458 } else if (c == '\\') { | |
459 fprintf(logfile_, "\\\\"); | |
460 } else { | |
461 fprintf(logfile_, "%lc", c); | |
462 } | |
463 } | |
464 } | |
465 | |
466 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { | 497 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { |
467 // Prints "/" + re.source + "/" + | 498 // Prints "/" + re.source + "/" + |
468 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") | 499 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") |
| 500 LogMessageBuilder msg; |
469 | 501 |
470 Handle<Object> source = GetProperty(regexp, "source"); | 502 Handle<Object> source = GetProperty(regexp, "source"); |
471 if (!source->IsString()) { | 503 if (!source->IsString()) { |
472 fprintf(logfile_, "no source"); | 504 msg.Append("no source"); |
473 return; | 505 return; |
474 } | 506 } |
475 | 507 |
476 switch (regexp->TypeTag()) { | 508 switch (regexp->TypeTag()) { |
477 case JSRegExp::ATOM: | 509 case JSRegExp::ATOM: |
478 fprintf(logfile_, "a"); | 510 msg.Append('a'); |
479 break; | 511 break; |
480 default: | 512 default: |
481 break; | 513 break; |
482 } | 514 } |
483 fprintf(logfile_, "/"); | 515 msg.Append('/'); |
484 LogString(Handle<String>::cast(source), false); | 516 msg.AppendDetailed(*Handle<String>::cast(source), false); |
485 fprintf(logfile_, "/"); | 517 msg.Append('/'); |
486 | 518 |
487 // global flag | 519 // global flag |
488 Handle<Object> global = GetProperty(regexp, "global"); | 520 Handle<Object> global = GetProperty(regexp, "global"); |
489 if (global->IsTrue()) { | 521 if (global->IsTrue()) { |
490 fprintf(logfile_, "g"); | 522 msg.Append('g'); |
491 } | 523 } |
492 // ignorecase flag | 524 // ignorecase flag |
493 Handle<Object> ignorecase = GetProperty(regexp, "ignoreCase"); | 525 Handle<Object> ignorecase = GetProperty(regexp, "ignoreCase"); |
494 if (ignorecase->IsTrue()) { | 526 if (ignorecase->IsTrue()) { |
495 fprintf(logfile_, "i"); | 527 msg.Append('i'); |
496 } | 528 } |
497 // multiline flag | 529 // multiline flag |
498 Handle<Object> multiline = GetProperty(regexp, "multiline"); | 530 Handle<Object> multiline = GetProperty(regexp, "multiline"); |
499 if (multiline->IsTrue()) { | 531 if (multiline->IsTrue()) { |
500 fprintf(logfile_, "m"); | 532 msg.Append('m'); |
501 } | 533 } |
| 534 |
| 535 msg.WriteToLogFile(); |
502 } | 536 } |
503 #endif // ENABLE_LOGGING_AND_PROFILING | 537 #endif // ENABLE_LOGGING_AND_PROFILING |
504 | 538 |
505 | 539 |
506 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { | 540 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { |
507 #ifdef ENABLE_LOGGING_AND_PROFILING | 541 #ifdef ENABLE_LOGGING_AND_PROFILING |
508 if (logfile_ == NULL || !FLAG_log_regexp) return; | 542 if (logfile_ == NULL || !FLAG_log_regexp) return; |
509 ScopedLock sl(mutex_); | 543 LogMessageBuilder msg; |
510 | 544 msg.Append("regexp-compile,"); |
511 fprintf(logfile_, "regexp-compile,"); | |
512 LogRegExpSource(regexp); | 545 LogRegExpSource(regexp); |
513 fprintf(logfile_, in_cache ? ",hit\n" : ",miss\n"); | 546 msg.Append(in_cache ? ",hit\n" : ",miss\n"); |
| 547 msg.WriteToLogFile(); |
514 #endif | 548 #endif |
515 } | 549 } |
516 | 550 |
517 | 551 |
518 void Logger::LogRuntime(Vector<const char> format, JSArray* args) { | 552 void Logger::LogRuntime(Vector<const char> format, JSArray* args) { |
519 #ifdef ENABLE_LOGGING_AND_PROFILING | 553 #ifdef ENABLE_LOGGING_AND_PROFILING |
520 ScopedLock sl(mutex_); | 554 if (logfile_ == NULL || !FLAG_log_runtime) return; |
521 HandleScope scope; | 555 HandleScope scope; |
| 556 LogMessageBuilder msg; |
522 for (int i = 0; i < format.length(); i++) { | 557 for (int i = 0; i < format.length(); i++) { |
523 char c = format[i]; | 558 char c = format[i]; |
524 if (c == '%' && i <= format.length() - 2) { | 559 if (c == '%' && i <= format.length() - 2) { |
525 i++; | 560 i++; |
526 ASSERT('0' <= format[i] && format[i] <= '9'); | 561 ASSERT('0' <= format[i] && format[i] <= '9'); |
527 Object* obj = args->GetElement(format[i] - '0'); | 562 Object* obj = args->GetElement(format[i] - '0'); |
528 i++; | 563 i++; |
529 switch (format[i]) { | 564 switch (format[i]) { |
530 case 's': | 565 case 's': |
531 Logger::LogString(Handle<String>(String::cast(obj)), false); | 566 msg.AppendDetailed(String::cast(obj), false); |
532 break; | 567 break; |
533 case 'S': | 568 case 'S': |
534 Logger::LogString(Handle<String>(String::cast(obj)), true); | 569 msg.AppendDetailed(String::cast(obj), true); |
535 break; | 570 break; |
536 case 'r': | 571 case 'r': |
537 Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj))); | 572 Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj))); |
538 break; | 573 break; |
539 case 'x': | 574 case 'x': |
540 fprintf(logfile_, "0x%x", Smi::cast(obj)->value()); | 575 msg.Append("0x%x", Smi::cast(obj)->value()); |
541 break; | 576 break; |
542 case 'i': | 577 case 'i': |
543 fprintf(logfile_, "%i", Smi::cast(obj)->value()); | 578 msg.Append("%i", Smi::cast(obj)->value()); |
544 break; | 579 break; |
545 default: | 580 default: |
546 UNREACHABLE(); | 581 UNREACHABLE(); |
547 } | 582 } |
548 } else { | 583 } else { |
549 fputc(c, logfile_); | 584 msg.Append(c); |
550 } | 585 } |
551 } | 586 } |
552 fputc('\n', logfile_); | 587 msg.Append('\n'); |
| 588 msg.WriteToLogFile(); |
553 #endif | 589 #endif |
554 } | 590 } |
555 | 591 |
556 | 592 |
557 void Logger::ApiIndexedSecurityCheck(uint32_t index) { | 593 void Logger::ApiIndexedSecurityCheck(uint32_t index) { |
558 #ifdef ENABLE_LOGGING_AND_PROFILING | 594 #ifdef ENABLE_LOGGING_AND_PROFILING |
559 if (logfile_ == NULL || !FLAG_log_api) return; | 595 if (logfile_ == NULL || !FLAG_log_api) return; |
560 ApiEvent("api,check-security,%u\n", index); | 596 ApiEvent("api,check-security,%u\n", index); |
561 #endif | 597 #endif |
562 } | 598 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 #ifdef ENABLE_LOGGING_AND_PROFILING | 640 #ifdef ENABLE_LOGGING_AND_PROFILING |
605 if (logfile_ == NULL || !FLAG_log_api) return; | 641 if (logfile_ == NULL || !FLAG_log_api) return; |
606 Logger::ApiEvent("api,%s\n", name); | 642 Logger::ApiEvent("api,%s\n", name); |
607 #endif | 643 #endif |
608 } | 644 } |
609 | 645 |
610 | 646 |
611 void Logger::NewEvent(const char* name, void* object, size_t size) { | 647 void Logger::NewEvent(const char* name, void* object, size_t size) { |
612 #ifdef ENABLE_LOGGING_AND_PROFILING | 648 #ifdef ENABLE_LOGGING_AND_PROFILING |
613 if (logfile_ == NULL || !FLAG_log) return; | 649 if (logfile_ == NULL || !FLAG_log) return; |
614 ScopedLock sl(mutex_); | 650 LogMessageBuilder msg; |
615 fprintf(logfile_, "new,%s,0x%x,%u\n", name, | 651 msg.Append("new,%s,0x%x,%u\n", name, |
616 reinterpret_cast<unsigned int>(object), | 652 reinterpret_cast<unsigned int>(object), |
617 static_cast<unsigned int>(size)); | 653 static_cast<unsigned int>(size)); |
| 654 msg.WriteToLogFile(); |
618 #endif | 655 #endif |
619 } | 656 } |
620 | 657 |
621 | 658 |
622 void Logger::DeleteEvent(const char* name, void* object) { | 659 void Logger::DeleteEvent(const char* name, void* object) { |
623 #ifdef ENABLE_LOGGING_AND_PROFILING | 660 #ifdef ENABLE_LOGGING_AND_PROFILING |
624 if (logfile_ == NULL || !FLAG_log) return; | 661 if (logfile_ == NULL || !FLAG_log) return; |
625 ScopedLock sl(mutex_); | 662 LogMessageBuilder msg; |
626 fprintf(logfile_, "delete,%s,0x%x\n", name, | 663 msg.Append("delete,%s,0x%x\n", name, |
627 reinterpret_cast<unsigned int>(object)); | 664 reinterpret_cast<unsigned int>(object)); |
| 665 msg.WriteToLogFile(); |
628 #endif | 666 #endif |
629 } | 667 } |
630 | 668 |
631 | 669 |
632 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { | 670 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { |
633 #ifdef ENABLE_LOGGING_AND_PROFILING | 671 #ifdef ENABLE_LOGGING_AND_PROFILING |
634 if (logfile_ == NULL || !FLAG_log_code) return; | 672 if (logfile_ == NULL || !FLAG_log_code) return; |
635 LogMessageBuilder msg; | 673 LogMessageBuilder msg; |
636 msg.Append("code-creation,%s,0x%x,%d,\"", tag, | 674 msg.Append("code-creation,%s,0x%x,%d,\"", tag, |
637 reinterpret_cast<unsigned int>(code->address()), | 675 reinterpret_cast<unsigned int>(code->address()), |
638 code->instruction_size()); | 676 code->instruction_size()); |
639 for (const char* p = comment; *p != '\0'; p++) { | 677 for (const char* p = comment; *p != '\0'; p++) { |
640 if (*p == '\"') fprintf(logfile_, "\\"); | 678 if (*p == '"') { |
| 679 msg.Append('\\'); |
| 680 } |
641 msg.Append(*p); | 681 msg.Append(*p); |
642 } | 682 } |
643 msg.Append('"'); | 683 msg.Append('"'); |
644 msg.Append('\n'); | 684 msg.Append('\n'); |
645 msg.WriteToLogFile(); | 685 msg.WriteToLogFile(); |
646 #endif | 686 #endif |
647 } | 687 } |
648 | 688 |
649 | 689 |
650 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { | 690 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 reinterpret_cast<unsigned int>(masm), | 790 reinterpret_cast<unsigned int>(masm), |
751 masm->pc_offset()); | 791 masm->pc_offset()); |
752 msg.WriteToLogFile(); | 792 msg.WriteToLogFile(); |
753 #endif | 793 #endif |
754 } | 794 } |
755 | 795 |
756 | 796 |
757 void Logger::ResourceEvent(const char* name, const char* tag) { | 797 void Logger::ResourceEvent(const char* name, const char* tag) { |
758 #ifdef ENABLE_LOGGING_AND_PROFILING | 798 #ifdef ENABLE_LOGGING_AND_PROFILING |
759 if (logfile_ == NULL || !FLAG_log) return; | 799 if (logfile_ == NULL || !FLAG_log) return; |
760 ScopedLock sl(mutex_); | 800 LogMessageBuilder msg; |
761 fprintf(logfile_, "%s,%s,", name, tag); | 801 msg.Append("%s,%s,", name, tag); |
762 | 802 |
763 uint32_t sec, usec; | 803 uint32_t sec, usec; |
764 if (OS::GetUserTime(&sec, &usec) != -1) { | 804 if (OS::GetUserTime(&sec, &usec) != -1) { |
765 fprintf(logfile_, "%d,%d,", sec, usec); | 805 msg.Append("%d,%d,", sec, usec); |
766 } | 806 } |
767 fprintf(logfile_, "%.0f", OS::TimeCurrentMillis()); | 807 msg.Append("%.0f", OS::TimeCurrentMillis()); |
768 | 808 |
769 fprintf(logfile_, "\n"); | 809 msg.Append('\n'); |
| 810 msg.WriteToLogFile(); |
770 #endif | 811 #endif |
771 } | 812 } |
772 | 813 |
773 | 814 |
774 void Logger::SuspectReadEvent(String* name, Object* obj) { | 815 void Logger::SuspectReadEvent(String* name, Object* obj) { |
775 #ifdef ENABLE_LOGGING_AND_PROFILING | 816 #ifdef ENABLE_LOGGING_AND_PROFILING |
776 if (logfile_ == NULL || !FLAG_log_suspect) return; | 817 if (logfile_ == NULL || !FLAG_log_suspect) return; |
| 818 LogMessageBuilder msg; |
777 String* class_name = obj->IsJSObject() | 819 String* class_name = obj->IsJSObject() |
778 ? JSObject::cast(obj)->class_name() | 820 ? JSObject::cast(obj)->class_name() |
779 : Heap::empty_string(); | 821 : Heap::empty_string(); |
780 ScopedLock sl(mutex_); | 822 ScopedLock sl(mutex_); |
781 fprintf(logfile_, "suspect-read,"); | 823 msg.Append("suspect-read,"); |
782 class_name->PrintOn(logfile_); | 824 msg.Append(class_name); |
783 fprintf(logfile_, ",\""); | 825 msg.Append(','); |
784 name->PrintOn(logfile_); | 826 msg.Append('"'); |
785 fprintf(logfile_, "\"\n"); | 827 msg.Append(name); |
| 828 msg.Append('"'); |
| 829 msg.Append('\n'); |
| 830 msg.WriteToLogFile(); |
786 #endif | 831 #endif |
787 } | 832 } |
788 | 833 |
789 | 834 |
790 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { | 835 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { |
791 #ifdef ENABLE_LOGGING_AND_PROFILING | 836 #ifdef ENABLE_LOGGING_AND_PROFILING |
792 if (logfile_ == NULL || !FLAG_log_gc) return; | 837 if (logfile_ == NULL || !FLAG_log_gc) return; |
793 ScopedLock sl(mutex_); | 838 LogMessageBuilder msg; |
794 fprintf(logfile_, "heap-sample-begin,\"%s\",\"%s\"\n", space, kind); | 839 msg.Append("heap-sample-begin,\"%s\",\"%s\"\n", space, kind); |
| 840 msg.WriteToLogFile(); |
795 #endif | 841 #endif |
796 } | 842 } |
797 | 843 |
798 | 844 |
799 void Logger::HeapSampleEndEvent(const char* space, const char* kind) { | 845 void Logger::HeapSampleEndEvent(const char* space, const char* kind) { |
800 #ifdef ENABLE_LOGGING_AND_PROFILING | 846 #ifdef ENABLE_LOGGING_AND_PROFILING |
801 if (logfile_ == NULL || !FLAG_log_gc) return; | 847 if (logfile_ == NULL || !FLAG_log_gc) return; |
802 ScopedLock sl(mutex_); | 848 LogMessageBuilder msg; |
803 fprintf(logfile_, "heap-sample-end,\"%s\",\"%s\"\n", space, kind); | 849 msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind); |
| 850 msg.WriteToLogFile(); |
804 #endif | 851 #endif |
805 } | 852 } |
806 | 853 |
807 | 854 |
808 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { | 855 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { |
809 #ifdef ENABLE_LOGGING_AND_PROFILING | 856 #ifdef ENABLE_LOGGING_AND_PROFILING |
810 if (logfile_ == NULL || !FLAG_log_gc) return; | 857 if (logfile_ == NULL || !FLAG_log_gc) return; |
811 ScopedLock sl(mutex_); | 858 LogMessageBuilder msg; |
812 fprintf(logfile_, "heap-sample-item,%s,%d,%d\n", type, number, bytes); | 859 msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes); |
| 860 msg.WriteToLogFile(); |
813 #endif | 861 #endif |
814 } | 862 } |
815 | 863 |
816 | 864 |
817 void Logger::DebugTag(const char* call_site_tag) { | 865 void Logger::DebugTag(const char* call_site_tag) { |
818 #ifdef ENABLE_LOGGING_AND_PROFILING | 866 #ifdef ENABLE_LOGGING_AND_PROFILING |
819 if (logfile_ == NULL || !FLAG_log) return; | 867 if (logfile_ == NULL || !FLAG_log) return; |
820 ScopedLock sl(mutex_); | 868 LogMessageBuilder msg; |
821 fprintf(logfile_, "debug-tag,%s\n", call_site_tag); | 869 msg.Append("debug-tag,%s\n", call_site_tag); |
| 870 msg.WriteToLogFile(); |
822 #endif | 871 #endif |
823 } | 872 } |
824 | 873 |
825 | 874 |
826 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { | 875 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { |
827 #ifdef ENABLE_LOGGING_AND_PROFILING | 876 #ifdef ENABLE_LOGGING_AND_PROFILING |
828 if (logfile_ == NULL || !FLAG_log) return; | 877 if (logfile_ == NULL || !FLAG_log) return; |
829 StringBuilder s(parameter.length() + 1); | 878 StringBuilder s(parameter.length() + 1); |
830 for (int i = 0; i < parameter.length(); ++i) { | 879 for (int i = 0; i < parameter.length(); ++i) { |
831 s.AddCharacter(static_cast<char>(parameter[i])); | 880 s.AddCharacter(static_cast<char>(parameter[i])); |
832 } | 881 } |
833 char* parameter_string = s.Finalize(); | 882 char* parameter_string = s.Finalize(); |
834 ScopedLock sl(mutex_); | 883 LogMessageBuilder msg; |
835 fprintf(logfile_, | 884 msg.Append("debug-queue-event,%s,%15.3f,%s\n", |
836 "debug-queue-event,%s,%15.3f,%s\n", | 885 event_type, |
837 event_type, | 886 OS::TimeCurrentMillis(), |
838 OS::TimeCurrentMillis(), | 887 parameter_string); |
839 parameter_string); | |
840 DeleteArray(parameter_string); | 888 DeleteArray(parameter_string); |
| 889 msg.WriteToLogFile(); |
841 #endif | 890 #endif |
842 } | 891 } |
843 | 892 |
844 | 893 |
845 #ifdef ENABLE_LOGGING_AND_PROFILING | 894 #ifdef ENABLE_LOGGING_AND_PROFILING |
846 void Logger::TickEvent(TickSample* sample, bool overflow) { | 895 void Logger::TickEvent(TickSample* sample, bool overflow) { |
847 if (logfile_ == NULL || !FLAG_prof) return; | 896 if (logfile_ == NULL || !FLAG_prof) return; |
848 ScopedLock sl(mutex_); | 897 LogMessageBuilder msg; |
849 fprintf(logfile_, "tick,0x%x,0x%x,%d", sample->pc, sample->sp, | 898 msg.Append("tick,0x%x,0x%x,%d", sample->pc, sample->sp, |
850 static_cast<int>(sample->state)); | 899 static_cast<int>(sample->state)); |
851 if (overflow) fprintf(logfile_, ",overflow"); | 900 if (overflow) { |
852 fprintf(logfile_, "\n"); | 901 msg.Append(",overflow"); |
| 902 } |
| 903 msg.Append('\n'); |
| 904 msg.WriteToLogFile(); |
853 } | 905 } |
854 | 906 |
855 | 907 |
856 bool Logger::IsProfilerPaused() { | 908 bool Logger::IsProfilerPaused() { |
857 return profiler_->paused(); | 909 return profiler_->paused(); |
858 } | 910 } |
859 | 911 |
860 | 912 |
861 void Logger::PauseProfiler() { | 913 void Logger::PauseProfiler() { |
862 profiler_->pause(); | 914 profiler_->pause(); |
863 } | 915 } |
864 | 916 |
865 | 917 |
866 void Logger::ResumeProfiler() { | 918 void Logger::ResumeProfiler() { |
867 profiler_->resume(); | 919 profiler_->resume(); |
868 } | 920 } |
869 #endif | 921 #endif |
870 | 922 |
871 | 923 |
872 bool Logger::Setup() { | 924 bool Logger::Setup() { |
873 #ifdef ENABLE_LOGGING_AND_PROFILING | 925 #ifdef ENABLE_LOGGING_AND_PROFILING |
874 // --log-all enables all the log flags. | 926 // --log-all enables all the log flags. |
875 if (FLAG_log_all) { | 927 if (FLAG_log_all) { |
| 928 FLAG_log_runtime = true; |
876 FLAG_log_api = true; | 929 FLAG_log_api = true; |
877 FLAG_log_code = true; | 930 FLAG_log_code = true; |
878 FLAG_log_gc = true; | 931 FLAG_log_gc = true; |
879 FLAG_log_suspect = true; | 932 FLAG_log_suspect = true; |
880 FLAG_log_handles = true; | 933 FLAG_log_handles = true; |
881 FLAG_log_regexp = true; | 934 FLAG_log_regexp = true; |
882 } | 935 } |
883 | 936 |
884 // --prof implies --log-code. | 937 // --prof implies --log-code. |
885 if (FLAG_prof) FLAG_log_code = true; | 938 if (FLAG_prof) FLAG_log_code = true; |
886 | 939 |
887 bool open_log_file = FLAG_log || FLAG_log_api || FLAG_log_code | 940 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api |
888 || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect | 941 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect |
889 || FLAG_log_regexp || FLAG_log_state_changes; | 942 || FLAG_log_regexp || FLAG_log_state_changes; |
890 | 943 |
891 // If we're logging anything, we need to open the log file. | 944 // If we're logging anything, we need to open the log file. |
892 if (open_log_file) { | 945 if (open_log_file) { |
893 if (strcmp(FLAG_logfile, "-") == 0) { | 946 if (strcmp(FLAG_logfile, "-") == 0) { |
894 logfile_ = stdout; | 947 logfile_ = stdout; |
895 } else if (strchr(FLAG_logfile, '%') != NULL) { | 948 } else if (strchr(FLAG_logfile, '%') != NULL) { |
896 // If there's a '%' in the log file name we have to expand | 949 // If there's a '%' in the log file name we have to expand |
897 // placeholders. | 950 // placeholders. |
898 HeapStringAllocator allocator; | 951 HeapStringAllocator allocator; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 if (FLAG_log_state_changes) { | 1098 if (FLAG_log_state_changes) { |
1046 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); | 1099 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); |
1047 if (previous_) { | 1100 if (previous_) { |
1048 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); | 1101 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); |
1049 } | 1102 } |
1050 } | 1103 } |
1051 } | 1104 } |
1052 #endif | 1105 #endif |
1053 | 1106 |
1054 } } // namespace v8::internal | 1107 } } // namespace v8::internal |
OLD | NEW |