1 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 #ifndef V8_V8_COUNTERS_H_ 29 #define V8_V8_COUNTERS_H_ 30 31 #include "allocation.h" 32 #include "counters.h" 33 #include "objects.h" 34 #include "v8globals.h" 35 36 namespace v8 { 37 namespace internal { 38 39 #define HISTOGRAM_TIMER_LIST(HT) \ 40 /* Garbage collection timers. */ \ 41 HT(gc_compactor, V8.GCCompactor) \ 42 HT(gc_scavenger, V8.GCScavenger) \ 43 HT(gc_context, V8.GCContext) /* GC context cleanup time */ \ 44 /* Parsing timers. */ \ 45 HT(parse, V8.Parse) \ 46 HT(parse_lazy, V8.ParseLazy) \ 47 HT(pre_parse, V8.PreParse) \ 48 /* Total compilation times. */ \ 49 HT(compile, V8.Compile) \ 50 HT(compile_eval, V8.CompileEval) \ 51 HT(compile_lazy, V8.CompileLazy) 52 53 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ 54 HP(external_fragmentation_total, \ 55 V8.MemoryExternalFragmentationTotal) \ 56 HP(external_fragmentation_old_pointer_space, \ 57 V8.MemoryExternalFragmentationOldPointerSpace) \ 58 HP(external_fragmentation_old_data_space, \ 59 V8.MemoryExternalFragmentationOldDataSpace) \ 60 HP(external_fragmentation_code_space, \ 61 V8.MemoryExternalFragmentationCodeSpace) \ 62 HP(external_fragmentation_map_space, \ 63 V8.MemoryExternalFragmentationMapSpace) \ 64 HP(external_fragmentation_cell_space, \ 65 V8.MemoryExternalFragmentationCellSpace) \ 66 HP(external_fragmentation_property_cell_space, \ 67 V8.MemoryExternalFragmentationPropertyCellSpace) \ 68 HP(external_fragmentation_lo_space, \ 69 V8.MemoryExternalFragmentationLoSpace) \ 70 HP(heap_fraction_map_space, \ 71 V8.MemoryHeapFractionMapSpace) \ 72 HP(heap_fraction_cell_space, \ 73 V8.MemoryHeapFractionCellSpace) \ 74 HP(heap_fraction_property_cell_space, \ 75 V8.MemoryHeapFractionPropertyCellSpace) \ 76 77 78 #define HISTOGRAM_MEMORY_LIST(HM) \ 79 HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \ 80 HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \ 81 HM(heap_sample_map_space_committed, \ 82 V8.MemoryHeapSampleMapSpaceCommitted) \ 83 HM(heap_sample_cell_space_committed, \ 84 V8.MemoryHeapSampleCellSpaceCommitted) \ 85 HM(heap_sample_property_cell_space_committed, \ 86 V8.MemoryHeapSamplePropertyCellSpaceCommitted) \ 87 88 89 // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC 90 // Intellisense to crash. It was broken into two macros (each of length 40 91 // lines) rather than one macro (of length about 80 lines) to work around 92 // this problem. Please avoid using recursive macros of this length when 93 // possible. 94 #define STATS_COUNTER_LIST_1(SC) \ 95 /* Global Handle Count*/ \ 96 SC(global_handles, V8.GlobalHandles) \ 97 /* OS Memory allocated */ \ 98 SC(memory_allocated, V8.OsMemoryAllocated) \ 99 SC(normalized_maps, V8.NormalizedMaps) \ 100 SC(props_to_dictionary, V8.ObjectPropertiesToDictionary) \ 101 SC(elements_to_dictionary, V8.ObjectElementsToDictionary) \ 102 SC(alive_after_last_gc, V8.AliveAfterLastGC) \ 103 SC(objs_since_last_young, V8.ObjsSinceLastYoung) \ 104 SC(objs_since_last_full, V8.ObjsSinceLastFull) \ 105 SC(string_table_capacity, V8.StringTableCapacity) \ 106 SC(number_of_symbols, V8.NumberOfSymbols) \ 107 SC(script_wrappers, V8.ScriptWrappers) \ 108 SC(call_initialize_stubs, V8.CallInitializeStubs) \ 109 SC(call_premonomorphic_stubs, V8.CallPreMonomorphicStubs) \ 110 SC(call_normal_stubs, V8.CallNormalStubs) \ 111 SC(call_megamorphic_stubs, V8.CallMegamorphicStubs) \ 112 SC(arguments_adaptors, V8.ArgumentsAdaptors) \ 113 SC(compilation_cache_hits, V8.CompilationCacheHits) \ 114 SC(compilation_cache_misses, V8.CompilationCacheMisses) \ 115 SC(string_ctor_calls, V8.StringConstructorCalls) \ 116 SC(string_ctor_conversions, V8.StringConstructorConversions) \ 117 SC(string_ctor_cached_number, V8.StringConstructorCachedNumber) \ 118 SC(string_ctor_string_value, V8.StringConstructorStringValue) \ 119 SC(string_ctor_gc_required, V8.StringConstructorGCRequired) \ 120 /* Amount of evaled source code. */ \ 121 SC(total_eval_size, V8.TotalEvalSize) \ 122 /* Amount of loaded source code. */ \ 123 SC(total_load_size, V8.TotalLoadSize) \ 124 /* Amount of parsed source code. */ \ 125 SC(total_parse_size, V8.TotalParseSize) \ 126 /* Amount of source code skipped over using preparsing. */ \ 127 SC(total_preparse_skipped, V8.TotalPreparseSkipped) \ 128 /* Number of symbol lookups skipped using preparsing */ \ 129 SC(total_preparse_symbols_skipped, V8.TotalPreparseSymbolSkipped) \ 130 /* Amount of compiled source code. */ \ 131 SC(total_compile_size, V8.TotalCompileSize) \ 132 /* Amount of source code compiled with the full codegen. */ \ 133 SC(total_full_codegen_source_size, V8.TotalFullCodegenSourceSize) \ 134 /* Number of contexts created from scratch. */ \ 135 SC(contexts_created_from_scratch, V8.ContextsCreatedFromScratch) \ 136 /* Number of contexts created by partial snapshot. */ \ 137 SC(contexts_created_by_snapshot, V8.ContextsCreatedBySnapshot) \ 138 /* Number of code objects found from pc. */ \ 139 SC(pc_to_code, V8.PcToCode) \ 140 SC(pc_to_code_cached, V8.PcToCodeCached) \ 141 /* The store-buffer implementation of the write barrier. */ \ 142 SC(store_buffer_compactions, V8.StoreBufferCompactions) \ 143 SC(store_buffer_overflows, V8.StoreBufferOverflows) 144 145 146 #define STATS_COUNTER_LIST_2(SC) \ 147 /* Number of code stubs. */ \ 148 SC(code_stubs, V8.CodeStubs) \ 149 /* Amount of stub code. */ \ 150 SC(total_stubs_code_size, V8.TotalStubsCodeSize) \ 151 /* Amount of (JS) compiled code. */ \ 152 SC(total_compiled_code_size, V8.TotalCompiledCodeSize) \ 153 SC(gc_compactor_caused_by_request, V8.GCCompactorCausedByRequest) \ 154 SC(gc_compactor_caused_by_promoted_data, \ 155 V8.GCCompactorCausedByPromotedData) \ 156 SC(gc_compactor_caused_by_oldspace_exhaustion, \ 157 V8.GCCompactorCausedByOldspaceExhaustion) \ 158 SC(gc_last_resort_from_js, V8.GCLastResortFromJS) \ 159 SC(gc_last_resort_from_handles, V8.GCLastResortFromHandles) \ 160 /* How is the generic keyed-load stub used? */ \ 161 SC(keyed_load_generic_smi, V8.KeyedLoadGenericSmi) \ 162 SC(keyed_load_generic_symbol, V8.KeyedLoadGenericSymbol) \ 163 SC(keyed_load_generic_lookup_cache, V8.KeyedLoadGenericLookupCache) \ 164 SC(keyed_load_generic_slow, V8.KeyedLoadGenericSlow) \ 165 SC(keyed_load_polymorphic_stubs, V8.KeyedLoadPolymorphicStubs) \ 166 SC(keyed_load_external_array_slow, V8.KeyedLoadExternalArraySlow) \ 167 /* How is the generic keyed-call stub used? */ \ 168 SC(keyed_call_generic_smi_fast, V8.KeyedCallGenericSmiFast) \ 169 SC(keyed_call_generic_smi_dict, V8.KeyedCallGenericSmiDict) \ 170 SC(keyed_call_generic_lookup_cache, V8.KeyedCallGenericLookupCache) \ 171 SC(keyed_call_generic_lookup_dict, V8.KeyedCallGenericLookupDict) \ 172 SC(keyed_call_generic_slow, V8.KeyedCallGenericSlow) \ 173 SC(keyed_call_generic_slow_load, V8.KeyedCallGenericSlowLoad) \ 174 SC(named_load_global_stub, V8.NamedLoadGlobalStub) \ 175 SC(named_store_global_inline, V8.NamedStoreGlobalInline) \ 176 SC(named_store_global_inline_miss, V8.NamedStoreGlobalInlineMiss) \ 177 SC(keyed_store_polymorphic_stubs, V8.KeyedStorePolymorphicStubs) \ 178 SC(keyed_store_external_array_slow, V8.KeyedStoreExternalArraySlow) \ 179 SC(store_normal_miss, V8.StoreNormalMiss) \ 180 SC(store_normal_hit, V8.StoreNormalHit) \ 181 SC(cow_arrays_created_stub, V8.COWArraysCreatedStub) \ 182 SC(cow_arrays_created_runtime, V8.COWArraysCreatedRuntime) \ 183 SC(cow_arrays_converted, V8.COWArraysConverted) \ 184 SC(call_miss, V8.CallMiss) \ 185 SC(keyed_call_miss, V8.KeyedCallMiss) \ 186 SC(load_miss, V8.LoadMiss) \ 187 SC(keyed_load_miss, V8.KeyedLoadMiss) \ 188 SC(call_const, V8.CallConst) \ 189 SC(call_const_fast_api, V8.CallConstFastApi) \ 190 SC(call_const_interceptor, V8.CallConstInterceptor) \ 191 SC(call_const_interceptor_fast_api, V8.CallConstInterceptorFastApi) \ 192 SC(call_global_inline, V8.CallGlobalInline) \ 193 SC(call_global_inline_miss, V8.CallGlobalInlineMiss) \ 194 SC(constructed_objects, V8.ConstructedObjects) \ 195 SC(constructed_objects_runtime, V8.ConstructedObjectsRuntime) \ 196 SC(negative_lookups, V8.NegativeLookups) \ 197 SC(negative_lookups_miss, V8.NegativeLookupsMiss) \ 198 SC(megamorphic_stub_cache_probes, V8.MegamorphicStubCacheProbes) \ 199 SC(megamorphic_stub_cache_misses, V8.MegamorphicStubCacheMisses) \ 200 SC(megamorphic_stub_cache_updates, V8.MegamorphicStubCacheUpdates) \ 201 SC(array_function_runtime, V8.ArrayFunctionRuntime) \ 202 SC(array_function_native, V8.ArrayFunctionNative) \ 203 SC(for_in, V8.ForIn) \ 204 SC(enum_cache_hits, V8.EnumCacheHits) \ 205 SC(enum_cache_misses, V8.EnumCacheMisses) \ 206 SC(zone_segment_bytes, V8.ZoneSegmentBytes) \ 207 SC(generic_binary_stub_calls, V8.GenericBinaryStubCalls) \ 208 SC(fast_new_closure_total, V8.FastNewClosureTotal) \ 209 SC(fast_new_closure_try_optimized, V8.FastNewClosureTryOptimized) \ 210 SC(fast_new_closure_install_optimized, V8.FastNewClosureInstallOptimized) \ 211 SC(string_add_runtime, V8.StringAddRuntime) \ 212 SC(string_add_native, V8.StringAddNative) \ 213 SC(string_add_runtime_ext_to_ascii, V8.StringAddRuntimeExtToAscii) \ 214 SC(sub_string_runtime, V8.SubStringRuntime) \ 215 SC(sub_string_native, V8.SubStringNative) \ 216 SC(string_add_make_two_char, V8.StringAddMakeTwoChar) \ 217 SC(string_compare_native, V8.StringCompareNative) \ 218 SC(string_compare_runtime, V8.StringCompareRuntime) \ 219 SC(regexp_entry_runtime, V8.RegExpEntryRuntime) \ 220 SC(regexp_entry_native, V8.RegExpEntryNative) \ 221 SC(number_to_string_native, V8.NumberToStringNative) \ 222 SC(number_to_string_runtime, V8.NumberToStringRuntime) \ 223 SC(math_acos, V8.MathAcos) \ 224 SC(math_asin, V8.MathAsin) \ 225 SC(math_atan, V8.MathAtan) \ 226 SC(math_atan2, V8.MathAtan2) \ 227 SC(math_ceil, V8.MathCeil) \ 228 SC(math_cos, V8.MathCos) \ 229 SC(math_exp, V8.MathExp) \ 230 SC(math_floor, V8.MathFloor) \ 231 SC(math_log, V8.MathLog) \ 232 SC(math_pow, V8.MathPow) \ 233 SC(math_round, V8.MathRound) \ 234 SC(math_sin, V8.MathSin) \ 235 SC(math_sqrt, V8.MathSqrt) \ 236 SC(math_tan, V8.MathTan) \ 237 SC(transcendental_cache_hit, V8.TranscendentalCacheHit) \ 238 SC(transcendental_cache_miss, V8.TranscendentalCacheMiss) \ 239 SC(stack_interrupts, V8.StackInterrupts) \ 240 SC(runtime_profiler_ticks, V8.RuntimeProfilerTicks) \ 241 SC(bounds_checks_eliminated, V8.BoundsChecksEliminated) \ 242 SC(bounds_checks_hoisted, V8.BoundsChecksHoisted) \ 243 SC(soft_deopts_requested, V8.SoftDeoptsRequested) \ 244 SC(soft_deopts_inserted, V8.SoftDeoptsInserted) \ 245 SC(soft_deopts_executed, V8.SoftDeoptsExecuted) \ 246 SC(new_space_bytes_available, V8.MemoryNewSpaceBytesAvailable) \ 247 SC(new_space_bytes_committed, V8.MemoryNewSpaceBytesCommitted) \ 248 SC(new_space_bytes_used, V8.MemoryNewSpaceBytesUsed) \ 249 SC(old_pointer_space_bytes_available, \ 250 V8.MemoryOldPointerSpaceBytesAvailable) \ 251 SC(old_pointer_space_bytes_committed, \ 252 V8.MemoryOldPointerSpaceBytesCommitted) \ 253 SC(old_pointer_space_bytes_used, V8.MemoryOldPointerSpaceBytesUsed) \ 254 SC(old_data_space_bytes_available, V8.MemoryOldDataSpaceBytesAvailable) \ 255 SC(old_data_space_bytes_committed, V8.MemoryOldDataSpaceBytesCommitted) \ 256 SC(old_data_space_bytes_used, V8.MemoryOldDataSpaceBytesUsed) \ 257 SC(code_space_bytes_available, V8.MemoryCodeSpaceBytesAvailable) \ 258 SC(code_space_bytes_committed, V8.MemoryCodeSpaceBytesCommitted) \ 259 SC(code_space_bytes_used, V8.MemoryCodeSpaceBytesUsed) \ 260 SC(map_space_bytes_available, V8.MemoryMapSpaceBytesAvailable) \ 261 SC(map_space_bytes_committed, V8.MemoryMapSpaceBytesCommitted) \ 262 SC(map_space_bytes_used, V8.MemoryMapSpaceBytesUsed) \ 263 SC(cell_space_bytes_available, V8.MemoryCellSpaceBytesAvailable) \ 264 SC(cell_space_bytes_committed, V8.MemoryCellSpaceBytesCommitted) \ 265 SC(cell_space_bytes_used, V8.MemoryCellSpaceBytesUsed) \ 266 SC(property_cell_space_bytes_available, \ 267 V8.MemoryPropertyCellSpaceBytesAvailable) \ 268 SC(property_cell_space_bytes_committed, \ 269 V8.MemoryPropertyCellSpaceBytesCommitted) \ 270 SC(property_cell_space_bytes_used, \ 271 V8.MemoryPropertyCellSpaceBytesUsed) \ 272 SC(lo_space_bytes_available, V8.MemoryLoSpaceBytesAvailable) \ 273 SC(lo_space_bytes_committed, V8.MemoryLoSpaceBytesCommitted) \ 274 SC(lo_space_bytes_used, V8.MemoryLoSpaceBytesUsed) 275 276 277 // This file contains all the v8 counters that are in use. 278 class Counters { 279 public: 280 #define HT(name, caption) \ 281 HistogramTimer* name() { return &name##_; } 282 HISTOGRAM_TIMER_LIST(HT) 283 #undef HT 284 285 #define HP(name, caption) \ 286 Histogram* name() { return &name##_; } 287 HISTOGRAM_PERCENTAGE_LIST(HP) 288 #undef HP 289 290 #define HM(name, caption) \ 291 Histogram* name() { return &name##_; } 292 HISTOGRAM_MEMORY_LIST(HM) 293 #undef HM 294 295 #define SC(name, caption) \ 296 StatsCounter* name() { return &name##_; } 297 STATS_COUNTER_LIST_1(SC) 298 STATS_COUNTER_LIST_2(SC) 299 #undef SC 300 301 #define SC(name) \ 302 StatsCounter* count_of_##name() { return &count_of_##name##_; } \ 303 StatsCounter* size_of_##name() { return &size_of_##name##_; } 304 INSTANCE_TYPE_LIST(SC) 305 #undef SC 306 307 #define SC(name) \ 308 StatsCounter* count_of_CODE_TYPE_##name() \ 309 { return &count_of_CODE_TYPE_##name##_; } \ 310 StatsCounter* size_of_CODE_TYPE_##name() \ 311 { return &size_of_CODE_TYPE_##name##_; } 312 CODE_KIND_LIST(SC) 313 #undef SC 314 315 #define SC(name) \ 316 StatsCounter* count_of_FIXED_ARRAY_##name() \ 317 { return &count_of_FIXED_ARRAY_##name##_; } \ 318 StatsCounter* size_of_FIXED_ARRAY_##name() \ 319 { return &size_of_FIXED_ARRAY_##name##_; } 320 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) 321 #undef SC 322 323 enum Id { 324 #define RATE_ID(name, caption) k_##name, 325 HISTOGRAM_TIMER_LIST(RATE_ID) 326 #undef RATE_ID 327 #define PERCENTAGE_ID(name, caption) k_##name, 328 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) 329 #undef PERCENTAGE_ID 330 #define MEMORY_ID(name, caption) k_##name, 331 HISTOGRAM_MEMORY_LIST(MEMORY_ID) 332 #undef MEMORY_ID 333 #define COUNTER_ID(name, caption) k_##name, 334 STATS_COUNTER_LIST_1(COUNTER_ID) 335 STATS_COUNTER_LIST_2(COUNTER_ID) 336 #undef COUNTER_ID 337 #define COUNTER_ID(name) kCountOf##name, kSizeOf##name, 338 INSTANCE_TYPE_LIST(COUNTER_ID) 339 #undef COUNTER_ID 340 #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \ 341 kSizeOfCODE_TYPE_##name, 342 CODE_KIND_LIST(COUNTER_ID) 343 #undef COUNTER_ID 344 #define COUNTER_ID(name) kCountOfFIXED_ARRAY__##name, \ 345 kSizeOfFIXED_ARRAY__##name, 346 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COUNTER_ID) 347 #undef COUNTER_ID 348 stats_counter_count 349 }; 350 351 void ResetHistograms(); 352 353 private: 354 #define HT(name, caption) \ 355 HistogramTimer name##_; 356 HISTOGRAM_TIMER_LIST(HT) 357 #undef HT 358 359 #define HP(name, caption) \ 360 Histogram name##_; 361 HISTOGRAM_PERCENTAGE_LIST(HP) 362 #undef HP 363 364 #define HM(name, caption) \ 365 Histogram name##_; 366 HISTOGRAM_MEMORY_LIST(HM) 367 #undef HM 368 369 #define SC(name, caption) \ 370 StatsCounter name##_; 371 STATS_COUNTER_LIST_1(SC) 372 STATS_COUNTER_LIST_2(SC) 373 #undef SC 374 375 #define SC(name) \ 376 StatsCounter size_of_##name##_; \ 377 StatsCounter count_of_##name##_; 378 INSTANCE_TYPE_LIST(SC) 379 #undef SC 380 381 #define SC(name) \ 382 StatsCounter size_of_CODE_TYPE_##name##_; \ 383 StatsCounter count_of_CODE_TYPE_##name##_; 384 CODE_KIND_LIST(SC) 385 #undef SC 386 387 #define SC(name) \ 388 StatsCounter size_of_FIXED_ARRAY_##name##_; \ 389 StatsCounter count_of_FIXED_ARRAY_##name##_; 390 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) 391 #undef SC 392 393 friend class Isolate; 394 395 explicit Counters(Isolate* isolate); 396 397 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 398 }; 399 400 } } // namespace v8::internal 401 402 #endif // V8_V8_COUNTERS_H_ 403