Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Unified Diff: src/log-utils.cc

Issue 125114: Involve more log compression techniques. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/log-utils.h ('k') | test/cctest/test-log-utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/log-utils.cc
diff --git a/src/log-utils.cc b/src/log-utils.cc
index 45f1131419a801c4d9b93d5999b3987bb0bc2251..b3b3192b2fb26ed5d82d13b0714ba04e58e773d3 100644
--- a/src/log-utils.cc
+++ b/src/log-utils.cc
@@ -127,18 +127,11 @@ LogDynamicBuffer* Log::output_buffer_ = NULL;
const char* Log::kDynamicBufferSeal = "profiler,\"pause\"\n";
Mutex* Log::mutex_ = NULL;
char* Log::message_buffer_ = NULL;
-LogRecordCompressor* Log::record_compressor_ = NULL;
-// Must be the same as compressed tick event name from Logger.
-const char* Log::kCompressedTickEventName = "t,";
void Log::Init() {
mutex_ = OS::CreateMutex();
message_buffer_ = NewArray<char>(kMessageBufferSize);
- if (FLAG_compress_log) {
- record_compressor_ = new LogRecordCompressor(
- kRecordCompressorWindow, strlen(kCompressedTickEventName));
- }
}
@@ -180,9 +173,6 @@ void Log::Close() {
}
Write = NULL;
- delete record_compressor_;
- record_compressor_ = NULL;
-
DeleteArray(message_buffer_);
message_buffer_ = NULL;
@@ -263,6 +253,27 @@ void LogMessageBuilder::Append(String* str) {
}
+void LogMessageBuilder::AppendAddress(Address addr) {
+ static Address last_address_ = NULL;
+ AppendAddress(addr, last_address_);
+ last_address_ = addr;
+}
+
+
+void LogMessageBuilder::AppendAddress(Address addr, Address bias) {
+ if (!FLAG_compress_log || bias == NULL) {
+ Append("0x%" V8PRIxPTR, addr);
+ } else {
+ intptr_t delta = addr - bias;
+ // To avoid printing negative offsets in an unsigned form,
+ // we are printing an absolute value with a sign.
+ const char sign = delta >= 0 ? '+' : '-';
+ if (sign == '-') { delta = -delta; }
+ Append("%c%" V8PRIxPTR, sign, delta);
+ }
+}
+
+
void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
AssertNoAllocation no_heap_allocation; // Ensure string stay valid.
int len = str->length();
@@ -293,24 +304,19 @@ void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
}
-bool LogMessageBuilder::StoreInCompressor() {
- if (!FLAG_compress_log) return true;
- ASSERT(Log::record_compressor_ != NULL);
- return Log::record_compressor_->Store(
- Vector<const char>(Log::message_buffer_, pos_));
+bool LogMessageBuilder::StoreInCompressor(LogRecordCompressor* compressor) {
+ return compressor->Store(Vector<const char>(Log::message_buffer_, pos_));
}
-bool LogMessageBuilder::RetrieveCompressedPrevious(const char* prefix) {
- if (!FLAG_compress_log) return true;
- ASSERT(Log::record_compressor_ != NULL);
+bool LogMessageBuilder::RetrieveCompressedPrevious(
+ LogRecordCompressor* compressor, const char* prefix) {
pos_ = 0;
if (prefix[0] != '\0') Append(prefix);
Vector<char> prev_record(Log::message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
- const bool has_previous =
- Log::record_compressor_->RetrievePreviousCompressed(&prev_record);
- if (!has_previous) return false;
+ const bool has_prev = compressor->RetrievePreviousCompressed(&prev_record);
+ if (!has_prev) return false;
pos_ += prev_record.length();
return true;
}
@@ -334,6 +340,10 @@ void LogMessageBuilder::WriteCStringToLogFile(const char* str) {
}
+// Formatting string for back references to the whole line. E.g. "#2" means
+// "the second line above".
+const char* LogRecordCompressor::kLineBackwardReferenceFormat = "#%d";
+
// Formatting string for back references. E.g. "#2:10" means
// "the second line above, start from char 10 (0-based)".
const char* LogRecordCompressor::kBackwardReferenceFormat = "#%d:%d";
@@ -346,6 +356,34 @@ LogRecordCompressor::~LogRecordCompressor() {
}
+static int GetNumberLength(int number) {
+ ASSERT(number >= 0);
+ ASSERT(number < 10000);
+ if (number < 10) return 1;
+ if (number < 100) return 2;
+ if (number < 1000) return 3;
+ return 4;
+}
+
+
+int LogRecordCompressor::GetBackwardReferenceSize(int distance, int pos) {
+ // See kLineBackwardReferenceFormat and kBackwardReferenceFormat.
+ return pos == 0 ? GetNumberLength(distance) + 1
+ : GetNumberLength(distance) + GetNumberLength(pos) + 2;
+}
+
+
+void LogRecordCompressor::PrintBackwardReference(Vector<char> dest,
+ int distance,
+ int pos) {
+ if (pos == 0) {
+ OS::SNPrintF(dest, kLineBackwardReferenceFormat, distance);
+ } else {
+ OS::SNPrintF(dest, kBackwardReferenceFormat, distance, pos);
+ }
+}
+
+
bool LogRecordCompressor::Store(const Vector<const char>& record) {
// Check if the record is the same as the last stored one.
if (curr_ != -1) {
@@ -379,9 +417,10 @@ bool LogRecordCompressor::RetrievePreviousCompressed(
intptr_t truncated_len;
int distance;
int copy_from_pos;
- } best = {-1, 0, 0};
+ int backref_size;
+ } best = {-1, 0, 0, 0};
Vector<const char>& prev = buffer_[prev_];
- const char* const prev_start = prev.start() + start_pos_;
+ const char* const prev_start = prev.start();
const char* const prev_end = prev.start() + prev.length();
do {
// We're moving backwards until we reach the current record.
@@ -402,13 +441,19 @@ bool LogRecordCompressor::RetrievePreviousCompressed(
--data_ptr;
}
const intptr_t truncated_len = prev_end - prev_ptr;
- if (truncated_len < kUncompressibleBound) continue;
+ const int copy_from_pos = data_ptr - data.start();
+ // Check if the length of compressed tail is enough.
+ if (truncated_len <= kMaxBackwardReferenceSize
+ && truncated_len <= GetBackwardReferenceSize(distance, copy_from_pos)) {
+ continue;
+ }
// Record compression results.
if (truncated_len > best.truncated_len) {
best.truncated_len = truncated_len;
best.distance = distance;
- best.copy_from_pos = data_ptr - data.start();
+ best.copy_from_pos = copy_from_pos;
+ best.backref_size = GetBackwardReferenceSize(distance, copy_from_pos);
}
} while (true);
@@ -420,14 +465,15 @@ bool LogRecordCompressor::RetrievePreviousCompressed(
} else {
// Copy the uncompressible part unchanged.
const intptr_t unchanged_len = prev.length() - best.truncated_len;
- ASSERT(prev_record->length() >= unchanged_len + kUncompressibleBound);
+ // + 1 for '\0'.
+ ASSERT(prev_record->length() >= unchanged_len + best.backref_size + 1);
memcpy(prev_record->start(), prev.start(), unchanged_len);
// Append the backward reference.
- Vector<char> patch(prev_record->start() + unchanged_len,
- kUncompressibleBound);
- OS::SNPrintF(patch, kBackwardReferenceFormat,
- best.distance, best.copy_from_pos);
- prev_record->Truncate(unchanged_len + strlen(patch.start()));
+ Vector<char> backref(
+ prev_record->start() + unchanged_len, best.backref_size + 1);
+ PrintBackwardReference(backref, best.distance, best.copy_from_pos);
+ ASSERT(strlen(backref.start()) - best.backref_size == 0);
+ prev_record->Truncate(unchanged_len + best.backref_size);
}
return true;
}
« no previous file with comments | « src/log-utils.h ('k') | test/cctest/test-log-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698