tawasuyu

sergio/takana

> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…

TOML 1572Shell 203Rust 109Markdown 993728 Definitions

⎇ 607fbbc3494f5b1f0f9908d26f32be0b9c264a39 recipes/firefox-patches/glean-stub.patch 292 lines · 10.4 KB History raw

firefox 154.0 — la cabeza de la familia Gecko (receta, sin construir todavía) 428be5e8d · Sergio ·

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