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

Current logger code is messy. It mixes together

four or even five different logging destinations.
I think we can extract the code related to a destination
into a separate class, do the same for the all destinations
and have four classes with more or less simple common logging
API

BUG=none
Meta-bug= https://code.google.com/p/chromium/issues/detail?id=260203

R=yangguo@chromium.org, yurys@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 01080fa7
......@@ -35,26 +35,19 @@ namespace internal {
const char* const Log::kLogToTemporaryFile = "&";
const char* const Log::kLogToConsole = "-";
Log::Log(Logger* logger)
: is_stopped_(false),
output_handle_(NULL),
ll_output_handle_(NULL),
mutex_(NULL),
message_buffer_(NULL),
logger_(logger) {
}
static void AddIsolateIdIfNeeded(StringStream* stream) {
Isolate* isolate = Isolate::Current();
if (isolate->IsDefaultIsolate()) return;
stream->Add("isolate-%p-", isolate);
}
void Log::Initialize() {
void Log::Initialize(const char* log_file_name) {
mutex_ = OS::CreateMutex();
message_buffer_ = NewArray<char>(kMessageBufferSize);
......@@ -81,55 +74,12 @@ void Log::Initialize() {
// If we're logging anything, we need to open the log file.
if (Log::InitLogAtStart()) {
if (strcmp(FLAG_logfile, "-") == 0) {
if (strcmp(log_file_name, kLogToConsole) == 0) {
OpenStdout();
} else if (strcmp(FLAG_logfile, kLogToTemporaryFile) == 0) {
} else if (strcmp(log_file_name, kLogToTemporaryFile) == 0) {
OpenTemporaryFile();
} else {
if (strchr(FLAG_logfile, '%') != NULL ||
!Isolate::Current()->IsDefaultIsolate()) {
// If there's a '%' in the log file name we have to expand
// placeholders.
HeapStringAllocator allocator;
StringStream stream(&allocator);
AddIsolateIdIfNeeded(&stream);
for (const char* p = FLAG_logfile; *p; p++) {
if (*p == '%') {
p++;
switch (*p) {
case '\0':
// If there's a % at the end of the string we back up
// one character so we can escape the loop properly.
p--;
break;
case 'p':
stream.Add("%d", OS::GetCurrentProcessId());
break;
case 't': {
// %t expands to the current time in milliseconds.
double time = OS::TimeCurrentMillis();
stream.Add("%.0f", FmtElm(time));
break;
}
case '%':
// %% expands (contracts really) to %.
stream.Put('%');
break;
default:
// All other %'s expand to themselves.
stream.Put('%');
stream.Put(*p);
break;
}
} else {
stream.Put(*p);
}
}
SmartArrayPointer<const char> expanded = stream.ToCString();
OpenFile(*expanded);
} else {
OpenFile(FLAG_logfile);
}
OpenFile(log_file_name);
}
}
}
......@@ -147,27 +97,9 @@ void Log::OpenTemporaryFile() {
}
// Extension added to V8 log file name to get the low-level log name.
static const char kLowLevelLogExt[] = ".ll";
// File buffer size of the low-level log. We don't use the default to
// minimize the associated overhead.
static const int kLowLevelLogBufferSize = 2 * MB;
void Log::OpenFile(const char* name) {
ASSERT(!IsEnabled());
output_handle_ = OS::FOpen(name, OS::LogFileOpenMode);
if (FLAG_ll_prof) {
// Open the low-level log file.
size_t len = strlen(name);
ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLowLevelLogExt)));
OS::MemCopy(ll_name.start(), name, len);
OS::MemCopy(ll_name.start() + len,
kLowLevelLogExt, sizeof(kLowLevelLogExt));
ll_output_handle_ = OS::FOpen(ll_name.start(), OS::LogFileOpenMode);
setvbuf(ll_output_handle_, NULL, _IOFBF, kLowLevelLogBufferSize);
}
}
......@@ -181,8 +113,6 @@ FILE* Log::Close() {
}
}
output_handle_ = NULL;
if (ll_output_handle_ != NULL) fclose(ll_output_handle_);
ll_output_handle_ = NULL;
DeleteArray(message_buffer_);
message_buffer_ = NULL;
......
......@@ -39,7 +39,7 @@ class Logger;
class Log {
public:
// Performs process-wide initialization.
void Initialize();
void Initialize(const char* log_file_name);
// Disables logging, but preserves acquired resources.
void stop() { is_stopped_ = true; }
......@@ -66,6 +66,7 @@ class Log {
// This mode is only used in tests, as temporary files are automatically
// deleted on close and thus can't be accessed afterwards.
static const char* const kLogToTemporaryFile;
static const char* const kLogToConsole;
private:
explicit Log(Logger* logger);
......@@ -96,9 +97,6 @@ class Log {
// destination. mutex_ should be acquired before using output_handle_.
FILE* output_handle_;
// Used when low-level profiling is active.
FILE* ll_output_handle_;
// mutex_ is a Mutex used for enforcing exclusive
// access to the formatting buffer and the log file or log memory buffer.
Mutex* mutex_;
......
This diff is collapsed.
......@@ -151,6 +151,7 @@ class CompilationInfo;
// original tags when writing to the log.
class LowLevelLogger;
class Sampler;
......@@ -430,30 +431,8 @@ class Logger {
// Appends symbol for the name.
void AppendSymbolName(LogMessageBuilder*, Symbol*);
// Emits general information about generated code.
void LogCodeInfo();
void RegisterSnapshotCodeName(Code* code, const char* name, int name_size);
// Low-level logging support.
void LowLevelCodeCreateEvent(Code* code, const char* name, int name_size);
void LowLevelCodeMoveEvent(Address from, Address to);
void LowLevelCodeDeleteEvent(Address from);
void LowLevelSnapshotPositionEvent(Address addr, int pos);
void LowLevelLogWriteBytes(const char* bytes, int size);
template <typename T>
void LowLevelLogWriteStruct(const T& s) {
char tag = T::kTag;
LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag));
LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s));
}
// Emits a profiler tick event. Used by the profiler thread.
void TickEvent(TickSample* sample, bool overflow);
......@@ -495,6 +474,7 @@ class Logger {
int cpu_profiler_nesting_;
Log* log_;
LowLevelLogger* ll_logger_;
NameBuffer* name_buffer_;
......
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