From: Patrycja Rosa Date: Mon, 1 Jun 2026 19:20:39 +0200 Subject: [PATCH] stub out some glean metrics play stupid games, win `rustc-LLVM ERROR: out of memory` --- .../components/glean/api/src/ffi/boolean.rs | 11 +- .../components/glean/api/src/ffi/counter.rs | 8 +- toolkit/components/glean/api/src/ffi/event.rs | 127 +----------------- .../components/glean/api/src/ffi/string.rs | 14 +- .../build_scripts/glean_parser_ext/rust.py | 19 +++ 5 files changed, 34 insertions(+), 145 deletions(-) diff --git a/toolkit/components/glean/api/src/ffi/boolean.rs b/toolkit/components/glean/api/src/ffi/boolean.rs index 9184b23c0098e..fa13206627272 100644 --- a/toolkit/components/glean/api/src/ffi/boolean.rs +++ b/toolkit/components/glean/api/src/ffi/boolean.rs @@ -8,21 +8,18 @@ use nsstring::nsACString; #[no_mangle] pub extern "C" fn fog_boolean_test_has_value(id: u32, ping_name: &nsACString) -> bool { - with_metric!(BOOLEAN_MAP, id, metric, test_has!(metric, ping_name)) + false } #[no_mangle] pub extern "C" fn fog_boolean_test_get_value(id: u32, ping_name: &nsACString) -> bool { - with_metric!(BOOLEAN_MAP, id, metric, test_get!(metric, ping_name)) + false } #[no_mangle] pub extern "C" fn fog_boolean_test_get_error(id: u32, error_str: &mut nsACString) -> bool { - let err = with_metric!(BOOLEAN_MAP, id, metric, test_get_errors!(metric)); - err.map(|err_str| error_str.assign(&err_str)).is_some() + false } #[no_mangle] -pub extern "C" fn fog_boolean_set(id: u32, value: bool) { - with_metric!(BOOLEAN_MAP, id, metric, metric.set(value)); -} +pub extern "C" fn fog_boolean_set(id: u32, value: bool) {} diff --git a/toolkit/components/glean/api/src/ffi/counter.rs b/toolkit/components/glean/api/src/ffi/counter.rs index cf24d79d7dd8e..06a7017a7718c 100644 --- a/toolkit/components/glean/api/src/ffi/counter.rs +++ b/toolkit/components/glean/api/src/ffi/counter.rs @@ -8,23 +8,21 @@ use nsstring::nsACString; #[no_mangle] pub unsafe extern "C" fn fog_counter_add(id: u32, amount: i32) { - with_metric!(COUNTER_MAP, id, metric, metric.add(amount)); } #[no_mangle] pub unsafe extern "C" fn fog_counter_test_has_value(id: u32, ping_name: &nsACString) -> bool { - with_metric!(COUNTER_MAP, id, metric, test_has!(metric, ping_name)) + true } #[no_mangle] pub unsafe extern "C" fn fog_counter_test_get_value(id: u32, ping_name: &nsACString) -> i32 { - with_metric!(COUNTER_MAP, id, metric, test_get!(metric, ping_name)) + 0 } #[no_mangle] pub extern "C" fn fog_counter_test_get_error(id: u32, error_str: &mut nsACString) -> bool { - let err = with_metric!(COUNTER_MAP, id, metric, test_get_errors!(metric)); - err.map(|err_str| error_str.assign(&err_str)).is_some() + false } #[no_mangle] diff --git a/toolkit/components/glean/api/src/ffi/event.rs b/toolkit/components/glean/api/src/ffi/event.rs index f75eebdddf32e..a29f92eaba55d 100644 --- a/toolkit/components/glean/api/src/ffi/event.rs +++ b/toolkit/components/glean/api/src/ffi/event.rs @@ -15,91 +15,16 @@ pub extern "C" fn fog_event_record( id: u32, extra_keys: &ThinVec, extra_values: &ThinVec, -) { - // If no extra keys are passed, we can shortcut here. - if extra_keys.is_empty() { - if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 { - let map = crate::factory::__jog_metric_maps::EVENT_MAP - .read() - .expect("Read lock for dynamic metric map was poisoned"); - match map.get(&id.into()) { - Some(m) => m.record_raw(Default::default()), - None => panic!("No (dynamic) metric for event with id {}", id), - } - return; - } - - if metric_maps::record_event_by_id(id, Default::default()).is_err() { - panic!("No event for id {}", id); - } - - return; - } - - assert_eq!( - extra_keys.len(), - extra_values.len(), - "Extra keys and values differ in length. ID: {}", - id - ); - - // Otherwise we need to decode them and pass them along. - let extra = extra_keys - .iter() - .zip(extra_values.iter()) - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 { - let map = crate::factory::__jog_metric_maps::EVENT_MAP - .read() - .expect("Read lock for dynamic metric map was poisoned"); - match map.get(&id.into()) { - Some(m) => m.record_raw(extra), - None => panic!("No (dynamic) metric for event with id {}", id), - } - } else { - match metric_maps::record_event_by_id(id, extra) { - Ok(()) => {} - Err(EventRecordingError::InvalidId) => panic!("No event for id {}", id), - Err(_) => panic!("Unpossible!"), - } - } -} +) {} #[no_mangle] pub unsafe extern "C" fn fog_event_test_has_value(id: u32, ping_name: &nsACString) -> bool { - let storage = if ping_name.is_empty() { - None - } else { - Some(ping_name.to_utf8().into_owned()) - }; - if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 { - let map = crate::factory::__jog_metric_maps::EVENT_MAP - .read() - .expect("Read lock for dynamic metric map was poisoned"); - match map.get(&id.into()) { - Some(m) => m.test_get_value(storage).is_some(), - None => panic!("No (dynamic) metric for event with id {}", id), - } - } else { - metric_maps::event_test_get_value_wrapper(id, storage).is_some() - } + false } #[no_mangle] pub extern "C" fn fog_event_test_get_error(id: u32, error_str: &mut nsACString) -> bool { - let err = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 { - let map = crate::factory::__jog_metric_maps::EVENT_MAP - .read() - .expect("Read lock for dynamic metric map was poisoned"); - match map.get(&id.into()) { - Some(m) => test_get_errors!(m), - None => panic!("No (dynamic) metric for event with id {}", id), - } - } else { - metric_maps::event_test_get_error(id) - }; - err.map(|err_str| error_str.assign(&err_str)).is_some() + false } /// FFI-compatible representation of recorded event data. @@ -118,48 +43,4 @@ pub extern "C" fn fog_event_test_get_value( id: u32, ping_name: &nsACString, out_events: &mut ThinVec, -) { - let storage = if ping_name.is_empty() { - None - } else { - Some(ping_name.to_utf8().into_owned()) - }; - - let events = if id & (1 << crate::factory::DYNAMIC_METRIC_BIT) > 0 { - let map = crate::factory::__jog_metric_maps::EVENT_MAP - .read() - .expect("Read lock for dynamic metric map was poisoned"); - let events = match map.get(&id.into()) { - Some(m) => m.test_get_value(storage), - None => return, - }; - match events { - Some(events) => events, - None => return, - } - } else { - match metric_maps::event_test_get_value_wrapper(id, storage) { - Some(events) => events, - None => return, - } - }; - - for event in events { - let extra = event.extra.unwrap_or_default(); - let extra_len = extra.len(); - let mut extras = ThinVec::with_capacity(extra_len * 2); - for (k, v) in extra.into_iter() { - extras.push(nsCString::from(k)); - extras.push(nsCString::from(v)); - } - - let event = FfiRecordedEvent { - timestamp: event.timestamp, - category: nsCString::from(event.category), - name: nsCString::from(event.name), - extras, - }; - - out_events.push(event); - } -} +) {} diff --git a/toolkit/components/glean/api/src/ffi/string.rs b/toolkit/components/glean/api/src/ffi/string.rs index fc28e03a3860f..a1a4c140b988a 100644 --- a/toolkit/components/glean/api/src/ffi/string.rs +++ b/toolkit/components/glean/api/src/ffi/string.rs @@ -8,7 +8,7 @@ use nsstring::nsACString; #[no_mangle] pub extern "C" fn fog_string_test_has_value(id: u32, ping_name: &nsACString) -> bool { - with_metric!(STRING_MAP, id, metric, test_has!(metric, ping_name)) + false } #[no_mangle] @@ -16,18 +16,12 @@ pub extern "C" fn fog_string_test_get_value( id: u32, ping_name: &nsACString, value: &mut nsACString, -) { - let val = with_metric!(STRING_MAP, id, metric, test_get!(metric, ping_name)); - value.assign(&val); -} +) {} #[no_mangle] -pub extern "C" fn fog_string_set(id: u32, value: &nsACString) { - with_metric!(STRING_MAP, id, metric, metric.set(value.to_utf8())); -} +pub extern "C" fn fog_string_set(id: u32, value: &nsACString) {} #[no_mangle] pub extern "C" fn fog_string_test_get_error(id: u32, error_str: &mut nsACString) -> bool { - let err = with_metric!(STRING_MAP, id, metric, test_get_errors!(metric)); - err.map(|err_str| error_str.assign(&err_str)).is_some() + false } diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py b/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py index e37f704e502ba..ebaf0e84e4bd1 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/rust.py @@ -299,6 +299,25 @@ def output_rust(objs, output_fd, ping_names_by_app_id, options={}): else: template_filename = "rust.jinja2" objs = get_metrics(objs) + + # copy one metric of each type into a separate list + metric_per_type = {} + for category_name, category_value in objs.items(): + for metric in category_value.values(): + metric_per_type[metric.type] = metric + + # remove types that we stubbed out + whitelist = ["fog.ipc"] + types_to_remove = ["counter", "event", "string", "boolean"] + for category_name, category_value in objs.items(): + if category_name in whitelist: continue + objs[category_name] = { + name: metric + for name, metric in category_value.items() + if metric.type not in types_to_remove + } + objs['dummy'] = metric_per_type + for category_name, category_value in objs.items(): for metric in category_value.values(): # The constant is all uppercase and suffixed by `_MAP` -- 2.54.0