namespace v8 {
namespace internal {
-//
-// 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:
- explicit SlidingStateWindow(Isolate* isolate);
- ~SlidingStateWindow();
- void AddState(StateTag state);
-
- private:
- static const int kBufferSize = 256;
- Counters* counters_;
- 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.
public:
Ticker(Isolate* isolate, int interval):
Sampler(isolate, interval),
- window_(NULL),
profiler_(NULL) {}
~Ticker() { if (IsActive()) Stop(); }
virtual void Tick(TickSample* sample) {
if (profiler_) profiler_->Insert(sample);
- if (window_) window_->AddState(sample->state);
- }
-
- void SetWindow(SlidingStateWindow* window) {
- window_ = window;
- if (!IsActive()) Start();
- }
-
- void ClearWindow() {
- window_ = NULL;
- if (!profiler_ && IsActive() && !RuntimeProfiler::IsEnabled()) Stop();
}
void SetProfiler(Profiler* profiler) {
void ClearProfiler() {
DecreaseProfilingDepth();
profiler_ = NULL;
- if (!window_ && IsActive() && !RuntimeProfiler::IsEnabled()) Stop();
+ if (IsActive()) Stop();
}
protected:
}
private:
- SlidingStateWindow* window_;
Profiler* profiler_;
};
//
-// SlidingStateWindow implementation.
-//
-SlidingStateWindow::SlidingStateWindow(Isolate* isolate)
- : counters_(isolate->counters()), current_index_(0), is_full_(false) {
- for (int i = 0; i < kBufferSize; i++) {
- buffer_[i] = static_cast<byte>(OTHER);
- }
- isolate->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(Isolate* isolate)
Logger::Logger()
: ticker_(NULL),
profiler_(NULL),
- sliding_state_window_(NULL),
log_events_(NULL),
logging_nesting_(0),
cpu_profiler_nesting_(0),
if (--cpu_profiler_nesting_ == 0) {
profiler_->pause();
if (FLAG_prof_lazy) {
- if (!FLAG_sliding_state_window && !RuntimeProfiler::IsEnabled()) {
- ticker_->Stop();
- }
+ ticker_->Stop();
FLAG_log_code = false;
LOG(ISOLATE, UncheckedStringEvent("profiler", "pause"));
}
FLAG_log_code = true;
LogCompiledFunctions();
LogAccessorCallbacks();
- if (!FLAG_sliding_state_window && !ticker_->IsActive()) {
- ticker_->Start();
- }
+ if (!ticker_->IsActive()) ticker_->Start();
}
profiler_->resume();
}
Isolate* isolate = Isolate::Current();
ticker_ = new Ticker(isolate, kSamplingIntervalMs);
- if (FLAG_sliding_state_window && sliding_state_window_ == NULL) {
- sliding_state_window_ = new SlidingStateWindow(isolate);
- }
-
bool start_logging = FLAG_log || FLAG_log_runtime || FLAG_log_api
|| FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
|| FLAG_log_regexp || FLAG_log_state_changes || FLAG_ll_prof
profiler_ = NULL;
}
- delete sliding_state_window_;
- sliding_state_window_ = NULL;
-
delete ticker_;
ticker_ = NULL;
}
-void Logger::EnableSlidingStateWindow() {
- // 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(Isolate::Current());
- }
-}
-
// Protects the state below.
static Mutex* active_samplers_mutex = NULL;