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_LOGGING_COUNTERS_H_
6 #define V8_LOGGING_COUNTERS_H_
7
8 #include <memory>
9
10 #include "include/v8-callbacks.h"
11 #include "src/base/atomic-utils.h"
12 #include "src/base/optional.h"
13 #include "src/base/platform/elapsed-timer.h"
14 #include "src/base/platform/time.h"
15 #include "src/common/globals.h"
16 #include "src/logging/counters-definitions.h"
17 #include "src/logging/runtime-call-stats.h"
18 #include "src/objects/code-kind.h"
19 #include "src/objects/fixed-array.h"
20 #include "src/objects/objects.h"
21 #include "src/utils/allocation.h"
22
23 namespace v8 {
24 namespace internal {
25
26 // StatsCounters is an interface for plugging into external
27 // counters for monitoring. Counters can be looked up and
28 // manipulated by name.
29
30 class Counters;
31 class Isolate;
32
33 class StatsTable {
34 public:
35 StatsTable(const StatsTable&) = delete;
36 StatsTable& operator=(const StatsTable&) = delete;
37
38 // Register an application-defined function for recording
39 // subsequent counter statistics.
40 void SetCounterFunction(CounterLookupCallback f);
41
42 // Register an application-defined function to create histograms for
43 // recording subsequent histogram samples.
SetCreateHistogramFunction(CreateHistogramCallback f)44 void SetCreateHistogramFunction(CreateHistogramCallback f) {
45 create_histogram_function_ = f;
46 }
47
48 // Register an application-defined function to add a sample
49 // to a histogram created with CreateHistogram function.
SetAddHistogramSampleFunction(AddHistogramSampleCallback f)50 void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
51 add_histogram_sample_function_ = f;
52 }
53
HasCounterFunction()54 bool HasCounterFunction() const { return lookup_function_ != nullptr; }
55
56 // Lookup the location of a counter by name. If the lookup
57 // is successful, returns a non-nullptr pointer for writing the
58 // value of the counter. Each thread calling this function
59 // may receive a different location to store it's counter.
60 // The return value must not be cached and re-used across
61 // threads, although a single thread is free to cache it.
FindLocation(const char * name)62 int* FindLocation(const char* name) {
63 if (!lookup_function_) return nullptr;
64 return lookup_function_(name);
65 }
66
67 // Create a histogram by name. If the create is successful,
68 // returns a non-nullptr pointer for use with AddHistogramSample
69 // function. min and max define the expected minimum and maximum
70 // sample values. buckets is the maximum number of buckets
71 // that the samples will be grouped into.
CreateHistogram(const char * name,int min,int max,size_t buckets)72 void* CreateHistogram(const char* name, int min, int max, size_t buckets) {
73 if (!create_histogram_function_) return nullptr;
74 return create_histogram_function_(name, min, max, buckets);
75 }
76
77 // Add a sample to a histogram created with the CreateHistogram
78 // function.
AddHistogramSample(void * histogram,int sample)79 void AddHistogramSample(void* histogram, int sample) {
80 if (!add_histogram_sample_function_) return;
81 return add_histogram_sample_function_(histogram, sample);
82 }
83
84 private:
85 friend class Counters;
86
87 explicit StatsTable(Counters* counters);
88
89 CounterLookupCallback lookup_function_;
90 CreateHistogramCallback create_histogram_function_;
91 AddHistogramSampleCallback add_histogram_sample_function_;
92 };
93
94 // StatsCounters are dynamically created values which can be tracked in the
95 // StatsTable. They are designed to be lightweight to create and easy to use.
96 //
97 // Internally, a counter represents a value in a row of a StatsTable.
98 // The row has a 32bit value for each process/thread in the table and also
99 // a name (stored in the table metadata). Since the storage location can be
100 // thread-specific, this class cannot be shared across threads.
101 // This class is thread-safe.
102 class StatsCounter {
103 public:
Set(int value)104 void Set(int value) { GetPtr()->store(value, std::memory_order_relaxed); }
105
106 void Increment(int value = 1) {
107 GetPtr()->fetch_add(value, std::memory_order_relaxed);
108 }
109
110 void Decrement(int value = 1) {
111 GetPtr()->fetch_sub(value, std::memory_order_relaxed);
112 }
113
114 // Returns true if this counter is enabled (a lookup function was provided and
115 // it returned a non-null pointer).
116 V8_EXPORT_PRIVATE bool Enabled();
117
118 // Get the internal pointer to the counter. This is used
119 // by the code generator to emit code that manipulates a
120 // given counter without calling the runtime system.
GetInternalPointer()121 std::atomic<int>* GetInternalPointer() { return GetPtr(); }
122
123 private:
124 friend class Counters;
125
Init(Counters * counters,const char * name)126 void Init(Counters* counters, const char* name) {
127 DCHECK_NULL(counters_);
128 DCHECK_NOT_NULL(counters);
129 // Counter names always start with "c:V8.".
130 DCHECK_EQ(0, memcmp(name, "c:V8.", 5));
131 counters_ = counters;
132 name_ = name;
133 }
134
135 V8_NOINLINE V8_EXPORT_PRIVATE std::atomic<int>* SetupPtrFromStatsTable();
136
137 // Reset the cached internal pointer.
Reset()138 void Reset() { ptr_.store(nullptr, std::memory_order_relaxed); }
139
140 // Returns the cached address of this counter location.
GetPtr()141 std::atomic<int>* GetPtr() {
142 auto* ptr = ptr_.load(std::memory_order_acquire);
143 if (V8_LIKELY(ptr)) return ptr;
144 return SetupPtrFromStatsTable();
145 }
146
147 Counters* counters_ = nullptr;
148 const char* name_ = nullptr;
149 // A pointer to an atomic, set atomically in {GetPtr}.
150 std::atomic<std::atomic<int>*> ptr_{nullptr};
151 };
152
153 // A Histogram represents a dynamically created histogram in the
154 // StatsTable. Note: This class is thread safe.
155 class Histogram {
156 public:
157 // Add a single sample to this histogram.
158 void AddSample(int sample);
159
160 // Returns true if this histogram is enabled.
Enabled()161 bool Enabled() { return histogram_ != nullptr; }
162
name()163 const char* name() const { return name_; }
164
min()165 int min() const { return min_; }
max()166 int max() const { return max_; }
num_buckets()167 int num_buckets() const { return num_buckets_; }
168
169 // Asserts that |expected_counters| are the same as the Counters this
170 // Histogram reports to.
AssertReportsToCounters(Counters * expected_counters)171 void AssertReportsToCounters(Counters* expected_counters) {
172 DCHECK_EQ(counters_, expected_counters);
173 }
174
175 protected:
176 Histogram() = default;
177 Histogram(const Histogram&) = delete;
178 Histogram& operator=(const Histogram&) = delete;
179
Initialize(const char * name,int min,int max,int num_buckets,Counters * counters)180 void Initialize(const char* name, int min, int max, int num_buckets,
181 Counters* counters) {
182 name_ = name;
183 min_ = min;
184 max_ = max;
185 num_buckets_ = num_buckets;
186 histogram_ = nullptr;
187 counters_ = counters;
188 DCHECK_NOT_NULL(counters_);
189 }
190
counters()191 Counters* counters() const { return counters_; }
192
193 // Reset the cached internal pointer to nullptr; the histogram will be
194 // created lazily, the first time it is needed.
Reset()195 void Reset() { histogram_ = nullptr; }
196
197 // Lazily create the histogram, if it has not been created yet.
198 void EnsureCreated(bool create_new = true) {
199 if (create_new && histogram_.load(std::memory_order_acquire) == nullptr) {
200 base::MutexGuard Guard(&mutex_);
201 if (histogram_.load(std::memory_order_relaxed) == nullptr)
202 histogram_.store(CreateHistogram(), std::memory_order_release);
203 }
204 }
205
206 private:
207 friend class Counters;
208
209 V8_EXPORT_PRIVATE void* CreateHistogram() const;
210
211 const char* name_;
212 int min_;
213 int max_;
214 int num_buckets_;
215 std::atomic<void*> histogram_;
216 Counters* counters_;
217 base::Mutex mutex_;
218 };
219
220 enum class TimedHistogramResolution { MILLISECOND, MICROSECOND };
221
222 // A thread safe histogram timer. It also allows distributions of
223 // nested timed results.
224 class TimedHistogram : public Histogram {
225 public:
226 // Records a TimeDelta::Max() result. Useful to record percentage of tasks
227 // that never got to run in a given scenario. Log if isolate non-null.
228 void RecordAbandon(base::ElapsedTimer* timer, Isolate* isolate);
229
230 // Add a single sample to this histogram.
231 V8_EXPORT_PRIVATE void AddTimedSample(base::TimeDelta sample);
232
233 #ifdef DEBUG
234 // Ensures that we don't have nested timers for TimedHistogram per thread, use
235 // NestedTimedHistogram which correctly pause and resume timers.
236 // This method assumes that each timer is alternating between stopped and
237 // started on a single thread. Multiple timers can be active on different
238 // threads.
239 bool ToggleRunningState(bool expected_is_running) const;
240 #endif // DEBUG
241
242 protected:
243 void Stop(base::ElapsedTimer* timer);
244 void LogStart(Isolate* isolate);
245 void LogEnd(Isolate* isolate);
246
247 friend class Counters;
248 TimedHistogramResolution resolution_;
249
250 TimedHistogram() = default;
251 TimedHistogram(const TimedHistogram&) = delete;
252 TimedHistogram& operator=(const TimedHistogram&) = delete;
253
Initialize(const char * name,int min,int max,TimedHistogramResolution resolution,int num_buckets,Counters * counters)254 void Initialize(const char* name, int min, int max,
255 TimedHistogramResolution resolution, int num_buckets,
256 Counters* counters) {
257 Histogram::Initialize(name, min, max, num_buckets, counters);
258 resolution_ = resolution;
259 }
260 };
261
262 class NestedTimedHistogramScope;
263 class PauseNestedTimedHistogramScope;
264
265 // A NestedTimedHistogram allows distributions of nested timed results.
266 class NestedTimedHistogram : public TimedHistogram {
267 public:
268 // Note: public for testing purposes only.
NestedTimedHistogram(const char * name,int min,int max,TimedHistogramResolution resolution,int num_buckets,Counters * counters)269 NestedTimedHistogram(const char* name, int min, int max,
270 TimedHistogramResolution resolution, int num_buckets,
271 Counters* counters)
272 : NestedTimedHistogram() {
273 Initialize(name, min, max, resolution, num_buckets, counters);
274 }
275
276 private:
277 friend class Counters;
278 friend class NestedTimedHistogramScope;
279 friend class PauseNestedTimedHistogramScope;
280
Enter(NestedTimedHistogramScope * next)281 inline NestedTimedHistogramScope* Enter(NestedTimedHistogramScope* next) {
282 NestedTimedHistogramScope* previous = current_;
283 current_ = next;
284 return previous;
285 }
286
Leave(NestedTimedHistogramScope * previous)287 inline void Leave(NestedTimedHistogramScope* previous) {
288 current_ = previous;
289 }
290
291 NestedTimedHistogramScope* current_ = nullptr;
292
293 NestedTimedHistogram() = default;
294 NestedTimedHistogram(const NestedTimedHistogram&) = delete;
295 NestedTimedHistogram& operator=(const NestedTimedHistogram&) = delete;
296 };
297
298 // A histogram timer that can aggregate events within a larger scope.
299 //
300 // Intended use of this timer is to have an outer (aggregating) and an inner
301 // (to be aggregated) scope, where the inner scope measure the time of events,
302 // and all those inner scope measurements will be summed up by the outer scope.
303 // An example use might be to aggregate the time spent in lazy compilation
304 // while running a script.
305 //
306 // Helpers:
307 // - AggregatingHistogramTimerScope, the "outer" scope within which
308 // times will be summed up.
309 // - AggregatedHistogramTimerScope, the "inner" scope which defines the
310 // events to be timed.
311 class AggregatableHistogramTimer : public Histogram {
312 public:
313 // Start/stop the "outer" scope.
Start()314 void Start() { time_ = base::TimeDelta(); }
Stop()315 void Stop() {
316 if (time_ != base::TimeDelta()) {
317 // Only add non-zero samples, since zero samples represent situations
318 // where there were no aggregated samples added.
319 AddSample(static_cast<int>(time_.InMicroseconds()));
320 }
321 }
322
323 // Add a time value ("inner" scope).
Add(base::TimeDelta other)324 void Add(base::TimeDelta other) { time_ += other; }
325
326 private:
327 friend class Counters;
328
329 AggregatableHistogramTimer() = default;
330 AggregatableHistogramTimer(const AggregatableHistogramTimer&) = delete;
331 AggregatableHistogramTimer& operator=(const AggregatableHistogramTimer&) =
332 delete;
333
334 base::TimeDelta time_;
335 };
336
337 // A helper class for use with AggregatableHistogramTimer. This is the
338 // // outer-most timer scope used with an AggregatableHistogramTimer. It will
339 // // aggregate the information from the inner AggregatedHistogramTimerScope.
340 class V8_NODISCARD AggregatingHistogramTimerScope {
341 public:
AggregatingHistogramTimerScope(AggregatableHistogramTimer * histogram)342 explicit AggregatingHistogramTimerScope(AggregatableHistogramTimer* histogram)
343 : histogram_(histogram) {
344 histogram_->Start();
345 }
~AggregatingHistogramTimerScope()346 ~AggregatingHistogramTimerScope() { histogram_->Stop(); }
347
348 private:
349 AggregatableHistogramTimer* histogram_;
350 };
351
352 // A helper class for use with AggregatableHistogramTimer, the "inner" scope
353 // // which defines the events to be timed.
354 class V8_NODISCARD AggregatedHistogramTimerScope {
355 public:
AggregatedHistogramTimerScope(AggregatableHistogramTimer * histogram)356 explicit AggregatedHistogramTimerScope(AggregatableHistogramTimer* histogram)
357 : histogram_(histogram) {
358 timer_.Start();
359 }
~AggregatedHistogramTimerScope()360 ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); }
361
362 private:
363 base::ElapsedTimer timer_;
364 AggregatableHistogramTimer* histogram_;
365 };
366
367 // AggretatedMemoryHistogram collects (time, value) sample pairs and turns
368 // them into time-uniform samples for the backing historgram, such that the
369 // backing histogram receives one sample every T ms, where the T is controlled
370 // by the FLAG_histogram_interval.
371 //
372 // More formally: let F be a real-valued function that maps time to sample
373 // values. We define F as a linear interpolation between adjacent samples. For
374 // each time interval [x; x + T) the backing histogram gets one sample value
375 // that is the average of F(t) in the interval.
376 template <typename Histogram>
377 class AggregatedMemoryHistogram {
378 public:
379 // Note: public for testing purposes only.
AggregatedMemoryHistogram(Histogram * backing_histogram)380 explicit AggregatedMemoryHistogram(Histogram* backing_histogram)
381 : AggregatedMemoryHistogram() {
382 backing_histogram_ = backing_histogram;
383 }
384
385 // Invariants that hold before and after AddSample if
386 // is_initialized_ is true:
387 //
388 // 1) For we processed samples that came in before start_ms_ and sent the
389 // corresponding aggregated samples to backing histogram.
390 // 2) (last_ms_, last_value_) is the last received sample.
391 // 3) last_ms_ < start_ms_ + FLAG_histogram_interval.
392 // 4) aggregate_value_ is the average of the function that is constructed by
393 // linearly interpolating samples received between start_ms_ and last_ms_.
394 void AddSample(double current_ms, double current_value);
395
396 private:
397 friend class Counters;
398
AggregatedMemoryHistogram()399 AggregatedMemoryHistogram()
400 : is_initialized_(false),
401 start_ms_(0.0),
402 last_ms_(0.0),
403 aggregate_value_(0.0),
404 last_value_(0.0),
405 backing_histogram_(nullptr) {}
406 double Aggregate(double current_ms, double current_value);
407
408 bool is_initialized_;
409 double start_ms_;
410 double last_ms_;
411 double aggregate_value_;
412 double last_value_;
413 Histogram* backing_histogram_;
414 };
415
416 template <typename Histogram>
AddSample(double current_ms,double current_value)417 void AggregatedMemoryHistogram<Histogram>::AddSample(double current_ms,
418 double current_value) {
419 if (!is_initialized_) {
420 aggregate_value_ = current_value;
421 start_ms_ = current_ms;
422 last_value_ = current_value;
423 last_ms_ = current_ms;
424 is_initialized_ = true;
425 } else {
426 const double kEpsilon = 1e-6;
427 const int kMaxSamples = 1000;
428 if (current_ms < last_ms_ + kEpsilon) {
429 // Two samples have the same time, remember the last one.
430 last_value_ = current_value;
431 } else {
432 double sample_interval_ms = FLAG_histogram_interval;
433 double end_ms = start_ms_ + sample_interval_ms;
434 if (end_ms <= current_ms + kEpsilon) {
435 // Linearly interpolate between the last_ms_ and the current_ms.
436 double slope = (current_value - last_value_) / (current_ms - last_ms_);
437 int i;
438 // Send aggregated samples to the backing histogram from the start_ms
439 // to the current_ms.
440 for (i = 0; i < kMaxSamples && end_ms <= current_ms + kEpsilon; i++) {
441 double end_value = last_value_ + (end_ms - last_ms_) * slope;
442 double sample_value;
443 if (i == 0) {
444 // Take aggregate_value_ into account.
445 sample_value = Aggregate(end_ms, end_value);
446 } else {
447 // There is no aggregate_value_ for i > 0.
448 sample_value = (last_value_ + end_value) / 2;
449 }
450 backing_histogram_->AddSample(static_cast<int>(sample_value + 0.5));
451 last_value_ = end_value;
452 last_ms_ = end_ms;
453 end_ms += sample_interval_ms;
454 }
455 if (i == kMaxSamples) {
456 // We hit the sample limit, ignore the remaining samples.
457 aggregate_value_ = current_value;
458 start_ms_ = current_ms;
459 } else {
460 aggregate_value_ = last_value_;
461 start_ms_ = last_ms_;
462 }
463 }
464 aggregate_value_ = current_ms > start_ms_ + kEpsilon
465 ? Aggregate(current_ms, current_value)
466 : aggregate_value_;
467 last_value_ = current_value;
468 last_ms_ = current_ms;
469 }
470 }
471 }
472
473 template <typename Histogram>
Aggregate(double current_ms,double current_value)474 double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
475 double current_value) {
476 double interval_ms = current_ms - start_ms_;
477 double value = (current_value + last_value_) / 2;
478 // The aggregate_value_ is the average for [start_ms_; last_ms_].
479 // The value is the average for [last_ms_; current_ms].
480 // Return the weighted average of the aggregate_value_ and the value.
481 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) +
482 value * ((current_ms - last_ms_) / interval_ms);
483 }
484
485 // This file contains all the v8 counters that are in use.
486 class Counters : public std::enable_shared_from_this<Counters> {
487 public:
488 explicit Counters(Isolate* isolate);
489
490 // Register an application-defined function for recording
491 // subsequent counter statistics. Note: Must be called on the main
492 // thread.
493 void ResetCounterFunction(CounterLookupCallback f);
494
495 // Register an application-defined function to create histograms for
496 // recording subsequent histogram samples. Note: Must be called on
497 // the main thread.
498 void ResetCreateHistogramFunction(CreateHistogramCallback f);
499
500 // Register an application-defined function to add a sample
501 // to a histogram. Will be used in all subsequent sample additions.
502 // Note: Must be called on the main thread.
SetAddHistogramSampleFunction(AddHistogramSampleCallback f)503 void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
504 stats_table_.SetAddHistogramSampleFunction(f);
505 }
506
507 #define HR(name, caption, min, max, num_buckets) \
508 Histogram* name() { \
509 name##_.EnsureCreated(); \
510 return &name##_; \
511 }
512 HISTOGRAM_RANGE_LIST(HR)
513 #undef HR
514
515 #define HT(name, caption, max, res) \
516 NestedTimedHistogram* name() { \
517 name##_.EnsureCreated(); \
518 return &name##_; \
519 }
520 NESTED_TIMED_HISTOGRAM_LIST(HT)
521 #undef HT
522
523 #define HT(name, caption, max, res) \
524 NestedTimedHistogram* name() { \
525 name##_.EnsureCreated(FLAG_slow_histograms); \
526 return &name##_; \
527 }
528 NESTED_TIMED_HISTOGRAM_LIST_SLOW(HT)
529 #undef HT
530
531 #define HT(name, caption, max, res) \
532 TimedHistogram* name() { \
533 name##_.EnsureCreated(); \
534 return &name##_; \
535 }
536 TIMED_HISTOGRAM_LIST(HT)
537 #undef HT
538
539 #define AHT(name, caption) \
540 AggregatableHistogramTimer* name() { \
541 name##_.EnsureCreated(); \
542 return &name##_; \
543 }
544 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
545 #undef AHT
546
547 #define HP(name, caption) \
548 Histogram* name() { \
549 name##_.EnsureCreated(); \
550 return &name##_; \
551 }
552 HISTOGRAM_PERCENTAGE_LIST(HP)
553 #undef HP
554
555 #define HM(name, caption) \
556 Histogram* name() { \
557 name##_.EnsureCreated(); \
558 return &name##_; \
559 }
560 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
561 #undef HM
562
563 #define SC(name, caption) \
564 StatsCounter* name() { return &name##_; }
565 STATS_COUNTER_LIST_1(SC)
566 STATS_COUNTER_LIST_2(SC)
567 STATS_COUNTER_NATIVE_CODE_LIST(SC)
568 #undef SC
569
570 // clang-format off
571 enum Id {
572 #define RATE_ID(name, caption, max, res) k_##name,
573 NESTED_TIMED_HISTOGRAM_LIST(RATE_ID)
574 NESTED_TIMED_HISTOGRAM_LIST_SLOW(RATE_ID)
575 TIMED_HISTOGRAM_LIST(RATE_ID)
576 #undef RATE_ID
577 #define AGGREGATABLE_ID(name, caption) k_##name,
578 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
579 #undef AGGREGATABLE_ID
580 #define PERCENTAGE_ID(name, caption) k_##name,
581 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
582 #undef PERCENTAGE_ID
583 #define MEMORY_ID(name, caption) k_##name,
584 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID)
585 #undef MEMORY_ID
586 #define COUNTER_ID(name, caption) k_##name,
587 STATS_COUNTER_LIST_1(COUNTER_ID)
588 STATS_COUNTER_LIST_2(COUNTER_ID)
589 STATS_COUNTER_NATIVE_CODE_LIST(COUNTER_ID)
590 #undef COUNTER_ID
591 #define COUNTER_ID(name) kCountOf##name, kSizeOf##name,
592 INSTANCE_TYPE_LIST(COUNTER_ID)
593 #undef COUNTER_ID
594 #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \
595 kSizeOfCODE_TYPE_##name,
596 CODE_KIND_LIST(COUNTER_ID)
597 #undef COUNTER_ID
598 #define COUNTER_ID(name) kCountOfFIXED_ARRAY__##name, \
599 kSizeOfFIXED_ARRAY__##name,
600 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COUNTER_ID)
601 #undef COUNTER_ID
602 stats_counter_count
603 };
604 // clang-format on
605
606 #ifdef V8_RUNTIME_CALL_STATS
runtime_call_stats()607 RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; }
608
worker_thread_runtime_call_stats()609 WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats() {
610 return &worker_thread_runtime_call_stats_;
611 }
612 #else // V8_RUNTIME_CALL_STATS
runtime_call_stats()613 RuntimeCallStats* runtime_call_stats() { return nullptr; }
614
worker_thread_runtime_call_stats()615 WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats() {
616 return nullptr;
617 }
618 #endif // V8_RUNTIME_CALL_STATS
619
620 private:
621 friend class StatsTable;
622 friend class StatsCounter;
623 friend class Histogram;
624 friend class NestedTimedHistogramScope;
625
FindLocation(const char * name)626 int* FindLocation(const char* name) {
627 return stats_table_.FindLocation(name);
628 }
629
CreateHistogram(const char * name,int min,int max,size_t buckets)630 void* CreateHistogram(const char* name, int min, int max, size_t buckets) {
631 return stats_table_.CreateHistogram(name, min, max, buckets);
632 }
633
AddHistogramSample(void * histogram,int sample)634 void AddHistogramSample(void* histogram, int sample) {
635 stats_table_.AddHistogramSample(histogram, sample);
636 }
637
isolate()638 Isolate* isolate() { return isolate_; }
639
640 #define HR(name, caption, min, max, num_buckets) Histogram name##_;
641 HISTOGRAM_RANGE_LIST(HR)
642 #undef HR
643
644 #define HT(name, caption, max, res) NestedTimedHistogram name##_;
645 NESTED_TIMED_HISTOGRAM_LIST(HT)
646 NESTED_TIMED_HISTOGRAM_LIST_SLOW(HT)
647 #undef HT
648
649 #define HT(name, caption, max, res) TimedHistogram name##_;
650 TIMED_HISTOGRAM_LIST(HT)
651 #undef HT
652
653 #define AHT(name, caption) AggregatableHistogramTimer name##_;
654 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
655 #undef AHT
656
657 #define HP(name, caption) Histogram name##_;
658 HISTOGRAM_PERCENTAGE_LIST(HP)
659 #undef HP
660
661 #define HM(name, caption) Histogram name##_;
662 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
663 #undef HM
664
665 #define SC(name, caption) StatsCounter name##_;
666 STATS_COUNTER_LIST_1(SC)
667 STATS_COUNTER_LIST_2(SC)
668 STATS_COUNTER_NATIVE_CODE_LIST(SC)
669 #undef SC
670
671 #define SC(name) \
672 StatsCounter size_of_##name##_; \
673 StatsCounter count_of_##name##_;
674 INSTANCE_TYPE_LIST(SC)
675 #undef SC
676
677 #define SC(name) \
678 StatsCounter size_of_CODE_TYPE_##name##_; \
679 StatsCounter count_of_CODE_TYPE_##name##_;
680 CODE_KIND_LIST(SC)
681 #undef SC
682
683 #define SC(name) \
684 StatsCounter size_of_FIXED_ARRAY_##name##_; \
685 StatsCounter count_of_FIXED_ARRAY_##name##_;
686 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
687 #undef SC
688
689 #ifdef V8_RUNTIME_CALL_STATS
690 RuntimeCallStats runtime_call_stats_;
691 WorkerThreadRuntimeCallStats worker_thread_runtime_call_stats_;
692 #endif
693 Isolate* isolate_;
694 StatsTable stats_table_;
695
696 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
697 };
698
699
700 } // namespace internal
701 } // namespace v8
702
703 #endif // V8_LOGGING_COUNTERS_H_
704