Commit 761b4719 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

Reland "[logging] Use OFStream for log events"

This is a reland of 06ff9e97
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}

Change-Id: Iafda1c88d9180d188d6b8bd7d03d6d27100538d8
Reviewed-on: https://chromium-review.googlesource.com/731107
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48804}
parent 73109dd9
This diff is collapsed.
......@@ -13,6 +13,7 @@
#include "src/base/compiler-specific.h"
#include "src/base/platform/mutex.h"
#include "src/flags.h"
#include "src/ostreams.h"
namespace v8 {
namespace internal {
......@@ -22,8 +23,7 @@ class Logger;
// Functions and data for performing output of log messages.
class Log {
public:
// Performs process-wide initialization.
void Initialize(const char* log_file_name);
Log(Logger* log, const char* log_file_name);
// Disables logging, but preserves acquired resources.
void stop() { is_stopped_ = true; }
......@@ -66,11 +66,9 @@ 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);
......@@ -88,37 +86,32 @@ 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 AppendUnbufferedChar(char c);
void AppendUnbufferedCString(const char* str);
void AppendUnbufferedHeapString(String* source);
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;
}
// Write the log message to the log file currently opened.
// Finish the current log line an flush the it to the log file.
void WriteToLogFile();
private:
Log* log_;
base::LockGuard<base::Mutex> lock_guard_;
int pos_;
};
private:
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();
static FILE* CreateOutputHandle(const char* file_name);
// Implementation of writing to a log file.
int WriteToFile(const char* msg, int length) {
DCHECK_NOT_NULL(output_handle_);
size_t rv = fwrite(msg, 1, length, output_handle_);
DCHECK_EQ(length, rv);
USE(rv);
os_.write(msg, length);
DCHECK(!os_.bad());
return length;
}
......@@ -128,6 +121,7 @@ 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.
......@@ -135,7 +129,7 @@ class Log {
// Buffer used for formatting log messages. This is a singleton buffer and
// mutex_ should be acquired before using it.
char* message_buffer_;
char* format_buffer_;
Logger* logger_;
......
This diff is collapsed.
......@@ -187,6 +187,13 @@ if (typeof result !== "string") {
(c[2] ? c[2] : "---") + " " +
(c[3] ? c[3] : "---"));
}
out.push("================================================")
out.push("MAKE SURE TO USE A CLEAN ISOLATiE!");
out.push("Use tools/test.py");
out.push("================================================")
out.push("* Lines are the same");
out.push("--- Line is missing"
out.push("================================================")
}
result[0] ? true : out.join("\n");
} else {
......
......@@ -70,7 +70,7 @@ static const char* StrNStr(const char* s1, const char* s2, size_t n) {
// Look for a log line which starts with {prefix} and ends with {suffix}.
static const char* FindLogLine(i::Vector<const char>* log, const char* prefix,
const char* suffix) {
const char* suffix = nullptr) {
const char* start = log->start();
const char* end = start + log->length();
CHECK_EQ(end[0], '\0');
......@@ -79,6 +79,7 @@ static const char* FindLogLine(i::Vector<const char>* log, const char* prefix,
while (start < end) {
const char* prefixResult = StrNStr(start, prefix, (end - start));
if (!prefixResult) return NULL;
if (suffix == nullptr) return prefixResult;
const char* suffixResult =
StrNStr(prefixResult, suffix, (end - prefixResult));
if (!suffixResult) return NULL;
......@@ -122,6 +123,8 @@ class ScopedLoggerInitializer {
Logger* logger() { return logger_; }
void PrintLog() { printf("%s", log_.start()); }
v8::Local<v8::String> GetLogString() {
return v8::String::NewFromUtf8(isolate_, log_.start(),
v8::NewStringType::kNormal, log_.length())
......@@ -134,7 +137,7 @@ class ScopedLoggerInitializer {
CHECK(exists);
}
const char* FindLine(const char* prefix, const char* suffix) {
const char* FindLine(const char* prefix, const char* suffix = nullptr) {
return FindLogLine(&log_, prefix, suffix);
}
......@@ -176,6 +179,9 @@ TEST(FindLogLine) {
"prefix4 suffix4";
// Make sure the vector contains the terminating \0 character.
i::Vector<const char> log(string, strlen(string));
CHECK(FindLogLine(&log, "prefix1, stuff, suffix1"));
CHECK(FindLogLine(&log, "prefix1, stuff"));
CHECK(FindLogLine(&log, "prefix1"));
CHECK(FindLogLine(&log, "prefix1", "suffix1"));
CHECK(FindLogLine(&log, "prefix1", "suffix1"));
CHECK(!FindLogLine(&log, "prefix2", "suffix2"));
......@@ -654,3 +660,40 @@ TEST(Issue539892) {
}
isolate->Dispose();
}
TEST(LogAll) {
SETUP_FLAGS();
i::FLAG_log_all = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
ScopedLoggerInitializer logger(saved_log, saved_prof, isolate);
// Function that will
const char* source_text =
"function testAddFn(a,b) { return a + b };"
"let result;"
"for (let i = 0; i < 100000; i++) { result = testAddFn(i, i); };"
"testAddFn('1', 1);"
"for (let i = 0; i < 100000; i++) { result = testAddFn('1', i); }";
CompileRun(source_text);
logger.StopLogging();
// We should find at least one code-creation even for testAddFn();
CHECK(logger.FindLine("api,v8::Context::New"));
CHECK(logger.FindLine("timer-event-start", "V8.CompileCode"));
CHECK(logger.FindLine("timer-event-end", "V8.CompileCode"));
CHECK(logger.FindLine("code-creation,Script", ":1:1"));
CHECK(logger.FindLine("api,v8::Script::Run"));
CHECK(logger.FindLine("code-creation,LazyCompile,", "testAddFn"));
if (i::FLAG_opt && !i::FLAG_always_opt) {
CHECK(logger.FindLine("code-deopt,", "soft"));
CHECK(logger.FindLine("timer-event-start", "V8.DeoptimizeCode"));
CHECK(logger.FindLine("timer-event-end", "V8.DeoptimizeCode"));
}
}
isolate->Dispose();
}
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