LCOV - code coverage report
Current view: top level - src - counters.h (source / functions) Hit Total Coverage
Test: app.info Lines: 86 106 81.1 %
Date: 2017-10-20 Functions: 16 17 94.1 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_COUNTERS_H_
       6             : #define V8_COUNTERS_H_
       7             : 
       8             : #include "include/v8.h"
       9             : #include "src/allocation.h"
      10             : #include "src/base/atomic-utils.h"
      11             : #include "src/base/platform/elapsed-timer.h"
      12             : #include "src/base/platform/time.h"
      13             : #include "src/globals.h"
      14             : #include "src/heap-symbols.h"
      15             : #include "src/isolate.h"
      16             : #include "src/objects.h"
      17             : #include "src/runtime/runtime.h"
      18             : #include "src/tracing/trace-event.h"
      19             : #include "src/tracing/traced-value.h"
      20             : #include "src/tracing/tracing-category-observer.h"
      21             : 
      22             : namespace v8 {
      23             : namespace internal {
      24             : 
      25             : // StatsCounters is an interface for plugging into external
      26             : // counters for monitoring.  Counters can be looked up and
      27             : // manipulated by name.
      28             : 
      29             : class Counters;
      30             : 
      31             : class StatsTable {
      32             :  public:
      33             :   // Register an application-defined function for recording
      34             :   // subsequent counter statistics.
      35             :   void SetCounterFunction(CounterLookupCallback f);
      36             : 
      37             :   // Register an application-defined function to create histograms for
      38             :   // recording subsequent histogram samples.
      39             :   void SetCreateHistogramFunction(CreateHistogramCallback f) {
      40           5 :     create_histogram_function_ = f;
      41             :   }
      42             : 
      43             :   // Register an application-defined function to add a sample
      44             :   // to a histogram created with CreateHistogram function.
      45             :   void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
      46           5 :     add_histogram_sample_function_ = f;
      47             :   }
      48             : 
      49             :   bool HasCounterFunction() const { return lookup_function_ != nullptr; }
      50             : 
      51             :   // Lookup the location of a counter by name.  If the lookup
      52             :   // is successful, returns a non-nullptr pointer for writing the
      53             :   // value of the counter.  Each thread calling this function
      54             :   // may receive a different location to store it's counter.
      55             :   // The return value must not be cached and re-used across
      56             :   // threads, although a single thread is free to cache it.
      57             :   int* FindLocation(const char* name) {
      58     1155978 :     if (!lookup_function_) return nullptr;
      59           0 :     return lookup_function_(name);
      60             :   }
      61             : 
      62             :   // Create a histogram by name. If the create is successful,
      63             :   // returns a non-nullptr pointer for use with AddHistogramSample
      64             :   // function. min and max define the expected minimum and maximum
      65             :   // sample values. buckets is the maximum number of buckets
      66             :   // that the samples will be grouped into.
      67             :   void* CreateHistogram(const char* name,
      68             :                         int min,
      69             :                         int max,
      70             :                         size_t buckets) {
      71         350 :     if (!create_histogram_function_) return nullptr;
      72           0 :     return create_histogram_function_(name, min, max, buckets);
      73             :   }
      74             : 
      75             :   // Add a sample to a histogram created with the CreateHistogram
      76             :   // function.
      77             :   void AddHistogramSample(void* histogram, int sample) {
      78           0 :     if (!add_histogram_sample_function_) return;
      79           0 :     return add_histogram_sample_function_(histogram, sample);
      80             :   }
      81             : 
      82             :  private:
      83             :   friend class Counters;
      84             : 
      85             :   explicit StatsTable(Counters* counters);
      86             : 
      87             :   CounterLookupCallback lookup_function_;
      88             :   CreateHistogramCallback create_histogram_function_;
      89             :   AddHistogramSampleCallback add_histogram_sample_function_;
      90             : 
      91             :   DISALLOW_COPY_AND_ASSIGN(StatsTable);
      92             : };
      93             : 
      94             : // Base class for stats counters.
      95             : class StatsCounterBase {
      96             :  protected:
      97             :   Counters* counters_;
      98             :   const char* name_;
      99             :   int* ptr_;
     100             : 
     101             :   StatsCounterBase() {}
     102             :   StatsCounterBase(Counters* counters, const char* name)
     103      164997 :       : counters_(counters), name_(name), ptr_(nullptr) {}
     104             : 
     105           0 :   void SetLoc(int* loc, int value) { *loc = value; }
     106           0 :   void IncrementLoc(int* loc) { (*loc)++; }
     107           0 :   void IncrementLoc(int* loc, int value) { (*loc) += value; }
     108           0 :   void DecrementLoc(int* loc) { (*loc)--; }
     109           0 :   void DecrementLoc(int* loc, int value) { (*loc) -= value; }
     110             : 
     111             :   int* FindLocationInStatsTable() const;
     112             : };
     113             : 
     114             : // StatsCounters are dynamically created values which can be tracked in
     115             : // the StatsTable.  They are designed to be lightweight to create and
     116             : // easy to use.
     117             : //
     118             : // Internally, a counter represents a value in a row of a StatsTable.
     119             : // The row has a 32bit value for each process/thread in the table and also
     120             : // a name (stored in the table metadata).  Since the storage location can be
     121             : // thread-specific, this class cannot be shared across threads. Note: This
     122             : // class is not thread safe.
     123             : class StatsCounter : public StatsCounterBase {
     124             :  public:
     125             :   // Sets the counter to a specific value.
     126     1699388 :   void Set(int value) {
     127     1699388 :     if (int* loc = GetPtr()) SetLoc(loc, value);
     128     1699388 :   }
     129             : 
     130             :   // Increments the counter.
     131   225818362 :   void Increment() {
     132   225818362 :     if (int* loc = GetPtr()) IncrementLoc(loc);
     133   225818362 :   }
     134             : 
     135    18842411 :   void Increment(int value) {
     136    18842411 :     if (int* loc = GetPtr()) IncrementLoc(loc, value);
     137    18842411 :   }
     138             : 
     139             :   // Decrements the counter.
     140     2983389 :   void Decrement() {
     141     2983389 :     if (int* loc = GetPtr()) DecrementLoc(loc);
     142     2983389 :   }
     143             : 
     144     1031813 :   void Decrement(int value) {
     145     1031813 :     if (int* loc = GetPtr()) DecrementLoc(loc, value);
     146     1031813 :   }
     147             : 
     148             :   // Is this counter enabled?
     149             :   // Returns false if table is full.
     150             :   bool Enabled() { return GetPtr() != nullptr; }
     151             : 
     152             :   // Get the internal pointer to the counter. This is used
     153             :   // by the code generator to emit code that manipulates a
     154             :   // given counter without calling the runtime system.
     155             :   int* GetInternalPointer() {
     156             :     int* loc = GetPtr();
     157             :     DCHECK_NOT_NULL(loc);
     158             :     return loc;
     159             :   }
     160             : 
     161             :  private:
     162             :   friend class Counters;
     163             : 
     164             :   StatsCounter() {}
     165             :   StatsCounter(Counters* counters, const char* name)
     166             :       : StatsCounterBase(counters, name), lookup_done_(false) {}
     167             : 
     168             :   // Reset the cached internal pointer.
     169          10 :   void Reset() { lookup_done_ = false; }
     170             : 
     171             :   // Returns the cached address of this counter location.
     172             :   int* GetPtr() {
     173   250375363 :     if (lookup_done_) return ptr_;
     174     1155963 :     lookup_done_ = true;
     175     1155963 :     ptr_ = FindLocationInStatsTable();
     176             :     return ptr_;
     177             :   }
     178             : 
     179             :   bool lookup_done_;
     180             : };
     181             : 
     182             : // Thread safe version of StatsCounter.
     183       53365 : class StatsCounterThreadSafe : public StatsCounterBase {
     184             :  public:
     185             :   void Set(int Value);
     186             :   void Increment();
     187             :   void Increment(int value);
     188             :   void Decrement();
     189             :   void Decrement(int value);
     190             :   bool Enabled() { return ptr_ != nullptr; }
     191             :   int* GetInternalPointer() {
     192             :     DCHECK_NOT_NULL(ptr_);
     193             :     return ptr_;
     194             :   }
     195             : 
     196             :  private:
     197             :   friend class Counters;
     198             : 
     199             :   StatsCounterThreadSafe(Counters* counters, const char* name);
     200          15 :   void Reset() { ptr_ = FindLocationInStatsTable(); }
     201             : 
     202             :   base::Mutex mutex_;
     203             : 
     204             :   DISALLOW_IMPLICIT_CONSTRUCTORS(StatsCounterThreadSafe);
     205             : };
     206             : 
     207             : // A Histogram represents a dynamically created histogram in the
     208             : // StatsTable.  Note: This class is thread safe.
     209             : class Histogram {
     210             :  public:
     211             :   // Add a single sample to this histogram.
     212             :   void AddSample(int sample);
     213             : 
     214             :   // Returns true if this histogram is enabled.
     215             :   bool Enabled() { return histogram_ != nullptr; }
     216             : 
     217             :   const char* name() { return name_; }
     218             : 
     219             :  protected:
     220             :   Histogram() {}
     221             :   Histogram(const char* name, int min, int max, int num_buckets,
     222             :             Counters* counters)
     223             :       : name_(name),
     224             :         min_(min),
     225             :         max_(max),
     226             :         num_buckets_(num_buckets),
     227             :         histogram_(nullptr),
     228           5 :         counters_(counters) {}
     229             : 
     230             :   Counters* counters() const { return counters_; }
     231             : 
     232             :   // Reset the cached internal pointer.
     233         700 :   void Reset() { histogram_ = CreateHistogram(); }
     234             : 
     235             :  private:
     236             :   friend class Counters;
     237             : 
     238             :   void* CreateHistogram() const;
     239             : 
     240             :   const char* name_;
     241             :   int min_;
     242             :   int max_;
     243             :   int num_buckets_;
     244             :   void* histogram_;
     245             :   Counters* counters_;
     246             : };
     247             : 
     248             : enum class HistogramTimerResolution { MILLISECOND, MICROSECOND };
     249             : 
     250             : // A thread safe histogram timer. It also allows distributions of
     251             : // nested timed results.
     252             : class TimedHistogram : public Histogram {
     253             :  public:
     254             :   // Start the timer. Log if isolate non-null.
     255             :   void Start(base::ElapsedTimer* timer, Isolate* isolate);
     256             : 
     257             :   // Stop the timer and record the results. Log if isolate non-null.
     258             :   void Stop(base::ElapsedTimer* timer, Isolate* isolate);
     259             : 
     260             :  protected:
     261             :   friend class Counters;
     262             :   HistogramTimerResolution resolution_;
     263             : 
     264             :   TimedHistogram() {}
     265             :   TimedHistogram(const char* name, int min, int max,
     266             :                  HistogramTimerResolution resolution, int num_buckets,
     267             :                  Counters* counters)
     268             :       : Histogram(name, min, max, num_buckets, counters),
     269           5 :         resolution_(resolution) {}
     270             :   void AddTimeSample();
     271             : };
     272             : 
     273             : // Helper class for scoping a TimedHistogram.
     274             : class TimedHistogramScope {
     275             :  public:
     276             :   explicit TimedHistogramScope(TimedHistogram* histogram,
     277             :                                Isolate* isolate = nullptr)
     278     1006590 :       : histogram_(histogram), isolate_(isolate) {
     279     1006590 :     histogram_->Start(&timer_, isolate);
     280             :   }
     281     1006582 :   ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); }
     282             : 
     283             :  private:
     284             :   base::ElapsedTimer timer_;
     285             :   TimedHistogram* histogram_;
     286             :   Isolate* isolate_;
     287             : 
     288             :   DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope);
     289             : };
     290             : 
     291             : // A HistogramTimer allows distributions of non-nested timed results
     292             : // to be created. WARNING: This class is not thread safe and can only
     293             : // be run on the foreground thread.
     294             : class HistogramTimer : public TimedHistogram {
     295             :  public:
     296             :   // Note: public for testing purposes only.
     297             :   HistogramTimer(const char* name, int min, int max,
     298             :                  HistogramTimerResolution resolution, int num_buckets,
     299             :                  Counters* counters)
     300             :       : TimedHistogram(name, min, max, resolution, num_buckets, counters) {}
     301             : 
     302             :   inline void Start();
     303             :   inline void Stop();
     304             : 
     305             :   // Returns true if the timer is running.
     306             :   bool Running() {
     307             :     return Enabled() && timer_.IsStarted();
     308             :   }
     309             : 
     310             :   // TODO(bmeurer): Remove this when HistogramTimerScope is fixed.
     311             : #ifdef DEBUG
     312             :   base::ElapsedTimer* timer() { return &timer_; }
     313             : #endif
     314             : 
     315             :  private:
     316             :   friend class Counters;
     317             : 
     318             :   base::ElapsedTimer timer_;
     319             : 
     320             :   HistogramTimer() {}
     321             : };
     322             : 
     323             : // Helper class for scoping a HistogramTimer.
     324             : // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the
     325             : // Parser is currently reentrant (when it throws an error, we call back
     326             : // into JavaScript and all bets are off), but ElapsedTimer is not
     327             : // reentry-safe. Fix this properly and remove |allow_nesting|.
     328             : class HistogramTimerScope BASE_EMBEDDED {
     329             :  public:
     330             :   explicit HistogramTimerScope(HistogramTimer* timer,
     331             :                                bool allow_nesting = false)
     332             : #ifdef DEBUG
     333             :       : timer_(timer),
     334             :         skipped_timer_start_(false) {
     335             :     if (timer_->timer()->IsStarted() && allow_nesting) {
     336             :       skipped_timer_start_ = true;
     337             :     } else {
     338             :       timer_->Start();
     339             :     }
     340             :   }
     341             : #else
     342             :       : timer_(timer) {
     343             :     timer_->Start();
     344             :   }
     345             : #endif
     346             :   ~HistogramTimerScope() {
     347             : #ifdef DEBUG
     348             :     if (!skipped_timer_start_) {
     349             :       timer_->Stop();
     350             :     }
     351             : #else
     352             :     timer_->Stop();
     353             : #endif
     354             :   }
     355             : 
     356             :  private:
     357             :   HistogramTimer* timer_;
     358             : #ifdef DEBUG
     359             :   bool skipped_timer_start_;
     360             : #endif
     361             : };
     362             : 
     363             : // A histogram timer that can aggregate events within a larger scope.
     364             : //
     365             : // Intended use of this timer is to have an outer (aggregating) and an inner
     366             : // (to be aggregated) scope, where the inner scope measure the time of events,
     367             : // and all those inner scope measurements will be summed up by the outer scope.
     368             : // An example use might be to aggregate the time spent in lazy compilation
     369             : // while running a script.
     370             : //
     371             : // Helpers:
     372             : // - AggregatingHistogramTimerScope, the "outer" scope within which
     373             : //     times will be summed up.
     374             : // - AggregatedHistogramTimerScope, the "inner" scope which defines the
     375             : //     events to be timed.
     376       54999 : class AggregatableHistogramTimer : public Histogram {
     377             :  public:
     378             :   // Start/stop the "outer" scope.
     379             :   void Start() { time_ = base::TimeDelta(); }
     380      229594 :   void Stop() { AddSample(static_cast<int>(time_.InMicroseconds())); }
     381             : 
     382             :   // Add a time value ("inner" scope).
     383             :   void Add(base::TimeDelta other) { time_ += other; }
     384             : 
     385             :  private:
     386             :   friend class Counters;
     387             : 
     388             :   AggregatableHistogramTimer() {}
     389             :   AggregatableHistogramTimer(const char* name, int min, int max,
     390             :                              int num_buckets, Counters* counters)
     391             :       : Histogram(name, min, max, num_buckets, counters) {}
     392             : 
     393             :   base::TimeDelta time_;
     394             : };
     395             : 
     396             : // A helper class for use with AggregatableHistogramTimer. This is the
     397             : // // outer-most timer scope used with an AggregatableHistogramTimer. It will
     398             : // // aggregate the information from the inner AggregatedHistogramTimerScope.
     399             : class AggregatingHistogramTimerScope {
     400             :  public:
     401             :   explicit AggregatingHistogramTimerScope(AggregatableHistogramTimer* histogram)
     402             :       : histogram_(histogram) {
     403             :     histogram_->Start();
     404             :   }
     405             :   ~AggregatingHistogramTimerScope() { histogram_->Stop(); }
     406             : 
     407             :  private:
     408             :   AggregatableHistogramTimer* histogram_;
     409             : };
     410             : 
     411             : // A helper class for use with AggregatableHistogramTimer, the "inner" scope
     412             : // // which defines the events to be timed.
     413             : class AggregatedHistogramTimerScope {
     414             :  public:
     415             :   explicit AggregatedHistogramTimerScope(AggregatableHistogramTimer* histogram)
     416      576607 :       : histogram_(histogram) {
     417             :     timer_.Start();
     418             :   }
     419     1729821 :   ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); }
     420             : 
     421             :  private:
     422             :   base::ElapsedTimer timer_;
     423             :   AggregatableHistogramTimer* histogram_;
     424             : };
     425             : 
     426             : 
     427             : // AggretatedMemoryHistogram collects (time, value) sample pairs and turns
     428             : // them into time-uniform samples for the backing historgram, such that the
     429             : // backing histogram receives one sample every T ms, where the T is controlled
     430             : // by the FLAG_histogram_interval.
     431             : //
     432             : // More formally: let F be a real-valued function that maps time to sample
     433             : // values. We define F as a linear interpolation between adjacent samples. For
     434             : // each time interval [x; x + T) the backing histogram gets one sample value
     435             : // that is the average of F(t) in the interval.
     436             : template <typename Histogram>
     437             : class AggregatedMemoryHistogram {
     438             :  public:
     439             :   // Note: public for testing purposes only.
     440             :   explicit AggregatedMemoryHistogram(Histogram* backing_histogram)
     441             :       : AggregatedMemoryHistogram() {
     442          14 :     backing_histogram_ = backing_histogram;
     443             :   }
     444             : 
     445             :   // Invariants that hold before and after AddSample if
     446             :   // is_initialized_ is true:
     447             :   //
     448             :   // 1) For we processed samples that came in before start_ms_ and sent the
     449             :   // corresponding aggregated samples to backing histogram.
     450             :   // 2) (last_ms_, last_value_) is the last received sample.
     451             :   // 3) last_ms_ < start_ms_ + FLAG_histogram_interval.
     452             :   // 4) aggregate_value_ is the average of the function that is constructed by
     453             :   // linearly interpolating samples received between start_ms_ and last_ms_.
     454             :   void AddSample(double current_ms, double current_value);
     455             : 
     456             :  private:
     457             :   friend class Counters;
     458             : 
     459             :   AggregatedMemoryHistogram()
     460             :       : is_initialized_(false),
     461             :         start_ms_(0.0),
     462             :         last_ms_(0.0),
     463             :         aggregate_value_(0.0),
     464             :         last_value_(0.0),
     465       55013 :         backing_histogram_(nullptr) {}
     466             :   double Aggregate(double current_ms, double current_value);
     467             : 
     468             :   bool is_initialized_;
     469             :   double start_ms_;
     470             :   double last_ms_;
     471             :   double aggregate_value_;
     472             :   double last_value_;
     473             :   Histogram* backing_histogram_;
     474             : };
     475             : 
     476             : 
     477             : template <typename Histogram>
     478      356808 : void AggregatedMemoryHistogram<Histogram>::AddSample(double current_ms,
     479             :                                                      double current_value) {
     480      356808 :   if (!is_initialized_) {
     481       34427 :     aggregate_value_ = current_value;
     482       34427 :     start_ms_ = current_ms;
     483       34427 :     last_value_ = current_value;
     484       34427 :     last_ms_ = current_ms;
     485       34427 :     is_initialized_ = true;
     486             :   } else {
     487             :     const double kEpsilon = 1e-6;
     488             :     const int kMaxSamples = 1000;
     489      322381 :     if (current_ms < last_ms_ + kEpsilon) {
     490             :       // Two samples have the same time, remember the last one.
     491          22 :       last_value_ = current_value;
     492             :     } else {
     493      322359 :       double sample_interval_ms = FLAG_histogram_interval;
     494      322359 :       double end_ms = start_ms_ + sample_interval_ms;
     495      322359 :       if (end_ms <= current_ms + kEpsilon) {
     496             :         // Linearly interpolate between the last_ms_ and the current_ms.
     497          18 :         double slope = (current_value - last_value_) / (current_ms - last_ms_);
     498             :         int i;
     499             :         // Send aggregated samples to the backing histogram from the start_ms
     500             :         // to the current_ms.
     501        2038 :         for (i = 0; i < kMaxSamples && end_ms <= current_ms + kEpsilon; i++) {
     502        2020 :           double end_value = last_value_ + (end_ms - last_ms_) * slope;
     503             :           double sample_value;
     504        2020 :           if (i == 0) {
     505             :             // Take aggregate_value_ into account.
     506             :             sample_value = Aggregate(end_ms, end_value);
     507             :           } else {
     508             :             // There is no aggregate_value_ for i > 0.
     509        2002 :             sample_value = (last_value_ + end_value) / 2;
     510             :           }
     511        2020 :           backing_histogram_->AddSample(static_cast<int>(sample_value + 0.5));
     512        2020 :           last_value_ = end_value;
     513        2020 :           last_ms_ = end_ms;
     514        2020 :           end_ms += sample_interval_ms;
     515             :         }
     516          18 :         if (i == kMaxSamples) {
     517             :           // We hit the sample limit, ignore the remaining samples.
     518           2 :           aggregate_value_ = current_value;
     519           2 :           start_ms_ = current_ms;
     520             :         } else {
     521          16 :           aggregate_value_ = last_value_;
     522          16 :           start_ms_ = last_ms_;
     523             :         }
     524             :       }
     525      322375 :       aggregate_value_ = current_ms > start_ms_ + kEpsilon
     526             :                              ? Aggregate(current_ms, current_value)
     527             :                              : aggregate_value_;
     528      322359 :       last_value_ = current_value;
     529      322359 :       last_ms_ = current_ms;
     530             :     }
     531             :   }
     532      356808 : }
     533             : 
     534             : 
     535             : template <typename Histogram>
     536             : double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
     537             :                                                        double current_value) {
     538      322361 :   double interval_ms = current_ms - start_ms_;
     539      322361 :   double value = (current_value + last_value_) / 2;
     540             :   // The aggregate_value_ is the average for [start_ms_; last_ms_].
     541             :   // The value is the average for [last_ms_; current_ms].
     542             :   // Return the weighted average of the aggregate_value_ and the value.
     543             :   return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) +
     544      322361 :          value * ((current_ms - last_ms_) / interval_ms);
     545             : }
     546             : 
     547             : class RuntimeCallCounter final {
     548             :  public:
     549             :   explicit RuntimeCallCounter(const char* name)
     550     2131328 :       : name_(name), count_(0), time_(0) {}
     551             :   V8_NOINLINE void Reset();
     552             :   V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
     553             :   void Add(RuntimeCallCounter* other);
     554             : 
     555             :   const char* name() const { return name_; }
     556             :   int64_t count() const { return count_; }
     557             :   base::TimeDelta time() const {
     558             :     return base::TimeDelta::FromMicroseconds(time_);
     559             :   }
     560           0 :   void Increment() { count_++; }
     561           0 :   void Add(base::TimeDelta delta) { time_ += delta.InMicroseconds(); }
     562             : 
     563             :  private:
     564             :   friend class RuntimeCallStats;
     565             : 
     566             :   RuntimeCallCounter() {}
     567             : 
     568             :   const char* name_;
     569             :   int64_t count_;
     570             :   // Stored as int64_t so that its initialization can be deferred.
     571             :   int64_t time_;
     572             : };
     573             : 
     574             : // RuntimeCallTimer is used to keep track of the stack of currently active
     575             : // timers used for properly measuring the own time of a RuntimeCallCounter.
     576   328841763 : class RuntimeCallTimer final {
     577             :  public:
     578             :   RuntimeCallCounter* counter() { return counter_; }
     579           0 :   void set_counter(RuntimeCallCounter* counter) { counter_ = counter; }
     580             :   RuntimeCallTimer* parent() const { return parent_.Value(); }
     581             :   void set_parent(RuntimeCallTimer* timer) { parent_.SetValue(timer); }
     582           0 :   const char* name() const { return counter_->name(); }
     583             : 
     584             :   inline bool IsStarted();
     585             : 
     586             :   inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent);
     587             :   void Snapshot();
     588             :   inline RuntimeCallTimer* Stop();
     589             : 
     590             :  private:
     591             :   inline void Pause(base::TimeTicks now);
     592             :   inline void Resume(base::TimeTicks now);
     593             :   inline void CommitTimeToCounter();
     594             :   inline base::TimeTicks Now();
     595             : 
     596             :   RuntimeCallCounter* counter_ = nullptr;
     597             :   base::AtomicValue<RuntimeCallTimer*> parent_;
     598             :   base::TimeTicks start_ticks_;
     599             :   base::TimeDelta elapsed_;
     600             : };
     601             : 
     602             : #define FOR_EACH_GC_COUNTER(V) TRACER_SCOPES(V)
     603             : 
     604             : #define FOR_EACH_API_COUNTER(V)                            \
     605             :   V(ArrayBuffer_Cast)                                      \
     606             :   V(ArrayBuffer_Neuter)                                    \
     607             :   V(ArrayBuffer_New)                                       \
     608             :   V(Array_CloneElementAt)                                  \
     609             :   V(Array_New)                                             \
     610             :   V(BooleanObject_BooleanValue)                            \
     611             :   V(BooleanObject_New)                                     \
     612             :   V(Context_New)                                           \
     613             :   V(Context_NewRemoteContext)                              \
     614             :   V(DataView_New)                                          \
     615             :   V(Date_DateTimeConfigurationChangeNotification)          \
     616             :   V(Date_New)                                              \
     617             :   V(Date_NumberValue)                                      \
     618             :   V(Debug_Call)                                            \
     619             :   V(Error_New)                                             \
     620             :   V(External_New)                                          \
     621             :   V(Float32Array_New)                                      \
     622             :   V(Float64Array_New)                                      \
     623             :   V(Function_Call)                                         \
     624             :   V(Function_New)                                          \
     625             :   V(Function_NewInstance)                                  \
     626             :   V(FunctionTemplate_GetFunction)                          \
     627             :   V(FunctionTemplate_New)                                  \
     628             :   V(FunctionTemplate_NewRemoteInstance)                    \
     629             :   V(FunctionTemplate_NewWithCache)                         \
     630             :   V(FunctionTemplate_NewWithFastHandler)                   \
     631             :   V(Int16Array_New)                                        \
     632             :   V(Int32Array_New)                                        \
     633             :   V(Int8Array_New)                                         \
     634             :   V(JSON_Parse)                                            \
     635             :   V(JSON_Stringify)                                        \
     636             :   V(Map_AsArray)                                           \
     637             :   V(Map_Clear)                                             \
     638             :   V(Map_Delete)                                            \
     639             :   V(Map_Get)                                               \
     640             :   V(Map_Has)                                               \
     641             :   V(Map_New)                                               \
     642             :   V(Map_Set)                                               \
     643             :   V(Message_GetEndColumn)                                  \
     644             :   V(Message_GetLineNumber)                                 \
     645             :   V(Message_GetSourceLine)                                 \
     646             :   V(Message_GetStartColumn)                                \
     647             :   V(Module_Evaluate)                                       \
     648             :   V(Module_InstantiateModule)                              \
     649             :   V(NumberObject_New)                                      \
     650             :   V(NumberObject_NumberValue)                              \
     651             :   V(Object_CallAsConstructor)                              \
     652             :   V(Object_CallAsFunction)                                 \
     653             :   V(Object_CreateDataProperty)                             \
     654             :   V(Object_DefineOwnProperty)                              \
     655             :   V(Object_DefineProperty)                                 \
     656             :   V(Object_Delete)                                         \
     657             :   V(Object_DeleteProperty)                                 \
     658             :   V(Object_ForceSet)                                       \
     659             :   V(Object_Get)                                            \
     660             :   V(Object_GetOwnPropertyDescriptor)                       \
     661             :   V(Object_GetOwnPropertyNames)                            \
     662             :   V(Object_GetPropertyAttributes)                          \
     663             :   V(Object_GetPropertyNames)                               \
     664             :   V(Object_GetRealNamedProperty)                           \
     665             :   V(Object_GetRealNamedPropertyAttributes)                 \
     666             :   V(Object_GetRealNamedPropertyAttributesInPrototypeChain) \
     667             :   V(Object_GetRealNamedPropertyInPrototypeChain)           \
     668             :   V(Object_Has)                                            \
     669             :   V(Object_HasOwnProperty)                                 \
     670             :   V(Object_HasRealIndexedProperty)                         \
     671             :   V(Object_HasRealNamedCallbackProperty)                   \
     672             :   V(Object_HasRealNamedProperty)                           \
     673             :   V(Object_New)                                            \
     674             :   V(Object_ObjectProtoToString)                            \
     675             :   V(Object_Set)                                            \
     676             :   V(Object_SetAccessor)                                    \
     677             :   V(Object_SetIntegrityLevel)                              \
     678             :   V(Object_SetPrivate)                                     \
     679             :   V(Object_SetPrototype)                                   \
     680             :   V(ObjectTemplate_New)                                    \
     681             :   V(ObjectTemplate_NewInstance)                            \
     682             :   V(Object_ToArrayIndex)                                   \
     683             :   V(Object_ToDetailString)                                 \
     684             :   V(Object_ToInt32)                                        \
     685             :   V(Object_ToInteger)                                      \
     686             :   V(Object_ToNumber)                                       \
     687             :   V(Object_ToObject)                                       \
     688             :   V(Object_ToString)                                       \
     689             :   V(Object_ToUint32)                                       \
     690             :   V(Persistent_New)                                        \
     691             :   V(Private_New)                                           \
     692             :   V(Promise_Catch)                                         \
     693             :   V(Promise_Chain)                                         \
     694             :   V(Promise_HasRejectHandler)                              \
     695             :   V(Promise_Resolver_New)                                  \
     696             :   V(Promise_Resolver_Resolve)                              \
     697             :   V(Promise_Resolver_Reject)                               \
     698             :   V(Promise_Result)                                        \
     699             :   V(Promise_Status)                                        \
     700             :   V(Promise_Then)                                          \
     701             :   V(Proxy_New)                                             \
     702             :   V(RangeError_New)                                        \
     703             :   V(ReferenceError_New)                                    \
     704             :   V(RegExp_New)                                            \
     705             :   V(ScriptCompiler_Compile)                                \
     706             :   V(ScriptCompiler_CompileFunctionInContext)               \
     707             :   V(ScriptCompiler_CompileUnbound)                         \
     708             :   V(Script_Run)                                            \
     709             :   V(Set_Add)                                               \
     710             :   V(Set_AsArray)                                           \
     711             :   V(Set_Clear)                                             \
     712             :   V(Set_Delete)                                            \
     713             :   V(Set_Has)                                               \
     714             :   V(Set_New)                                               \
     715             :   V(SharedArrayBuffer_New)                                 \
     716             :   V(String_Concat)                                         \
     717             :   V(String_NewExternalOneByte)                             \
     718             :   V(String_NewExternalTwoByte)                             \
     719             :   V(String_NewFromOneByte)                                 \
     720             :   V(String_NewFromTwoByte)                                 \
     721             :   V(String_NewFromUtf8)                                    \
     722             :   V(StringObject_New)                                      \
     723             :   V(StringObject_StringValue)                              \
     724             :   V(String_Write)                                          \
     725             :   V(String_WriteUtf8)                                      \
     726             :   V(Symbol_New)                                            \
     727             :   V(SymbolObject_New)                                      \
     728             :   V(SymbolObject_SymbolValue)                              \
     729             :   V(SyntaxError_New)                                       \
     730             :   V(TryCatch_StackTrace)                                   \
     731             :   V(TypeError_New)                                         \
     732             :   V(Uint16Array_New)                                       \
     733             :   V(Uint32Array_New)                                       \
     734             :   V(Uint8Array_New)                                        \
     735             :   V(Uint8ClampedArray_New)                                 \
     736             :   V(UnboundScript_GetId)                                   \
     737             :   V(UnboundScript_GetLineNumber)                           \
     738             :   V(UnboundScript_GetName)                                 \
     739             :   V(UnboundScript_GetSourceMappingURL)                     \
     740             :   V(UnboundScript_GetSourceURL)                            \
     741             :   V(Value_InstanceOf)                                      \
     742             :   V(Value_IntegerValue)                                    \
     743             :   V(Value_Int32Value)                                      \
     744             :   V(Value_NumberValue)                                     \
     745             :   V(Value_TypeOf)                                          \
     746             :   V(Value_Uint32Value)                                     \
     747             :   V(ValueDeserializer_ReadHeader)                          \
     748             :   V(ValueDeserializer_ReadValue)                           \
     749             :   V(ValueSerializer_WriteValue)
     750             : 
     751             : #define FOR_EACH_MANUAL_COUNTER(V)             \
     752             :   V(AccessorGetterCallback)                    \
     753             :   V(AccessorNameGetterCallback)                \
     754             :   V(AccessorNameSetterCallback)                \
     755             :   V(ArrayLengthGetter)                         \
     756             :   V(ArrayLengthSetter)                         \
     757             :   V(BoundFunctionNameGetter)                   \
     758             :   V(BoundFunctionLengthGetter)                 \
     759             :   V(CompileCodeLazy)                           \
     760             :   V(CompileDeserialize)                        \
     761             :   V(CompileEval)                               \
     762             :   V(CompileFullCode)                           \
     763             :   V(CompileAnalyse)                            \
     764             :   V(CompileBackgroundIgnition)                 \
     765             :   V(CompileFunction)                           \
     766             :   V(CompileGetFromOptimizedCodeMap)            \
     767             :   V(CompileIgnition)                           \
     768             :   V(CompileIgnitionFinalization)               \
     769             :   V(CompileInnerFunction)                      \
     770             :   V(CompileRenumber)                           \
     771             :   V(CompileRewriteReturnResult)                \
     772             :   V(CompileScopeAnalysis)                      \
     773             :   V(CompileScript)                             \
     774             :   V(CompileSerialize)                          \
     775             :   V(CompileWaitForDispatcher)                  \
     776             :   V(DeoptimizeCode)                            \
     777             :   V(FunctionCallback)                          \
     778             :   V(FunctionPrototypeGetter)                   \
     779             :   V(FunctionPrototypeSetter)                   \
     780             :   V(GC_Custom_AllAvailableGarbage)             \
     781             :   V(GC_Custom_IncrementalMarkingObserver)      \
     782             :   V(GC_Custom_SlowAllocateRaw)                 \
     783             :   V(GCEpilogueCallback)                        \
     784             :   V(GCPrologueCallback)                        \
     785             :   V(GenericNamedPropertyDefinerCallback)       \
     786             :   V(GenericNamedPropertyDeleterCallback)       \
     787             :   V(GenericNamedPropertyDescriptorCallback)    \
     788             :   V(GenericNamedPropertyQueryCallback)         \
     789             :   V(GenericNamedPropertySetterCallback)        \
     790             :   V(GetMoreDataCallback)                       \
     791             :   V(IndexedPropertyDefinerCallback)            \
     792             :   V(IndexedPropertyDeleterCallback)            \
     793             :   V(IndexedPropertyDescriptorCallback)         \
     794             :   V(IndexedPropertyGetterCallback)             \
     795             :   V(IndexedPropertyQueryCallback)              \
     796             :   V(IndexedPropertySetterCallback)             \
     797             :   V(InvokeApiInterruptCallbacks)               \
     798             :   V(InvokeFunctionCallback)                    \
     799             :   V(JS_Execution)                              \
     800             :   V(Map_SetPrototype)                          \
     801             :   V(Map_TransitionToAccessorProperty)          \
     802             :   V(Map_TransitionToDataProperty)              \
     803             :   V(Object_DeleteProperty)                     \
     804             :   V(OptimizeCode)                              \
     805             :   V(ParseArrowFunctionLiteral)                 \
     806             :   V(ParseBackgroundArrowFunctionLiteral)       \
     807             :   V(ParseBackgroundFunctionLiteral)            \
     808             :   V(ParseEval)                                 \
     809             :   V(ParseFunction)                             \
     810             :   V(ParseFunctionLiteral)                      \
     811             :   V(ParseProgram)                              \
     812             :   V(PreParseArrowFunctionLiteral)              \
     813             :   V(PreParseBackgroundArrowFunctionLiteral)    \
     814             :   V(PreParseBackgroundNoVariableResolution)    \
     815             :   V(PreParseBackgroundWithVariableResolution)  \
     816             :   V(PreParseNoVariableResolution)              \
     817             :   V(PreParseWithVariableResolution)            \
     818             :   V(PropertyCallback)                          \
     819             :   V(PrototypeMap_TransitionToAccessorProperty) \
     820             :   V(PrototypeMap_TransitionToDataProperty)     \
     821             :   V(PrototypeObject_DeleteProperty)            \
     822             :   V(RecompileConcurrent)                       \
     823             :   V(RecompileSynchronous)                      \
     824             :   V(ReconfigureToDataProperty)                 \
     825             :   V(StringLengthGetter)                        \
     826             :   V(TestCounter1)                              \
     827             :   V(TestCounter2)                              \
     828             :   V(TestCounter3)
     829             : 
     830             : #define FOR_EACH_HANDLER_COUNTER(V)              \
     831             :   V(KeyedLoadIC_LoadIndexedStringStub)           \
     832             :   V(KeyedLoadIC_LoadIndexedInterceptorStub)      \
     833             :   V(KeyedLoadIC_KeyedLoadSloppyArgumentsStub)    \
     834             :   V(KeyedLoadIC_LoadElementDH)                   \
     835             :   V(KeyedLoadIC_SlowStub)                        \
     836             :   V(KeyedStoreIC_ElementsTransitionAndStoreStub) \
     837             :   V(KeyedStoreIC_KeyedStoreSloppyArgumentsStub)  \
     838             :   V(KeyedStoreIC_SlowStub)                       \
     839             :   V(KeyedStoreIC_StoreFastElementStub)           \
     840             :   V(KeyedStoreIC_StoreElementStub)               \
     841             :   V(LoadIC_FunctionPrototypeStub)                \
     842             :   V(LoadIC_HandlerCacheHit_Accessor)             \
     843             :   V(LoadIC_LoadAccessorDH)                       \
     844             :   V(LoadIC_LoadAccessorFromPrototypeDH)          \
     845             :   V(LoadIC_LoadApiGetterDH)                      \
     846             :   V(LoadIC_LoadApiGetterFromPrototypeDH)         \
     847             :   V(LoadIC_LoadCallback)                         \
     848             :   V(LoadIC_LoadConstantDH)                       \
     849             :   V(LoadIC_LoadConstantFromPrototypeDH)          \
     850             :   V(LoadIC_LoadFieldDH)                          \
     851             :   V(LoadIC_LoadFieldFromPrototypeDH)             \
     852             :   V(LoadIC_LoadGlobalDH)                         \
     853             :   V(LoadIC_LoadGlobalFromPrototypeDH)            \
     854             :   V(LoadIC_LoadIntegerIndexedExoticDH)           \
     855             :   V(LoadIC_LoadInterceptorDH)                    \
     856             :   V(LoadIC_LoadNonMaskingInterceptorDH)          \
     857             :   V(LoadIC_LoadInterceptorFromPrototypeDH)       \
     858             :   V(LoadIC_LoadNonexistentDH)                    \
     859             :   V(LoadIC_LoadNormalDH)                         \
     860             :   V(LoadIC_LoadNormalFromPrototypeDH)            \
     861             :   V(LoadIC_LoadScriptContextFieldStub)           \
     862             :   V(LoadIC_LoadViaGetter)                        \
     863             :   V(LoadIC_NonReceiver)                          \
     864             :   V(LoadIC_Premonomorphic)                       \
     865             :   V(LoadIC_SlowStub)                             \
     866             :   V(LoadIC_StringLength)                         \
     867             :   V(StoreIC_HandlerCacheHit_Accessor)            \
     868             :   V(StoreIC_NonReceiver)                         \
     869             :   V(StoreIC_Premonomorphic)                      \
     870             :   V(StoreIC_SlowStub)                            \
     871             :   V(StoreIC_StoreCallback)                       \
     872             :   V(StoreIC_StoreFieldDH)                        \
     873             :   V(StoreIC_StoreGlobalDH)                       \
     874             :   V(StoreIC_StoreGlobalTransitionDH)             \
     875             :   V(StoreIC_StoreInterceptorStub)                \
     876             :   V(StoreIC_StoreNormalDH)                       \
     877             :   V(StoreIC_StoreScriptContextFieldStub)         \
     878             :   V(StoreIC_StoreTransitionDH)                   \
     879             :   V(StoreIC_StoreViaSetter)
     880             : 
     881             : class RuntimeCallStats final : public ZoneObject {
     882             :  public:
     883             :   typedef RuntimeCallCounter RuntimeCallStats::*CounterId;
     884             :   V8_EXPORT_PRIVATE RuntimeCallStats();
     885             : 
     886             : #define CALL_RUNTIME_COUNTER(name) RuntimeCallCounter GC_##name;
     887             :   FOR_EACH_GC_COUNTER(CALL_RUNTIME_COUNTER)
     888             : #undef CALL_RUNTIME_COUNTER
     889             : #define CALL_RUNTIME_COUNTER(name) RuntimeCallCounter name;
     890             :   FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER)
     891             : #undef CALL_RUNTIME_COUNTER
     892             : #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \
     893             :   RuntimeCallCounter Runtime_##name;
     894             :   FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER)
     895             : #undef CALL_RUNTIME_COUNTER
     896             : #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter Builtin_##name;
     897             :   BUILTIN_LIST_C(CALL_BUILTIN_COUNTER)
     898             : #undef CALL_BUILTIN_COUNTER
     899             : #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter API_##name;
     900             :   FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER)
     901             : #undef CALL_BUILTIN_COUNTER
     902             : #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter Handler_##name;
     903             :   FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER)
     904             : #undef CALL_BUILTIN_COUNTER
     905             : 
     906             :   static const CounterId counters[];
     907             :   static const int counters_count;
     908             : 
     909             :   // Starting measuring the time for a function. This will establish the
     910             :   // connection to the parent counter for properly calculating the own times.
     911             :   V8_EXPORT_PRIVATE static void Enter(RuntimeCallStats* stats,
     912             :                                       RuntimeCallTimer* timer,
     913             :                                       CounterId counter_id);
     914             : 
     915             :   // Leave a scope for a measured runtime function. This will properly add
     916             :   // the time delta to the current_counter and subtract the delta from its
     917             :   // parent.
     918             :   V8_EXPORT_PRIVATE static void Leave(RuntimeCallStats* stats,
     919             :                                       RuntimeCallTimer* timer);
     920             : 
     921             :   // Set counter id for the innermost measurement. It can be used to refine
     922             :   // event kind when a runtime entry counter is too generic.
     923             :   V8_EXPORT_PRIVATE static void CorrectCurrentCounterId(RuntimeCallStats* stats,
     924             :                                                         CounterId counter_id);
     925             : 
     926             :   V8_EXPORT_PRIVATE void Reset();
     927             :   // Add all entries from another stats object.
     928             :   void Add(RuntimeCallStats* other);
     929             :   V8_EXPORT_PRIVATE void Print(std::ostream& os);
     930             :   V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
     931             : 
     932             :   ThreadId thread_id() const { return thread_id_; }
     933             :   RuntimeCallTimer* current_timer() { return current_timer_.Value(); }
     934             :   RuntimeCallCounter* current_counter() { return current_counter_.Value(); }
     935             :   bool InUse() { return in_use_; }
     936             :   bool IsCalledOnTheSameThread();
     937             : 
     938             :  private:
     939             :   // Top of a stack of active timers.
     940             :   base::AtomicValue<RuntimeCallTimer*> current_timer_;
     941             :   // Active counter object associated with current timer.
     942             :   base::AtomicValue<RuntimeCallCounter*> current_counter_;
     943             :   // Used to track nested tracing scopes.
     944             :   bool in_use_;
     945             :   ThreadId thread_id_;
     946             : };
     947             : 
     948             : #define CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats, counter_name) \
     949             :   do {                                                                   \
     950             :     if (V8_UNLIKELY(FLAG_runtime_stats)) {                               \
     951             :       RuntimeCallStats::CorrectCurrentCounterId(                         \
     952             :           runtime_call_stats, &RuntimeCallStats::counter_name);          \
     953             :     }                                                                    \
     954             :   } while (false)
     955             : 
     956             : #define TRACE_HANDLER_STATS(isolate, counter_name)                          \
     957             :   CHANGE_CURRENT_RUNTIME_COUNTER(isolate->counters()->runtime_call_stats(), \
     958             :                                  Handler_##counter_name)
     959             : 
     960             : // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
     961             : // the time of C++ scope.
     962             : class RuntimeCallTimerScope {
     963             :  public:
     964             :   inline RuntimeCallTimerScope(Isolate* isolate,
     965             :                                RuntimeCallStats::CounterId counter_id);
     966             :   // This constructor is here just to avoid calling GetIsolate() when the
     967             :   // stats are disabled and the isolate is not directly available.
     968             :   inline RuntimeCallTimerScope(HeapObject* heap_object,
     969             :                                RuntimeCallStats::CounterId counter_id);
     970    19963745 :   inline RuntimeCallTimerScope(RuntimeCallStats* stats,
     971    19963745 :                                RuntimeCallStats::CounterId counter_id) {
     972    39927490 :     if (V8_LIKELY(!FLAG_runtime_stats || stats == nullptr)) return;
     973           0 :     stats_ = stats;
     974           0 :     RuntimeCallStats::Enter(stats_, &timer_, counter_id);
     975             :   }
     976             : 
     977             :   inline ~RuntimeCallTimerScope() {
     978   323799473 :     if (V8_UNLIKELY(stats_ != nullptr)) {
     979           0 :       RuntimeCallStats::Leave(stats_, &timer_);
     980             :     }
     981             :   }
     982             : 
     983             :  private:
     984             :   RuntimeCallStats* stats_ = nullptr;
     985             :   RuntimeCallTimer timer_;
     986             : 
     987             :   DISALLOW_COPY_AND_ASSIGN(RuntimeCallTimerScope);
     988             : };
     989             : 
     990             : #define HISTOGRAM_RANGE_LIST(HR)                                               \
     991             :   /* Generic range histograms: HR(name, caption, min, max, num_buckets) */     \
     992             :   HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21)         \
     993             :   HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6)              \
     994             :   HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20)         \
     995             :   HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7)                       \
     996             :   HR(incremental_marking_reason, V8.GCIncrementalMarkingReason, 0, 21, 22)     \
     997             :   HR(incremental_marking_sum, V8.GCIncrementalMarkingSum, 0, 10000, 101)       \
     998             :   HR(mark_compact_reason, V8.GCMarkCompactReason, 0, 21, 22)                   \
     999             :   HR(scavenge_reason, V8.GCScavengeReason, 0, 21, 22)                          \
    1000             :   HR(young_generation_handling, V8.GCYoungGenerationHandling, 0, 2, 3)         \
    1001             :   /* Asm/Wasm. */                                                              \
    1002             :   HR(wasm_functions_per_asm_module, V8.WasmFunctionsPerModule.asm, 1, 100000,  \
    1003             :      51)                                                                       \
    1004             :   HR(wasm_functions_per_wasm_module, V8.WasmFunctionsPerModule.wasm, 1,        \
    1005             :      100000, 51)                                                               \
    1006             :   HR(array_buffer_big_allocations, V8.ArrayBufferLargeAllocations, 0, 4096,    \
    1007             :      13)                                                                       \
    1008             :   HR(array_buffer_new_size_failures, V8.ArrayBufferNewSizeFailures, 0, 4096,   \
    1009             :      13)                                                                       \
    1010             :   HR(shared_array_allocations, V8.SharedArrayAllocationSizes, 0, 4096, 13)     \
    1011             :   HR(wasm_asm_function_size_bytes, V8.WasmFunctionSizeBytes.asm, 1, GB, 51)    \
    1012             :   HR(wasm_wasm_function_size_bytes, V8.WasmFunctionSizeBytes.wasm, 1, GB, 51)  \
    1013             :   HR(wasm_asm_module_size_bytes, V8.WasmModuleSizeBytes.asm, 1, GB, 51)        \
    1014             :   HR(wasm_wasm_module_size_bytes, V8.WasmModuleSizeBytes.wasm, 1, GB, 51)      \
    1015             :   HR(wasm_asm_min_mem_pages_count, V8.WasmMinMemPagesCount.asm, 1, 2 << 16,    \
    1016             :      51)                                                                       \
    1017             :   HR(wasm_wasm_min_mem_pages_count, V8.WasmMinMemPagesCount.wasm, 1, 2 << 16,  \
    1018             :      51)                                                                       \
    1019             :   HR(wasm_wasm_max_mem_pages_count, V8.WasmMaxMemPagesCount.wasm, 1, 2 << 16,  \
    1020             :      51)                                                                       \
    1021             :   HR(wasm_decode_asm_module_peak_memory_bytes,                                 \
    1022             :      V8.WasmDecodeModulePeakMemoryBytes.asm, 1, GB, 51)                        \
    1023             :   HR(wasm_decode_wasm_module_peak_memory_bytes,                                \
    1024             :      V8.WasmDecodeModulePeakMemoryBytes.wasm, 1, GB, 51)                       \
    1025             :   HR(asm_wasm_translation_peak_memory_bytes,                                   \
    1026             :      V8.AsmWasmTranslationPeakMemoryBytes, 1, GB, 51)                          \
    1027             :   HR(wasm_compile_function_peak_memory_bytes,                                  \
    1028             :      V8.WasmCompileFunctionPeakMemoryBytes, 1, GB, 51)                         \
    1029             :   HR(asm_module_size_bytes, V8.AsmModuleSizeBytes, 1, GB, 51)                  \
    1030             :   HR(asm_wasm_translation_throughput, V8.AsmWasmTranslationThroughput, 1, 100, \
    1031             :      20)                                                                       \
    1032             :   HR(wasm_lazy_compilation_throughput, V8.WasmLazyCompilationThroughput, 1,    \
    1033             :      10000, 50)
    1034             : 
    1035             : #define HISTOGRAM_TIMER_LIST(HT)                                               \
    1036             :   /* Garbage collection timers. */                                             \
    1037             :   HT(gc_compactor, V8.GCCompactor, 10000, MILLISECOND)                         \
    1038             :   HT(gc_finalize, V8.GCFinalizeMC, 10000, MILLISECOND)                         \
    1039             :   HT(gc_finalize_reduce_memory, V8.GCFinalizeMCReduceMemory, 10000,            \
    1040             :      MILLISECOND)                                                              \
    1041             :   HT(gc_scavenger, V8.GCScavenger, 10000, MILLISECOND)                         \
    1042             :   HT(gc_context, V8.GCContext, 10000,                                          \
    1043             :      MILLISECOND) /* GC context cleanup time */                                \
    1044             :   HT(gc_idle_notification, V8.GCIdleNotification, 10000, MILLISECOND)          \
    1045             :   HT(gc_incremental_marking, V8.GCIncrementalMarking, 10000, MILLISECOND)      \
    1046             :   HT(gc_incremental_marking_start, V8.GCIncrementalMarkingStart, 10000,        \
    1047             :      MILLISECOND)                                                              \
    1048             :   HT(gc_incremental_marking_finalize, V8.GCIncrementalMarkingFinalize, 10000,  \
    1049             :      MILLISECOND)                                                              \
    1050             :   HT(gc_low_memory_notification, V8.GCLowMemoryNotification, 10000,            \
    1051             :      MILLISECOND)                                                              \
    1052             :   /* Compilation times. */                                                     \
    1053             :   HT(compile, V8.CompileMicroSeconds, 1000000, MICROSECOND)                    \
    1054             :   HT(compile_eval, V8.CompileEvalMicroSeconds, 1000000, MICROSECOND)           \
    1055             :   /* Serialization as part of compilation (code caching) */                    \
    1056             :   HT(compile_serialize, V8.CompileSerializeMicroSeconds, 100000, MICROSECOND)  \
    1057             :   HT(compile_deserialize, V8.CompileDeserializeMicroSeconds, 1000000,          \
    1058             :      MICROSECOND)                                                              \
    1059             :   /* Total compilation time incl. caching/parsing */                           \
    1060             :   HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND)       \
    1061             :   /* Total JavaScript execution time (including callbacks and runtime calls */ \
    1062             :   HT(execute, V8.Execute, 1000000, MICROSECOND)                                \
    1063             :   /* Asm/Wasm */                                                               \
    1064             :   HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000,    \
    1065             :      MICROSECOND)                                                              \
    1066             :   HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000,  \
    1067             :      MICROSECOND)                                                              \
    1068             :   HT(wasm_execution_time, V8.WasmExecutionTimeMicroSeconds, 10000000,          \
    1069             :      MICROSECOND)
    1070             : 
    1071             : #define TIMED_HISTOGRAM_LIST(HT)                                               \
    1072             :   HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm,         \
    1073             :      1000000, MICROSECOND)                                                     \
    1074             :   HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm,       \
    1075             :      1000000, MICROSECOND)                                                     \
    1076             :   HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm,     \
    1077             :      1000000, MICROSECOND)                                                     \
    1078             :   HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm,   \
    1079             :      1000000, MICROSECOND)                                                     \
    1080             :   HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm,       \
    1081             :      10000000, MICROSECOND)                                                    \
    1082             :   HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm,     \
    1083             :      10000000, MICROSECOND)                                                    \
    1084             :   HT(wasm_compile_asm_function_time, V8.WasmCompileFunctionMicroSeconds.asm,   \
    1085             :      1000000, MICROSECOND)                                                     \
    1086             :   HT(wasm_compile_wasm_function_time, V8.WasmCompileFunctionMicroSeconds.wasm, \
    1087             :      1000000, MICROSECOND)                                                     \
    1088             :   HT(wasm_instantiate_wasm_module_time,                                        \
    1089             :      V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND)         \
    1090             :   HT(wasm_instantiate_asm_module_time,                                         \
    1091             :      V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND)
    1092             : 
    1093             : #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \
    1094             :   AHT(compile_lazy, V8.CompileLazyMicroSeconds)
    1095             : 
    1096             : #define HISTOGRAM_PERCENTAGE_LIST(HP)                                          \
    1097             :   /* Heap fragmentation. */                                                    \
    1098             :   HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal)        \
    1099             :   HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \
    1100             :   HP(external_fragmentation_code_space,                                        \
    1101             :      V8.MemoryExternalFragmentationCodeSpace)                                  \
    1102             :   HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \
    1103             :   HP(external_fragmentation_lo_space, V8.MemoryExternalFragmentationLoSpace)
    1104             : 
    1105             : // Note: These use Histogram with options (min=1000, max=500000, buckets=50).
    1106             : #define HISTOGRAM_LEGACY_MEMORY_LIST(HM)                                      \
    1107             :   HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted)          \
    1108             :   HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed)                    \
    1109             :   HM(heap_sample_map_space_committed, V8.MemoryHeapSampleMapSpaceCommitted)   \
    1110             :   HM(heap_sample_code_space_committed, V8.MemoryHeapSampleCodeSpaceCommitted) \
    1111             :   HM(heap_sample_maximum_committed, V8.MemoryHeapSampleMaximumCommitted)
    1112             : 
    1113             : // Note: These define both Histogram and AggregatedMemoryHistogram<Histogram>
    1114             : // histograms with options (min=4000, max=2000000, buckets=100).
    1115             : #define HISTOGRAM_MEMORY_LIST(HM)                   \
    1116             :   HM(memory_heap_committed, V8.MemoryHeapCommitted) \
    1117             :   HM(memory_heap_used, V8.MemoryHeapUsed)
    1118             : 
    1119             : // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
    1120             : // Intellisense to crash.  It was broken into two macros (each of length 40
    1121             : // lines) rather than one macro (of length about 80 lines) to work around
    1122             : // this problem.  Please avoid using recursive macros of this length when
    1123             : // possible.
    1124             : #define STATS_COUNTER_LIST_1(SC)                                    \
    1125             :   /* Global Handle Count*/                                          \
    1126             :   SC(global_handles, V8.GlobalHandles)                              \
    1127             :   /* OS Memory allocated */                                         \
    1128             :   SC(memory_allocated, V8.OsMemoryAllocated)                        \
    1129             :   SC(maps_normalized, V8.MapsNormalized)                            \
    1130             :   SC(maps_created, V8.MapsCreated)                                  \
    1131             :   SC(elements_transitions, V8.ObjectElementsTransitions)            \
    1132             :   SC(props_to_dictionary, V8.ObjectPropertiesToDictionary)          \
    1133             :   SC(elements_to_dictionary, V8.ObjectElementsToDictionary)         \
    1134             :   SC(alive_after_last_gc, V8.AliveAfterLastGC)                      \
    1135             :   SC(objs_since_last_young, V8.ObjsSinceLastYoung)                  \
    1136             :   SC(objs_since_last_full, V8.ObjsSinceLastFull)                    \
    1137             :   SC(string_table_capacity, V8.StringTableCapacity)                 \
    1138             :   SC(number_of_symbols, V8.NumberOfSymbols)                         \
    1139             :   SC(script_wrappers, V8.ScriptWrappers)                            \
    1140             :   SC(inlined_copied_elements, V8.InlinedCopiedElements)             \
    1141             :   SC(arguments_adaptors, V8.ArgumentsAdaptors)                      \
    1142             :   SC(compilation_cache_hits, V8.CompilationCacheHits)               \
    1143             :   SC(compilation_cache_misses, V8.CompilationCacheMisses)           \
    1144             :   /* Amount of evaled source code. */                               \
    1145             :   SC(total_eval_size, V8.TotalEvalSize)                             \
    1146             :   /* Amount of loaded source code. */                               \
    1147             :   SC(total_load_size, V8.TotalLoadSize)                             \
    1148             :   /* Amount of parsed source code. */                               \
    1149             :   SC(total_parse_size, V8.TotalParseSize)                           \
    1150             :   /* Amount of source code skipped over using preparsing. */        \
    1151             :   SC(total_preparse_skipped, V8.TotalPreparseSkipped)               \
    1152             :   /* Amount of compiled source code. */                             \
    1153             :   SC(total_compile_size, V8.TotalCompileSize)                       \
    1154             :   /* Amount of source code compiled with the full codegen. */       \
    1155             :   SC(total_full_codegen_source_size, V8.TotalFullCodegenSourceSize) \
    1156             :   /* Number of contexts created from scratch. */                    \
    1157             :   SC(contexts_created_from_scratch, V8.ContextsCreatedFromScratch)  \
    1158             :   /* Number of contexts created by partial snapshot. */             \
    1159             :   SC(contexts_created_by_snapshot, V8.ContextsCreatedBySnapshot)    \
    1160             :   /* Number of code objects found from pc. */                       \
    1161             :   SC(pc_to_code, V8.PcToCode)                                       \
    1162             :   SC(pc_to_code_cached, V8.PcToCodeCached)                          \
    1163             :   /* The store-buffer implementation of the write barrier. */       \
    1164             :   SC(store_buffer_overflows, V8.StoreBufferOverflows)
    1165             : 
    1166             : #define STATS_COUNTER_LIST_2(SC)                                               \
    1167             :   /* Number of code stubs. */                                                  \
    1168             :   SC(code_stubs, V8.CodeStubs)                                                 \
    1169             :   /* Amount of stub code. */                                                   \
    1170             :   SC(total_stubs_code_size, V8.TotalStubsCodeSize)                             \
    1171             :   /* Amount of (JS) compiled code. */                                          \
    1172             :   SC(total_compiled_code_size, V8.TotalCompiledCodeSize)                       \
    1173             :   SC(gc_compactor_caused_by_request, V8.GCCompactorCausedByRequest)            \
    1174             :   SC(gc_compactor_caused_by_promoted_data, V8.GCCompactorCausedByPromotedData) \
    1175             :   SC(gc_compactor_caused_by_oldspace_exhaustion,                               \
    1176             :      V8.GCCompactorCausedByOldspaceExhaustion)                                 \
    1177             :   SC(gc_last_resort_from_js, V8.GCLastResortFromJS)                            \
    1178             :   SC(gc_last_resort_from_handles, V8.GCLastResortFromHandles)                  \
    1179             :   SC(ic_keyed_load_generic_smi, V8.ICKeyedLoadGenericSmi)                      \
    1180             :   SC(ic_keyed_load_generic_symbol, V8.ICKeyedLoadGenericSymbol)                \
    1181             :   SC(ic_keyed_load_generic_slow, V8.ICKeyedLoadGenericSlow)                    \
    1182             :   SC(ic_named_load_global_stub, V8.ICNamedLoadGlobalStub)                      \
    1183             :   SC(ic_store_normal_miss, V8.ICStoreNormalMiss)                               \
    1184             :   SC(ic_store_normal_hit, V8.ICStoreNormalHit)                                 \
    1185             :   SC(ic_binary_op_miss, V8.ICBinaryOpMiss)                                     \
    1186             :   SC(ic_compare_miss, V8.ICCompareMiss)                                        \
    1187             :   SC(ic_call_miss, V8.ICCallMiss)                                              \
    1188             :   SC(ic_keyed_call_miss, V8.ICKeyedCallMiss)                                   \
    1189             :   SC(ic_store_miss, V8.ICStoreMiss)                                            \
    1190             :   SC(ic_keyed_store_miss, V8.ICKeyedStoreMiss)                                 \
    1191             :   SC(cow_arrays_converted, V8.COWArraysConverted)                              \
    1192             :   SC(constructed_objects, V8.ConstructedObjects)                               \
    1193             :   SC(constructed_objects_runtime, V8.ConstructedObjectsRuntime)                \
    1194             :   SC(negative_lookups, V8.NegativeLookups)                                     \
    1195             :   SC(negative_lookups_miss, V8.NegativeLookupsMiss)                            \
    1196             :   SC(megamorphic_stub_cache_probes, V8.MegamorphicStubCacheProbes)             \
    1197             :   SC(megamorphic_stub_cache_misses, V8.MegamorphicStubCacheMisses)             \
    1198             :   SC(megamorphic_stub_cache_updates, V8.MegamorphicStubCacheUpdates)           \
    1199             :   SC(enum_cache_hits, V8.EnumCacheHits)                                        \
    1200             :   SC(enum_cache_misses, V8.EnumCacheMisses)                                    \
    1201             :   SC(fast_new_closure_total, V8.FastNewClosureTotal)                           \
    1202             :   SC(string_add_runtime, V8.StringAddRuntime)                                  \
    1203             :   SC(string_add_native, V8.StringAddNative)                                    \
    1204             :   SC(string_add_runtime_ext_to_one_byte, V8.StringAddRuntimeExtToOneByte)      \
    1205             :   SC(sub_string_runtime, V8.SubStringRuntime)                                  \
    1206             :   SC(sub_string_native, V8.SubStringNative)                                    \
    1207             :   SC(string_compare_native, V8.StringCompareNative)                            \
    1208             :   SC(string_compare_runtime, V8.StringCompareRuntime)                          \
    1209             :   SC(regexp_entry_runtime, V8.RegExpEntryRuntime)                              \
    1210             :   SC(regexp_entry_native, V8.RegExpEntryNative)                                \
    1211             :   SC(number_to_string_native, V8.NumberToStringNative)                         \
    1212             :   SC(number_to_string_runtime, V8.NumberToStringRuntime)                       \
    1213             :   SC(math_exp_runtime, V8.MathExpRuntime)                                      \
    1214             :   SC(math_log_runtime, V8.MathLogRuntime)                                      \
    1215             :   SC(math_pow_runtime, V8.MathPowRuntime)                                      \
    1216             :   SC(stack_interrupts, V8.StackInterrupts)                                     \
    1217             :   SC(runtime_profiler_ticks, V8.RuntimeProfilerTicks)                          \
    1218             :   SC(runtime_calls, V8.RuntimeCalls)                                           \
    1219             :   SC(bounds_checks_eliminated, V8.BoundsChecksEliminated)                      \
    1220             :   SC(bounds_checks_hoisted, V8.BoundsChecksHoisted)                            \
    1221             :   SC(soft_deopts_requested, V8.SoftDeoptsRequested)                            \
    1222             :   SC(soft_deopts_inserted, V8.SoftDeoptsInserted)                              \
    1223             :   SC(soft_deopts_executed, V8.SoftDeoptsExecuted)                              \
    1224             :   /* Number of write barriers in generated code. */                            \
    1225             :   SC(write_barriers_dynamic, V8.WriteBarriersDynamic)                          \
    1226             :   SC(write_barriers_static, V8.WriteBarriersStatic)                            \
    1227             :   SC(new_space_bytes_available, V8.MemoryNewSpaceBytesAvailable)               \
    1228             :   SC(new_space_bytes_committed, V8.MemoryNewSpaceBytesCommitted)               \
    1229             :   SC(new_space_bytes_used, V8.MemoryNewSpaceBytesUsed)                         \
    1230             :   SC(old_space_bytes_available, V8.MemoryOldSpaceBytesAvailable)               \
    1231             :   SC(old_space_bytes_committed, V8.MemoryOldSpaceBytesCommitted)               \
    1232             :   SC(old_space_bytes_used, V8.MemoryOldSpaceBytesUsed)                         \
    1233             :   SC(code_space_bytes_available, V8.MemoryCodeSpaceBytesAvailable)             \
    1234             :   SC(code_space_bytes_committed, V8.MemoryCodeSpaceBytesCommitted)             \
    1235             :   SC(code_space_bytes_used, V8.MemoryCodeSpaceBytesUsed)                       \
    1236             :   SC(map_space_bytes_available, V8.MemoryMapSpaceBytesAvailable)               \
    1237             :   SC(map_space_bytes_committed, V8.MemoryMapSpaceBytesCommitted)               \
    1238             :   SC(map_space_bytes_used, V8.MemoryMapSpaceBytesUsed)                         \
    1239             :   SC(lo_space_bytes_available, V8.MemoryLoSpaceBytesAvailable)                 \
    1240             :   SC(lo_space_bytes_committed, V8.MemoryLoSpaceBytesCommitted)                 \
    1241             :   SC(lo_space_bytes_used, V8.MemoryLoSpaceBytesUsed)                           \
    1242             :   /* Total code size (including metadata) of baseline code or bytecode. */     \
    1243             :   SC(total_baseline_code_size, V8.TotalBaselineCodeSize)                       \
    1244             :   /* Total count of functions compiled using the baseline compiler. */         \
    1245             :   SC(total_baseline_compile_count, V8.TotalBaselineCompileCount)
    1246             : 
    1247             : #define STATS_COUNTER_TS_LIST(SC)                         \
    1248             :   SC(wasm_generated_code_size, V8.WasmGeneratedCodeBytes) \
    1249             :   SC(wasm_reloc_size, V8.WasmRelocBytes)                  \
    1250             :   SC(wasm_lazily_compiled_functions, V8.WasmLazilyCompiledFunctions)
    1251             : 
    1252             : // This file contains all the v8 counters that are in use.
    1253      106730 : class Counters : public std::enable_shared_from_this<Counters> {
    1254             :  public:
    1255             :   explicit Counters(Isolate* isolate);
    1256             : 
    1257             :   // Register an application-defined function for recording
    1258             :   // subsequent counter statistics. Note: Must be called on the main
    1259             :   // thread.
    1260             :   void ResetCounterFunction(CounterLookupCallback f);
    1261             : 
    1262             :   // Register an application-defined function to create histograms for
    1263             :   // recording subsequent histogram samples. Note: Must be called on
    1264             :   // the main thread.
    1265             :   void ResetCreateHistogramFunction(CreateHistogramCallback f);
    1266             : 
    1267             :   // Register an application-defined function to add a sample
    1268             :   // to a histogram. Will be used in all subsequent sample additions.
    1269             :   // Note: Must be called on the main thread.
    1270             :   void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
    1271             :     stats_table_.SetAddHistogramSampleFunction(f);
    1272             :   }
    1273             : 
    1274             : #define HR(name, caption, min, max, num_buckets) \
    1275             :   Histogram* name() { return &name##_; }
    1276             :   HISTOGRAM_RANGE_LIST(HR)
    1277             : #undef HR
    1278             : 
    1279             : #define HT(name, caption, max, res) \
    1280             :   HistogramTimer* name() { return &name##_; }
    1281             :   HISTOGRAM_TIMER_LIST(HT)
    1282             : #undef HT
    1283             : 
    1284             : #define HT(name, caption, max, res) \
    1285             :   TimedHistogram* name() { return &name##_; }
    1286             :   TIMED_HISTOGRAM_LIST(HT)
    1287             : #undef HT
    1288             : 
    1289             : #define AHT(name, caption) \
    1290             :   AggregatableHistogramTimer* name() { return &name##_; }
    1291             :   AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
    1292             : #undef AHT
    1293             : 
    1294             : #define HP(name, caption) \
    1295             :   Histogram* name() { return &name##_; }
    1296             :   HISTOGRAM_PERCENTAGE_LIST(HP)
    1297             : #undef HP
    1298             : 
    1299             : #define HM(name, caption) \
    1300             :   Histogram* name() { return &name##_; }
    1301             :   HISTOGRAM_LEGACY_MEMORY_LIST(HM)
    1302             :   HISTOGRAM_MEMORY_LIST(HM)
    1303             : #undef HM
    1304             : 
    1305             : #define HM(name, caption)                                     \
    1306             :   AggregatedMemoryHistogram<Histogram>* aggregated_##name() { \
    1307             :     return &aggregated_##name##_;                             \
    1308             :   }
    1309             :   HISTOGRAM_MEMORY_LIST(HM)
    1310             : #undef HM
    1311             : 
    1312             : #define SC(name, caption) \
    1313             :   StatsCounter* name() { return &name##_; }
    1314             :   STATS_COUNTER_LIST_1(SC)
    1315     8065487 :   STATS_COUNTER_LIST_2(SC)
    1316             : #undef SC
    1317             : 
    1318             : #define SC(name, caption) \
    1319             :   StatsCounterThreadSafe* name() { return &name##_; }
    1320             :   STATS_COUNTER_TS_LIST(SC)
    1321             : #undef SC
    1322             : 
    1323             : #define SC(name) \
    1324             :   StatsCounter* count_of_##name() { return &count_of_##name##_; } \
    1325             :   StatsCounter* size_of_##name() { return &size_of_##name##_; }
    1326             :   INSTANCE_TYPE_LIST(SC)
    1327             : #undef SC
    1328             : 
    1329             : #define SC(name) \
    1330             :   StatsCounter* count_of_CODE_TYPE_##name() \
    1331             :     { return &count_of_CODE_TYPE_##name##_; } \
    1332             :   StatsCounter* size_of_CODE_TYPE_##name() \
    1333             :     { return &size_of_CODE_TYPE_##name##_; }
    1334             :   CODE_KIND_LIST(SC)
    1335             : #undef SC
    1336             : 
    1337             : #define SC(name) \
    1338             :   StatsCounter* count_of_FIXED_ARRAY_##name() \
    1339             :     { return &count_of_FIXED_ARRAY_##name##_; } \
    1340             :   StatsCounter* size_of_FIXED_ARRAY_##name() \
    1341             :     { return &size_of_FIXED_ARRAY_##name##_; }
    1342             :   FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
    1343             : #undef SC
    1344             : 
    1345             :   // clang-format off
    1346             :   enum Id {
    1347             : #define RATE_ID(name, caption, max, res) k_##name,
    1348             :     HISTOGRAM_TIMER_LIST(RATE_ID)
    1349             :     TIMED_HISTOGRAM_LIST(RATE_ID)
    1350             : #undef RATE_ID
    1351             : #define AGGREGATABLE_ID(name, caption) k_##name,
    1352             :     AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
    1353             : #undef AGGREGATABLE_ID
    1354             : #define PERCENTAGE_ID(name, caption) k_##name,
    1355             :     HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
    1356             : #undef PERCENTAGE_ID
    1357             : #define MEMORY_ID(name, caption) k_##name,
    1358             :     HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID)
    1359             :     HISTOGRAM_MEMORY_LIST(MEMORY_ID)
    1360             : #undef MEMORY_ID
    1361             : #define COUNTER_ID(name, caption) k_##name,
    1362             :     STATS_COUNTER_LIST_1(COUNTER_ID)
    1363             :     STATS_COUNTER_LIST_2(COUNTER_ID)
    1364             :     STATS_COUNTER_TS_LIST(COUNTER_ID)
    1365             : #undef COUNTER_ID
    1366             : #define COUNTER_ID(name) kCountOf##name, kSizeOf##name,
    1367             :     INSTANCE_TYPE_LIST(COUNTER_ID)
    1368             : #undef COUNTER_ID
    1369             : #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \
    1370             :     kSizeOfCODE_TYPE_##name,
    1371             :     CODE_KIND_LIST(COUNTER_ID)
    1372             : #undef COUNTER_ID
    1373             : #define COUNTER_ID(name) kCountOfFIXED_ARRAY__##name, \
    1374             :     kSizeOfFIXED_ARRAY__##name,
    1375             :     FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COUNTER_ID)
    1376             : #undef COUNTER_ID
    1377             :     stats_counter_count
    1378             :   };
    1379             :   // clang-format on
    1380             : 
    1381           0 :   RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; }
    1382             : 
    1383             :  private:
    1384             :   friend class StatsTable;
    1385             :   friend class StatsCounterBase;
    1386             :   friend class Histogram;
    1387             :   friend class HistogramTimer;
    1388             : 
    1389             :   Isolate* isolate_;
    1390             :   StatsTable stats_table_;
    1391             : 
    1392             :   int* FindLocation(const char* name) {
    1393     1155978 :     return stats_table_.FindLocation(name);
    1394             :   }
    1395             : 
    1396             :   void* CreateHistogram(const char* name, int min, int max, size_t buckets) {
    1397         350 :     return stats_table_.CreateHistogram(name, min, max, buckets);
    1398             :   }
    1399             : 
    1400             :   void AddHistogramSample(void* histogram, int sample) {
    1401           0 :     stats_table_.AddHistogramSample(histogram, sample);
    1402             :   }
    1403             : 
    1404             :   Isolate* isolate() { return isolate_; }
    1405             : 
    1406             : #define HR(name, caption, min, max, num_buckets) Histogram name##_;
    1407             :   HISTOGRAM_RANGE_LIST(HR)
    1408             : #undef HR
    1409             : 
    1410             : #define HT(name, caption, max, res) HistogramTimer name##_;
    1411             :   HISTOGRAM_TIMER_LIST(HT)
    1412             : #undef HT
    1413             : 
    1414             : #define HT(name, caption, max, res) TimedHistogram name##_;
    1415             :   TIMED_HISTOGRAM_LIST(HT)
    1416             : #undef HT
    1417             : 
    1418             : #define AHT(name, caption) \
    1419             :   AggregatableHistogramTimer name##_;
    1420             :   AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
    1421             : #undef AHT
    1422             : 
    1423             : #define HP(name, caption) \
    1424             :   Histogram name##_;
    1425             :   HISTOGRAM_PERCENTAGE_LIST(HP)
    1426             : #undef HP
    1427             : 
    1428             : #define HM(name, caption) \
    1429             :   Histogram name##_;
    1430             :   HISTOGRAM_LEGACY_MEMORY_LIST(HM)
    1431             :   HISTOGRAM_MEMORY_LIST(HM)
    1432             : #undef HM
    1433             : 
    1434             : #define HM(name, caption) \
    1435             :   AggregatedMemoryHistogram<Histogram> aggregated_##name##_;
    1436             :   HISTOGRAM_MEMORY_LIST(HM)
    1437             : #undef HM
    1438             : 
    1439             : #define SC(name, caption) \
    1440             :   StatsCounter name##_;
    1441             :   STATS_COUNTER_LIST_1(SC)
    1442             :   STATS_COUNTER_LIST_2(SC)
    1443             : #undef SC
    1444             : 
    1445             : #define SC(name, caption) StatsCounterThreadSafe name##_;
    1446             :   STATS_COUNTER_TS_LIST(SC)
    1447             : #undef SC
    1448             : 
    1449             : #define SC(name) \
    1450             :   StatsCounter size_of_##name##_; \
    1451             :   StatsCounter count_of_##name##_;
    1452             :   INSTANCE_TYPE_LIST(SC)
    1453             : #undef SC
    1454             : 
    1455             : #define SC(name) \
    1456             :   StatsCounter size_of_CODE_TYPE_##name##_; \
    1457             :   StatsCounter count_of_CODE_TYPE_##name##_;
    1458             :   CODE_KIND_LIST(SC)
    1459             : #undef SC
    1460             : 
    1461             : #define SC(name) \
    1462             :   StatsCounter size_of_FIXED_ARRAY_##name##_; \
    1463             :   StatsCounter count_of_FIXED_ARRAY_##name##_;
    1464             :   FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
    1465             : #undef SC
    1466             : 
    1467             :   RuntimeCallStats runtime_call_stats_;
    1468             : 
    1469             :   DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
    1470             : };
    1471             : 
    1472             : void HistogramTimer::Start() {
    1473     2030746 :   TimedHistogram::Start(&timer_, counters()->isolate());
    1474             : }
    1475             : 
    1476             : void HistogramTimer::Stop() {
    1477     2030751 :   TimedHistogram::Stop(&timer_, counters()->isolate());
    1478             : }
    1479             : 
    1480   303835518 : RuntimeCallTimerScope::RuntimeCallTimerScope(
    1481   303835518 :     Isolate* isolate, RuntimeCallStats::CounterId counter_id) {
    1482   607671036 :   if (V8_LIKELY(!FLAG_runtime_stats)) return;
    1483           0 :   stats_ = isolate->counters()->runtime_call_stats();
    1484           0 :   RuntimeCallStats::Enter(stats_, &timer_, counter_id);
    1485             : }
    1486             : 
    1487             : }  // namespace internal
    1488             : }  // namespace v8
    1489             : 
    1490             : #endif  // V8_COUNTERS_H_

Generated by: LCOV version 1.10