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

Unified Diff: src/log-utils.cc

Issue 115859: Handle filling up of memory buffer to make log processing in DevTools Profiler easier. (Closed)
Patch Set: Created 11 years, 7 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
Index: src/log-utils.cc
diff --git a/src/log-utils.cc b/src/log-utils.cc
index a16b07964334dabb98a5c60277374a82f084d381..8a6989b3140122b28fab806ae3ab762d4bfa3da8 100644
--- a/src/log-utils.cc
+++ b/src/log-utils.cc
@@ -34,11 +34,14 @@ namespace internal {
#ifdef ENABLE_LOGGING_AND_PROFILING
-LogDynamicBuffer::LogDynamicBuffer(int block_size, int max_size)
+LogDynamicBuffer::LogDynamicBuffer(
+ int block_size, int max_size, const char* seal, int seal_size)
: block_size_(block_size),
max_size_(max_size - (max_size % block_size_)),
+ seal_(seal),
+ seal_size_(seal_size),
blocks_(max_size_ / block_size_ + 1),
- write_pos_(0), block_index_(0), block_write_pos_(0) {
+ write_pos_(0), block_index_(0), block_write_pos_(0), is_sealed_(false) {
ASSERT(BlocksCount() > 0);
AllocateBlock(0);
for (int i = 1; i < BlocksCount(); ++i) {
@@ -78,8 +81,24 @@ int LogDynamicBuffer::Read(int from_pos, char* dest_buf, int buf_size) {
}
+int LogDynamicBuffer::Seal() {
+ WriteInternal(seal_, seal_size_);
+ is_sealed_ = true;
+ return 0;
+}
+
+
int LogDynamicBuffer::Write(const char* data, int data_size) {
- if ((write_pos_ + data_size) > max_size_) return 0;
+ if (is_sealed_) return 0;
Søren Thygesen Gjesse 2009/05/28 13:23:35 Please use {} for one line if's.
Mikhail Naganov 2009/05/28 13:52:52 Done.
+ if ((write_pos_ + data_size) <= (max_size_ - seal_size_)) {
+ return WriteInternal(data, data_size);
+ } else {
+ return Seal();
+ }
+}
+
+
+int LogDynamicBuffer::WriteInternal(const char* data, int data_size) {
int data_pos = 0;
while (data_pos < data_size) {
const int write_size =
@@ -98,9 +117,12 @@ int LogDynamicBuffer::Write(const char* data, int data_size) {
}
+bool Log::is_stopped_ = false;
Log::WritePtr Log::Write = NULL;
FILE* Log::output_handle_ = NULL;
LogDynamicBuffer* Log::output_buffer_ = NULL;
+// Must be the same message as in Logger::PauseProfiler
+const char* Log::kDynamicBufferSeal = "profiler,\"pause\"\n";
Mutex* Log::mutex_ = NULL;
char* Log::message_buffer_ = NULL;
@@ -130,7 +152,8 @@ void Log::OpenFile(const char* name) {
void Log::OpenMemoryBuffer() {
ASSERT(!IsEnabled());
output_buffer_ = new LogDynamicBuffer(
- kDynamicBufferBlockSize, kMaxDynamicBufferSize);
+ kDynamicBufferBlockSize, kMaxDynamicBufferSize,
+ kDynamicBufferSeal, strlen(kDynamicBufferSeal));
Write = WriteToMemory;
Init();
}
@@ -150,6 +173,8 @@ void Log::Close() {
delete mutex_;
mutex_ = NULL;
+
+ is_stopped_ = false;
}
@@ -171,6 +196,10 @@ int Log::GetLogLines(int from_pos, char* dest_buf, int max_size) {
}
+LogMessageBuilder::WriteFailureHandler
+ LogMessageBuilder::write_failure_handler = NULL;
+
+
LogMessageBuilder::LogMessageBuilder(): sl(Log::mutex_), pos_(0) {
ASSERT(Log::message_buffer_ != NULL);
}
@@ -251,13 +280,17 @@ void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
void LogMessageBuilder::WriteToLogFile() {
ASSERT(pos_ <= Log::kMessageBufferSize);
- Log::Write(Log::message_buffer_, pos_);
+ if (pos_ != Log::Write(Log::message_buffer_, pos_)) {
Søren Thygesen Gjesse 2009/05/28 13:23:35 I would suggest the following: int written = Log:
Mikhail Naganov 2009/05/28 13:52:52 Done. Thanks for noticing.
+ if (write_failure_handler != NULL) write_failure_handler();
+ }
}
void LogMessageBuilder::WriteCStringToLogFile(const char* str) {
int len = strlen(str);
- Log::Write(str, len);
+ if (len != Log::Write(str, len)) {
Søren Thygesen Gjesse 2009/05/28 13:23:35 Ditto.
Mikhail Naganov 2009/05/28 13:52:52 Done.
+ if (write_failure_handler != NULL) write_failure_handler();
+ }
}
#endif // ENABLE_LOGGING_AND_PROFILING
« src/log-utils.h ('K') | « 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