Commit a00a9142 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

Revert "[logging] Use OFStream for log events"

This reverts commit 06ff9e97.

Reason for revert: Breaks deopt information with --prof. Deopts no longer show up properly in the logfile / profview

Original change's description:
> [logging] Use OFStream for log events
> 
> This simplifies a few operations and removes the size limitations
> implied by the message buffer used.
> 
> Change-Id: I8b873a0ffa399a037ff5c2501ba4b68158810968
> Reviewed-on: https://chromium-review.googlesource.com/724285
> Commit-Queue: Camillo Bruni <cbruni@chromium.org>
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#48766}

TBR=adamk@chromium.org,cbruni@chromium.org

Change-Id: I290da0b2472ad0e765b765b26bdde334253376e3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/730164Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48776}
parent f0aa474e
......@@ -18,26 +18,15 @@ namespace internal {
const char* const Log::kLogToTemporaryFile = "&";
const char* const Log::kLogToConsole = "-";
// static
FILE* Log::CreateOutputHandle(const char* file_name) {
// If we're logging anything, we need to open the log file.
if (!Log::InitLogAtStart()) {
return nullptr;
} else if (strcmp(file_name, kLogToConsole) == 0) {
return stdout;
} else if (strcmp(file_name, kLogToTemporaryFile) == 0) {
return base::OS::OpenTemporaryFile();
} else {
return base::OS::FOpen(file_name, base::OS::LogFileOpenMode);
}
}
Log::Log(Logger* logger, const char* file_name)
Log::Log(Logger* logger)
: is_stopped_(false),
output_handle_(Log::CreateOutputHandle(file_name)),
os_(output_handle_ == nullptr ? stdout : output_handle_),
format_buffer_(NewArray<char>(kMessageBufferSize)),
logger_(logger) {
output_handle_(nullptr),
message_buffer_(nullptr),
logger_(logger) {}
void Log::Initialize(const char* log_file_name) {
message_buffer_ = NewArray<char>(kMessageBufferSize);
// --log-all enables all the log flags.
if (FLAG_log_all) {
FLAG_log_api = true;
......@@ -51,19 +40,49 @@ Log::Log(Logger* logger, const char* file_name)
// --prof implies --log-code.
if (FLAG_prof) FLAG_log_code = true;
// If we're logging anything, we need to open the log file.
if (Log::InitLogAtStart()) {
if (strcmp(log_file_name, kLogToConsole) == 0) {
OpenStdout();
} else if (strcmp(log_file_name, kLogToTemporaryFile) == 0) {
OpenTemporaryFile();
} else {
OpenFile(log_file_name);
}
if (output_handle_ != nullptr) {
Log::MessageBuilder msg(this);
if (strlen(Version::GetEmbedder()) == 0) {
msg.Append("v8-version,%d,%d,%d,%d,%d", Version::GetMajor(),
Version::GetMinor(), Version::GetBuild(), Version::GetPatch(),
Version::IsCandidate());
Version::GetMinor(), Version::GetBuild(),
Version::GetPatch(), Version::IsCandidate());
} else {
msg.Append("v8-version,%d,%d,%d,%d,%s,%d", Version::GetMajor(),
Version::GetMinor(), Version::GetBuild(), Version::GetPatch(),
Version::GetEmbedder(), Version::IsCandidate());
Version::GetMinor(), Version::GetBuild(),
Version::GetPatch(), Version::GetEmbedder(),
Version::IsCandidate());
}
msg.WriteToLogFile();
}
}
}
void Log::OpenStdout() {
DCHECK(!IsEnabled());
output_handle_ = stdout;
}
void Log::OpenTemporaryFile() {
DCHECK(!IsEnabled());
output_handle_ = base::OS::OpenTemporaryFile();
}
void Log::OpenFile(const char* name) {
DCHECK(!IsEnabled());
output_handle_ = base::OS::FOpen(name, base::OS::LogFileOpenMode);
}
FILE* Log::Close() {
......@@ -77,63 +96,74 @@ FILE* Log::Close() {
}
output_handle_ = nullptr;
DeleteArray(format_buffer_);
format_buffer_ = nullptr;
DeleteArray(message_buffer_);
message_buffer_ = nullptr;
is_stopped_ = false;
return result;
}
Log::MessageBuilder::MessageBuilder(Log* log)
: log_(log), lock_guard_(&log_->mutex_) {
DCHECK_NOT_NULL(log_->format_buffer_);
: log_(log),
lock_guard_(&log_->mutex_),
pos_(0) {
DCHECK_NOT_NULL(log_->message_buffer_);
}
void Log::MessageBuilder::Append(const char* format, ...) {
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
va_list args;
va_start(args, format);
AppendVA(format, args);
va_end(args);
DCHECK_LE(pos_, Log::kMessageBufferSize);
}
void Log::MessageBuilder::AppendVA(const char* format, va_list args) {
Vector<char> buf(log_->format_buffer_, Log::kMessageBufferSize);
int length = v8::internal::VSNPrintF(buf, format, args);
// {length} is -1 if output was truncated.
if (length == -1) {
length = Log::kMessageBufferSize;
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
int result = v8::internal::VSNPrintF(buf, format, args);
// Result is -1 if output was truncated.
if (result >= 0) {
pos_ += result;
} else {
pos_ = Log::kMessageBufferSize;
}
DCHECK_LE(pos_, Log::kMessageBufferSize);
}
void Log::MessageBuilder::Append(const char c) {
if (pos_ < Log::kMessageBufferSize) {
log_->message_buffer_[pos_++] = c;
}
DCHECK_LE(length, Log::kMessageBufferSize);
AppendStringPart(log_->format_buffer_, length);
DCHECK_LE(pos_, Log::kMessageBufferSize);
}
void Log::MessageBuilder::AppendDoubleQuotedString(const char* string) {
OFStream& os = log_->os_;
// TODO(cbruni): unify escaping.
os << '"';
Append('"');
for (const char* p = string; *p != '\0'; p++) {
if (*p == '"') os << '\\';
os << *p;
if (*p == '"') {
Append('\\');
}
os << '"';
Append(*p);
}
Append('"');
}
void Log::MessageBuilder::AppendDoubleQuotedString(String* string) {
OFStream& os = log_->os_;
os << '"';
// TODO(cbruni): unify escaping.
AppendEscapedString(string);
os << '"';
}
void Log::MessageBuilder::Append(String* string) {
void Log::MessageBuilder::Append(String* str) {
DisallowHeapAllocation no_gc; // Ensure string stay valid.
std::unique_ptr<char[]> characters =
string->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
log_->os_ << characters.get();
int length = str->length();
for (int i = 0; i < length; i++) {
Append(static_cast<char>(str->Get(i)));
}
}
void Log::MessageBuilder::AppendAddress(Address addr) {
......@@ -142,69 +172,109 @@ void Log::MessageBuilder::AppendAddress(Address addr) {
void Log::MessageBuilder::AppendSymbolName(Symbol* symbol) {
DCHECK(symbol);
OFStream& os = log_->os_;
os << "symbol(";
Append("symbol(");
if (!symbol->name()->IsUndefined(symbol->GetIsolate())) {
os << "\"";
Append("\"");
AppendDetailed(String::cast(symbol->name()), false);
os << "\" ";
Append("\" ");
}
os << "hash " << std::hex << symbol->Hash() << std::dec << ")";
Append("hash %x)", symbol->Hash());
}
void Log::MessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
if (str == nullptr) return;
DisallowHeapAllocation no_gc; // Ensure string stay valid.
OFStream& os = log_->os_;
int len = str->length();
if (len > 0x1000) len = 0x1000;
if (len > 0x1000)
len = 0x1000;
if (show_impl_info) {
os << (str->IsOneByteRepresentation() ? 'a' : '2');
if (StringShape(str).IsExternal()) os << 'e';
if (StringShape(str).IsInternalized()) os << '#';
os << ':' << str->length() << ':';
Append(str->IsOneByteRepresentation() ? 'a' : '2');
if (StringShape(str).IsExternal())
Append('e');
if (StringShape(str).IsInternalized())
Append('#');
Append(":%i:", str->length());
}
for (int i = 0; i < len; i++) {
uc32 c = str->Get(i);
if (c > 0xff) {
Append("\\u%04x", c);
} else if (c < 32 || c > 126) {
Append("\\x%02x", c);
} else if (c == ',') {
Append("\\,");
} else if (c == '\\') {
Append("\\\\");
} else if (c == '\"') {
Append("\"\"");
} else {
Append("%lc", c);
}
}
AppendEscapedString(str, len);
}
void Log::MessageBuilder::AppendEscapedString(String* str) {
void Log::MessageBuilder::AppendUnbufferedHeapString(String* str) {
if (str == nullptr) return;
int len = str->length();
AppendEscapedString(str, len);
}
void Log::MessageBuilder::AppendEscapedString(String* str, int len) {
DCHECK_LE(len, str->length());
DisallowHeapAllocation no_gc; // Ensure string stay valid.
OFStream& os = log_->os_;
// TODO(cbruni): unify escaping.
ScopedVector<char> buffer(16);
int len = str->length();
for (int i = 0; i < len; i++) {
uc32 c = str->Get(i);
if (c >= 32 && c <= 126) {
if (c == '\"') {
os << "\"\"";
AppendUnbufferedCString("\"\"");
} else if (c == '\\') {
os << "\\\\";
} else if (c == ',') {
os << "\\,";
AppendUnbufferedCString("\\\\");
} else {
os << static_cast<char>(c);
AppendUnbufferedChar(c);
}
} else if (c > 0xff) {
Append("\\u%04x", c);
int length = v8::internal::SNPrintF(buffer, "\\u%04x", c);
DCHECK_EQ(6, length);
log_->WriteToFile(buffer.start(), length);
} else {
DCHECK(c < 32 || (c > 126 && c <= 0xff));
Append("\\x%02x", c);
DCHECK_LE(c, 0xffff);
int length = v8::internal::SNPrintF(buffer, "\\x%02x", c);
DCHECK_EQ(4, length);
log_->WriteToFile(buffer.start(), length);
}
}
}
void Log::MessageBuilder::AppendUnbufferedChar(char c) {
log_->WriteToFile(&c, 1);
}
void Log::MessageBuilder::AppendUnbufferedCString(const char* str) {
log_->WriteToFile(str, static_cast<int>(strlen(str)));
}
void Log::MessageBuilder::AppendStringPart(const char* str, int len) {
log_->os_.write(str, len);
if (pos_ + len > Log::kMessageBufferSize) {
len = Log::kMessageBufferSize - pos_;
DCHECK_GE(len, 0);
if (len == 0) return;
}
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
StrNCpy(buf, str, len);
pos_ += len;
DCHECK_LE(pos_, Log::kMessageBufferSize);
}
void Log::MessageBuilder::WriteToLogFile() { log_->os_ << std::endl; }
void Log::MessageBuilder::WriteToLogFile() {
DCHECK_LE(pos_, Log::kMessageBufferSize);
// Assert that we do not already have a new line at the end.
DCHECK(pos_ == 0 || log_->message_buffer_[pos_ - 1] != '\n');
if (pos_ == Log::kMessageBufferSize) pos_--;
log_->message_buffer_[pos_++] = '\n';
const int written = log_->WriteToFile(log_->message_buffer_, pos_);
if (written != pos_) {
log_->stop();
log_->logger_->LogFailure();
}
}
} // namespace internal
} // namespace v8
......@@ -13,7 +13,6 @@
#include "src/base/compiler-specific.h"
#include "src/base/platform/mutex.h"
#include "src/flags.h"
#include "src/ostreams.h"
namespace v8 {
namespace internal {
......@@ -23,7 +22,8 @@ class Logger;
// Functions and data for performing output of log messages.
class Log {
public:
Log(Logger* log, const char* log_file_name);
// Performs process-wide initialization.
void Initialize(const char* log_file_name);
// Disables logging, but preserves acquired resources.
void stop() { is_stopped_ = true; }
......@@ -66,9 +66,11 @@ class Log {
// Append string data to the log message.
void PRINTF_FORMAT(2, 0) AppendVA(const char* format, va_list args);
// Append a character to the log message.
void Append(const char c);
// Append double quoted string to the log message.
void AppendDoubleQuotedString(const char* string);
void AppendDoubleQuotedString(String* string);
// Append a heap string.
void Append(String* str);
......@@ -86,32 +88,37 @@ class Log {
// Helpers for appending char, C-string and heap string without
// buffering. This is useful for entries that can exceed the 2kB
// limit.
void AppendEscapedString(String* source);
void AppendEscapedString(String* source, int len);
// Delegate insertion to the underlying {log_}.
template <typename T>
MessageBuilder& operator<<(T value) {
log_->os_ << value;
return *this;
}
void AppendUnbufferedChar(char c);
void AppendUnbufferedCString(const char* str);
void AppendUnbufferedHeapString(String* source);
// Finish the current log line an flush the it to the log file.
// Write the log message to the log file currently opened.
void WriteToLogFile();
private:
Log* log_;
base::LockGuard<base::Mutex> lock_guard_;
int pos_;
};
private:
static FILE* CreateOutputHandle(const char* file_name);
explicit Log(Logger* logger);
// Opens stdout for logging.
void OpenStdout();
// Opens file for logging.
void OpenFile(const char* name);
// Opens a temporary file for logging.
void OpenTemporaryFile();
// Implementation of writing to a log file.
int WriteToFile(const char* msg, int length) {
DCHECK_NOT_NULL(output_handle_);
os_.write(msg, length);
DCHECK(!os_.bad());
size_t rv = fwrite(msg, 1, length, output_handle_);
DCHECK_EQ(length, rv);
USE(rv);
return length;
}
......@@ -121,7 +128,6 @@ class Log {
// When logging is active output_handle_ is used to store a pointer to log
// destination. mutex_ should be acquired before using output_handle_.
FILE* output_handle_;
OFStream os_;
// mutex_ is a Mutex used for enforcing exclusive
// access to the formatting buffer and the log file or log memory buffer.
......@@ -129,7 +135,7 @@ class Log {
// Buffer used for formatting log messages. This is a singleton buffer and
// mutex_ should be acquired before using it.
char* format_buffer_;
char* message_buffer_;
Logger* logger_;
......
......@@ -725,7 +725,7 @@ Logger::Logger(Isolate* isolate)
profiler_(nullptr),
log_events_(nullptr),
is_logging_(false),
log_(nullptr),
log_(new Log(this)),
perf_basic_logger_(nullptr),
perf_jit_logger_(nullptr),
ll_logger_(nullptr),
......@@ -749,7 +749,7 @@ void Logger::removeCodeEventListener(CodeEventListener* listener) {
void Logger::ProfilerBeginEvent() {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << "profiler,\"begin\"," << FLAG_prof_sampling_interval;
msg.Append("profiler,\"begin\",%d", FLAG_prof_sampling_interval);
msg.WriteToLogFile();
}
......@@ -762,7 +762,7 @@ void Logger::StringEvent(const char* name, const char* value) {
void Logger::UncheckedStringEvent(const char* name, const char* value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << name << ",\"" << value << "\"";
msg.Append("%s,\"%s\"", name, value);
msg.WriteToLogFile();
}
......@@ -780,7 +780,7 @@ void Logger::IntPtrTEvent(const char* name, intptr_t value) {
void Logger::UncheckedIntEvent(const char* name, int value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << name << "," << value;
msg.Append("%s,%d", name, value);
msg.WriteToLogFile();
}
......@@ -796,7 +796,7 @@ void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
void Logger::HandleEvent(const char* name, Object** location) {
if (!log_->IsEnabled() || !FLAG_log_handles) return;
Log::MessageBuilder msg(log_);
msg << name << "," << static_cast<void*>(location);
msg.Append("%s,%p", name, static_cast<void*>(location));
msg.WriteToLogFile();
}
......@@ -825,9 +825,9 @@ void Logger::SharedLibraryEvent(const std::string& library_path,
intptr_t aslr_slide) {
if (!log_->IsEnabled() || !FLAG_prof_cpp) return;
Log::MessageBuilder msg(log_);
msg << "shared-library,\"" << library_path.c_str() << "\","
<< reinterpret_cast<void*>(start) << "," << reinterpret_cast<void*>(end)
<< "," << aslr_slide;
msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR
",%" V8PRIdPTR,
library_path.c_str(), start, end, aslr_slide);
msg.WriteToLogFile();
}
......@@ -837,7 +837,7 @@ void Logger::CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(code, pc);
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg << "code-deopt," << since_epoch << "," << code->CodeSize() << ",";
msg.Append("code-deopt,%d,%d,", since_epoch, code->CodeSize());
msg.AppendAddress(code->instruction_start());
// Deoptimization position.
......@@ -851,20 +851,20 @@ void Logger::CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
} else {
deopt_location << "<unknown>";
}
msg << "," << inlining_id << "," << script_offset;
msg.Append(",%d,%d,", inlining_id, script_offset);
switch (kind) {
case kLazy:
msg << "\"lazy\",";
msg.Append("\"lazy\",");
break;
case kSoft:
msg << "\"soft\",";
msg.Append("\"soft\",");
break;
case kEager:
msg << "\"eager\",";
msg.Append("\"eager\",");
break;
}
msg.AppendDoubleQuotedString(deopt_location.str().c_str());
msg << ",";
msg.Append(",");
msg.AppendDoubleQuotedString(DeoptimizeReasonToString(info.deopt_reason));
msg.WriteToLogFile();
}
......@@ -875,7 +875,7 @@ void Logger::CurrentTimeEvent() {
DCHECK(FLAG_log_internal_timer_events);
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg << "current-time," << since_epoch;
msg.Append("current-time,%d", since_epoch);
msg.WriteToLogFile();
}
......@@ -883,19 +883,12 @@ void Logger::CurrentTimeEvent() {
void Logger::TimerEvent(Logger::StartEnd se, const char* name) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
switch (se) {
case START:
msg << "timer-event-start";
break;
case END:
msg << "timer-event-end";
break;
case STAMP:
msg << "timer-event";
}
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg.AppendDoubleQuotedString(name);
msg << "," << since_epoch;
const char* format = (se == START)
? "timer-event-start,\"%s\",%ld"
: (se == END) ? "timer-event-end,\"%s\",%ld"
: "timer-event,\"%s\",%ld";
msg.Append(format, name, since_epoch);
msg.WriteToLogFile();
}
......@@ -979,8 +972,7 @@ void Logger::ApiEntryCall(const char* name) {
void Logger::NewEvent(const char* name, void* object, size_t size) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg << "new," << name << "," << object << ","
<< static_cast<unsigned int>(size);
msg.Append("new,%s,%p,%u", name, object, static_cast<unsigned int>(size));
msg.WriteToLogFile();
}
......@@ -988,7 +980,7 @@ void Logger::NewEvent(const char* name, void* object, size_t size) {
void Logger::DeleteEvent(const char* name, void* object) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg << "delete," << name << "," << object;
msg.Append("delete,%s,%p", name, object);
msg.WriteToLogFile();
}
......@@ -997,19 +989,27 @@ void Logger::CallbackEventInternal(const char* prefix, Name* name,
Address entry_point) {
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT] << ","
<< kLogEventsNames[CodeEventListener::CALLBACK_TAG] << ",-2,";
msg.Append("%s,%s,-2,",
kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT],
kLogEventsNames[CodeEventListener::CALLBACK_TAG]);
int timestamp = static_cast<int>(timer_.Elapsed().InMicroseconds());
msg << timestamp << ",";
msg.Append("%d,", timestamp);
msg.AppendAddress(entry_point);
if (name->IsString()) {
msg << ",1,\"" << prefix;
msg.AppendEscapedString(String::cast(name));
msg << "\"";
std::unique_ptr<char[]> str =
String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append(",1,\"%s%s\"", prefix, str.get());
} else {
Symbol* symbol = Symbol::cast(name);
msg << ",1,";
msg.AppendSymbolName(symbol);
if (symbol->name()->IsUndefined(symbol->GetIsolate())) {
msg.Append(",1,symbol(hash %x)", symbol->Hash());
} else {
std::unique_ptr<char[]> str =
String::cast(symbol->name())
->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(),
symbol->Hash());
}
}
msg.WriteToLogFile();
}
......@@ -1031,15 +1031,17 @@ void Logger::SetterCallbackEvent(Name* name, Address entry_point) {
namespace {
void AppendCodeCreateHeader(Log::MessageBuilder& msg,
void AppendCodeCreateHeader(Log::MessageBuilder* msg,
CodeEventListener::LogEventsAndTags tag,
AbstractCode* code, base::ElapsedTimer* timer) {
msg << kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT] << ","
<< kLogEventsNames[tag] << "," << code->kind();
DCHECK(msg);
msg->Append("%s,%s,%d,",
kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT],
kLogEventsNames[tag], code->kind());
int timestamp = static_cast<int>(timer->Elapsed().InMicroseconds());
msg << "," << timestamp << ",";
msg.AppendAddress(code->instruction_start());
msg << "," << code->instruction_size() << ",";
msg->Append("%d,", timestamp);
msg->AppendAddress(code->instruction_start());
msg->Append(",%d,", code->instruction_size());
}
} // namespace
......@@ -1049,7 +1051,7 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
if (!is_logging_code_events()) return;
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(msg, tag, code, &timer_);
AppendCodeCreateHeader(&msg, tag, code, &timer_);
msg.AppendDoubleQuotedString(comment);
msg.WriteToLogFile();
}
......@@ -1059,9 +1061,11 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
if (!is_logging_code_events()) return;
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(msg, tag, code, &timer_);
AppendCodeCreateHeader(&msg, tag, code, &timer_);
if (name->IsString()) {
msg.AppendDoubleQuotedString(String::cast(name));
msg.Append('"');
msg.AppendDetailed(String::cast(name), false);
msg.Append('"');
} else {
msg.AppendSymbolName(Symbol::cast(name));
}
......@@ -1079,15 +1083,17 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
}
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(msg, tag, code, &timer_);
AppendCodeCreateHeader(&msg, tag, code, &timer_);
if (name->IsString()) {
msg.AppendDoubleQuotedString(String::cast(name));
std::unique_ptr<char[]> str =
String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("\"%s\"", str.get());
} else {
msg.AppendSymbolName(Symbol::cast(name));
}
msg << ',';
msg.Append(',');
msg.AppendAddress(shared->address());
msg << "," << ComputeMarker(shared, code);
msg.Append(",%s", ComputeMarker(shared, code));
msg.WriteToLogFile();
}
......@@ -1101,50 +1107,57 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
if (!is_logging_code_events()) return;
if (!FLAG_log_code || !log_->IsEnabled()) return;
{
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(msg, tag, code, &timer_);
msg << "\"";
msg.AppendEscapedString(shared->DebugName());
msg << " ";
AppendCodeCreateHeader(&msg, tag, code, &timer_);
std::unique_ptr<char[]> name =
shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("\"%s ", name.get());
if (source->IsString()) {
msg.AppendEscapedString(String::cast(source));
std::unique_ptr<char[]> sourcestr = String::cast(source)->ToCString(
DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("%s", sourcestr.get());
} else {
msg.AppendSymbolName(Symbol::cast(source));
}
msg << ":" << line << ":" << column << "\",";
msg.Append(":%d:%d\",", line, column);
msg.AppendAddress(shared->address());
msg << "," << ComputeMarker(shared, code);
msg.Append(",%s", ComputeMarker(shared, code));
msg.WriteToLogFile();
}
if (!FLAG_log_source_code) return;
if (FLAG_log_source_code) {
Object* script_object = shared->script();
if (!script_object->IsScript()) return;
if (script_object->IsScript()) {
// Make sure the script is written to the log file.
std::ostringstream os;
Script* script = Script::cast(script_object);
int script_id = script->id();
if (logged_source_code_.find(script_id) != logged_source_code_.end()) {
return;
}
if (logged_source_code_.find(script_id) == logged_source_code_.end()) {
// This script has not been logged yet.
logged_source_code_.insert(script_id);
Object* source_object = script->source();
if (source_object->IsString()) {
Log::MessageBuilder msg(log_);
String* source_code = String::cast(source_object);
msg << "script," << script_id << ",\"";
os << "script," << script_id << ",\"";
msg.AppendUnbufferedCString(os.str().c_str());
// Log the script name.
if (script->name()->IsString()) {
msg.AppendEscapedString(String::cast(script->name()));
msg << "\",\"";
msg.AppendUnbufferedHeapString(String::cast(script->name()));
msg.AppendUnbufferedCString("\",\"");
} else {
msg << "<unknown>\",\"";
msg.AppendUnbufferedCString("<unknown>\",\"");
}
// Log the source code.
msg.AppendEscapedString(source_code);
msg << "\"";
msg.WriteToLogFile();
msg.AppendUnbufferedHeapString(source_code);
os.str("");
os << "\"" << std::endl;
msg.AppendUnbufferedCString(os.str().c_str());
os.str("");
}
}
// We log source code information in the form:
......@@ -1168,7 +1181,7 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
// <function-id> is an index into the <fns> function table
// <fns> is the function table encoded as a sequence of strings
// S<shared-function-info-address>
msg << "code-source-info," << static_cast<void*>(code->instruction_start())
os << "code-source-info," << static_cast<void*>(code->instruction_start())
<< "," << script_id << "," << shared->start_position() << ","
<< shared->end_position() << ",";
......@@ -1180,13 +1193,14 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
is_first = false;
}
SourcePosition pos = iterator.source_position();
msg << "C" << iterator.code_offset() << "O" << pos.ScriptOffset();
os << "C" << iterator.code_offset();
os << "O" << pos.ScriptOffset();
if (pos.isInlined()) {
msg << "I" << pos.InliningId();
os << "I" << pos.InliningId();
hasInlined = true;
}
}
msg << ",";
os << ",";
int maxInlinedId = -1;
if (hasInlined) {
PodArray<InliningPosition>* inlining_positions =
......@@ -1194,33 +1208,38 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
->InliningPositions();
for (int i = 0; i < inlining_positions->length(); i++) {
InliningPosition inlining_pos = inlining_positions->get(i);
msg << "F";
os << "F";
if (inlining_pos.inlined_function_id != -1) {
msg << inlining_pos.inlined_function_id;
os << inlining_pos.inlined_function_id;
if (inlining_pos.inlined_function_id > maxInlinedId) {
maxInlinedId = inlining_pos.inlined_function_id;
}
}
SourcePosition pos = inlining_pos.position;
msg << "O" << pos.ScriptOffset();
os << "O" << pos.ScriptOffset();
if (pos.isInlined()) {
msg << "I" << pos.InliningId();
os << "I" << pos.InliningId();
}
}
}
msg << ",";
os << ",";
if (hasInlined) {
DeoptimizationData* deopt_data =
DeoptimizationData::cast(Code::cast(code)->deoptimization_data());
msg << std::hex;
os << std::hex;
for (int i = 0; i <= maxInlinedId; i++) {
msg << "S"
<< static_cast<void*>(deopt_data->GetInlinedFunction(i)->address());
os << "S"
<< static_cast<void*>(
deopt_data->GetInlinedFunction(i)->address());
}
os << std::dec;
}
os << std::endl;
Log::MessageBuilder msg(log_);
msg.AppendUnbufferedCString(os.str().c_str());
}
msg << std::dec;
}
msg.WriteToLogFile();
}
void Logger::CodeDisableOptEvent(AbstractCode* code,
......@@ -1228,11 +1247,11 @@ void Logger::CodeDisableOptEvent(AbstractCode* code,
if (!is_logging_code_events()) return;
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT] << ",";
msg.AppendDoubleQuotedString(shared->DebugName());
msg << ",";
msg.AppendDoubleQuotedString(
GetBailoutReason(shared->disable_optimization_reason()));
msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]);
std::unique_ptr<char[]> name =
shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("\"%s\",", name.get());
msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason()));
msg.WriteToLogFile();
}
......@@ -1247,10 +1266,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) {
if (!is_logging_code_events()) return;
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(msg, CodeEventListener::REG_EXP_TAG, code, &timer_);
msg << '"';
AppendCodeCreateHeader(&msg, CodeEventListener::REG_EXP_TAG, code, &timer_);
msg.Append('"');
msg.AppendDetailed(source, false);
msg << '"';
msg.Append('"');
msg.WriteToLogFile();
}
......@@ -1282,8 +1301,8 @@ void Logger::CodeLinePosInfoRecordEvent(AbstractCode* code,
void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) {
if (code_name == nullptr) return; // Not a code object.
Log::MessageBuilder msg(log_);
msg << kLogEventsNames[CodeEventListener::SNAPSHOT_CODE_NAME_EVENT] << ","
<< pos;
msg.Append("%s,%d,",
kLogEventsNames[CodeEventListener::SNAPSHOT_CODE_NAME_EVENT], pos);
msg.AppendDoubleQuotedString(code_name);
msg.WriteToLogFile();
}
......@@ -1298,9 +1317,9 @@ void Logger::MoveEventInternal(CodeEventListener::LogEventsAndTags event,
Address from, Address to) {
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg << kLogEventsNames[event] << ",";
msg.Append("%s,", kLogEventsNames[event]);
msg.AppendAddress(from);
msg << ",";
msg.Append(',');
msg.AppendAddress(to);
msg.WriteToLogFile();
}
......@@ -1309,11 +1328,11 @@ void Logger::MoveEventInternal(CodeEventListener::LogEventsAndTags event,
void Logger::ResourceEvent(const char* name, const char* tag) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg << name << "," << tag << ",";
msg.Append("%s,%s,", name, tag);
uint32_t sec, usec;
if (base::OS::GetUserTime(&sec, &usec) != -1) {
msg << sec << "," << usec << ",";
msg.Append("%d,%d,", sec, usec);
}
msg.Append("%.0f", V8::GetCurrentPlatform()->CurrentClockTimeMillis());
msg.WriteToLogFile();
......@@ -1326,9 +1345,13 @@ void Logger::SuspectReadEvent(Name* name, Object* obj) {
String* class_name = obj->IsJSObject()
? JSObject::cast(obj)->class_name()
: isolate_->heap()->empty_string();
msg << "suspect-read," << class_name << ",";
msg.Append("suspect-read,");
msg.Append(class_name);
msg.Append(',');
if (name->IsString()) {
msg.AppendDoubleQuotedString(String::cast(name));
msg.Append('"');
msg.Append(String::cast(name));
msg.Append('"');
} else {
msg.AppendSymbolName(Symbol::cast(name));
}
......@@ -1341,8 +1364,8 @@ void Logger::HeapSampleBeginEvent(const char* space, const char* kind) {
Log::MessageBuilder msg(log_);
// Using non-relative system time in order to be able to synchronize with
// external memory profiling events (e.g. DOM memory size).
msg << "heap-sample-begin,\"" << space << "\",\"" << kind << "\",";
msg.Append("%.0f", V8::GetCurrentPlatform()->CurrentClockTimeMillis());
msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f", space, kind,
V8::GetCurrentPlatform()->CurrentClockTimeMillis());
msg.WriteToLogFile();
}
......@@ -1350,7 +1373,7 @@ void Logger::HeapSampleBeginEvent(const char* space, const char* kind) {
void Logger::HeapSampleEndEvent(const char* space, const char* kind) {
if (!log_->IsEnabled() || !FLAG_log_gc) return;
Log::MessageBuilder msg(log_);
msg << "heap-sample-end,\"" << space << "\",\"" << kind << "\"";
msg.Append("heap-sample-end,\"%s\",\"%s\"", space, kind);
msg.WriteToLogFile();
}
......@@ -1358,7 +1381,7 @@ void Logger::HeapSampleEndEvent(const char* space, const char* kind) {
void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
if (!log_->IsEnabled() || !FLAG_log_gc) return;
Log::MessageBuilder msg(log_);
msg << "heap-sample-item,\"" << type << "\"," << number << "," << bytes;
msg.Append("heap-sample-item,%s,%d,%d", type, number, bytes);
msg.WriteToLogFile();
}
......@@ -1368,7 +1391,7 @@ void Logger::RuntimeCallTimerEvent() {
RuntimeCallCounter* counter = stats->current_counter();
if (counter == nullptr) return;
Log::MessageBuilder msg(log_);
msg << "active-runtime-timer,";
msg.Append("active-runtime-timer,");
msg.AppendDoubleQuotedString(counter->name());
msg.WriteToLogFile();
}
......@@ -1380,20 +1403,24 @@ void Logger::TickEvent(v8::TickSample* sample, bool overflow) {
RuntimeCallTimerEvent();
}
Log::MessageBuilder msg(log_);
msg << kLogEventsNames[CodeEventListener::TICK_EVENT] << ','
<< reinterpret_cast<void*>(sample->pc) << ','
<< static_cast<int>(timer_.Elapsed().InMicroseconds());
msg.Append("%s,", kLogEventsNames[CodeEventListener::TICK_EVENT]);
msg.AppendAddress(reinterpret_cast<Address>(sample->pc));
msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds()));
if (sample->has_external_callback) {
msg << ",1," << reinterpret_cast<void*>(sample->external_callback_entry);
msg.Append(",1,");
msg.AppendAddress(
reinterpret_cast<Address>(sample->external_callback_entry));
} else {
msg << ",0," << reinterpret_cast<void*>(sample->tos);
msg.Append(",0,");
msg.AppendAddress(reinterpret_cast<Address>(sample->tos));
}
msg << ',' << static_cast<int>(sample->state);
msg.Append(",%d", static_cast<int>(sample->state));
if (overflow) {
msg << ",overflow";
msg.Append(",overflow");
}
for (unsigned i = 0; i < sample->frames_count; ++i) {
msg << ',' << reinterpret_cast<void*>(sample->stack[i]);
msg.Append(',');
msg.AppendAddress(reinterpret_cast<Address>(sample->stack[i]));
}
msg.WriteToLogFile();
}
......@@ -1404,21 +1431,26 @@ void Logger::ICEvent(const char* type, bool keyed, const Address pc, int line,
const char* slow_stub_reason) {
if (!log_->IsEnabled() || !FLAG_trace_ic) return;
Log::MessageBuilder msg(log_);
if (keyed) msg << "Keyed";
msg << type << ",";
if (keyed) msg.Append("Keyed");
msg.Append("%s,", type);
msg.AppendAddress(pc);
msg << "," << line << "," << column << "," << old_state << "," << new_state
<< "," << reinterpret_cast<void*>(map) << ",";
msg.Append(",%d,%d,", line, column);
msg.Append(old_state);
msg.Append(",");
msg.Append(new_state);
msg.Append(",");
msg.AppendAddress(reinterpret_cast<Address>(map));
msg.Append(",");
if (key->IsSmi()) {
msg << Smi::ToInt(key);
msg.Append("%d", Smi::ToInt(key));
} else if (key->IsNumber()) {
msg << key->Number();
msg.Append("%lf", key->Number());
} else if (key->IsString()) {
msg.AppendDetailed(String::cast(key), false);
} else if (key->IsSymbol()) {
msg.AppendSymbolName(Symbol::cast(key));
}
msg << "," << modifier << ",";
msg.Append(",%s,", modifier);
if (slow_stub_reason != nullptr) {
msg.AppendDoubleQuotedString(slow_stub_reason);
}
......@@ -1434,6 +1466,7 @@ void Logger::StopProfiler() {
}
}
// This function can be called when Log's mutex is acquired,
// either from main or Profiler's thread.
void Logger::LogFailure() {
......@@ -1749,7 +1782,7 @@ bool Logger::SetUp(Isolate* isolate) {
std::ostringstream log_file_name;
std::ostringstream source_log_file_name;
PrepareLogFileName(log_file_name, isolate, FLAG_logfile);
log_ = new Log(this, log_file_name.str().c_str());
log_->Initialize(log_file_name.str().c_str());
if (FLAG_perf_basic_prof) {
perf_basic_logger_ = new PerfBasicLogger();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment