Skip to content

Commit ae3d19b

Browse files
Remove support for logging into a memory buffer.
The only usage of it was in logging tests, I've switched them for using a file. I've left out support for "--logfile=*" for now, as Chromium uses it. Will be removed after the next V8 roll. [email protected] BUG=859 TEST=mjsunit/log-* Review URL: http://codereview.chromium.org/7310025 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@8629 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent e5ee49b commit ae3d19b

20 files changed

+532
-1125
lines changed

include/v8.h

-25
Original file line numberDiff line numberDiff line change
@@ -2983,31 +2983,6 @@ class V8EXPORT V8 {
29832983
*/
29842984
static bool IsProfilerPaused();
29852985

2986-
/**
2987-
* If logging is performed into a memory buffer (via --logfile=*), allows to
2988-
* retrieve previously written messages. This can be used for retrieving
2989-
* profiler log data in the application. This function is thread-safe.
2990-
*
2991-
* Caller provides a destination buffer that must exist during GetLogLines
2992-
* call. Only whole log lines are copied into the buffer.
2993-
*
2994-
* \param from_pos specified a point in a buffer to read from, 0 is the
2995-
* beginning of a buffer. It is assumed that caller updates its current
2996-
* position using returned size value from the previous call.
2997-
* \param dest_buf destination buffer for log data.
2998-
* \param max_size size of the destination buffer.
2999-
* \returns actual size of log data copied into buffer.
3000-
*/
3001-
static int GetLogLines(int from_pos, char* dest_buf, int max_size);
3002-
3003-
/**
3004-
* The minimum allowed size for a log lines buffer. If the size of
3005-
* the buffer given will not be enough to hold a line of the maximum
3006-
* length, an attempt to find a log line end in GetLogLines will
3007-
* fail, and an empty result will be returned.
3008-
*/
3009-
static const int kMinimumSizeForLogLinesBuffer = 2048;
3010-
30112986
/**
30122987
* Retrieve the V8 thread id of the calling thread.
30132988
*

src/api.cc

-6
Original file line numberDiff line numberDiff line change
@@ -4842,12 +4842,6 @@ bool V8::IsProfilerPaused() {
48424842
}
48434843

48444844

4845-
int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
4846-
ASSERT(max_size >= kMinimumSizeForLogLinesBuffer);
4847-
return LOGGER->GetLogLines(from_pos, dest_buf, max_size);
4848-
}
4849-
4850-
48514845
int V8::GetCurrentThreadId() {
48524846
i::Isolate* isolate = i::Isolate::Current();
48534847
EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()");

src/log-utils.cc

+26-136
Original file line numberDiff line numberDiff line change
@@ -33,99 +33,14 @@
3333
namespace v8 {
3434
namespace internal {
3535

36-
LogDynamicBuffer::LogDynamicBuffer(
37-
int block_size, int max_size, const char* seal, int seal_size)
38-
: block_size_(block_size),
39-
max_size_(max_size - (max_size % block_size_)),
40-
seal_(seal),
41-
seal_size_(seal_size),
42-
blocks_(max_size_ / block_size_ + 1),
43-
write_pos_(0), block_index_(0), block_write_pos_(0), is_sealed_(false) {
44-
ASSERT(BlocksCount() > 0);
45-
AllocateBlock(0);
46-
for (int i = 1; i < BlocksCount(); ++i) {
47-
blocks_[i] = NULL;
48-
}
49-
}
50-
51-
52-
LogDynamicBuffer::~LogDynamicBuffer() {
53-
for (int i = 0; i < BlocksCount(); ++i) {
54-
DeleteArray(blocks_[i]);
55-
}
56-
}
57-
58-
59-
int LogDynamicBuffer::Read(int from_pos, char* dest_buf, int buf_size) {
60-
if (buf_size == 0) return 0;
61-
int read_pos = from_pos;
62-
int block_read_index = BlockIndex(from_pos);
63-
int block_read_pos = PosInBlock(from_pos);
64-
int dest_buf_pos = 0;
65-
// Read until dest_buf is filled, or write_pos_ encountered.
66-
while (read_pos < write_pos_ && dest_buf_pos < buf_size) {
67-
const int read_size = Min(write_pos_ - read_pos,
68-
Min(buf_size - dest_buf_pos, block_size_ - block_read_pos));
69-
memcpy(dest_buf + dest_buf_pos,
70-
blocks_[block_read_index] + block_read_pos, read_size);
71-
block_read_pos += read_size;
72-
dest_buf_pos += read_size;
73-
read_pos += read_size;
74-
if (block_read_pos == block_size_) {
75-
block_read_pos = 0;
76-
++block_read_index;
77-
}
78-
}
79-
return dest_buf_pos;
80-
}
81-
82-
83-
int LogDynamicBuffer::Seal() {
84-
WriteInternal(seal_, seal_size_);
85-
is_sealed_ = true;
86-
return 0;
87-
}
88-
89-
90-
int LogDynamicBuffer::Write(const char* data, int data_size) {
91-
if (is_sealed_) {
92-
return 0;
93-
}
94-
if ((write_pos_ + data_size) <= (max_size_ - seal_size_)) {
95-
return WriteInternal(data, data_size);
96-
} else {
97-
return Seal();
98-
}
99-
}
10036

37+
const char* Log::kLogToTemporaryFile = "&";
10138

102-
int LogDynamicBuffer::WriteInternal(const char* data, int data_size) {
103-
int data_pos = 0;
104-
while (data_pos < data_size) {
105-
const int write_size =
106-
Min(data_size - data_pos, block_size_ - block_write_pos_);
107-
memcpy(blocks_[block_index_] + block_write_pos_, data + data_pos,
108-
write_size);
109-
block_write_pos_ += write_size;
110-
data_pos += write_size;
111-
if (block_write_pos_ == block_size_) {
112-
block_write_pos_ = 0;
113-
AllocateBlock(++block_index_);
114-
}
115-
}
116-
write_pos_ += data_size;
117-
return data_size;
118-
}
119-
120-
// Must be the same message as in Logger::PauseProfiler.
121-
const char* const Log::kDynamicBufferSeal = "profiler,\"pause\"\n";
12239

12340
Log::Log(Logger* logger)
124-
: write_to_file_(false),
125-
is_stopped_(false),
41+
: is_stopped_(false),
12642
output_handle_(NULL),
12743
ll_output_handle_(NULL),
128-
output_buffer_(NULL),
12944
mutex_(NULL),
13045
message_buffer_(NULL),
13146
logger_(logger) {
@@ -163,19 +78,19 @@ void Log::Initialize() {
16378
FLAG_prof_auto = false;
16479
}
16580

166-
bool start_logging = FLAG_log || FLAG_log_runtime || FLAG_log_api
81+
bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api
16782
|| FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
16883
|| FLAG_log_regexp || FLAG_log_state_changes || FLAG_ll_prof;
16984

170-
bool open_log_file = start_logging || FLAG_prof_lazy;
171-
17285
// If we're logging anything, we need to open the log file.
17386
if (open_log_file) {
17487
if (strcmp(FLAG_logfile, "-") == 0) {
17588
OpenStdout();
17689
} else if (strcmp(FLAG_logfile, "*") == 0) {
177-
OpenMemoryBuffer();
178-
} else {
90+
// Does nothing for now. Will be removed.
91+
} else if (strcmp(FLAG_logfile, kLogToTemporaryFile) == 0) {
92+
OpenTemporaryFile();
93+
} else {
17994
if (strchr(FLAG_logfile, '%') != NULL ||
18095
!Isolate::Current()->IsDefaultIsolate()) {
18196
// If there's a '%' in the log file name we have to expand
@@ -225,7 +140,12 @@ void Log::Initialize() {
225140
void Log::OpenStdout() {
226141
ASSERT(!IsEnabled());
227142
output_handle_ = stdout;
228-
write_to_file_ = true;
143+
}
144+
145+
146+
void Log::OpenTemporaryFile() {
147+
ASSERT(!IsEnabled());
148+
output_handle_ = i::OS::OpenTemporaryFile();
229149
}
230150

231151

@@ -240,7 +160,6 @@ static const int kLowLevelLogBufferSize = 2 * MB;
240160
void Log::OpenFile(const char* name) {
241161
ASSERT(!IsEnabled());
242162
output_handle_ = OS::FOpen(name, OS::LogFileOpenMode);
243-
write_to_file_ = true;
244163
if (FLAG_ll_prof) {
245164
// Open the low-level log file.
246165
size_t len = strlen(name);
@@ -253,25 +172,18 @@ void Log::OpenFile(const char* name) {
253172
}
254173

255174

256-
void Log::OpenMemoryBuffer() {
257-
ASSERT(!IsEnabled());
258-
output_buffer_ = new LogDynamicBuffer(
259-
kDynamicBufferBlockSize, kMaxDynamicBufferSize,
260-
kDynamicBufferSeal, StrLength(kDynamicBufferSeal));
261-
write_to_file_ = false;
262-
}
263-
264-
265-
void Log::Close() {
266-
if (write_to_file_) {
267-
if (output_handle_ != NULL) fclose(output_handle_);
268-
output_handle_ = NULL;
269-
if (ll_output_handle_ != NULL) fclose(ll_output_handle_);
270-
ll_output_handle_ = NULL;
271-
} else {
272-
delete output_buffer_;
273-
output_buffer_ = NULL;
175+
FILE* Log::Close() {
176+
FILE* result = NULL;
177+
if (output_handle_ != NULL) {
178+
if (strcmp(FLAG_logfile, kLogToTemporaryFile) != 0) {
179+
fclose(output_handle_);
180+
} else {
181+
result = output_handle_;
182+
}
274183
}
184+
output_handle_ = NULL;
185+
if (ll_output_handle_ != NULL) fclose(ll_output_handle_);
186+
ll_output_handle_ = NULL;
275187

276188
DeleteArray(message_buffer_);
277189
message_buffer_ = NULL;
@@ -280,27 +192,7 @@ void Log::Close() {
280192
mutex_ = NULL;
281193

282194
is_stopped_ = false;
283-
}
284-
285-
286-
int Log::GetLogLines(int from_pos, char* dest_buf, int max_size) {
287-
if (write_to_file_) return 0;
288-
ASSERT(output_buffer_ != NULL);
289-
ASSERT(from_pos >= 0);
290-
ASSERT(max_size >= 0);
291-
int actual_size = output_buffer_->Read(from_pos, dest_buf, max_size);
292-
ASSERT(actual_size <= max_size);
293-
if (actual_size == 0) return 0;
294-
295-
// Find previous log line boundary.
296-
char* end_pos = dest_buf + actual_size - 1;
297-
while (end_pos >= dest_buf && *end_pos != '\n') --end_pos;
298-
actual_size = static_cast<int>(end_pos - dest_buf + 1);
299-
// If the assertion below is hit, it means that there was no line end
300-
// found --- something wrong has happened.
301-
ASSERT(actual_size > 0);
302-
ASSERT(actual_size <= max_size);
303-
return actual_size;
195+
return result;
304196
}
305197

306198

@@ -409,9 +301,7 @@ void LogMessageBuilder::AppendStringPart(const char* str, int len) {
409301

410302
void LogMessageBuilder::WriteToLogFile() {
411303
ASSERT(pos_ <= Log::kMessageBufferSize);
412-
const int written = log_->write_to_file_ ?
413-
log_->WriteToFile(log_->message_buffer_, pos_) :
414-
log_->WriteToMemory(log_->message_buffer_, pos_);
304+
const int written = log_->WriteToFile(log_->message_buffer_, pos_);
415305
if (written != pos_) {
416306
log_->stop();
417307
log_->logger_->LogFailure();

0 commit comments

Comments
 (0)