Debian Codegraph @

js/public/friend/UsageStatistics.h

raw
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 * Legacy telemetry metrics passed to the accumulate telemetry callback.
21 *
22 * It's OK for these enum values to change as they will be mapped to a fixed
23 * member of the mozilla::Telemetry::HistogramID enum by the callback.
24 */
25 #define FOR_EACH_JS_LEGACY_METRIC(_) \
26 _(GC_REASON_2, Enumeration) \
27 _(GC_IS_COMPARTMENTAL, Boolean) \
28 _(GC_ZONE_COUNT, QuantityDistribution) \
29 _(GC_ZONES_COLLECTED, QuantityDistribution) \
30 _(GC_MS, TimeDuration_MS) \
31 _(GC_BUDGET_MS_2, TimeDuration_MS) \
32 _(GC_BUDGET_WAS_INCREASED, Boolean) \
33 _(GC_SLICE_WAS_LONG, Boolean) \
34 _(GC_BUDGET_OVERRUN, TimeDuration_US) \
35 _(GC_ANIMATION_MS, TimeDuration_MS) \
36 _(GC_MAX_PAUSE_MS_2, TimeDuration_MS) \
37 _(GC_PREPARE_MS, TimeDuration_MS) \
38 _(GC_MARK_MS, TimeDuration_MS) \
39 _(GC_SWEEP_MS, TimeDuration_MS) \
40 _(GC_COMPACT_MS, TimeDuration_MS) \
41 _(GC_MARK_ROOTS_US, TimeDuration_US) \
42 _(GC_MARK_GRAY_MS_2, TimeDuration_MS) \
43 _(GC_MARK_WEAK_MS, TimeDuration_MS) \
44 _(GC_SLICE_MS, TimeDuration_MS) \
45 _(GC_SLOW_PHASE, Enumeration) \
46 _(GC_SLOW_TASK, Enumeration) \
47 _(GC_MMU_50, Percentage) \
48 _(GC_RESET, Boolean) \
49 _(GC_RESET_REASON, Enumeration) \
50 _(GC_NON_INCREMENTAL, Boolean) \
51 _(GC_NON_INCREMENTAL_REASON, Enumeration) \
52 _(GC_MINOR_REASON, Enumeration) \
53 _(GC_MINOR_REASON_LONG, Enumeration) \
54 _(GC_MINOR_US, TimeDuration_US) \
55 _(GC_NURSERY_BYTES_2, MemoryDistribution) \
56 _(GC_PRETENURE_COUNT_2, QuantityDistribution) \
57 _(GC_NURSERY_PROMOTION_RATE, Percentage) \
58 _(GC_TENURED_SURVIVAL_RATE, Percentage) \
59 _(GC_MARK_RATE_2, QuantityDistribution) \
60 _(GC_TIME_BETWEEN_S, TimeDuration_S) \
61 _(GC_TIME_BETWEEN_SLICES_MS, TimeDuration_MS) \
62 _(GC_SLICE_COUNT, QuantityDistribution) \
63 _(GC_EFFECTIVENESS, MemoryDistribution) \
64 _(GC_PARALLEL_MARK, Boolean) \
65 _(GC_PARALLEL_MARK_SPEEDUP, Integer) \
66 _(GC_PARALLEL_MARK_UTILIZATION, Percentage) \
67 _(GC_PARALLEL_MARK_INTERRUPTIONS, Integer) \
68 _(GC_TASK_START_DELAY_US, TimeDuration_US)
69
70 /*
71 * Append any glean only telemetry metrics to the following list.
72 * However, unlike the legacy list, each glean metric must be manually added
73 * to the switch statement in AccumulateTelemetryCallback().
74 */
75 #define FOR_EACH_JS_GLEAN_METRIC(_) \
76 _(ION_COMPILE_TIME, TimeDuration_US) \
77 _(GC_GLEAN_SLOW_PHASE, Enumeration) \
78 _(GC_GLEAN_SLOW_TASK, Enumeration)
79
80 #define FOR_EACH_JS_METRIC(_) \
81 FOR_EACH_JS_LEGACY_METRIC(_) \
82 FOR_EACH_JS_GLEAN_METRIC(_)
83
84 // clang-format off
85 #define ENUM_DEF(NAME, _) NAME,
86 enum class JSMetric {
87 FOR_EACH_JS_METRIC(ENUM_DEF)
88 Count
89 };
90 #undef ENUM_DEF
91 // clang-format on
92
93 using JSAccumulateTelemetryDataCallback = void (*)(JSMetric, uint32_t);
94
95 extern JS_PUBLIC_API void JS_SetAccumulateTelemetryCallback(
96 JSContext* cx, JSAccumulateTelemetryDataCallback callback);
97
98 #define FOR_EACH_JS_USE_COUNTER(_) \
99 _(ASMJS, AsmJS) \
100 _(WASM, Wasm) \
101 _(WASM_LEGACY_EXCEPTIONS, WasmLegacyExceptions) \
102 _(ISHTMLDDA_FUSE, IsHTMLDDAFuse) \
103 _(OPTIMIZE_GET_ITERATOR_FUSE, OptimizeGetIteratorFuse) \
104 _(THENABLE_USE, ThenableUse) \
105 _(THENABLE_USE_PROTO, ThenableUseProto) \
106 _(THENABLE_USE_STANDARD_PROTO, ThenableUseStandardProto) \
107 _(THENABLE_USE_OBJECT_PROTO, ThenableUseObjectProto) \
108 _(LEGACY_LANG_SUBTAG, LegacyLangSubtag) \
109 _(IC_STUB_TOO_LARGE, ICStubTooLarge) \
110 _(IC_STUB_OOM, ICStubOOM) \
111 _(ERRORSTACK_GETTER, ErrorStackGetter) \
112 _(ERRORSTACK_GETTER_NO_ERRORDATA, ErrorStackGetterNoErrorData) \
113 _(ERRORSTACK_SETTER, ErrorStackSetter) \
114 _(ERRORSTACK_SETTER_NONSTRING, ErrorStackSetterNonString) \
115 _(ERRORSTACK_SETTER_NO_ERRORDATA, ErrorStackSetterNoErrorData) \
116 _(DATEPARSE, DateParse) \
117 _(DATEPARSE_IMPL_DEF, DateParseImplDef) \
118 _(OPTIMIZE_ARRAY_SPECIES_FUSE, OptimizeArraySpeciesFuse) \
119 _(OPTIMIZE_PROMISE_LOOKUP_FUSE, OptimizePromiseLookupFuse) \
120 _(REGEXP_SYMBOL_PROTOCOL_ON_PRIMITIVE, RegExpSymbolProtocolOnPrimitive)
121
122 /*
123 * Use counter names passed to the accumulate use counter callback.
124 *
125 * It's OK to for these enum values to change as they will be mapped to a
126 * fixed member of the mozilla::UseCounter enum by the callback.
127 */
128
129 #define ENUM_DEF(NAME, _) NAME,
130 enum class JSUseCounter { FOR_EACH_JS_USE_COUNTER(ENUM_DEF) COUNT };
131 #undef ENUM_DEF
132
133 using JSSetUseCounterCallback = void (*)(JSObject*, JSUseCounter);
134
135 extern JS_PUBLIC_API void JS_SetSetUseCounterCallback(
136 JSContext* cx, JSSetUseCounterCallback callback);
137
138 #endif // js_friend_UsageStatistics_h