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.
8 #include "include/v8.h"
9 #include "src/allocation.h"
10 #include "src/base/platform/elapsed-timer.h"
11 #include "src/base/platform/time.h"
12 #include "src/globals.h"
13 #include "src/objects.h"
18 // StatsCounters is an interface for plugging into external
19 // counters for monitoring. Counters can be looked up and
20 // manipulated by name.
24 // Register an application-defined function where
25 // counters can be looked up.
26 void SetCounterFunction(CounterLookupCallback f) {
30 // Register an application-defined function to create
31 // a histogram for passing to the AddHistogramSample function
32 void SetCreateHistogramFunction(CreateHistogramCallback f) {
33 create_histogram_function_ = f;
36 // Register an application-defined function to add a sample
37 // to a histogram created with CreateHistogram function
38 void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
39 add_histogram_sample_function_ = f;
42 bool HasCounterFunction() const {
43 return lookup_function_ != NULL;
46 // Lookup the location of a counter by name. If the lookup
47 // is successful, returns a non-NULL pointer for writing the
48 // value of the counter. Each thread calling this function
49 // may receive a different location to store it's counter.
50 // The return value must not be cached and re-used across
51 // threads, although a single thread is free to cache it.
52 int* FindLocation(const char* name) {
53 if (!lookup_function_) return NULL;
54 return lookup_function_(name);
57 // Create a histogram by name. If the create is successful,
58 // returns a non-NULL pointer for use with AddHistogramSample
59 // function. min and max define the expected minimum and maximum
60 // sample values. buckets is the maximum number of buckets
61 // that the samples will be grouped into.
62 void* CreateHistogram(const char* name,
66 if (!create_histogram_function_) return NULL;
67 return create_histogram_function_(name, min, max, buckets);
70 // Add a sample to a histogram created with the CreateHistogram
72 void AddHistogramSample(void* histogram, int sample) {
73 if (!add_histogram_sample_function_) return;
74 return add_histogram_sample_function_(histogram, sample);
80 CounterLookupCallback lookup_function_;
81 CreateHistogramCallback create_histogram_function_;
82 AddHistogramSampleCallback add_histogram_sample_function_;
86 DISALLOW_COPY_AND_ASSIGN(StatsTable);
89 // StatsCounters are dynamically created values which can be tracked in
90 // the StatsTable. They are designed to be lightweight to create and
93 // Internally, a counter represents a value in a row of a StatsTable.
94 // The row has a 32bit value for each process/thread in the table and also
95 // a name (stored in the table metadata). Since the storage location can be
96 // thread-specific, this class cannot be shared across threads.
100 explicit StatsCounter(Isolate* isolate, const char* name)
101 : isolate_(isolate), name_(name), ptr_(NULL), lookup_done_(false) { }
103 // Sets the counter to a specific value.
104 void Set(int value) {
106 if (loc) *loc = value;
109 // Increments the counter.
115 void Increment(int value) {
121 // Decrements the counter.
127 void Decrement(int value) {
129 if (loc) (*loc) -= value;
132 // Is this counter enabled?
133 // Returns false if table is full.
135 return GetPtr() != NULL;
138 // Get the internal pointer to the counter. This is used
139 // by the code generator to emit code that manipulates a
140 // given counter without calling the runtime system.
141 int* GetInternalPointer() {
147 // Reset the cached internal pointer.
148 void Reset() { lookup_done_ = false; }
151 // Returns the cached address of this counter location.
153 if (lookup_done_) return ptr_;
155 ptr_ = FindLocationInStatsTable();
160 int* FindLocationInStatsTable() const;
168 // A Histogram represents a dynamically created histogram in the StatsTable.
169 // It will be registered with the histogram system on first use.
173 Histogram(const char* name,
181 num_buckets_(num_buckets),
184 isolate_(isolate) { }
186 // Add a single sample to this histogram.
187 void AddSample(int sample);
189 // Returns true if this histogram is enabled.
191 return GetHistogram() != NULL;
194 // Reset the cached internal pointer.
196 lookup_done_ = false;
200 // Returns the handle to the histogram.
201 void* GetHistogram() {
204 histogram_ = CreateHistogram();
209 const char* name() { return name_; }
210 Isolate* isolate() const { return isolate_; }
213 void* CreateHistogram() const;
224 // A HistogramTimer allows distributions of results to be created.
225 class HistogramTimer : public Histogram {
233 HistogramTimer(const char* name, int min, int max, Resolution resolution,
234 int num_buckets, Isolate* isolate)
235 : Histogram(name, min, max, num_buckets, isolate),
236 resolution_(resolution) {}
241 // Stop the timer and record the results.
244 // Returns true if the timer is running.
246 return Enabled() && timer_.IsStarted();
249 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed.
251 base::ElapsedTimer* timer() { return &timer_; }
255 base::ElapsedTimer timer_;
256 Resolution resolution_;
259 // Helper class for scoping a HistogramTimer.
260 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the
261 // Parser is currently reentrant (when it throws an error, we call back
262 // into JavaScript and all bets are off), but ElapsedTimer is not
263 // reentry-safe. Fix this properly and remove |allow_nesting|.
264 class HistogramTimerScope BASE_EMBEDDED {
266 explicit HistogramTimerScope(HistogramTimer* timer,
267 bool allow_nesting = false)
270 skipped_timer_start_(false) {
271 if (timer_->timer()->IsStarted() && allow_nesting) {
272 skipped_timer_start_ = true;
282 ~HistogramTimerScope() {
284 if (!skipped_timer_start_) {
293 HistogramTimer* timer_;
295 bool skipped_timer_start_;
300 // A histogram timer that can aggregate events within a larger scope.
302 // Intended use of this timer is to have an outer (aggregating) and an inner
303 // (to be aggregated) scope, where the inner scope measure the time of events,
304 // and all those inner scope measurements will be summed up by the outer scope.
305 // An example use might be to aggregate the time spent in lazy compilation
306 // while running a script.
309 // - AggregatingHistogramTimerScope, the "outer" scope within which
310 // times will be summed up.
311 // - AggregatedHistogramTimerScope, the "inner" scope which defines the
312 // events to be timed.
313 class AggregatableHistogramTimer : public Histogram {
315 AggregatableHistogramTimer() {}
316 AggregatableHistogramTimer(const char* name, int min, int max,
317 int num_buckets, Isolate* isolate)
318 : Histogram(name, min, max, num_buckets, isolate) {}
320 // Start/stop the "outer" scope.
321 void Start() { time_ = base::TimeDelta(); }
322 void Stop() { AddSample(static_cast<int>(time_.InMicroseconds())); }
324 // Add a time value ("inner" scope).
325 void Add(base::TimeDelta other) { time_ += other; }
328 base::TimeDelta time_;
332 // A helper class for use with AggregatableHistogramTimer.
333 class AggregatingHistogramTimerScope {
335 explicit AggregatingHistogramTimerScope(AggregatableHistogramTimer* histogram)
336 : histogram_(histogram) {
339 ~AggregatingHistogramTimerScope() { histogram_->Stop(); }
342 AggregatableHistogramTimer* histogram_;
346 // A helper class for use with AggregatableHistogramTimer.
347 class AggregatedHistogramTimerScope {
349 explicit AggregatedHistogramTimerScope(AggregatableHistogramTimer* histogram)
350 : histogram_(histogram) {
353 ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); }
356 base::ElapsedTimer timer_;
357 AggregatableHistogramTimer* histogram_;
361 // AggretatedMemoryHistogram collects (time, value) sample pairs and turns
362 // them into time-uniform samples for the backing historgram, such that the
363 // backing histogram receives one sample every T ms, where the T is controlled
364 // by the FLAG_histogram_interval.
366 // More formally: let F be a real-valued function that maps time to sample
367 // values. We define F as a linear interpolation between adjacent samples. For
368 // each time interval [x; x + T) the backing histogram gets one sample value
369 // that is the average of F(t) in the interval.
370 template <typename Histogram>
371 class AggregatedMemoryHistogram {
373 AggregatedMemoryHistogram()
374 : is_initialized_(false),
377 aggregate_value_(0.0),
379 backing_histogram_(NULL) {}
381 explicit AggregatedMemoryHistogram(Histogram* backing_histogram)
382 : AggregatedMemoryHistogram() {
383 backing_histogram_ = backing_histogram;
386 // Invariants that hold before and after AddSample if
387 // is_initialized_ is true:
389 // 1) For we processed samples that came in before start_ms_ and sent the
390 // corresponding aggregated samples to backing histogram.
391 // 2) (last_ms_, last_value_) is the last received sample.
392 // 3) last_ms_ < start_ms_ + FLAG_histogram_interval.
393 // 4) aggregate_value_ is the average of the function that is constructed by
394 // linearly interpolating samples received between start_ms_ and last_ms_.
395 void AddSample(double current_ms, double current_value);
398 double Aggregate(double current_ms, double current_value);
399 bool is_initialized_;
402 double aggregate_value_;
404 Histogram* backing_histogram_;
408 template <typename Histogram>
409 void AggregatedMemoryHistogram<Histogram>::AddSample(double current_ms,
410 double current_value) {
411 if (!is_initialized_) {
412 aggregate_value_ = current_value;
413 start_ms_ = current_ms;
414 last_value_ = current_value;
415 last_ms_ = current_ms;
416 is_initialized_ = true;
418 const double kEpsilon = 1e-6;
419 const int kMaxSamples = 1000;
420 if (current_ms < last_ms_ + kEpsilon) {
421 // Two samples have the same time, remember the last one.
422 last_value_ = current_value;
424 double sample_interval_ms = FLAG_histogram_interval;
425 double end_ms = start_ms_ + sample_interval_ms;
426 if (end_ms <= current_ms + kEpsilon) {
427 // Linearly interpolate between the last_ms_ and the current_ms.
428 double slope = (current_value - last_value_) / (current_ms - last_ms_);
430 // Send aggregated samples to the backing histogram from the start_ms
431 // to the current_ms.
432 for (i = 0; i < kMaxSamples && end_ms <= current_ms + kEpsilon; i++) {
433 double end_value = last_value_ + (end_ms - last_ms_) * slope;
436 // Take aggregate_value_ into account.
437 sample_value = Aggregate(end_ms, end_value);
439 // There is no aggregate_value_ for i > 0.
440 sample_value = (last_value_ + end_value) / 2;
442 backing_histogram_->AddSample(static_cast<int>(sample_value + 0.5));
443 last_value_ = end_value;
445 end_ms += sample_interval_ms;
447 if (i == kMaxSamples) {
448 // We hit the sample limit, ignore the remaining samples.
449 aggregate_value_ = current_value;
450 start_ms_ = current_ms;
452 aggregate_value_ = last_value_;
453 start_ms_ = last_ms_;
456 aggregate_value_ = current_ms > start_ms_ + kEpsilon
457 ? Aggregate(current_ms, current_value)
459 last_value_ = current_value;
460 last_ms_ = current_ms;
466 template <typename Histogram>
467 double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
468 double current_value) {
469 double interval_ms = current_ms - start_ms_;
470 double value = (current_value + last_value_) / 2;
471 // The aggregate_value_ is the average for [start_ms_; last_ms_].
472 // The value is the average for [last_ms_; current_ms].
473 // Return the weighted average of the aggregate_value_ and the value.
474 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) +
475 value * ((current_ms - last_ms_) / interval_ms);
479 #define HISTOGRAM_RANGE_LIST(HR) \
480 /* Generic range histograms */ \
481 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
482 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \
483 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
484 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \
486 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6)
488 #define HISTOGRAM_TIMER_LIST(HT) \
489 /* Garbage collection timers. */ \
490 HT(gc_compactor, V8.GCCompactor, 10000, MILLISECOND) \
491 HT(gc_scavenger, V8.GCScavenger, 10000, MILLISECOND) \
492 HT(gc_context, V8.GCContext, 10000, \
493 MILLISECOND) /* GC context cleanup time */ \
494 HT(gc_idle_notification, V8.GCIdleNotification, 10000, MILLISECOND) \
495 HT(gc_incremental_marking, V8.GCIncrementalMarking, 10000, MILLISECOND) \
496 HT(gc_low_memory_notification, V8.GCLowMemoryNotification, 10000, \
498 /* Parsing timers. */ \
499 HT(parse, V8.ParseMicroSeconds, 1000000, MICROSECOND) \
500 HT(parse_lazy, V8.ParseLazyMicroSeconds, 1000000, MICROSECOND) \
501 HT(pre_parse, V8.PreParseMicroSeconds, 1000000, MICROSECOND) \
502 /* Compilation times. */ \
503 HT(compile, V8.CompileMicroSeconds, 1000000, MICROSECOND) \
504 HT(compile_eval, V8.CompileEvalMicroSeconds, 1000000, MICROSECOND) \
505 /* Serialization as part of compilation (code caching) */ \
506 HT(compile_serialize, V8.CompileSerializeMicroSeconds, 100000, MICROSECOND) \
507 HT(compile_deserialize, V8.CompileDeserializeMicroSeconds, 1000000, \
509 /* Total compilation time incl. caching/parsing */ \
510 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND)
513 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \
514 AHT(compile_lazy, V8.CompileLazyMicroSeconds)
517 #define HISTOGRAM_PERCENTAGE_LIST(HP) \
518 /* Heap fragmentation. */ \
519 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \
520 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \
521 HP(external_fragmentation_code_space, \
522 V8.MemoryExternalFragmentationCodeSpace) \
523 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \
524 HP(external_fragmentation_lo_space, V8.MemoryExternalFragmentationLoSpace) \
525 /* Percentages of heap committed to each space. */ \
526 HP(heap_fraction_new_space, V8.MemoryHeapFractionNewSpace) \
527 HP(heap_fraction_old_space, V8.MemoryHeapFractionOldSpace) \
528 HP(heap_fraction_code_space, V8.MemoryHeapFractionCodeSpace) \
529 HP(heap_fraction_map_space, V8.MemoryHeapFractionMapSpace) \
530 HP(heap_fraction_lo_space, V8.MemoryHeapFractionLoSpace) \
531 /* Percentage of crankshafted codegen. */ \
532 HP(codegen_fraction_crankshaft, V8.CodegenFractionCrankshaft)
535 #define HISTOGRAM_LEGACY_MEMORY_LIST(HM) \
536 HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \
537 HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \
538 HM(heap_sample_map_space_committed, V8.MemoryHeapSampleMapSpaceCommitted) \
539 HM(heap_sample_code_space_committed, V8.MemoryHeapSampleCodeSpaceCommitted) \
540 HM(heap_sample_maximum_committed, V8.MemoryHeapSampleMaximumCommitted)
542 #define HISTOGRAM_MEMORY_LIST(HM) \
543 HM(memory_heap_committed, V8.MemoryHeapCommitted) \
544 HM(memory_heap_used, V8.MemoryHeapUsed)
547 // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
548 // Intellisense to crash. It was broken into two macros (each of length 40
549 // lines) rather than one macro (of length about 80 lines) to work around
550 // this problem. Please avoid using recursive macros of this length when
552 #define STATS_COUNTER_LIST_1(SC) \
553 /* Global Handle Count*/ \
554 SC(global_handles, V8.GlobalHandles) \
555 /* OS Memory allocated */ \
556 SC(memory_allocated, V8.OsMemoryAllocated) \
557 SC(normalized_maps, V8.NormalizedMaps) \
558 SC(props_to_dictionary, V8.ObjectPropertiesToDictionary) \
559 SC(elements_to_dictionary, V8.ObjectElementsToDictionary) \
560 SC(alive_after_last_gc, V8.AliveAfterLastGC) \
561 SC(objs_since_last_young, V8.ObjsSinceLastYoung) \
562 SC(objs_since_last_full, V8.ObjsSinceLastFull) \
563 SC(string_table_capacity, V8.StringTableCapacity) \
564 SC(number_of_symbols, V8.NumberOfSymbols) \
565 SC(script_wrappers, V8.ScriptWrappers) \
566 SC(call_initialize_stubs, V8.CallInitializeStubs) \
567 SC(call_premonomorphic_stubs, V8.CallPreMonomorphicStubs) \
568 SC(call_normal_stubs, V8.CallNormalStubs) \
569 SC(call_megamorphic_stubs, V8.CallMegamorphicStubs) \
570 SC(inlined_copied_elements, V8.InlinedCopiedElements) \
571 SC(arguments_adaptors, V8.ArgumentsAdaptors) \
572 SC(compilation_cache_hits, V8.CompilationCacheHits) \
573 SC(compilation_cache_misses, V8.CompilationCacheMisses) \
574 SC(string_ctor_calls, V8.StringConstructorCalls) \
575 SC(string_ctor_conversions, V8.StringConstructorConversions) \
576 SC(string_ctor_cached_number, V8.StringConstructorCachedNumber) \
577 SC(string_ctor_string_value, V8.StringConstructorStringValue) \
578 SC(string_ctor_gc_required, V8.StringConstructorGCRequired) \
579 /* Amount of evaled source code. */ \
580 SC(total_eval_size, V8.TotalEvalSize) \
581 /* Amount of loaded source code. */ \
582 SC(total_load_size, V8.TotalLoadSize) \
583 /* Amount of parsed source code. */ \
584 SC(total_parse_size, V8.TotalParseSize) \
585 /* Amount of source code skipped over using preparsing. */ \
586 SC(total_preparse_skipped, V8.TotalPreparseSkipped) \
587 /* Number of symbol lookups skipped using preparsing */ \
588 SC(total_preparse_symbols_skipped, V8.TotalPreparseSymbolSkipped) \
589 /* Amount of compiled source code. */ \
590 SC(total_compile_size, V8.TotalCompileSize) \
591 /* Amount of source code compiled with the full codegen. */ \
592 SC(total_full_codegen_source_size, V8.TotalFullCodegenSourceSize) \
593 /* Number of contexts created from scratch. */ \
594 SC(contexts_created_from_scratch, V8.ContextsCreatedFromScratch) \
595 /* Number of contexts created by partial snapshot. */ \
596 SC(contexts_created_by_snapshot, V8.ContextsCreatedBySnapshot) \
597 /* Number of code objects found from pc. */ \
598 SC(pc_to_code, V8.PcToCode) \
599 SC(pc_to_code_cached, V8.PcToCodeCached) \
600 /* The store-buffer implementation of the write barrier. */ \
601 SC(store_buffer_compactions, V8.StoreBufferCompactions) \
602 SC(store_buffer_overflows, V8.StoreBufferOverflows)
605 #define STATS_COUNTER_LIST_2(SC) \
606 /* Number of code stubs. */ \
607 SC(code_stubs, V8.CodeStubs) \
608 /* Amount of stub code. */ \
609 SC(total_stubs_code_size, V8.TotalStubsCodeSize) \
610 /* Amount of (JS) compiled code. */ \
611 SC(total_compiled_code_size, V8.TotalCompiledCodeSize) \
612 SC(gc_compactor_caused_by_request, V8.GCCompactorCausedByRequest) \
613 SC(gc_compactor_caused_by_promoted_data, V8.GCCompactorCausedByPromotedData) \
614 SC(gc_compactor_caused_by_oldspace_exhaustion, \
615 V8.GCCompactorCausedByOldspaceExhaustion) \
616 SC(gc_last_resort_from_js, V8.GCLastResortFromJS) \
617 SC(gc_last_resort_from_handles, V8.GCLastResortFromHandles) \
618 /* How is the generic keyed-load stub used? */ \
619 SC(keyed_load_generic_smi, V8.KeyedLoadGenericSmi) \
620 SC(keyed_load_generic_symbol, V8.KeyedLoadGenericSymbol) \
621 SC(keyed_load_generic_lookup_cache, V8.KeyedLoadGenericLookupCache) \
622 SC(keyed_load_generic_slow, V8.KeyedLoadGenericSlow) \
623 SC(keyed_load_polymorphic_stubs, V8.KeyedLoadPolymorphicStubs) \
624 SC(keyed_load_external_array_slow, V8.KeyedLoadExternalArraySlow) \
625 /* How is the generic keyed-call stub used? */ \
626 SC(keyed_call_generic_smi_fast, V8.KeyedCallGenericSmiFast) \
627 SC(keyed_call_generic_smi_dict, V8.KeyedCallGenericSmiDict) \
628 SC(keyed_call_generic_lookup_cache, V8.KeyedCallGenericLookupCache) \
629 SC(keyed_call_generic_lookup_dict, V8.KeyedCallGenericLookupDict) \
630 SC(keyed_call_generic_slow, V8.KeyedCallGenericSlow) \
631 SC(keyed_call_generic_slow_load, V8.KeyedCallGenericSlowLoad) \
632 SC(named_load_global_stub, V8.NamedLoadGlobalStub) \
633 SC(named_store_global_inline, V8.NamedStoreGlobalInline) \
634 SC(named_store_global_inline_miss, V8.NamedStoreGlobalInlineMiss) \
635 SC(keyed_store_polymorphic_stubs, V8.KeyedStorePolymorphicStubs) \
636 SC(keyed_store_external_array_slow, V8.KeyedStoreExternalArraySlow) \
637 SC(store_normal_miss, V8.StoreNormalMiss) \
638 SC(store_normal_hit, V8.StoreNormalHit) \
639 SC(cow_arrays_created_stub, V8.COWArraysCreatedStub) \
640 SC(cow_arrays_created_runtime, V8.COWArraysCreatedRuntime) \
641 SC(cow_arrays_converted, V8.COWArraysConverted) \
642 SC(call_miss, V8.CallMiss) \
643 SC(keyed_call_miss, V8.KeyedCallMiss) \
644 SC(load_miss, V8.LoadMiss) \
645 SC(keyed_load_miss, V8.KeyedLoadMiss) \
646 SC(call_const, V8.CallConst) \
647 SC(call_const_fast_api, V8.CallConstFastApi) \
648 SC(call_const_interceptor, V8.CallConstInterceptor) \
649 SC(call_const_interceptor_fast_api, V8.CallConstInterceptorFastApi) \
650 SC(call_global_inline, V8.CallGlobalInline) \
651 SC(call_global_inline_miss, V8.CallGlobalInlineMiss) \
652 SC(constructed_objects, V8.ConstructedObjects) \
653 SC(constructed_objects_runtime, V8.ConstructedObjectsRuntime) \
654 SC(negative_lookups, V8.NegativeLookups) \
655 SC(negative_lookups_miss, V8.NegativeLookupsMiss) \
656 SC(megamorphic_stub_cache_probes, V8.MegamorphicStubCacheProbes) \
657 SC(megamorphic_stub_cache_misses, V8.MegamorphicStubCacheMisses) \
658 SC(megamorphic_stub_cache_updates, V8.MegamorphicStubCacheUpdates) \
659 SC(array_function_runtime, V8.ArrayFunctionRuntime) \
660 SC(array_function_native, V8.ArrayFunctionNative) \
661 SC(enum_cache_hits, V8.EnumCacheHits) \
662 SC(enum_cache_misses, V8.EnumCacheMisses) \
663 SC(fast_new_closure_total, V8.FastNewClosureTotal) \
664 SC(fast_new_closure_try_optimized, V8.FastNewClosureTryOptimized) \
665 SC(fast_new_closure_install_optimized, V8.FastNewClosureInstallOptimized) \
666 SC(string_add_runtime, V8.StringAddRuntime) \
667 SC(string_add_native, V8.StringAddNative) \
668 SC(string_add_runtime_ext_to_one_byte, V8.StringAddRuntimeExtToOneByte) \
669 SC(sub_string_runtime, V8.SubStringRuntime) \
670 SC(sub_string_native, V8.SubStringNative) \
671 SC(string_add_make_two_char, V8.StringAddMakeTwoChar) \
672 SC(string_compare_native, V8.StringCompareNative) \
673 SC(string_compare_runtime, V8.StringCompareRuntime) \
674 SC(regexp_entry_runtime, V8.RegExpEntryRuntime) \
675 SC(regexp_entry_native, V8.RegExpEntryNative) \
676 SC(number_to_string_native, V8.NumberToStringNative) \
677 SC(number_to_string_runtime, V8.NumberToStringRuntime) \
678 SC(math_acos, V8.MathAcos) \
679 SC(math_asin, V8.MathAsin) \
680 SC(math_atan, V8.MathAtan) \
681 SC(math_atan2, V8.MathAtan2) \
682 SC(math_clz32, V8.MathClz32) \
683 SC(math_exp, V8.MathExp) \
684 SC(math_floor, V8.MathFloor) \
685 SC(math_log, V8.MathLog) \
686 SC(math_pow, V8.MathPow) \
687 SC(math_round, V8.MathRound) \
688 SC(math_sqrt, V8.MathSqrt) \
689 SC(stack_interrupts, V8.StackInterrupts) \
690 SC(runtime_profiler_ticks, V8.RuntimeProfilerTicks) \
691 SC(bounds_checks_eliminated, V8.BoundsChecksEliminated) \
692 SC(bounds_checks_hoisted, V8.BoundsChecksHoisted) \
693 SC(soft_deopts_requested, V8.SoftDeoptsRequested) \
694 SC(soft_deopts_inserted, V8.SoftDeoptsInserted) \
695 SC(soft_deopts_executed, V8.SoftDeoptsExecuted) \
696 /* Number of write barriers in generated code. */ \
697 SC(write_barriers_dynamic, V8.WriteBarriersDynamic) \
698 SC(write_barriers_static, V8.WriteBarriersStatic) \
699 SC(new_space_bytes_available, V8.MemoryNewSpaceBytesAvailable) \
700 SC(new_space_bytes_committed, V8.MemoryNewSpaceBytesCommitted) \
701 SC(new_space_bytes_used, V8.MemoryNewSpaceBytesUsed) \
702 SC(old_space_bytes_available, V8.MemoryOldSpaceBytesAvailable) \
703 SC(old_space_bytes_committed, V8.MemoryOldSpaceBytesCommitted) \
704 SC(old_space_bytes_used, V8.MemoryOldSpaceBytesUsed) \
705 SC(code_space_bytes_available, V8.MemoryCodeSpaceBytesAvailable) \
706 SC(code_space_bytes_committed, V8.MemoryCodeSpaceBytesCommitted) \
707 SC(code_space_bytes_used, V8.MemoryCodeSpaceBytesUsed) \
708 SC(map_space_bytes_available, V8.MemoryMapSpaceBytesAvailable) \
709 SC(map_space_bytes_committed, V8.MemoryMapSpaceBytesCommitted) \
710 SC(map_space_bytes_used, V8.MemoryMapSpaceBytesUsed) \
711 SC(lo_space_bytes_available, V8.MemoryLoSpaceBytesAvailable) \
712 SC(lo_space_bytes_committed, V8.MemoryLoSpaceBytesCommitted) \
713 SC(lo_space_bytes_used, V8.MemoryLoSpaceBytesUsed)
716 // This file contains all the v8 counters that are in use.
719 #define HR(name, caption, min, max, num_buckets) \
720 Histogram* name() { return &name##_; }
721 HISTOGRAM_RANGE_LIST(HR)
724 #define HT(name, caption, max, res) \
725 HistogramTimer* name() { return &name##_; }
726 HISTOGRAM_TIMER_LIST(HT)
729 #define AHT(name, caption) \
730 AggregatableHistogramTimer* name() { return &name##_; }
731 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
734 #define HP(name, caption) \
735 Histogram* name() { return &name##_; }
736 HISTOGRAM_PERCENTAGE_LIST(HP)
739 #define HM(name, caption) \
740 Histogram* name() { return &name##_; }
741 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
742 HISTOGRAM_MEMORY_LIST(HM)
745 #define HM(name, caption) \
746 AggregatedMemoryHistogram<Histogram>* aggregated_##name() { \
747 return &aggregated_##name##_; \
749 HISTOGRAM_MEMORY_LIST(HM)
752 #define SC(name, caption) \
753 StatsCounter* name() { return &name##_; }
754 STATS_COUNTER_LIST_1(SC)
755 STATS_COUNTER_LIST_2(SC)
759 StatsCounter* count_of_##name() { return &count_of_##name##_; } \
760 StatsCounter* size_of_##name() { return &size_of_##name##_; }
761 INSTANCE_TYPE_LIST(SC)
765 StatsCounter* count_of_CODE_TYPE_##name() \
766 { return &count_of_CODE_TYPE_##name##_; } \
767 StatsCounter* size_of_CODE_TYPE_##name() \
768 { return &size_of_CODE_TYPE_##name##_; }
773 StatsCounter* count_of_FIXED_ARRAY_##name() \
774 { return &count_of_FIXED_ARRAY_##name##_; } \
775 StatsCounter* size_of_FIXED_ARRAY_##name() \
776 { return &size_of_FIXED_ARRAY_##name##_; }
777 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
781 StatsCounter* count_of_CODE_AGE_##name() \
782 { return &count_of_CODE_AGE_##name##_; } \
783 StatsCounter* size_of_CODE_AGE_##name() \
784 { return &size_of_CODE_AGE_##name##_; }
785 CODE_AGE_LIST_COMPLETE(SC)
789 #define RATE_ID(name, caption, max, res) k_##name,
790 HISTOGRAM_TIMER_LIST(RATE_ID)
792 #define AGGREGATABLE_ID(name, caption) k_##name,
793 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
794 #undef AGGREGATABLE_ID
795 #define PERCENTAGE_ID(name, caption) k_##name,
796 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
798 #define MEMORY_ID(name, caption) k_##name,
799 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID)
800 HISTOGRAM_MEMORY_LIST(MEMORY_ID)
802 #define COUNTER_ID(name, caption) k_##name,
803 STATS_COUNTER_LIST_1(COUNTER_ID)
804 STATS_COUNTER_LIST_2(COUNTER_ID)
806 #define COUNTER_ID(name) kCountOf##name, kSizeOf##name,
807 INSTANCE_TYPE_LIST(COUNTER_ID)
809 #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \
810 kSizeOfCODE_TYPE_##name,
811 CODE_KIND_LIST(COUNTER_ID)
813 #define COUNTER_ID(name) kCountOfFIXED_ARRAY__##name, \
814 kSizeOfFIXED_ARRAY__##name,
815 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COUNTER_ID)
817 #define COUNTER_ID(name) kCountOfCODE_AGE__##name, \
818 kSizeOfCODE_AGE__##name,
819 CODE_AGE_LIST_COMPLETE(COUNTER_ID)
824 void ResetCounters();
825 void ResetHistograms();
828 #define HR(name, caption, min, max, num_buckets) Histogram name##_;
829 HISTOGRAM_RANGE_LIST(HR)
832 #define HT(name, caption, max, res) HistogramTimer name##_;
833 HISTOGRAM_TIMER_LIST(HT)
836 #define AHT(name, caption) \
837 AggregatableHistogramTimer name##_;
838 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
841 #define HP(name, caption) \
843 HISTOGRAM_PERCENTAGE_LIST(HP)
846 #define HM(name, caption) \
848 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
849 HISTOGRAM_MEMORY_LIST(HM)
852 #define HM(name, caption) \
853 AggregatedMemoryHistogram<Histogram> aggregated_##name##_;
854 HISTOGRAM_MEMORY_LIST(HM)
857 #define SC(name, caption) \
858 StatsCounter name##_;
859 STATS_COUNTER_LIST_1(SC)
860 STATS_COUNTER_LIST_2(SC)
864 StatsCounter size_of_##name##_; \
865 StatsCounter count_of_##name##_;
866 INSTANCE_TYPE_LIST(SC)
870 StatsCounter size_of_CODE_TYPE_##name##_; \
871 StatsCounter count_of_CODE_TYPE_##name##_;
876 StatsCounter size_of_FIXED_ARRAY_##name##_; \
877 StatsCounter count_of_FIXED_ARRAY_##name##_;
878 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
882 StatsCounter size_of_CODE_AGE_##name##_; \
883 StatsCounter count_of_CODE_AGE_##name##_;
884 CODE_AGE_LIST_COMPLETE(SC)
887 friend class Isolate;
889 explicit Counters(Isolate* isolate);
891 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
894 } } // namespace v8::internal
896 #endif // V8_COUNTERS_H_