V8 Project
v8::internal::Profiler Class Reference
+ Inheritance diagram for v8::internal::Profiler:
+ Collaboration diagram for v8::internal::Profiler:

Public Member Functions

 Profiler (Isolate *isolate)
 
void Engage ()
 
void Disengage ()
 
void Insert (TickSample *sample)
 
virtual void Run ()
 
void pause ()
 
void resume ()
 
- Public Member Functions inherited from v8::base::Thread
 Thread (const Options &options)
 
virtual ~Thread ()
 
void Start ()
 
void StartSynchronously ()
 
void Join ()
 
const char * name () const
 
PlatformDatadata ()
 
void NotifyStartedAndRun ()
 

Private Member Functions

bool Remove (TickSample *sample)
 
int Succ (int index)
 

Private Attributes

Isolateisolate_
 
TickSample buffer_ [kBufferSize]
 
int head_
 
int tail_
 
bool overflow_
 
base::Semaphore buffer_semaphore_
 
bool engaged_
 
bool running_
 
bool paused_
 

Static Private Attributes

static const int kBufferSize = 128
 

Additional Inherited Members

- Public Types inherited from v8::base::Thread
typedef int32_t LocalStorageKey
 
- Static Public Member Functions inherited from v8::base::Thread
static LocalStorageKey CreateThreadLocalKey ()
 
static void DeleteThreadLocalKey (LocalStorageKey key)
 
static void * GetThreadLocal (LocalStorageKey key)
 
static int GetThreadLocalInt (LocalStorageKey key)
 
static void SetThreadLocal (LocalStorageKey key, void *value)
 
static void SetThreadLocalInt (LocalStorageKey key, int value)
 
static bool HasThreadLocal (LocalStorageKey key)
 
static void * GetExistingThreadLocal (LocalStorageKey key)
 
static void YieldCPU ()
 
- Static Public Attributes inherited from v8::base::Thread
static const int kMaxThreadNameLength = 16
 

Detailed Description

Definition at line 597 of file log.cc.

Constructor & Destructor Documentation

◆ Profiler()

v8::internal::Profiler::Profiler ( Isolate isolate)
explicit

Definition at line 696 of file log.cc.

697  : base::Thread(Options("v8:Profiler")),
698  isolate_(isolate),
699  head_(0),
700  tail_(0),
701  overflow_(false),
703  engaged_(false),
704  running_(false),
705  paused_(false) {}
base::Semaphore buffer_semaphore_
Definition: log.cc:646
Isolate * isolate_
Definition: log.cc:637

Member Function Documentation

◆ Disengage()

void v8::internal::Profiler::Disengage ( )

Definition at line 731 of file log.cc.

731  {
732  if (!engaged_) return;
733 
734  // Stop receiving ticks.
736 
737  // Terminate the worker thread by setting running_ to false,
738  // inserting a fake element in the queue and then wait for
739  // the thread to terminate.
740  running_ = false;
741  TickSample sample;
742  // Reset 'paused_' flag, otherwise semaphore may not be signalled.
743  resume();
744  Insert(&sample);
745  Join();
746 
747  LOG(isolate_, UncheckedStringEvent("profiler", "end"));
748 }
Logger * logger()
Definition: isolate.h:866
Ticker * ticker_
Definition: log.h:386
void Insert(TickSample *sample)
Definition: log.cc:604
void ClearProfiler()
Definition: log.cc:682
#define LOG(isolate, Call)
Definition: log.h:69

References v8::internal::Ticker::ClearProfiler(), engaged_, Insert(), isolate_, v8::base::Thread::Join(), LOG, v8::internal::Isolate::logger(), resume(), running_, and v8::internal::Logger::ticker_.

Referenced by v8::internal::Logger::TearDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Engage()

void v8::internal::Profiler::Engage ( )

Definition at line 708 of file log.cc.

708  {
709  if (engaged_) return;
710  engaged_ = true;
711 
712  std::vector<base::OS::SharedLibraryAddress> addresses =
714  for (size_t i = 0; i < addresses.size(); ++i) {
715  LOG(isolate_, SharedLibraryEvent(
716  addresses[i].library_path, addresses[i].start, addresses[i].end));
717  }
718 
719  // Start thread processing the profiler buffer.
720  running_ = true;
721  Start();
722 
723  // Register to get ticks.
724  Logger* logger = isolate_->logger();
725  logger->ticker_->SetProfiler(this);
726 
727  logger->ProfilerBeginEvent();
728 }
static std::vector< SharedLibraryAddress > GetSharedLibraryAddresses()
void SetProfiler(Profiler *profiler)
Definition: log.cc:675

References engaged_, v8::base::OS::GetSharedLibraryAddresses(), isolate_, LOG, v8::internal::Isolate::logger(), v8::internal::Logger::ProfilerBeginEvent(), running_, v8::internal::Ticker::SetProfiler(), v8::base::Thread::Start(), and v8::internal::Logger::ticker_.

Referenced by v8::internal::Logger::SetUp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Insert()

void v8::internal::Profiler::Insert ( TickSample sample)
inline

Definition at line 604 of file log.cc.

604  {
605  if (paused_)
606  return;
607 
608  if (Succ(head_) == tail_) {
609  overflow_ = true;
610  } else {
611  buffer_[head_] = *sample;
612  head_ = Succ(head_);
613  buffer_semaphore_.Signal(); // Tell we have an element.
614  }
615  }
TickSample buffer_[kBufferSize]
Definition: log.cc:641
int Succ(int index)
Definition: log.cc:635

References buffer_, buffer_semaphore_, head_, overflow_, paused_, Succ(), and tail_.

Referenced by Disengage(), and v8::internal::Ticker::Tick().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pause()

void v8::internal::Profiler::pause ( )
inline

Definition at line 620 of file log.cc.

620 { paused_ = true; }

References paused_.

Referenced by v8::internal::Logger::StopProfiler().

+ Here is the caller graph for this function:

◆ Remove()

bool v8::internal::Profiler::Remove ( TickSample sample)
inlineprivate

Definition at line 625 of file log.cc.

625  {
626  buffer_semaphore_.Wait(); // Wait for an element.
627  *sample = buffer_[tail_];
628  bool result = overflow_;
629  tail_ = Succ(tail_);
630  overflow_ = false;
631  return result;
632  }

References buffer_, buffer_semaphore_, overflow_, Succ(), and tail_.

Referenced by Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resume()

void v8::internal::Profiler::resume ( )
inline

Definition at line 621 of file log.cc.

621 { paused_ = false; }

References paused_.

Referenced by Disengage().

+ Here is the caller graph for this function:

◆ Run()

void v8::internal::Profiler::Run ( )
virtual

Implements v8::base::Thread.

Definition at line 751 of file log.cc.

751  {
752  TickSample sample;
753  bool overflow = Remove(&sample);
754  while (running_) {
755  LOG(isolate_, TickEvent(&sample, overflow));
756  overflow = Remove(&sample);
757  }
758 }
bool Remove(TickSample *sample)
Definition: log.cc:625

References isolate_, LOG, v8::internal::overflow, Remove(), and running_.

+ Here is the call graph for this function:

◆ Succ()

int v8::internal::Profiler::Succ ( int  index)
inlineprivate

Definition at line 635 of file log.cc.

635 { return (index + 1) % kBufferSize; }
static const int kBufferSize
Definition: log.cc:640

References kBufferSize.

Referenced by Insert(), and Remove().

+ Here is the caller graph for this function:

Member Data Documentation

◆ buffer_

TickSample v8::internal::Profiler::buffer_[kBufferSize]
private

Definition at line 641 of file log.cc.

Referenced by Insert(), and Remove().

◆ buffer_semaphore_

base::Semaphore v8::internal::Profiler::buffer_semaphore_
private

Definition at line 646 of file log.cc.

Referenced by Insert(), and Remove().

◆ engaged_

bool v8::internal::Profiler::engaged_
private

Definition at line 649 of file log.cc.

Referenced by Disengage(), and Engage().

◆ head_

int v8::internal::Profiler::head_
private

Definition at line 642 of file log.cc.

Referenced by Insert().

◆ isolate_

Isolate* v8::internal::Profiler::isolate_
private

Definition at line 637 of file log.cc.

Referenced by Disengage(), Engage(), and Run().

◆ kBufferSize

const int v8::internal::Profiler::kBufferSize = 128
staticprivate

Definition at line 640 of file log.cc.

Referenced by Succ().

◆ overflow_

bool v8::internal::Profiler::overflow_
private

Definition at line 644 of file log.cc.

Referenced by Insert(), and Remove().

◆ paused_

bool v8::internal::Profiler::paused_
private

Definition at line 655 of file log.cc.

Referenced by Insert(), pause(), and resume().

◆ running_

bool v8::internal::Profiler::running_
private

Definition at line 652 of file log.cc.

Referenced by Disengage(), Engage(), and Run().

◆ tail_

int v8::internal::Profiler::tail_
private

Definition at line 643 of file log.cc.

Referenced by Insert(), and Remove().


The documentation for this class was generated from the following file: