Commit ea97288e authored by loislo@chromium.org's avatar loislo@chromium.org

Logger: remove dependency between Logger and LogMessageBuilder.

LogMessageBuilder is a helper class for Log.
So I made it a nested class and removed the dependency from Logger.

BUG=none
TEST=no changes in the logic
R=yangguo@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/19768003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15760 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 607a5314
......@@ -125,15 +125,15 @@ FILE* Log::Close() {
}
LogMessageBuilder::LogMessageBuilder(Logger* logger)
: log_(logger->log_),
Log::MessageBuilder::MessageBuilder(Log* log)
: log_(log),
sl(log_->mutex_),
pos_(0) {
ASSERT(log_->message_buffer_ != NULL);
}
void LogMessageBuilder::Append(const char* format, ...) {
void Log::MessageBuilder::Append(const char* format, ...) {
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
va_list args;
......@@ -144,7 +144,7 @@ void LogMessageBuilder::Append(const char* format, ...) {
}
void LogMessageBuilder::AppendVA(const char* format, va_list args) {
void Log::MessageBuilder::AppendVA(const char* format, va_list args) {
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
int result = v8::internal::OS::VSNPrintF(buf, format, args);
......@@ -159,7 +159,7 @@ void LogMessageBuilder::AppendVA(const char* format, va_list args) {
}
void LogMessageBuilder::Append(const char c) {
void Log::MessageBuilder::Append(const char c) {
if (pos_ < Log::kMessageBufferSize) {
log_->message_buffer_[pos_++] = c;
}
......@@ -167,7 +167,7 @@ void LogMessageBuilder::Append(const char c) {
}
void LogMessageBuilder::AppendDoubleQuotedString(const char* string) {
void Log::MessageBuilder::AppendDoubleQuotedString(const char* string) {
Append('"');
for (const char* p = string; *p != '\0'; p++) {
if (*p == '"') {
......@@ -179,7 +179,7 @@ void LogMessageBuilder::AppendDoubleQuotedString(const char* string) {
}
void LogMessageBuilder::Append(String* str) {
void Log::MessageBuilder::Append(String* str) {
DisallowHeapAllocation no_gc; // Ensure string stay valid.
int length = str->length();
for (int i = 0; i < length; i++) {
......@@ -188,12 +188,24 @@ void LogMessageBuilder::Append(String* str) {
}
void LogMessageBuilder::AppendAddress(Address addr) {
void Log::MessageBuilder::AppendAddress(Address addr) {
Append("0x%" V8PRIxPTR, addr);
}
void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
void Log::MessageBuilder::AppendSymbolName(Symbol* symbol) {
ASSERT(symbol);
Append("symbol(");
if (!symbol->name()->IsUndefined()) {
Append("\"");
AppendDetailed(String::cast(symbol->name()), false);
Append("\" ");
}
Append("hash %x)", symbol->Hash());
}
void Log::MessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
if (str == NULL) return;
DisallowHeapAllocation no_gc; // Ensure string stay valid.
int len = str->length();
......@@ -226,7 +238,7 @@ void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
}
void LogMessageBuilder::AppendStringPart(const char* str, int len) {
void Log::MessageBuilder::AppendStringPart(const char* str, int len) {
if (pos_ + len > Log::kMessageBufferSize) {
len = Log::kMessageBufferSize - pos_;
ASSERT(len >= 0);
......@@ -240,7 +252,7 @@ void LogMessageBuilder::AppendStringPart(const char* str, int len) {
}
void LogMessageBuilder::WriteToLogFile() {
void Log::MessageBuilder::WriteToLogFile() {
ASSERT(pos_ <= Log::kMessageBufferSize);
const int written = log_->WriteToFile(log_->message_buffer_, pos_);
if (written != pos_) {
......
......@@ -68,6 +68,49 @@ class Log {
static const char* const kLogToTemporaryFile;
static const char* const kLogToConsole;
// Utility class for formatting log messages. It fills the message into the
// static buffer in Log.
class MessageBuilder BASE_EMBEDDED {
public:
// Create a message builder starting from position 0.
// This acquires the mutex in the log as well.
explicit MessageBuilder(Log* log);
~MessageBuilder() { }
// Append string data to the log message.
void Append(const char* format, ...);
// Append string data to the log message.
void 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);
// Append a heap string.
void Append(String* str);
// Appends an address.
void AppendAddress(Address addr);
void AppendSymbolName(Symbol* symbol);
void AppendDetailed(String* str, bool show_impl_info);
// Append a portion of a string.
void AppendStringPart(const char* str, int len);
// Write the log message to the log file currently opened.
void WriteToLogFile();
private:
Log* log_;
ScopedLock sl;
int pos_;
};
private:
explicit Log(Logger* logger);
......@@ -108,51 +151,9 @@ class Log {
Logger* logger_;
friend class Logger;
friend class LogMessageBuilder;
};
// Utility class for formatting log messages. It fills the message into the
// static buffer in Log.
class LogMessageBuilder BASE_EMBEDDED {
public:
// Create a message builder starting from position 0. This acquires the mutex
// in the log as well.
explicit LogMessageBuilder(Logger* logger);
~LogMessageBuilder() { }
// Append string data to the log message.
void Append(const char* format, ...);
// Append string data to the log message.
void 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);
// Append a heap string.
void Append(String* str);
// Appends an address.
void AppendAddress(Address addr);
void AppendDetailed(String* str, bool show_impl_info);
// Append a portion of a string.
void AppendStringPart(const char* str, int len);
// Write the log message to the log file currently opened.
void WriteToLogFile();
private:
Log* log_;
ScopedLock sl;
int pos_;
};
} } // namespace v8::internal
#endif // V8_LOG_UTILS_H_
This diff is collapsed.
......@@ -31,7 +31,6 @@
#include "allocation.h"
#include "objects.h"
#include "platform.h"
#include "log-utils.h"
namespace v8 {
namespace internal {
......@@ -71,15 +70,15 @@ namespace internal {
// tick profiler requires code events, so --prof implies --log-code.
// Forward declarations.
class LogMessageBuilder;
class CompilationInfo;
class CpuProfiler;
class Isolate;
class Log;
class PositionsRecorder;
class Profiler;
class Semaphore;
struct TickSample;
class Ticker;
class Isolate;
class PositionsRecorder;
class CpuProfiler;
class CompilationInfo;
struct TickSample;
#undef LOG
#define LOG(isolate, Call) \
......@@ -409,12 +408,6 @@ class Logger {
// Helper method. It dumps name into name_buffer_.
void AppendName(Name* name);
// Appends standard code header.
void AppendCodeCreateHeader(LogMessageBuilder*, LogEventsAndTags, Code*);
// Appends symbol for the name.
void AppendSymbolName(LogMessageBuilder*, Symbol*);
void RegisterSnapshotCodeName(Code* code, const char* name, int name_size);
// Emits a profiler tick event. Used by the profiler thread.
......@@ -446,7 +439,6 @@ class Logger {
// private members.
friend class EventLog;
friend class Isolate;
friend class LogMessageBuilder;
friend class TimeLog;
friend class Profiler;
template <StateTag Tag> friend class VMState;
......
......@@ -36,6 +36,7 @@
#include "v8.h"
#include "log.h"
#include "log-utils.h"
#include "cpu-profiler.h"
#include "natives.h"
#include "v8threads.h"
......
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