UsageStatistics.h (4992B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* Telemetry and use counter functionality. */ 8 9 #ifndef js_friend_UsageStatistics_h 10 #define js_friend_UsageStatistics_h 11 12 #include <stdint.h> // uint32_t 13 14 #include "jstypes.h" // JS_PUBLIC_API 15 16 struct JS_PUBLIC_API JSContext; 17 class JS_PUBLIC_API JSObject; 18 19 /* 20 * Each glean metric must be manually added 21 * to the switch statement in AccumulateTelemetryCallback(). 22 */ 23 #define FOR_EACH_JS_METRIC(_) \ 24 _(GC_REASON_2, Enumeration) \ 25 _(GC_IS_COMPARTMENTAL, Boolean) \ 26 _(GC_ZONE_COUNT, QuantityDistribution) \ 27 _(GC_ZONES_COLLECTED, QuantityDistribution) \ 28 _(GC_MS, TimeDuration_MS) \ 29 _(GC_BUDGET_MS_2, TimeDuration_MS) \ 30 _(GC_BUDGET_WAS_INCREASED, Boolean) \ 31 _(GC_SLICE_WAS_LONG, Boolean) \ 32 _(GC_BUDGET_OVERRUN, TimeDuration_US) \ 33 _(GC_ANIMATION_MS, TimeDuration_MS) \ 34 _(GC_MAX_PAUSE_MS_2, TimeDuration_MS) \ 35 _(GC_PREPARE_MS, TimeDuration_MS) \ 36 _(GC_MARK_MS, TimeDuration_MS) \ 37 _(GC_SWEEP_MS, TimeDuration_MS) \ 38 _(GC_COMPACT_MS, TimeDuration_MS) \ 39 _(GC_MARK_ROOTS_US, TimeDuration_US) \ 40 _(GC_MARK_GRAY_MS_2, TimeDuration_MS) \ 41 _(GC_MARK_WEAK_MS, TimeDuration_MS) \ 42 _(GC_SLICE_MS, TimeDuration_MS) \ 43 _(GC_SLOW_PHASE, Enumeration) \ 44 _(GC_SLOW_TASK, Enumeration) \ 45 _(GC_MMU_50, Percentage) \ 46 _(GC_RESET, Boolean) \ 47 _(GC_RESET_REASON, Enumeration) \ 48 _(GC_NON_INCREMENTAL, Boolean) \ 49 _(GC_NON_INCREMENTAL_REASON, Enumeration) \ 50 _(GC_MINOR_REASON, Enumeration) \ 51 _(GC_MINOR_REASON_LONG, Enumeration) \ 52 _(GC_MINOR_US, TimeDuration_US) \ 53 _(GC_NURSERY_BYTES_2, MemoryDistribution) \ 54 _(GC_PRETENURE_COUNT_2, QuantityDistribution) \ 55 _(GC_NURSERY_PROMOTION_RATE, Percentage) \ 56 _(GC_TENURED_SURVIVAL_RATE, Percentage) \ 57 _(GC_MARK_RATE_2, QuantityDistribution) \ 58 _(GC_TIME_BETWEEN_S, TimeDuration_S) \ 59 _(GC_TIME_BETWEEN_SLICES_MS, TimeDuration_MS) \ 60 _(GC_SLICE_COUNT, QuantityDistribution) \ 61 _(GC_EFFECTIVENESS, MemoryDistribution) \ 62 _(GC_PARALLEL_MARK, Boolean) \ 63 _(GC_PARALLEL_MARK_SPEEDUP, Integer) \ 64 _(GC_PARALLEL_MARK_UTILIZATION, Percentage) \ 65 _(GC_PARALLEL_MARK_INTERRUPTIONS, Integer) \ 66 _(GC_TASK_START_DELAY_US, TimeDuration_US) \ 67 _(ION_COMPILE_TIME, TimeDuration_US) \ 68 _(GC_TIME_BETWEEN_MINOR_MS, TimeDuration_MS) 69 70 // clang-format off 71 #define ENUM_DEF(NAME, _) NAME, 72 enum class JSMetric { 73 FOR_EACH_JS_METRIC(ENUM_DEF) 74 Count 75 }; 76 #undef ENUM_DEF 77 // clang-format on 78 79 using JSAccumulateTelemetryDataCallback = void (*)(JSMetric, uint32_t); 80 81 extern JS_PUBLIC_API void JS_SetAccumulateTelemetryCallback( 82 JSContext* cx, JSAccumulateTelemetryDataCallback callback); 83 84 #define FOR_EACH_JS_USE_COUNTER(_) \ 85 _(ASMJS, AsmJS) \ 86 _(USE_ASM, UseAsm) \ 87 _(WASM, Wasm) \ 88 _(WASM_LEGACY_EXCEPTIONS, WasmLegacyExceptions) \ 89 _(ISHTMLDDA_FUSE, IsHTMLDDAFuse) \ 90 _(OPTIMIZE_GET_ITERATOR_FUSE, OptimizeGetIteratorFuse) \ 91 _(THENABLE_USE, ThenableUse) \ 92 _(THENABLE_USE_PROTO, ThenableUseProto) \ 93 _(THENABLE_USE_STANDARD_PROTO, ThenableUseStandardProto) \ 94 _(THENABLE_USE_OBJECT_PROTO, ThenableUseObjectProto) \ 95 _(LEGACY_LANG_SUBTAG, LegacyLangSubtag) \ 96 _(IC_STUB_TOO_LARGE, ICStubTooLarge) \ 97 _(IC_STUB_OOM, ICStubOOM) \ 98 _(DATEPARSE, DateParse) \ 99 _(DATEPARSE_IMPL_DEF, DateParseImplDef) \ 100 _(OPTIMIZE_ARRAY_SPECIES_FUSE, OptimizeArraySpeciesFuse) \ 101 _(OPTIMIZE_PROMISE_LOOKUP_FUSE, OptimizePromiseLookupFuse) 102 103 /* 104 * Use counter names passed to the accumulate use counter callback. 105 * 106 * It's OK to for these enum values to change as they will be mapped to a 107 * fixed member of the mozilla::UseCounter enum by the callback. 108 */ 109 110 #define ENUM_DEF(NAME, _) NAME, 111 enum class JSUseCounter { FOR_EACH_JS_USE_COUNTER(ENUM_DEF) COUNT }; 112 #undef ENUM_DEF 113 114 using JSSetUseCounterCallback = void (*)(JSObject*, JSUseCounter); 115 116 extern JS_PUBLIC_API void JS_SetSetUseCounterCallback( 117 JSContext* cx, JSSetUseCounterCallback callback); 118 119 #endif // js_friend_UsageStatistics_h