projects/aports·blob master · refs

294 lines · 10.5 KiB

1From 180b1eaf7731145341c93928402a00aa3e0c87ef Mon Sep 17 00:00:00 2001
2From: ptrcnull <[email protected]>
3Date: Mon, 1 Jun 2026 20:41:52 +0200
4Subject: [PATCH] glean-stub.patch
5
6stubs out some glean metrics
7
8play stupid games, win `rustc-LLVM ERROR: out of memory`
9---
10 .../components/glean/api/src/ffi/boolean.rs | 11 +-
11 .../components/glean/api/src/ffi/counter.rs | 8 +-
12 toolkit/components/glean/api/src/ffi/event.rs | 127 +-----------------
13 .../components/glean/api/src/ffi/string.rs | 14 +-
14 .../build_scripts/glean_parser_ext/rust.py | 19 +++
15 5 files changed, 34 insertions(+), 145 deletions(-)
16
17diff --git a/toolkit/components/glean/api/src/ffi/boolean.rs b/toolkit/components/glean/api/src/ffi/boolean.rs
18index 9184b23c0098e..fa13206627272 100644
19--- a/toolkit/components/glean/api/src/ffi/boolean.rs
20+++ b/toolkit/components/glean/api/src/ffi/boolean.rs
21@@ -8,21 +8,18 @@ use nsstring::nsACString;
22
23 #[no_mangle]
24 pub extern "C" fn fog_boolean_test_has_value(id: u32, ping_name: &nsACString) -> bool {
25- with_metric!(BOOLEAN_MAP, id, metric, test_has!(metric, ping_name))
26+ false
27 }
28
29 #[no_mangle]
30 pub extern "C" fn fog_boolean_test_get_value(id: u32, ping_name: &nsACString) -> bool {
31- with_metric!(BOOLEAN_MAP, id, metric, test_get!(metric, ping_name))
32+ false
33 }
34
35 #[no_mangle]
36 pub extern "C" fn fog_boolean_test_get_error(id: u32, error_str: &mut nsACString) -> bool {
37- let err = with_metric!(BOOLEAN_MAP, id, metric, test_get_errors!(metric));
38- err.map(|err_str| error_str.assign(&err_str)).is_some()
39+ false
40 }
41
42 #[no_mangle]
43-pub extern "C" fn fog_boolean_set(id: u32, value: bool) {
44- with_metric!(BOOLEAN_MAP, id, metric, metric.set(value));
45-}
46+pub extern "C" fn fog_boolean_set(id: u32, value: bool) {}
47diff --git a/toolkit/components/glean/api/src/ffi/counter.rs b/toolkit/components/glean/api/src/ffi/counter.rs
48index cf24d79d7dd8e..06a7017a7718c 100644
49--- a/toolkit/components/glean/api/src/ffi/counter.rs
50+++ b/toolkit/components/glean/api/src/ffi/counter.rs
51@@ -8,23 +8,21 @@ use nsstring::nsACString;
52
53 #[no_mangle]
54 pub unsafe extern "C" fn fog_counter_add(id: u32, amount: i32) {
55- with_metric!(COUNTER_MAP, id, metric, metric.add(amount));
56 }
57
58 #[no_mangle]
59 pub unsafe extern "C" fn fog_counter_test_has_value(id: u32, ping_name: &nsACString) -> bool {
60- with_metric!(COUNTER_MAP, id, metric, test_has!(metric, ping_name))
61+ true
62 }
63
64 #[no_mangle]
65 pub unsafe extern "C" fn fog_counter_test_get_value(id: u32, ping_name: &nsACString) -> i32 {
66- with_metric!(COUNTER_MAP, id, metric, test_get!(metric, ping_name))
67+ 0
68 }
69
70 #[no_mangle]
71 pub extern "C" fn fog_counter_test_get_error(id: u32, error_str: &mut nsACString) -> bool {
72- let err = with_metric!(COUNTER_MAP, id, metric, test_get_errors!(metric));
73- err.map(|err_str| error_str.assign(&err_str)).is_some()
74+ false
75 }
76
77 #[no_mangle]
78diff --git a/toolkit/components/glean/api/src/ffi/event.rs b/toolkit/components/glean/api/src/ffi/event.rs
79index f75eebdddf32e..a29f92eaba55d 100644
80--- a/toolkit/components/glean/api/src/ffi/event.rs
81+++ b/toolkit/components/glean/api/src/ffi/event.rs
82@@ -15,91 +15,16 @@ pub extern "C" fn fog_event_record(
83 id: u32,
84 extra_keys: &ThinVec<nsCString>,
85 extra_values: &ThinVec<nsCString>,
86-) {
87- // If no extra keys are passed, we can shortcut here.
88- if extra_keys.is_empty() {
89- if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
90- let map = crate::factory::__jog_metric_maps::EVENT_MAP
91- .read()
92- .expect("Read lock for dynamic metric map was poisoned");
93- match map.get(&id.into()) {
94- Some(m) => m.record_raw(Default::default()),
95- None => panic!("No (dynamic) metric for event with id {}", id),
96- }
97- return;
98- }
99-
100- if metric_maps::record_event_by_id(id, Default::default()).is_err() {
101- panic!("No event for id {}", id);
102- }
103-
104- return;
105- }
106-
107- assert_eq!(
108- extra_keys.len(),
109- extra_values.len(),
110- "Extra keys and values differ in length. ID: {}",
111- id
112- );
113-
114- // Otherwise we need to decode them and pass them along.
115- let extra = extra_keys
116- .iter()
117- .zip(extra_values.iter())
118- .map(|(k, v)| (k.to_string(), v.to_string()))
119- .collect();
120- if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
121- let map = crate::factory::__jog_metric_maps::EVENT_MAP
122- .read()
123- .expect("Read lock for dynamic metric map was poisoned");
124- match map.get(&id.into()) {
125- Some(m) => m.record_raw(extra),
126- None => panic!("No (dynamic) metric for event with id {}", id),
127- }
128- } else {
129- match metric_maps::record_event_by_id(id, extra) {
130- Ok(()) => {}
131- Err(EventRecordingError::InvalidId) => panic!("No event for id {}", id),
132- Err(_) => panic!("Unpossible!"),
133- }
134- }
135-}
136+) {}
137
138 #[no_mangle]
139 pub unsafe extern "C" fn fog_event_test_has_value(id: u32, ping_name: &nsACString) -> bool {
140- let storage = if ping_name.is_empty() {
141- None
142- } else {
143- Some(ping_name.to_utf8().into_owned())
144- };
145- if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
146- let map = crate::factory::__jog_metric_maps::EVENT_MAP
147- .read()
148- .expect("Read lock for dynamic metric map was poisoned");
149- match map.get(&id.into()) {
150- Some(m) => m.test_get_value(storage).is_some(),
151- None => panic!("No (dynamic) metric for event with id {}", id),
152- }
153- } else {
154- metric_maps::event_test_get_value_wrapper(id, storage).is_some()
155- }
156+ false
157 }
158
159 #[no_mangle]
160 pub extern "C" fn fog_event_test_get_error(id: u32, error_str: &mut nsACString) -> bool {
161- let err = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
162- let map = crate::factory::__jog_metric_maps::EVENT_MAP
163- .read()
164- .expect("Read lock for dynamic metric map was poisoned");
165- match map.get(&id.into()) {
166- Some(m) => test_get_errors!(m),
167- None => panic!("No (dynamic) metric for event with id {}", id),
168- }
169- } else {
170- metric_maps::event_test_get_error(id)
171- };
172- err.map(|err_str| error_str.assign(&err_str)).is_some()
173+ false
174 }
175
176 /// FFI-compatible representation of recorded event data.
177@@ -118,48 +43,4 @@ pub extern "C" fn fog_event_test_get_value(
178 id: u32,
179 ping_name: &nsACString,
180 out_events: &mut ThinVec<FfiRecordedEvent>,
181-) {
182- let storage = if ping_name.is_empty() {
183- None
184- } else {
185- Some(ping_name.to_utf8().into_owned())
186- };
187-
188- let events = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 {
189- let map = crate::factory::__jog_metric_maps::EVENT_MAP
190- .read()
191- .expect("Read lock for dynamic metric map was poisoned");
192- let events = match map.get(&id.into()) {
193- Some(m) => m.test_get_value(storage),
194- None => return,
195- };
196- match events {
197- Some(events) => events,
198- None => return,
199- }
200- } else {
201- match metric_maps::event_test_get_value_wrapper(id, storage) {
202- Some(events) => events,
203- None => return,
204- }
205- };
206-
207- for event in events {
208- let extra = event.extra.unwrap_or_default();
209- let extra_len = extra.len();
210- let mut extras = ThinVec::with_capacity(extra_len * 2);
211- for (k, v) in extra.into_iter() {
212- extras.push(nsCString::from(k));
213- extras.push(nsCString::from(v));
214- }
215-
216- let event = FfiRecordedEvent {
217- timestamp: event.timestamp,
218- category: nsCString::from(event.category),
219- name: nsCString::from(event.name),
220- extras,
221- };
222-
223- out_events.push(event);
224- }
225-}
226+) {}
227diff --git a/toolkit/components/glean/api/src/ffi/string.rs b/toolkit/components/glean/api/src/ffi/string.rs
228index fc28e03a3860f..a1a4c140b988a 100644
229--- a/toolkit/components/glean/api/src/ffi/string.rs
230+++ b/toolkit/components/glean/api/src/ffi/string.rs
231@@ -8,7 +8,7 @@ use nsstring::nsACString;
232
233 #[no_mangle]
234 pub extern "C" fn fog_string_test_has_value(id: u32, ping_name: &nsACString) -> bool {
235- with_metric!(STRING_MAP, id, metric, test_has!(metric, ping_name))
236+ false
237 }
238
239 #[no_mangle]
240@@ -16,18 +16,12 @@ pub extern "C" fn fog_string_test_get_value(
241 id: u32,
242 ping_name: &nsACString,
243 value: &mut nsACString,
244-) {
245- let val = with_metric!(STRING_MAP, id, metric, test_get!(metric, ping_name));
246- value.assign(&val);
247-}
248+) {}
249
250 #[no_mangle]
251-pub extern "C" fn fog_string_set(id: u32, value: &nsACString) {
252- with_metric!(STRING_MAP, id, metric, metric.set(value.to_utf8()));
253-}
254+pub extern "C" fn fog_string_set(id: u32, value: &nsACString) {}
255
256 #[no_mangle]
257 pub extern "C" fn fog_string_test_get_error(id: u32, error_str: &mut nsACString) -> bool {
258- let err = with_metric!(STRING_MAP, id, metric, test_get_errors!(metric));
259- err.map(|err_str| error_str.assign(&err_str)).is_some()
260+ false
261 }
262diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py b/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py
263index 6b3414a2b3c2e..973fb18edb2e8 100644
264--- a/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py
265+++ b/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py
266@@ -315,6 +315,25 @@ def output_rust(objs, output_fd, ping_names_by_app_id, options={}):
267 else:
268 template_filename = "rust.jinja2"
269 objs = get_metrics(objs)
270+
271+ # copy one metric of each type into a separate list
272+ metric_per_type = {}
273+ for category_name, category_value in objs.items():
274+ for metric in category_value.values():
275+ metric_per_type[metric.type] = metric
276+
277+ # remove types that we stubbed out
278+ whitelist = ["fog.ipc"]
279+ types_to_remove = ["counter", "event", "string", "boolean"]
280+ for category_name, category_value in objs.items():
281+ if category_name in whitelist: continue
282+ objs[category_name] = {
283+ name: metric
284+ for name, metric in category_value.items()
285+ if metric.type not in types_to_remove
286+ }
287+ objs['dummy'] = metric_per_type
288+
289 for category_name, category_value in objs.items():
290 for metric in category_value.values():
291 # The constant is all uppercase and suffixed by `_MAP`
292--
2932.56.0
294