2009-03-30 13:32:28 +00:00
|
|
|
// Copyright 2009 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2009-03-24 12:47:53 +00:00
|
|
|
#include "bootstrapper.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "log.h"
|
2009-03-24 12:47:53 +00:00
|
|
|
#include "macro-assembler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "platform.h"
|
2009-03-24 12:47:53 +00:00
|
|
|
#include "serialize.h"
|
2008-10-15 08:50:22 +00:00
|
|
|
#include "string-stream.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
namespace v8 { namespace internal {
|
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sliding state window. Updates counters to keep track of the last
|
|
|
|
// window of kBufferSize states. This is useful to track where we
|
|
|
|
// spent our time.
|
|
|
|
//
|
|
|
|
class SlidingStateWindow {
|
|
|
|
public:
|
|
|
|
SlidingStateWindow();
|
|
|
|
~SlidingStateWindow();
|
|
|
|
void AddState(StateTag state);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kBufferSize = 256;
|
|
|
|
int current_index_;
|
|
|
|
bool is_full_;
|
|
|
|
byte buffer_[kBufferSize];
|
|
|
|
|
|
|
|
|
|
|
|
void IncrementStateCounter(StateTag state) {
|
|
|
|
Counters::state_counters[state].Increment();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DecrementStateCounter(StateTag state) {
|
|
|
|
Counters::state_counters[state].Decrement();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// The Profiler samples pc and sp values for the main thread.
|
|
|
|
// Each sample is appended to a circular buffer.
|
|
|
|
// An independent thread removes data and writes it to the log.
|
|
|
|
// This design minimizes the time spent in the sampler.
|
|
|
|
//
|
|
|
|
class Profiler: public Thread {
|
|
|
|
public:
|
|
|
|
Profiler();
|
|
|
|
void Engage();
|
|
|
|
void Disengage();
|
|
|
|
|
|
|
|
// Inserts collected profiling data into buffer.
|
|
|
|
void Insert(TickSample* sample) {
|
2009-01-29 19:47:00 +00:00
|
|
|
if (paused_)
|
|
|
|
return;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
if (Succ(head_) == tail_) {
|
|
|
|
overflow_ = true;
|
|
|
|
} else {
|
|
|
|
buffer_[head_] = *sample;
|
|
|
|
head_ = Succ(head_);
|
|
|
|
buffer_semaphore_->Signal(); // Tell we have an element.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Waits for a signal and removes profiling data.
|
|
|
|
bool Remove(TickSample* sample) {
|
|
|
|
buffer_semaphore_->Wait(); // Wait for an element.
|
|
|
|
*sample = buffer_[tail_];
|
|
|
|
bool result = overflow_;
|
|
|
|
tail_ = Succ(tail_);
|
|
|
|
overflow_ = false;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
2009-01-29 19:47:00 +00:00
|
|
|
// Pause and Resume TickSample data collection.
|
|
|
|
static bool paused() { return paused_; }
|
|
|
|
static void pause() { paused_ = true; }
|
|
|
|
static void resume() { paused_ = false; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
// Returns the next index in the cyclic buffer.
|
|
|
|
int Succ(int index) { return (index + 1) % kBufferSize; }
|
|
|
|
|
|
|
|
// Cyclic buffer for communicating profiling samples
|
|
|
|
// between the signal handler and the worker thread.
|
|
|
|
static const int kBufferSize = 128;
|
|
|
|
TickSample buffer_[kBufferSize]; // Buffer storage.
|
|
|
|
int head_; // Index to the buffer head.
|
|
|
|
int tail_; // Index to the buffer tail.
|
|
|
|
bool overflow_; // Tell whether a buffer overflow has occurred.
|
|
|
|
Semaphore* buffer_semaphore_; // Sempahore used for buffer synchronization.
|
|
|
|
|
|
|
|
// Tells whether worker thread should continue running.
|
|
|
|
bool running_;
|
2009-01-29 19:47:00 +00:00
|
|
|
|
|
|
|
// Tells whether we are currently recording tick samples.
|
|
|
|
static bool paused_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2009-01-29 19:47:00 +00:00
|
|
|
bool Profiler::paused_ = false;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-25 16:00:21 +00:00
|
|
|
//
|
|
|
|
// StackTracer implementation
|
|
|
|
//
|
|
|
|
void StackTracer::Trace(TickSample* sample) {
|
2009-03-03 11:56:44 +00:00
|
|
|
if (sample->state == GC) {
|
2009-03-06 13:07:57 +00:00
|
|
|
sample->frames_count = 0;
|
2009-03-03 11:56:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-20 14:49:12 +00:00
|
|
|
SafeStackTraceFrameIterator it(
|
|
|
|
reinterpret_cast<Address>(sample->fp),
|
|
|
|
reinterpret_cast<Address>(sample->sp),
|
|
|
|
reinterpret_cast<Address>(sample->sp),
|
|
|
|
reinterpret_cast<Address>(low_stack_bound_));
|
|
|
|
int i = 0;
|
|
|
|
while (!it.done() && i < TickSample::kMaxFramesCount) {
|
|
|
|
sample->stack[i++] = it.frame()->pc();
|
|
|
|
it.Advance();
|
2009-02-25 16:00:21 +00:00
|
|
|
}
|
2009-03-20 14:49:12 +00:00
|
|
|
sample->frames_count = i;
|
2009-02-25 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// Ticker used to provide ticks to the profiler and the sliding state
|
|
|
|
// window.
|
|
|
|
//
|
2008-08-22 13:33:59 +00:00
|
|
|
class Ticker: public Sampler {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2009-05-07 09:27:42 +00:00
|
|
|
explicit Ticker(int interval, uintptr_t low_stack_bound):
|
2009-02-17 14:45:45 +00:00
|
|
|
Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL),
|
2009-02-25 16:00:21 +00:00
|
|
|
stack_tracer_(low_stack_bound) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
~Ticker() { if (IsActive()) Stop(); }
|
|
|
|
|
|
|
|
void Tick(TickSample* sample) {
|
2009-02-25 16:00:21 +00:00
|
|
|
if (IsProfiling()) stack_tracer_.Trace(sample);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (profiler_) profiler_->Insert(sample);
|
2008-08-22 13:33:59 +00:00
|
|
|
if (window_) window_->AddState(sample->state);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetWindow(SlidingStateWindow* window) {
|
|
|
|
window_ = window;
|
|
|
|
if (!IsActive()) Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearWindow() {
|
|
|
|
window_ = NULL;
|
|
|
|
if (!profiler_ && IsActive()) Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetProfiler(Profiler* profiler) {
|
|
|
|
profiler_ = profiler;
|
|
|
|
if (!IsActive()) Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearProfiler() {
|
|
|
|
profiler_ = NULL;
|
|
|
|
if (!window_ && IsActive()) Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SlidingStateWindow* window_;
|
|
|
|
Profiler* profiler_;
|
2009-02-25 16:00:21 +00:00
|
|
|
StackTracer stack_tracer_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SlidingStateWindow implementation.
|
|
|
|
//
|
|
|
|
SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) {
|
|
|
|
for (int i = 0; i < kBufferSize; i++) {
|
|
|
|
buffer_[i] = static_cast<byte>(OTHER);
|
|
|
|
}
|
|
|
|
Logger::ticker_->SetWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SlidingStateWindow::~SlidingStateWindow() {
|
|
|
|
Logger::ticker_->ClearWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SlidingStateWindow::AddState(StateTag state) {
|
|
|
|
if (is_full_) {
|
|
|
|
DecrementStateCounter(static_cast<StateTag>(buffer_[current_index_]));
|
|
|
|
} else if (current_index_ == kBufferSize - 1) {
|
|
|
|
is_full_ = true;
|
|
|
|
}
|
|
|
|
buffer_[current_index_] = static_cast<byte>(state);
|
|
|
|
IncrementStateCounter(state);
|
|
|
|
ASSERT(IsPowerOf2(kBufferSize));
|
|
|
|
current_index_ = (current_index_ + 1) & (kBufferSize - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Profiler implementation.
|
|
|
|
//
|
|
|
|
Profiler::Profiler() {
|
|
|
|
buffer_semaphore_ = OS::CreateSemaphore(0);
|
|
|
|
head_ = 0;
|
|
|
|
tail_ = 0;
|
|
|
|
overflow_ = false;
|
|
|
|
running_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Profiler::Engage() {
|
|
|
|
OS::LogSharedLibraryAddresses();
|
|
|
|
|
|
|
|
// Start thread processing the profiler buffer.
|
|
|
|
running_ = true;
|
|
|
|
Start();
|
|
|
|
|
|
|
|
// Register to get ticks.
|
|
|
|
Logger::ticker_->SetProfiler(this);
|
|
|
|
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("profiler", "begin"));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Profiler::Disengage() {
|
|
|
|
// Stop receiving ticks.
|
|
|
|
Logger::ticker_->ClearProfiler();
|
|
|
|
|
|
|
|
// Terminate the worker thread by setting running_ to false,
|
|
|
|
// inserting a fake element in the queue and then wait for
|
|
|
|
// the thread to terminate.
|
|
|
|
running_ = false;
|
|
|
|
TickSample sample;
|
|
|
|
Insert(&sample);
|
|
|
|
Join();
|
|
|
|
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("profiler", "end"));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Profiler::Run() {
|
|
|
|
TickSample sample;
|
|
|
|
bool overflow = Logger::profiler_->Remove(&sample);
|
|
|
|
while (running_) {
|
|
|
|
LOG(TickEvent(&sample, overflow));
|
|
|
|
overflow = Logger::profiler_->Remove(&sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-17 08:21:24 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
|
|
|
|
// Functions and data for performing output of log messages.
|
|
|
|
class Log : public AllStatic {
|
|
|
|
public:
|
|
|
|
// Opens stdout for logging.
|
|
|
|
static void OpenStdout();
|
|
|
|
|
|
|
|
// Opens file for logging.
|
|
|
|
static void OpenFile(const char* name);
|
|
|
|
|
|
|
|
// Opens memory buffer for logging.
|
|
|
|
static void OpenMemoryBuffer();
|
|
|
|
|
|
|
|
// Frees all resources acquired in Open... functions.
|
|
|
|
static void Close();
|
|
|
|
|
|
|
|
// See description in v8.h.
|
|
|
|
static int GetLogLines(int from_pos, char* dest_buf, int max_size);
|
|
|
|
|
|
|
|
static bool is_enabled() { return output_.handle != NULL; }
|
|
|
|
|
|
|
|
typedef int (*WritePtr)(const char* msg, int length);
|
|
|
|
private:
|
|
|
|
static void Init();
|
|
|
|
|
|
|
|
// Write functions assume that mutex_ is acquired by the caller.
|
|
|
|
static WritePtr Write;
|
|
|
|
|
|
|
|
static int WriteToFile(const char* msg, int length) {
|
|
|
|
ASSERT(output_.handle != NULL);
|
|
|
|
int rv = fwrite(msg, 1, length, output_.handle);
|
|
|
|
ASSERT(length == rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteToMemory(const char* msg, int length) {
|
|
|
|
ASSERT(output_.buffer != NULL);
|
|
|
|
ASSERT(output_buffer_write_pos_ >= output_.buffer);
|
|
|
|
if (output_buffer_write_pos_ + length
|
|
|
|
<= output_.buffer + kOutputBufferSize) {
|
|
|
|
memcpy(output_buffer_write_pos_, msg, length);
|
|
|
|
output_buffer_write_pos_ += length;
|
|
|
|
return length;
|
|
|
|
} else {
|
|
|
|
// Memory buffer is full, ignore write.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When logging is active, output_ refers the file or memory buffer
|
|
|
|
// events are written to.
|
|
|
|
// mutex_ should be acquired before using output_.
|
|
|
|
union Output {
|
|
|
|
FILE* handle;
|
|
|
|
char* buffer;
|
|
|
|
};
|
|
|
|
static Output output_;
|
|
|
|
|
|
|
|
// mutex_ is a Mutex used for enforcing exclusive
|
|
|
|
// access to the formatting buffer and the log file or log memory buffer.
|
|
|
|
static Mutex* mutex_;
|
|
|
|
|
|
|
|
// Size of buffer used for memory logging.
|
|
|
|
static const int kOutputBufferSize = 2 * 1024 * 1024;
|
|
|
|
|
|
|
|
// Writing position in a memory buffer.
|
|
|
|
static char* output_buffer_write_pos_;
|
|
|
|
|
|
|
|
// Size of buffer used for formatting log messages.
|
|
|
|
static const int kMessageBufferSize = 2048;
|
|
|
|
|
|
|
|
// Buffer used for formatting log messages. This is a singleton buffer and
|
|
|
|
// mutex_ should be acquired before using it.
|
|
|
|
static char* message_buffer_;
|
|
|
|
|
|
|
|
friend class LogMessageBuilder;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Log::WritePtr Log::Write = NULL;
|
|
|
|
Log::Output Log::output_ = {NULL};
|
|
|
|
Mutex* Log::mutex_ = NULL;
|
|
|
|
char* Log::output_buffer_write_pos_ = NULL;
|
|
|
|
char* Log::message_buffer_ = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void Log::Init() {
|
|
|
|
mutex_ = OS::CreateMutex();
|
|
|
|
message_buffer_ = NewArray<char>(kMessageBufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Log::OpenStdout() {
|
|
|
|
ASSERT(output_.handle == NULL);
|
|
|
|
output_.handle = stdout;
|
|
|
|
Write = WriteToFile;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Log::OpenFile(const char* name) {
|
|
|
|
ASSERT(output_.handle == NULL);
|
|
|
|
output_.handle = OS::FOpen(name, OS::LogFileOpenMode);
|
|
|
|
Write = WriteToFile;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Log::OpenMemoryBuffer() {
|
|
|
|
ASSERT(output_.buffer == NULL);
|
|
|
|
output_.buffer = NewArray<char>(kOutputBufferSize);
|
|
|
|
output_buffer_write_pos_ = output_.buffer;
|
|
|
|
Write = WriteToMemory;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Log::Close() {
|
|
|
|
if (Write == WriteToFile) {
|
|
|
|
fclose(output_.handle);
|
|
|
|
output_.handle = NULL;
|
|
|
|
} else if (Write == WriteToMemory) {
|
|
|
|
DeleteArray(output_.buffer);
|
|
|
|
output_.buffer = NULL;
|
|
|
|
} else {
|
|
|
|
ASSERT(Write == NULL);
|
|
|
|
}
|
|
|
|
Write = NULL;
|
|
|
|
|
|
|
|
delete mutex_;
|
|
|
|
mutex_ = NULL;
|
|
|
|
|
|
|
|
DeleteArray(message_buffer_);
|
|
|
|
message_buffer_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Log::GetLogLines(int from_pos, char* dest_buf, int max_size) {
|
2009-05-08 10:06:38 +00:00
|
|
|
if (Write != WriteToMemory) return 0;
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(output_.buffer != NULL);
|
|
|
|
ASSERT(output_buffer_write_pos_ >= output_.buffer);
|
|
|
|
ASSERT(from_pos >= 0);
|
|
|
|
ASSERT(max_size >= 0);
|
|
|
|
int actual_size = max_size;
|
|
|
|
char* buffer_read_pos = output_.buffer + from_pos;
|
|
|
|
ScopedLock sl(mutex_);
|
|
|
|
if (actual_size == 0
|
|
|
|
|| output_buffer_write_pos_ == output_.buffer
|
|
|
|
|| buffer_read_pos >= output_buffer_write_pos_) {
|
|
|
|
// No data requested or can be returned.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (buffer_read_pos + actual_size > output_buffer_write_pos_) {
|
|
|
|
// Requested size overlaps with current writing position and
|
|
|
|
// needs to be truncated.
|
|
|
|
actual_size = output_buffer_write_pos_ - buffer_read_pos;
|
|
|
|
ASSERT(actual_size == 0 || buffer_read_pos[actual_size - 1] == '\n');
|
|
|
|
} else {
|
|
|
|
// Find previous log line boundary.
|
|
|
|
char* end_pos = buffer_read_pos + actual_size - 1;
|
|
|
|
while (end_pos >= buffer_read_pos && *end_pos != '\n') --end_pos;
|
|
|
|
actual_size = end_pos - buffer_read_pos + 1;
|
|
|
|
}
|
|
|
|
ASSERT(actual_size <= max_size);
|
|
|
|
if (actual_size > 0) {
|
|
|
|
memcpy(dest_buf, buffer_read_pos, actual_size);
|
|
|
|
}
|
|
|
|
return actual_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-17 08:21:24 +00:00
|
|
|
// Utility class for formatting log messages. It fills the message into the
|
2009-05-05 15:57:47 +00:00
|
|
|
// static buffer in Log.
|
2009-02-17 08:21:24 +00:00
|
|
|
class LogMessageBuilder BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit LogMessageBuilder();
|
|
|
|
~LogMessageBuilder() { }
|
|
|
|
|
|
|
|
void Append(const char* format, ...);
|
2009-02-17 12:49:35 +00:00
|
|
|
void Append(const char* format, va_list args);
|
2009-02-17 08:21:24 +00:00
|
|
|
void Append(const char c);
|
2009-05-13 12:34:35 +00:00
|
|
|
void Append(String* str);
|
2009-02-17 12:49:35 +00:00
|
|
|
void AppendDetailed(String* str, bool show_impl_info);
|
2009-02-17 08:21:24 +00:00
|
|
|
|
|
|
|
void WriteToLogFile();
|
2009-03-31 09:06:37 +00:00
|
|
|
void WriteCStringToLogFile(const char* str);
|
2009-02-17 08:21:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ScopedLock sl;
|
|
|
|
int pos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Create a message builder starting from position 0. This acquires the mutex
|
|
|
|
// in the logger as well.
|
2009-05-05 15:57:47 +00:00
|
|
|
LogMessageBuilder::LogMessageBuilder(): sl(Log::mutex_), pos_(0) {
|
|
|
|
ASSERT(Log::message_buffer_ != NULL);
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Append string data to the log message.
|
|
|
|
void LogMessageBuilder::Append(const char* format, ...) {
|
2009-05-05 15:57:47 +00:00
|
|
|
Vector<char> buf(Log::message_buffer_ + pos_,
|
|
|
|
Log::kMessageBufferSize - pos_);
|
2009-02-17 08:21:24 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2009-02-17 12:49:35 +00:00
|
|
|
Append(format, args);
|
2009-02-17 08:21:24 +00:00
|
|
|
va_end(args);
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(pos_ <= Log::kMessageBufferSize);
|
2009-02-17 12:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Append string data to the log message.
|
|
|
|
void LogMessageBuilder::Append(const char* format, va_list args) {
|
2009-05-05 15:57:47 +00:00
|
|
|
Vector<char> buf(Log::message_buffer_ + pos_,
|
|
|
|
Log::kMessageBufferSize - pos_);
|
2009-02-17 12:49:35 +00:00
|
|
|
int result = v8::internal::OS::VSNPrintF(buf, format, args);
|
2009-02-17 08:21:24 +00:00
|
|
|
|
|
|
|
// Result is -1 if output was truncated.
|
|
|
|
if (result >= 0) {
|
|
|
|
pos_ += result;
|
|
|
|
} else {
|
2009-05-05 15:57:47 +00:00
|
|
|
pos_ = Log::kMessageBufferSize;
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(pos_ <= Log::kMessageBufferSize);
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Append a character to the log message.
|
|
|
|
void LogMessageBuilder::Append(const char c) {
|
2009-05-05 15:57:47 +00:00
|
|
|
if (pos_ < Log::kMessageBufferSize) {
|
|
|
|
Log::message_buffer_[pos_++] = c;
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(pos_ <= Log::kMessageBufferSize);
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-17 12:49:35 +00:00
|
|
|
// Append a heap string.
|
|
|
|
void LogMessageBuilder::Append(String* str) {
|
|
|
|
AssertNoAllocation no_heap_allocation; // Ensure string stay valid.
|
2009-03-17 09:33:06 +00:00
|
|
|
int length = str->length();
|
2009-02-17 12:49:35 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2009-03-17 09:33:06 +00:00
|
|
|
Append(static_cast<char>(str->Get(i)));
|
2009-02-17 12:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
|
|
|
|
AssertNoAllocation no_heap_allocation; // Ensure string stay valid.
|
2009-03-17 09:33:06 +00:00
|
|
|
int len = str->length();
|
2009-02-17 12:49:35 +00:00
|
|
|
if (len > 0x1000)
|
|
|
|
len = 0x1000;
|
|
|
|
if (show_impl_info) {
|
2009-05-01 11:16:29 +00:00
|
|
|
Append(str->IsAsciiRepresentation() ? 'a' : '2');
|
2009-03-17 09:33:06 +00:00
|
|
|
if (StringShape(str).IsExternal())
|
2009-02-17 12:49:35 +00:00
|
|
|
Append('e');
|
2009-03-17 09:33:06 +00:00
|
|
|
if (StringShape(str).IsSymbol())
|
2009-02-17 12:49:35 +00:00
|
|
|
Append('#');
|
|
|
|
Append(":%i:", str->length());
|
|
|
|
}
|
|
|
|
for (int i = 0; i < len; i++) {
|
2009-03-17 09:33:06 +00:00
|
|
|
uc32 c = str->Get(i);
|
2009-02-17 12:49:35 +00:00
|
|
|
if (c > 0xff) {
|
|
|
|
Append("\\u%04x", c);
|
|
|
|
} else if (c < 32 || c > 126) {
|
|
|
|
Append("\\x%02x", c);
|
|
|
|
} else if (c == ',') {
|
|
|
|
Append("\\,");
|
|
|
|
} else if (c == '\\') {
|
|
|
|
Append("\\\\");
|
|
|
|
} else {
|
|
|
|
Append("%lc", c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-17 08:21:24 +00:00
|
|
|
// Write the log message to the log file currently opened.
|
|
|
|
void LogMessageBuilder::WriteToLogFile() {
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(pos_ <= Log::kMessageBufferSize);
|
|
|
|
Log::Write(Log::message_buffer_, pos_);
|
2009-02-17 08:21:24 +00:00
|
|
|
}
|
2009-03-31 09:06:37 +00:00
|
|
|
|
|
|
|
// Write a null-terminated string to to the log file currently opened.
|
|
|
|
void LogMessageBuilder::WriteCStringToLogFile(const char* str) {
|
2009-05-05 15:57:47 +00:00
|
|
|
int len = strlen(str);
|
|
|
|
Log::Write(str, len);
|
2009-03-31 09:06:37 +00:00
|
|
|
}
|
2009-02-17 08:21:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// Logger class implementation.
|
|
|
|
//
|
|
|
|
Ticker* Logger::ticker_ = NULL;
|
|
|
|
Profiler* Logger::profiler_ = NULL;
|
|
|
|
VMState* Logger::current_state_ = NULL;
|
2009-03-30 13:32:28 +00:00
|
|
|
VMState Logger::bottom_state_(EXTERNAL);
|
2008-07-03 15:10:15 +00:00
|
|
|
SlidingStateWindow* Logger::sliding_state_window_ = NULL;
|
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
|
|
|
|
bool Logger::is_enabled() {
|
|
|
|
return Log::is_enabled();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif // ENABLE_LOGGING_AND_PROFILING
|
|
|
|
|
2009-02-17 08:21:24 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Logger::Preamble(const char* content) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-03-31 09:06:37 +00:00
|
|
|
msg.WriteCStringToLogFile(content);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::StringEvent(const char* name, const char* value) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-02-11 07:38:31 +00:00
|
|
|
if (FLAG_log) UncheckedStringEvent(name, value);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
void Logger::UncheckedStringEvent(const char* name, const char* value) {
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled()) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("%s,\"%s\"\n", name, value);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-11 07:38:31 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Logger::IntEvent(const char* name, int value) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("%s,%d\n", name, value);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::HandleEvent(const char* name, Object** location) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_handles) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-15 09:58:40 +00:00
|
|
|
msg.Append("%s,0x%" V8PRIxPTR "\n", name, location);
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
// ApiEvent is private so all the calls come from the Logger class. It is the
|
2009-05-05 15:57:47 +00:00
|
|
|
// caller's responsibility to ensure that log is enabled and that
|
2008-07-03 15:10:15 +00:00
|
|
|
// FLAG_log_api is true.
|
|
|
|
void Logger::ApiEvent(const char* format, ...) {
|
2009-05-05 15:57:47 +00:00
|
|
|
ASSERT(Log::is_enabled() && FLAG_log_api);
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2008-07-03 15:10:15 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::ApiNamedSecurityCheck(Object* key) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
if (key->IsString()) {
|
|
|
|
SmartPointer<char> str =
|
|
|
|
String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
ApiEvent("api,check-security,\"%s\"\n", *str);
|
|
|
|
} else if (key->IsUndefined()) {
|
|
|
|
ApiEvent("api,check-security,undefined\n");
|
|
|
|
} else {
|
|
|
|
ApiEvent("api,check-security,['no-name']\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::SharedLibraryEvent(const char* library_path,
|
|
|
|
unsigned start,
|
|
|
|
unsigned end) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_prof) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("shared-library,\"%s\",0x%08x,0x%08x\n", library_path,
|
|
|
|
start, end);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::SharedLibraryEvent(const wchar_t* library_path,
|
|
|
|
unsigned start,
|
|
|
|
unsigned end) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_prof) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("shared-library,\"%ls\",0x%08x,0x%08x\n", library_path,
|
|
|
|
start, end);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-12 17:25:38 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2008-09-23 11:45:43 +00:00
|
|
|
void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
|
2008-09-11 12:57:27 +00:00
|
|
|
// Prints "/" + re.source + "/" +
|
2008-09-11 11:24:45 +00:00
|
|
|
// (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2008-09-11 11:24:45 +00:00
|
|
|
|
|
|
|
Handle<Object> source = GetProperty(regexp, "source");
|
|
|
|
if (!source->IsString()) {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("no source");
|
2008-09-11 11:24:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
switch (regexp->TypeTag()) {
|
2008-10-02 15:35:28 +00:00
|
|
|
case JSRegExp::ATOM:
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('a');
|
2008-10-02 15:35:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('/');
|
|
|
|
msg.AppendDetailed(*Handle<String>::cast(source), false);
|
|
|
|
msg.Append('/');
|
2008-09-11 11:24:45 +00:00
|
|
|
|
|
|
|
// global flag
|
|
|
|
Handle<Object> global = GetProperty(regexp, "global");
|
|
|
|
if (global->IsTrue()) {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('g');
|
2008-09-11 11:24:45 +00:00
|
|
|
}
|
|
|
|
// ignorecase flag
|
|
|
|
Handle<Object> ignorecase = GetProperty(regexp, "ignoreCase");
|
|
|
|
if (ignorecase->IsTrue()) {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('i');
|
2008-09-11 11:24:45 +00:00
|
|
|
}
|
|
|
|
// multiline flag
|
|
|
|
Handle<Object> multiline = GetProperty(regexp, "multiline");
|
|
|
|
if (multiline->IsTrue()) {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('m');
|
2008-09-11 11:24:45 +00:00
|
|
|
}
|
2009-02-17 12:49:35 +00:00
|
|
|
|
|
|
|
msg.WriteToLogFile();
|
2008-09-11 11:24:45 +00:00
|
|
|
}
|
2008-09-12 17:25:38 +00:00
|
|
|
#endif // ENABLE_LOGGING_AND_PROFILING
|
2008-09-11 11:24:45 +00:00
|
|
|
|
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) {
|
2008-09-11 11:24:45 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_regexp) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("regexp-compile,");
|
2008-09-11 11:24:45 +00:00
|
|
|
LogRegExpSource(regexp);
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append(in_cache ? ",hit\n" : ",miss\n");
|
|
|
|
msg.WriteToLogFile();
|
2008-09-11 11:24:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-06 13:24:52 +00:00
|
|
|
void Logger::LogRuntime(Vector<const char> format, JSArray* args) {
|
2009-01-07 14:24:08 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_runtime) return;
|
2009-01-06 13:24:52 +00:00
|
|
|
HandleScope scope;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-01-06 13:24:52 +00:00
|
|
|
for (int i = 0; i < format.length(); i++) {
|
|
|
|
char c = format[i];
|
|
|
|
if (c == '%' && i <= format.length() - 2) {
|
|
|
|
i++;
|
|
|
|
ASSERT('0' <= format[i] && format[i] <= '9');
|
|
|
|
Object* obj = args->GetElement(format[i] - '0');
|
|
|
|
i++;
|
|
|
|
switch (format[i]) {
|
|
|
|
case 's':
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.AppendDetailed(String::cast(obj), false);
|
2009-01-06 13:24:52 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.AppendDetailed(String::cast(obj), true);
|
2009-01-06 13:24:52 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj)));
|
|
|
|
break;
|
|
|
|
case 'x':
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("0x%x", Smi::cast(obj)->value());
|
2009-01-06 13:24:52 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("%i", Smi::cast(obj)->value());
|
2009-01-06 13:24:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append(c);
|
2009-01-06 13:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('\n');
|
|
|
|
msg.WriteToLogFile();
|
2009-01-07 14:24:08 +00:00
|
|
|
#endif
|
2008-09-11 11:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Logger::ApiIndexedSecurityCheck(uint32_t index) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
ApiEvent("api,check-security,%u\n", index);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::ApiNamedPropertyAccess(const char* tag,
|
|
|
|
JSObject* holder,
|
|
|
|
Object* name) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
ASSERT(name->IsString());
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
String* class_name_obj = holder->class_name();
|
|
|
|
SmartPointer<char> class_name =
|
|
|
|
class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
SmartPointer<char> property_name =
|
|
|
|
String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
Logger::ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::ApiIndexedPropertyAccess(const char* tag,
|
|
|
|
JSObject* holder,
|
|
|
|
uint32_t index) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
String* class_name_obj = holder->class_name();
|
|
|
|
SmartPointer<char> class_name =
|
|
|
|
class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
Logger::ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::ApiObjectAccess(const char* tag, JSObject* object) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
String* class_name_obj = object->class_name();
|
|
|
|
SmartPointer<char> class_name =
|
|
|
|
class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
Logger::ApiEvent("api,%s,\"%s\"\n", tag, *class_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::ApiEntryCall(const char* name) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_api) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
Logger::ApiEvent("api,%s\n", name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::NewEvent(const char* name, void* object, size_t size) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-15 09:58:40 +00:00
|
|
|
msg.Append("new,%s,0x%" V8PRIxPTR ",%u\n", name, object,
|
2009-02-17 12:49:35 +00:00
|
|
|
static_cast<unsigned int>(size));
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::DeleteEvent(const char* name, void* object) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-15 09:58:40 +00:00
|
|
|
msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", tag, code->address(),
|
2009-03-05 10:53:08 +00:00
|
|
|
code->ExecutableSize());
|
2008-07-03 15:10:15 +00:00
|
|
|
for (const char* p = comment; *p != '\0'; p++) {
|
2009-02-17 12:49:35 +00:00
|
|
|
if (*p == '"') {
|
|
|
|
msg.Append('\\');
|
|
|
|
}
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.Append(*p);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.Append('"');
|
|
|
|
msg.Append('\n');
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2008-07-03 15:10:15 +00:00
|
|
|
SmartPointer<char> str =
|
|
|
|
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s\"\n",
|
|
|
|
tag, code->address(), code->ExecutableSize(), *str);
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-03 10:52:02 +00:00
|
|
|
void Logger::CodeCreateEvent(const char* tag, Code* code, String* name,
|
|
|
|
String* source, int line) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-02-03 10:52:02 +00:00
|
|
|
SmartPointer<char> str =
|
|
|
|
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
|
|
|
SmartPointer<char> sourcestr =
|
|
|
|
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s %s:%d\"\n",
|
2009-05-07 10:31:14 +00:00
|
|
|
tag, code->address(),
|
2009-03-05 10:53:08 +00:00
|
|
|
code->ExecutableSize(),
|
2009-02-18 10:29:56 +00:00
|
|
|
*str, *sourcestr, line);
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.WriteToLogFile();
|
2009-02-03 10:52:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"args_count: %d\"\n", tag,
|
2009-05-07 09:27:42 +00:00
|
|
|
code->address(),
|
2009-03-05 10:53:08 +00:00
|
|
|
code->ExecutableSize(),
|
2009-02-17 08:21:24 +00:00
|
|
|
args_count);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-31 09:06:37 +00:00
|
|
|
void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-03-31 09:06:37 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", "RegExp",
|
2009-05-07 09:27:42 +00:00
|
|
|
code->address(),
|
2009-03-31 09:06:37 +00:00
|
|
|
code->ExecutableSize());
|
|
|
|
msg.AppendDetailed(source, false);
|
|
|
|
msg.Append("\"\n");
|
|
|
|
msg.WriteToLogFile();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
void Logger::CodeAllocateEvent(Code* code, Assembler* assem) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-allocate,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n",
|
|
|
|
code->address(),
|
|
|
|
assem);
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-12-19 13:12:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Logger::CodeMoveEvent(Address from, Address to) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-move,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n", from, to);
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::CodeDeleteEvent(Address from) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_code) return;
|
2009-02-17 08:21:24 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("code-delete,0x%" V8PRIxPTR "\n", from);
|
2009-02-17 08:21:24 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-12-19 13:12:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Logger::ResourceEvent(const char* name, const char* tag) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("%s,%s,", name, tag);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
uint32_t sec, usec;
|
|
|
|
if (OS::GetUserTime(&sec, &usec) != -1) {
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("%d,%d,", sec, usec);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("%.0f", OS::TimeCurrentMillis());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('\n');
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-09 09:19:02 +00:00
|
|
|
void Logger::SuspectReadEvent(String* name, Object* obj) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_suspect) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2008-12-09 09:19:02 +00:00
|
|
|
String* class_name = obj->IsJSObject()
|
|
|
|
? JSObject::cast(obj)->class_name()
|
|
|
|
: Heap::empty_string();
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append("suspect-read,");
|
|
|
|
msg.Append(class_name);
|
|
|
|
msg.Append(',');
|
|
|
|
msg.Append('"');
|
|
|
|
msg.Append(name);
|
|
|
|
msg.Append('"');
|
|
|
|
msg.Append('\n');
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::HeapSampleBeginEvent(const char* space, const char* kind) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_gc) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("heap-sample-begin,\"%s\",\"%s\"\n", space, kind);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::HeapSampleEndEvent(const char* space, const char* kind) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_gc) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log_gc) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes);
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-06 10:02:49 +00:00
|
|
|
void Logger::DebugTag(const char* call_site_tag) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("debug-tag,%s\n", call_site_tag);
|
|
|
|
msg.WriteToLogFile();
|
2008-08-06 10:02:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_log) return;
|
2008-08-06 10:02:49 +00:00
|
|
|
StringBuilder s(parameter.length() + 1);
|
|
|
|
for (int i = 0; i < parameter.length(); ++i) {
|
|
|
|
s.AddCharacter(static_cast<char>(parameter[i]));
|
|
|
|
}
|
|
|
|
char* parameter_string = s.Finalize();
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
|
|
|
msg.Append("debug-queue-event,%s,%15.3f,%s\n",
|
|
|
|
event_type,
|
|
|
|
OS::TimeCurrentMillis(),
|
|
|
|
parameter_string);
|
2008-08-06 10:02:49 +00:00
|
|
|
DeleteArray(parameter_string);
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.WriteToLogFile();
|
2008-08-06 10:02:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
void Logger::TickEvent(TickSample* sample, bool overflow) {
|
2009-05-05 15:57:47 +00:00
|
|
|
if (!Log::is_enabled() || !FLAG_prof) return;
|
2009-02-17 12:49:35 +00:00
|
|
|
LogMessageBuilder msg;
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append("tick,0x%" V8PRIxPTR ",0x%" V8PRIxPTR ",%d",
|
|
|
|
sample->pc, sample->sp, static_cast<int>(sample->state));
|
2009-02-17 12:49:35 +00:00
|
|
|
if (overflow) {
|
|
|
|
msg.Append(",overflow");
|
|
|
|
}
|
2009-03-06 13:07:57 +00:00
|
|
|
for (int i = 0; i < sample->frames_count; ++i) {
|
2009-05-12 10:33:40 +00:00
|
|
|
msg.Append(",0x%" V8PRIxPTR, sample->stack[i]);
|
2009-02-17 14:45:45 +00:00
|
|
|
}
|
2009-02-17 12:49:35 +00:00
|
|
|
msg.Append('\n');
|
|
|
|
msg.WriteToLogFile();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-01-29 19:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Logger::IsProfilerPaused() {
|
|
|
|
return profiler_->paused();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::PauseProfiler() {
|
|
|
|
profiler_->pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::ResumeProfiler() {
|
|
|
|
profiler_->resume();
|
|
|
|
}
|
2009-05-05 15:57:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) {
|
|
|
|
return Log::GetLogLines(from_pos, dest_buf, max_size);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bool Logger::Setup() {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
// --log-all enables all the log flags.
|
|
|
|
if (FLAG_log_all) {
|
2009-02-17 12:49:35 +00:00
|
|
|
FLAG_log_runtime = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
FLAG_log_api = true;
|
|
|
|
FLAG_log_code = true;
|
|
|
|
FLAG_log_gc = true;
|
|
|
|
FLAG_log_suspect = true;
|
|
|
|
FLAG_log_handles = true;
|
2008-09-11 11:24:45 +00:00
|
|
|
FLAG_log_regexp = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --prof implies --log-code.
|
|
|
|
if (FLAG_prof) FLAG_log_code = true;
|
|
|
|
|
2009-02-17 12:49:35 +00:00
|
|
|
bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api
|
|
|
|
|| FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
|
2009-02-11 07:38:31 +00:00
|
|
|
|| FLAG_log_regexp || FLAG_log_state_changes;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// If we're logging anything, we need to open the log file.
|
2008-10-02 15:35:28 +00:00
|
|
|
if (open_log_file) {
|
2008-07-03 15:10:15 +00:00
|
|
|
if (strcmp(FLAG_logfile, "-") == 0) {
|
2009-05-05 15:57:47 +00:00
|
|
|
Log::OpenStdout();
|
|
|
|
} else if (strcmp(FLAG_logfile, "*") == 0) {
|
|
|
|
Log::OpenMemoryBuffer();
|
2008-10-15 08:50:22 +00:00
|
|
|
} else if (strchr(FLAG_logfile, '%') != NULL) {
|
|
|
|
// If there's a '%' in the log file name we have to expand
|
|
|
|
// placeholders.
|
|
|
|
HeapStringAllocator allocator;
|
|
|
|
StringStream stream(&allocator);
|
|
|
|
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 't': {
|
|
|
|
// %t expands to the current time in milliseconds.
|
|
|
|
uint32_t time = static_cast<uint32_t>(OS::TimeCurrentMillis());
|
|
|
|
stream.Add("%u", time);
|
|
|
|
break;
|
|
|
|
}
|
2008-10-15 08:50:34 +00:00
|
|
|
case '%':
|
|
|
|
// %% expands (contracts really) to %.
|
|
|
|
stream.Put('%');
|
|
|
|
break;
|
2008-10-15 08:50:22 +00:00
|
|
|
default:
|
|
|
|
// All other %'s expand to themselves.
|
2008-10-15 08:50:34 +00:00
|
|
|
stream.Put('%');
|
2008-10-15 08:50:22 +00:00
|
|
|
stream.Put(*p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream.Put(*p);
|
|
|
|
}
|
|
|
|
}
|
2008-11-11 14:16:24 +00:00
|
|
|
SmartPointer<const char> expanded = stream.ToCString();
|
2009-05-05 15:57:47 +00:00
|
|
|
Log::OpenFile(*expanded);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-05-05 15:57:47 +00:00
|
|
|
Log::OpenFile(FLAG_logfile);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 00:24:49 +00:00
|
|
|
current_state_ = &bottom_state_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-17 14:45:45 +00:00
|
|
|
// as log is initialized early with V8, we can assume that JS execution
|
|
|
|
// frames can never reach this point on stack
|
|
|
|
int stack_var;
|
2009-05-07 09:27:42 +00:00
|
|
|
ticker_ = new Ticker(1, reinterpret_cast<uintptr_t>(&stack_var));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
if (FLAG_sliding_state_window && sliding_state_window_ == NULL) {
|
|
|
|
sliding_state_window_ = new SlidingStateWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAG_prof) {
|
|
|
|
profiler_ = new Profiler();
|
2009-01-29 19:47:00 +00:00
|
|
|
if (!FLAG_prof_auto)
|
|
|
|
profiler_->pause();
|
2008-07-03 15:10:15 +00:00
|
|
|
profiler_->Engage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::TearDown() {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
// Stop the profiler before closing the file.
|
|
|
|
if (profiler_ != NULL) {
|
|
|
|
profiler_->Disengage();
|
|
|
|
delete profiler_;
|
|
|
|
profiler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete sliding_state_window_;
|
|
|
|
|
|
|
|
delete ticker_;
|
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
Log::Close();
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::EnableSlidingStateWindow() {
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
// If the ticker is NULL, Logger::Setup has not been called yet. In
|
|
|
|
// that case, we set the sliding_state_window flag so that the
|
|
|
|
// sliding window computation will be started when Logger::Setup is
|
|
|
|
// called.
|
|
|
|
if (ticker_ == NULL) {
|
|
|
|
FLAG_sliding_state_window = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise, if the sliding state window computation has not been
|
|
|
|
// started we do it now.
|
|
|
|
if (sliding_state_window_ == NULL) {
|
|
|
|
sliding_state_window_ = new SlidingStateWindow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// VMState class implementation. A simple stack of VM states held by the
|
|
|
|
// logger and partially threaded through the call stack. States are pushed by
|
|
|
|
// VMState construction and popped by destruction.
|
|
|
|
//
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
static const char* StateToString(StateTag state) {
|
|
|
|
switch (state) {
|
2009-02-11 07:38:31 +00:00
|
|
|
case JS:
|
|
|
|
return "JS";
|
2008-07-03 15:10:15 +00:00
|
|
|
case GC:
|
|
|
|
return "GC";
|
|
|
|
case COMPILER:
|
|
|
|
return "COMPILER";
|
|
|
|
case OTHER:
|
|
|
|
return "OTHER";
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VMState::VMState(StateTag state) {
|
2009-03-30 13:32:28 +00:00
|
|
|
#if !defined(ENABLE_HEAP_PROTECTION)
|
|
|
|
// When not protecting the heap, there is no difference between
|
|
|
|
// EXTERNAL and OTHER. As an optimizatin in that case, we will not
|
|
|
|
// perform EXTERNAL->OTHER transitions through the API. We thus
|
|
|
|
// compress the two states into one.
|
|
|
|
if (state == EXTERNAL) state = OTHER;
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
state_ = state;
|
|
|
|
previous_ = Logger::current_state_;
|
|
|
|
Logger::current_state_ = this;
|
|
|
|
|
|
|
|
if (FLAG_log_state_changes) {
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("Entering", StateToString(state_)));
|
2009-03-24 12:47:53 +00:00
|
|
|
if (previous_ != NULL) {
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-24 12:47:53 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_HEAP_PROTECTION
|
|
|
|
if (FLAG_protect_heap && previous_ != NULL) {
|
|
|
|
if (state_ == EXTERNAL) {
|
|
|
|
// We are leaving V8.
|
2009-03-27 12:32:28 +00:00
|
|
|
ASSERT(previous_->state_ != EXTERNAL);
|
2009-03-24 12:47:53 +00:00
|
|
|
Heap::Protect();
|
2009-03-27 12:32:28 +00:00
|
|
|
} else if (previous_->state_ == EXTERNAL) {
|
|
|
|
// We are entering V8.
|
|
|
|
Heap::Unprotect();
|
2009-03-24 12:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMState::~VMState() {
|
|
|
|
Logger::current_state_ = previous_;
|
|
|
|
|
|
|
|
if (FLAG_log_state_changes) {
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
|
2009-03-24 12:47:53 +00:00
|
|
|
if (previous_ != NULL) {
|
2009-02-11 07:38:31 +00:00
|
|
|
LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-24 12:47:53 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_HEAP_PROTECTION
|
|
|
|
if (FLAG_protect_heap && previous_ != NULL) {
|
|
|
|
if (state_ == EXTERNAL) {
|
2009-03-27 12:32:28 +00:00
|
|
|
// We are reentering V8.
|
|
|
|
ASSERT(previous_->state_ != EXTERNAL);
|
|
|
|
Heap::Unprotect();
|
|
|
|
} else if (previous_->state_ == EXTERNAL) {
|
|
|
|
// We are leaving V8.
|
|
|
|
Heap::Protect();
|
2009-03-24 12:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|