From d8286bd8793f4bca2991067247d12051395d0b1c Mon Sep 17 00:00:00 2001 From: Cameron Bytheway Date: Mon, 4 Nov 2024 10:37:16 -0700 Subject: [PATCH] pr feedback --- dc/s2n-quic-dc/events/connection.rs | 12 +- .../src/event/generated/metrics/aggregate.rs | 188 +++---- .../src/event/generated/metrics/probe.rs | 36 +- quic/s2n-quic-core/events/connection.rs | 4 +- .../src/event/generated/metrics/aggregate.rs | 492 +++++++++--------- .../src/event/generated/metrics/probe.rs | 12 +- .../src/event/metrics/aggregate/info.rs | 81 ++- .../event/metrics/aggregate/probe/dynamic.rs | 4 +- .../src/output/metrics/aggregate.rs | 52 +- 9 files changed, 462 insertions(+), 419 deletions(-) diff --git a/dc/s2n-quic-dc/events/connection.rs b/dc/s2n-quic-dc/events/connection.rs index a38fb193b..c90c6d9c3 100644 --- a/dc/s2n-quic-dc/events/connection.rs +++ b/dc/s2n-quic-dc/events/connection.rs @@ -4,23 +4,23 @@ #[event("application:write")] pub struct ApplicationWrite { /// The number of bytes that the application tried to write - #[measure("bytes.provided", "b")] + #[measure("provided", "b")] total_len: usize, /// The amount that was written - #[measure("bytes", "b")] - #[counter("bytes.total", "b")] + #[measure("committed", "b")] + #[counter("committed.total", "b")] write_len: usize, } #[event("application:read")] pub struct ApplicationRead { /// The number of bytes that the application tried to read - #[measure("bytes.capacity", "b")] + #[measure("capacity", "b")] capacity: usize, /// The amount that was read - #[measure("bytes", "b")] - #[counter("bytes.total", "b")] + #[measure("committed", "b")] + #[counter("committed.total", "b")] read_len: usize, } diff --git a/dc/s2n-quic-dc/src/event/generated/metrics/aggregate.rs b/dc/s2n-quic-dc/src/event/generated/metrics/aggregate.rs index 5fbe98f71..b0996e845 100644 --- a/dc/s2n-quic-dc/src/event/generated/metrics/aggregate.rs +++ b/dc/s2n-quic-dc/src/event/generated/metrics/aggregate.rs @@ -7,238 +7,238 @@ use crate::event::{ self, api, - metrics::aggregate::{info, AsMetric as _, Info, Recorder, Registry}, + metrics::aggregate::{ + info::{self, Str}, + AsMetric as _, Info, Recorder, Registry, + }, }; -const fn new_str(bytes: &'static str) -> info::Str<'static> { - unsafe { info::Str::new_unchecked(bytes) } -} static INFO: &[Info; 36usize] = &[ info::Builder { id: 0usize, - name: new_str("application_write\0"), - units: new_str("\0"), + name: Str::new("application_write\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 1usize, - name: new_str("application_write.bytes.provided\0"), - units: new_str("b\0"), + name: Str::new("application_write.provided\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 2usize, - name: new_str("application_write.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("application_write.committed.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 3usize, - name: new_str("application_write.bytes\0"), - units: new_str("b\0"), + name: Str::new("application_write.committed\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 4usize, - name: new_str("application_read\0"), - units: new_str("\0"), + name: Str::new("application_read\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 5usize, - name: new_str("application_read.bytes.capacity\0"), - units: new_str("b\0"), + name: Str::new("application_read.capacity\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 6usize, - name: new_str("application_read.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("application_read.committed.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 7usize, - name: new_str("application_read.bytes\0"), - units: new_str("b\0"), + name: Str::new("application_read.committed\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 8usize, - name: new_str("endpoint_initialized\0"), - units: new_str("\0"), + name: Str::new("endpoint_initialized\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 9usize, - name: new_str("path_secret_map_initialized\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_initialized\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 10usize, - name: new_str("path_secret_map_initialized.capacity\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_initialized.capacity\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 11usize, - name: new_str("path_secret_map_uninitialized\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_uninitialized\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 12usize, - name: new_str("path_secret_map_uninitialized.capacity\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_uninitialized.capacity\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 13usize, - name: new_str("path_secret_map_uninitialized.entries\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_uninitialized.entries\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 14usize, - name: new_str("path_secret_map_background_handshake_requested\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_background_handshake_requested\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 15usize, - name: new_str("path_secret_map_entry_inserted\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_entry_inserted\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 16usize, - name: new_str("path_secret_map_entry_ready\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_entry_ready\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 17usize, - name: new_str("path_secret_map_entry_replaced\0"), - units: new_str("\0"), + name: Str::new("path_secret_map_entry_replaced\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 18usize, - name: new_str("unknown_path_secret_packet_sent\0"), - units: new_str("\0"), + name: Str::new("unknown_path_secret_packet_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 19usize, - name: new_str("unknown_path_secret_packet_received\0"), - units: new_str("\0"), + name: Str::new("unknown_path_secret_packet_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 20usize, - name: new_str("unknown_path_secret_packet_accepted\0"), - units: new_str("\0"), + name: Str::new("unknown_path_secret_packet_accepted\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 21usize, - name: new_str("unknown_path_secret_packet_rejected\0"), - units: new_str("\0"), + name: Str::new("unknown_path_secret_packet_rejected\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 22usize, - name: new_str("unknown_path_secret_packet_dropped\0"), - units: new_str("\0"), + name: Str::new("unknown_path_secret_packet_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 23usize, - name: new_str("replay_definitely_detected\0"), - units: new_str("\0"), + name: Str::new("replay_definitely_detected\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 24usize, - name: new_str("replay_potentially_detected\0"), - units: new_str("\0"), + name: Str::new("replay_potentially_detected\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 25usize, - name: new_str("replay_potentially_detected.gap\0"), - units: new_str("\0"), + name: Str::new("replay_potentially_detected.gap\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 26usize, - name: new_str("replay_detected_packet_sent\0"), - units: new_str("\0"), + name: Str::new("replay_detected_packet_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 27usize, - name: new_str("replay_detected_packet_received\0"), - units: new_str("\0"), + name: Str::new("replay_detected_packet_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 28usize, - name: new_str("replay_detected_packet_accepted\0"), - units: new_str("\0"), + name: Str::new("replay_detected_packet_accepted\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 29usize, - name: new_str("replay_detected_packet_rejected\0"), - units: new_str("\0"), + name: Str::new("replay_detected_packet_rejected\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 30usize, - name: new_str("replay_detected_packet_dropped\0"), - units: new_str("\0"), + name: Str::new("replay_detected_packet_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 31usize, - name: new_str("stale_key_packet_sent\0"), - units: new_str("\0"), + name: Str::new("stale_key_packet_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 32usize, - name: new_str("stale_key_packet_received\0"), - units: new_str("\0"), + name: Str::new("stale_key_packet_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 33usize, - name: new_str("stale_key_packet_accepted\0"), - units: new_str("\0"), + name: Str::new("stale_key_packet_accepted\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 34usize, - name: new_str("stale_key_packet_rejected\0"), - units: new_str("\0"), + name: Str::new("stale_key_packet_rejected\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 35usize, - name: new_str("stale_key_packet_dropped\0"), - units: new_str("\0"), + name: Str::new("stale_key_packet_dropped\0"), + units: Str::new("\0"), } .build(), ]; pub struct Subscriber { #[allow(dead_code)] - counters: Box<[R::Counter]>, + counters: Box<[R::Counter; 28usize]>, #[allow(dead_code)] - measures: Box<[R::Measure]>, + measures: Box<[R::Measure; 8usize]>, #[allow(dead_code)] - gauges: Box<[R::Gauge]>, + gauges: Box<[R::Gauge; 0usize]>, #[allow(dead_code)] - timers: Box<[R::Timer]>, + timers: Box<[R::Timer; 0usize]>, #[allow(dead_code)] registry: R, } @@ -298,10 +298,14 @@ impl Subscriber { measures.push(registry.register_measure(&INFO[13usize])); measures.push(registry.register_measure(&INFO[25usize])); Self { - counters: counters.into(), - measures: measures.into(), - gauges: gauges.into(), - timers: timers.into(), + counters: counters + .try_into() + .unwrap_or_else(|_| panic!("invalid len")), + measures: measures + .try_into() + .unwrap_or_else(|_| panic!("invalid len")), + gauges: gauges.try_into().unwrap_or_else(|_| panic!("invalid len")), + timers: timers.try_into().unwrap_or_else(|_| panic!("invalid len")), registry, } } @@ -346,8 +350,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn count(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let counter = unsafe { self.counters.get_unchecked(id) }; + let info = &INFO[info]; + let counter = &self.counters[id]; counter.record(info, value); } #[doc = r" Returns all of the registered measures"] @@ -371,8 +375,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn measure(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let measure = unsafe { self.measures.get_unchecked(id) }; + let info = &INFO[info]; + let measure = &self.measures[id]; measure.record(info, value); } #[doc = r" Returns all of the registered gauges"] @@ -383,8 +387,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn gauge(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let gauge = unsafe { self.gauges.get_unchecked(id) }; + let info = &INFO[info]; + let gauge = &self.gauges[id]; gauge.record(info, value); } #[doc = r" Returns all of the registered timers"] @@ -395,8 +399,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn time(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let timer = unsafe { self.timers.get_unchecked(id) }; + let info = &INFO[info]; + let timer = &self.timers[id]; timer.record(info, value); } } diff --git a/dc/s2n-quic-dc/src/event/generated/metrics/probe.rs b/dc/s2n-quic-dc/src/event/generated/metrics/probe.rs index dc0614214..22bad2768 100644 --- a/dc/s2n-quic-dc/src/event/generated/metrics/probe.rs +++ b/dc/s2n-quic-dc/src/event/generated/metrics/probe.rs @@ -15,9 +15,9 @@ mod counter { pub(super) fn new(info: &'static Info) -> Self { match info.id { 0usize => Self(application_write), - 2usize => Self(application_write__bytes__total), + 2usize => Self(application_write__committed__total), 4usize => Self(application_read), - 6usize => Self(application_read__bytes__total), + 6usize => Self(application_read__committed__total), 8usize => Self(endpoint_initialized), 9usize => Self(path_secret_map_initialized), 11usize => Self(path_secret_map_uninitialized), @@ -55,12 +55,12 @@ mod counter { extern "probe" { # [link_name = s2n_quic_dc__event__counter__application_write] fn application_write(value: u64); - # [link_name = s2n_quic_dc__event__counter__application_write__bytes__total] - fn application_write__bytes__total(value: u64); + # [link_name = s2n_quic_dc__event__counter__application_write__committed__total] + fn application_write__committed__total(value: u64); # [link_name = s2n_quic_dc__event__counter__application_read] fn application_read(value: u64); - # [link_name = s2n_quic_dc__event__counter__application_read__bytes__total] - fn application_read__bytes__total(value: u64); + # [link_name = s2n_quic_dc__event__counter__application_read__committed__total] + fn application_read__committed__total(value: u64); # [link_name = s2n_quic_dc__event__counter__endpoint_initialized] fn endpoint_initialized(value: u64); # [link_name = s2n_quic_dc__event__counter__path_secret_map_initialized] @@ -119,10 +119,10 @@ mod measure { impl Recorder { pub(super) fn new(info: &'static Info) -> Self { match info.id { - 1usize => Self(application_write__bytes__provided), - 3usize => Self(application_write__bytes), - 5usize => Self(application_read__bytes__capacity), - 7usize => Self(application_read__bytes), + 1usize => Self(application_write__provided), + 3usize => Self(application_write__committed), + 5usize => Self(application_read__capacity), + 7usize => Self(application_read__committed), 10usize => Self(path_secret_map_initialized__capacity), 12usize => Self(path_secret_map_uninitialized__capacity), 13usize => Self(path_secret_map_uninitialized__entries), @@ -138,14 +138,14 @@ mod measure { } super::define!( extern "probe" { - # [link_name = s2n_quic_dc__event__measure__application_write__bytes__provided] - fn application_write__bytes__provided(value: u64); - # [link_name = s2n_quic_dc__event__measure__application_write__bytes] - fn application_write__bytes(value: u64); - # [link_name = s2n_quic_dc__event__measure__application_read__bytes__capacity] - fn application_read__bytes__capacity(value: u64); - # [link_name = s2n_quic_dc__event__measure__application_read__bytes] - fn application_read__bytes(value: u64); + # [link_name = s2n_quic_dc__event__measure__application_write__provided] + fn application_write__provided(value: u64); + # [link_name = s2n_quic_dc__event__measure__application_write__committed] + fn application_write__committed(value: u64); + # [link_name = s2n_quic_dc__event__measure__application_read__capacity] + fn application_read__capacity(value: u64); + # [link_name = s2n_quic_dc__event__measure__application_read__committed] + fn application_read__committed(value: u64); # [link_name = s2n_quic_dc__event__measure__path_secret_map_initialized__capacity] fn path_secret_map_initialized__capacity(value: u64); # [link_name = s2n_quic_dc__event__measure__path_secret_map_uninitialized__capacity] diff --git a/quic/s2n-quic-core/events/connection.rs b/quic/s2n-quic-core/events/connection.rs index 0a9d85257..6c0c525e1 100644 --- a/quic/s2n-quic-core/events/connection.rs +++ b/quic/s2n-quic-core/events/connection.rs @@ -87,8 +87,8 @@ struct FrameReceived<'a> { struct PacketLost<'a> { packet_header: PacketHeader, path: Path<'a>, - #[measure("bytes_lost", "b")] - #[counter("bytes_lost.total", "b")] + #[measure("bytes", "b")] + #[counter("bytes.total", "b")] bytes_lost: u16, is_mtu_probe: bool, } diff --git a/quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs b/quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs index eff9089b7..45c267ced 100644 --- a/quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs +++ b/quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs @@ -7,695 +7,695 @@ use crate::event::{ self, api, - metrics::aggregate::{info, AsMetric as _, Info, Recorder, Registry}, + metrics::aggregate::{ + info::{self, Str}, + AsMetric as _, Info, Recorder, Registry, + }, }; use alloc::{boxed::Box, vec::Vec}; -const fn new_str(bytes: &'static str) -> info::Str<'static> { - unsafe { info::Str::new_unchecked(bytes) } -} static INFO: &[Info; 112usize] = &[ info::Builder { id: 0usize, - name: new_str("application_protocol_information\0"), - units: new_str("\0"), + name: Str::new("application_protocol_information\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 1usize, - name: new_str("server_name_information\0"), - units: new_str("\0"), + name: Str::new("server_name_information\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 2usize, - name: new_str("packet_skipped\0"), - units: new_str("\0"), + name: Str::new("packet_skipped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 3usize, - name: new_str("packet_sent\0"), - units: new_str("\0"), + name: Str::new("packet_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 4usize, - name: new_str("packet_sent.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("packet_sent.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 5usize, - name: new_str("packet_sent.bytes\0"), - units: new_str("b\0"), + name: Str::new("packet_sent.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 6usize, - name: new_str("packet_received\0"), - units: new_str("\0"), + name: Str::new("packet_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 7usize, - name: new_str("active_path_updated\0"), - units: new_str("\0"), + name: Str::new("active_path_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 8usize, - name: new_str("path_created\0"), - units: new_str("\0"), + name: Str::new("path_created\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 9usize, - name: new_str("frame_sent\0"), - units: new_str("\0"), + name: Str::new("frame_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 10usize, - name: new_str("frame_received\0"), - units: new_str("\0"), + name: Str::new("frame_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 11usize, - name: new_str("packet_lost\0"), - units: new_str("\0"), + name: Str::new("packet_lost\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 12usize, - name: new_str("packet_lost.bytes_lost.total\0"), - units: new_str("b\0"), + name: Str::new("packet_lost.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 13usize, - name: new_str("packet_lost.bytes_lost\0"), - units: new_str("b\0"), + name: Str::new("packet_lost.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 14usize, - name: new_str("recovery_metrics\0"), - units: new_str("\0"), + name: Str::new("recovery_metrics\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 15usize, - name: new_str("recovery_metrics.min_rtt\0"), - units: new_str("us\0"), + name: Str::new("recovery_metrics.min_rtt\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 16usize, - name: new_str("recovery_metrics.smoothed_rtt\0"), - units: new_str("us\0"), + name: Str::new("recovery_metrics.smoothed_rtt\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 17usize, - name: new_str("recovery_metrics.latest_rtt\0"), - units: new_str("us\0"), + name: Str::new("recovery_metrics.latest_rtt\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 18usize, - name: new_str("recovery_metrics.rtt_variance\0"), - units: new_str("us\0"), + name: Str::new("recovery_metrics.rtt_variance\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 19usize, - name: new_str("recovery_metrics.max_ack_delay\0"), - units: new_str("us\0"), + name: Str::new("recovery_metrics.max_ack_delay\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 20usize, - name: new_str("recovery_metrics.pto_count\0"), - units: new_str("\0"), + name: Str::new("recovery_metrics.pto_count\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 21usize, - name: new_str("recovery_metrics.congestion_window\0"), - units: new_str("b\0"), + name: Str::new("recovery_metrics.congestion_window\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 22usize, - name: new_str("recovery_metrics.bytes_in_flight\0"), - units: new_str("b\0"), + name: Str::new("recovery_metrics.bytes_in_flight\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 23usize, - name: new_str("congestion\0"), - units: new_str("\0"), + name: Str::new("congestion\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 24usize, - name: new_str("rx_ack_range_dropped\0"), - units: new_str("\0"), + name: Str::new("rx_ack_range_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 25usize, - name: new_str("ack_range_received\0"), - units: new_str("\0"), + name: Str::new("ack_range_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 26usize, - name: new_str("ack_range_sent\0"), - units: new_str("\0"), + name: Str::new("ack_range_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 27usize, - name: new_str("packet_dropped\0"), - units: new_str("\0"), + name: Str::new("packet_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 28usize, - name: new_str("key_update\0"), - units: new_str("\0"), + name: Str::new("key_update\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 29usize, - name: new_str("key_space_discarded\0"), - units: new_str("\0"), + name: Str::new("key_space_discarded\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 30usize, - name: new_str("connection_started\0"), - units: new_str("\0"), + name: Str::new("connection_started\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 31usize, - name: new_str("connection_closed\0"), - units: new_str("\0"), + name: Str::new("connection_closed\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 32usize, - name: new_str("duplicate_packet\0"), - units: new_str("\0"), + name: Str::new("duplicate_packet\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 33usize, - name: new_str("transport_parameters_received\0"), - units: new_str("\0"), + name: Str::new("transport_parameters_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 34usize, - name: new_str("datagram_sent\0"), - units: new_str("\0"), + name: Str::new("datagram_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 35usize, - name: new_str("datagram_sent.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("datagram_sent.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 36usize, - name: new_str("datagram_sent.bytes\0"), - units: new_str("b\0"), + name: Str::new("datagram_sent.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 37usize, - name: new_str("datagram_sent.gso_offset\0"), - units: new_str("\0"), + name: Str::new("datagram_sent.gso_offset\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 38usize, - name: new_str("datagram_received\0"), - units: new_str("\0"), + name: Str::new("datagram_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 39usize, - name: new_str("datagram_received.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("datagram_received.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 40usize, - name: new_str("datagram_received.bytes\0"), - units: new_str("b\0"), + name: Str::new("datagram_received.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 41usize, - name: new_str("datagram_dropped\0"), - units: new_str("\0"), + name: Str::new("datagram_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 42usize, - name: new_str("datagram_dropped.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("datagram_dropped.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 43usize, - name: new_str("datagram_dropped.bytes\0"), - units: new_str("b\0"), + name: Str::new("datagram_dropped.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 44usize, - name: new_str("connection_id_updated\0"), - units: new_str("\0"), + name: Str::new("connection_id_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 45usize, - name: new_str("ecn_state_changed\0"), - units: new_str("\0"), + name: Str::new("ecn_state_changed\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 46usize, - name: new_str("connection_migration_denied\0"), - units: new_str("\0"), + name: Str::new("connection_migration_denied\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 47usize, - name: new_str("handshake_status_updated\0"), - units: new_str("\0"), + name: Str::new("handshake_status_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 48usize, - name: new_str("tls_exporter_ready\0"), - units: new_str("\0"), + name: Str::new("tls_exporter_ready\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 49usize, - name: new_str("path_challenge_updated\0"), - units: new_str("\0"), + name: Str::new("path_challenge_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 50usize, - name: new_str("tls_client_hello\0"), - units: new_str("\0"), + name: Str::new("tls_client_hello\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 51usize, - name: new_str("tls_server_hello\0"), - units: new_str("\0"), + name: Str::new("tls_server_hello\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 52usize, - name: new_str("rx_stream_progress\0"), - units: new_str("\0"), + name: Str::new("rx_stream_progress\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 53usize, - name: new_str("rx_stream_progress.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("rx_stream_progress.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 54usize, - name: new_str("rx_stream_progress.bytes\0"), - units: new_str("b\0"), + name: Str::new("rx_stream_progress.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 55usize, - name: new_str("tx_stream_progress\0"), - units: new_str("\0"), + name: Str::new("tx_stream_progress\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 56usize, - name: new_str("tx_stream_progress.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("tx_stream_progress.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 57usize, - name: new_str("tx_stream_progress.bytes\0"), - units: new_str("b\0"), + name: Str::new("tx_stream_progress.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 58usize, - name: new_str("keep_alive_timer_expired\0"), - units: new_str("\0"), + name: Str::new("keep_alive_timer_expired\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 59usize, - name: new_str("mtu_updated\0"), - units: new_str("\0"), + name: Str::new("mtu_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 60usize, - name: new_str("mtu_updated.mtu\0"), - units: new_str("b\0"), + name: Str::new("mtu_updated.mtu\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 61usize, - name: new_str("slow_start_exited\0"), - units: new_str("\0"), + name: Str::new("slow_start_exited\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 62usize, - name: new_str("slow_start_exited.congestion_window\0"), - units: new_str("b\0"), + name: Str::new("slow_start_exited.congestion_window\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 63usize, - name: new_str("delivery_rate_sampled\0"), - units: new_str("\0"), + name: Str::new("delivery_rate_sampled\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 64usize, - name: new_str("pacing_rate_updated\0"), - units: new_str("\0"), + name: Str::new("pacing_rate_updated\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 65usize, - name: new_str("pacing_rate_updated.bytes_per_second\0"), - units: new_str("b\0"), + name: Str::new("pacing_rate_updated.bytes_per_second\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 66usize, - name: new_str("pacing_rate_updated.burst_size\0"), - units: new_str("b\0"), + name: Str::new("pacing_rate_updated.burst_size\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 67usize, - name: new_str("bbr_state_changed\0"), - units: new_str("\0"), + name: Str::new("bbr_state_changed\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 68usize, - name: new_str("dc_state_changed\0"), - units: new_str("\0"), + name: Str::new("dc_state_changed\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 69usize, - name: new_str("version_information\0"), - units: new_str("\0"), + name: Str::new("version_information\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 70usize, - name: new_str("endpoint_packet_sent\0"), - units: new_str("\0"), + name: Str::new("endpoint_packet_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 71usize, - name: new_str("endpoint_packet_received\0"), - units: new_str("\0"), + name: Str::new("endpoint_packet_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 72usize, - name: new_str("endpoint_datagram_sent\0"), - units: new_str("\0"), + name: Str::new("endpoint_datagram_sent\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 73usize, - name: new_str("endpoint_datagram_sent.bytes\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_sent.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 74usize, - name: new_str("endpoint_datagram_sent.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_sent.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 75usize, - name: new_str("endpoint_datagram_sent.gso_offset\0"), - units: new_str("\0"), + name: Str::new("endpoint_datagram_sent.gso_offset\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 76usize, - name: new_str("endpoint_datagram_received\0"), - units: new_str("\0"), + name: Str::new("endpoint_datagram_received\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 77usize, - name: new_str("endpoint_datagram_received.bytes\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_received.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 78usize, - name: new_str("endpoint_datagram_received.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_received.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 79usize, - name: new_str("endpoint_datagram_dropped\0"), - units: new_str("\0"), + name: Str::new("endpoint_datagram_dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 80usize, - name: new_str("endpoint_datagram_dropped.bytes\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_dropped.bytes\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 81usize, - name: new_str("endpoint_datagram_dropped.bytes.total\0"), - units: new_str("b\0"), + name: Str::new("endpoint_datagram_dropped.bytes.total\0"), + units: Str::new("b\0"), } .build(), info::Builder { id: 82usize, - name: new_str("endpoint_connection_attempt_failed\0"), - units: new_str("\0"), + name: Str::new("endpoint_connection_attempt_failed\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 83usize, - name: new_str("platform_tx\0"), - units: new_str("\0"), + name: Str::new("platform_tx\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 84usize, - name: new_str("platform_tx.packets.total\0"), - units: new_str("\0"), + name: Str::new("platform_tx.packets.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 85usize, - name: new_str("platform_tx.packets\0"), - units: new_str("\0"), + name: Str::new("platform_tx.packets\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 86usize, - name: new_str("platform_tx.syscalls.total\0"), - units: new_str("\0"), + name: Str::new("platform_tx.syscalls.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 87usize, - name: new_str("platform_tx.syscalls\0"), - units: new_str("\0"), + name: Str::new("platform_tx.syscalls\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 88usize, - name: new_str("platform_tx.syscalls.blocked.total\0"), - units: new_str("\0"), + name: Str::new("platform_tx.syscalls.blocked.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 89usize, - name: new_str("platform_tx.syscalls.blocked\0"), - units: new_str("\0"), + name: Str::new("platform_tx.syscalls.blocked\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 90usize, - name: new_str("platform_tx.errors.total\0"), - units: new_str("\0"), + name: Str::new("platform_tx.errors.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 91usize, - name: new_str("platform_tx.errors\0"), - units: new_str("\0"), + name: Str::new("platform_tx.errors\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 92usize, - name: new_str("platform_tx.errors.dropped.total\0"), - units: new_str("\0"), + name: Str::new("platform_tx.errors.dropped.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 93usize, - name: new_str("platform_tx.errors.dropped\0"), - units: new_str("\0"), + name: Str::new("platform_tx.errors.dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 94usize, - name: new_str("platform_tx_error\0"), - units: new_str("\0"), + name: Str::new("platform_tx_error\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 95usize, - name: new_str("platform_rx\0"), - units: new_str("\0"), + name: Str::new("platform_rx\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 96usize, - name: new_str("platform_rx.packets.total\0"), - units: new_str("\0"), + name: Str::new("platform_rx.packets.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 97usize, - name: new_str("platform_rx.packets\0"), - units: new_str("\0"), + name: Str::new("platform_rx.packets\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 98usize, - name: new_str("platform_rx.syscalls.total\0"), - units: new_str("\0"), + name: Str::new("platform_rx.syscalls.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 99usize, - name: new_str("platform_rx.syscalls\0"), - units: new_str("\0"), + name: Str::new("platform_rx.syscalls\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 100usize, - name: new_str("platform_rx.syscalls.blocked.total\0"), - units: new_str("\0"), + name: Str::new("platform_rx.syscalls.blocked.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 101usize, - name: new_str("platform_rx.syscalls.blocked\0"), - units: new_str("\0"), + name: Str::new("platform_rx.syscalls.blocked\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 102usize, - name: new_str("platform_rx.errors.total\0"), - units: new_str("\0"), + name: Str::new("platform_rx.errors.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 103usize, - name: new_str("platform_rx.errors\0"), - units: new_str("\0"), + name: Str::new("platform_rx.errors\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 104usize, - name: new_str("platform_rx.errors.dropped.total\0"), - units: new_str("\0"), + name: Str::new("platform_rx.errors.dropped.total\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 105usize, - name: new_str("platform_rx.errors.dropped\0"), - units: new_str("\0"), + name: Str::new("platform_rx.errors.dropped\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 106usize, - name: new_str("platform_rx_error\0"), - units: new_str("\0"), + name: Str::new("platform_rx_error\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 107usize, - name: new_str("platform_feature_configured\0"), - units: new_str("\0"), + name: Str::new("platform_feature_configured\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 108usize, - name: new_str("platform_event_loop_wakeup\0"), - units: new_str("\0"), + name: Str::new("platform_event_loop_wakeup\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 109usize, - name: new_str("platform_event_loop_sleep\0"), - units: new_str("\0"), + name: Str::new("platform_event_loop_sleep\0"), + units: Str::new("\0"), } .build(), info::Builder { id: 110usize, - name: new_str("platform_event_loop_sleep.processing_duration\0"), - units: new_str("us\0"), + name: Str::new("platform_event_loop_sleep.processing_duration\0"), + units: Str::new("us\0"), } .build(), info::Builder { id: 111usize, - name: new_str("platform_event_loop_started\0"), - units: new_str("\0"), + name: Str::new("platform_event_loop_started\0"), + units: Str::new("\0"), } .build(), ]; pub struct Subscriber { #[allow(dead_code)] - counters: Box<[R::Counter]>, + counters: Box<[R::Counter; 74usize]>, #[allow(dead_code)] - measures: Box<[R::Measure]>, + measures: Box<[R::Measure; 37usize]>, #[allow(dead_code)] - gauges: Box<[R::Gauge]>, + gauges: Box<[R::Gauge; 0usize]>, #[allow(dead_code)] - timers: Box<[R::Timer]>, + timers: Box<[R::Timer; 1usize]>, #[allow(dead_code)] registry: R, } @@ -831,10 +831,14 @@ impl Subscriber { measures.push(registry.register_measure(&INFO[105usize])); timers.push(registry.register_timer(&INFO[110usize])); Self { - counters: counters.into(), - measures: measures.into(), - gauges: gauges.into(), - timers: timers.into(), + counters: counters + .try_into() + .unwrap_or_else(|_| panic!("invalid len")), + measures: measures + .try_into() + .unwrap_or_else(|_| panic!("invalid len")), + gauges: gauges.try_into().unwrap_or_else(|_| panic!("invalid len")), + timers: timers.try_into().unwrap_or_else(|_| panic!("invalid len")), registry, } } @@ -925,8 +929,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn count(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let counter = unsafe { self.counters.get_unchecked(id) }; + let info = &INFO[info]; + let counter = &self.counters[id]; counter.record(info, value); } #[doc = r" Returns all of the registered measures"] @@ -979,8 +983,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn measure(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let measure = unsafe { self.measures.get_unchecked(id) }; + let info = &INFO[info]; + let measure = &self.measures[id]; measure.record(info, value); } #[doc = r" Returns all of the registered gauges"] @@ -991,8 +995,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn gauge(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let gauge = unsafe { self.gauges.get_unchecked(id) }; + let info = &INFO[info]; + let gauge = &self.gauges[id]; gauge.record(info, value); } #[doc = r" Returns all of the registered timers"] @@ -1009,8 +1013,8 @@ impl Subscriber { #[allow(dead_code)] #[inline(always)] fn time(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let timer = unsafe { self.timers.get_unchecked(id) }; + let info = &INFO[info]; + let timer = &self.timers[id]; timer.record(info, value); } } diff --git a/quic/s2n-quic-core/src/event/generated/metrics/probe.rs b/quic/s2n-quic-core/src/event/generated/metrics/probe.rs index 458d45db7..3423b766e 100644 --- a/quic/s2n-quic-core/src/event/generated/metrics/probe.rs +++ b/quic/s2n-quic-core/src/event/generated/metrics/probe.rs @@ -27,7 +27,7 @@ mod counter { 9usize => Self(frame_sent), 10usize => Self(frame_received), 11usize => Self(packet_lost), - 12usize => Self(packet_lost__bytes_lost__total), + 12usize => Self(packet_lost__bytes__total), 14usize => Self(recovery_metrics), 23usize => Self(congestion), 24usize => Self(rx_ack_range_dropped), @@ -123,8 +123,8 @@ mod counter { fn frame_received(value: u64); # [link_name = s2n_quic__event__counter__packet_lost] fn packet_lost(value: u64); - # [link_name = s2n_quic__event__counter__packet_lost__bytes_lost__total] - fn packet_lost__bytes_lost__total(value: u64); + # [link_name = s2n_quic__event__counter__packet_lost__bytes__total] + fn packet_lost__bytes__total(value: u64); # [link_name = s2n_quic__event__counter__recovery_metrics] fn recovery_metrics(value: u64); # [link_name = s2n_quic__event__counter__congestion] @@ -260,7 +260,7 @@ mod measure { pub(super) fn new(info: &'static Info) -> Self { match info.id { 5usize => Self(packet_sent__bytes), - 13usize => Self(packet_lost__bytes_lost), + 13usize => Self(packet_lost__bytes), 15usize => Self(recovery_metrics__min_rtt), 16usize => Self(recovery_metrics__smoothed_rtt), 17usize => Self(recovery_metrics__latest_rtt), @@ -309,8 +309,8 @@ mod measure { extern "probe" { # [link_name = s2n_quic__event__measure__packet_sent__bytes] fn packet_sent__bytes(value: u64); - # [link_name = s2n_quic__event__measure__packet_lost__bytes_lost] - fn packet_lost__bytes_lost(value: u64); + # [link_name = s2n_quic__event__measure__packet_lost__bytes] + fn packet_lost__bytes(value: u64); # [link_name = s2n_quic__event__measure__recovery_metrics__min_rtt] fn recovery_metrics__min_rtt(value: u64); # [link_name = s2n_quic__event__measure__recovery_metrics__smoothed_rtt] diff --git a/quic/s2n-quic-core/src/event/metrics/aggregate/info.rs b/quic/s2n-quic-core/src/event/metrics/aggregate/info.rs index 60792d080..d124ace27 100644 --- a/quic/s2n-quic-core/src/event/metrics/aggregate/info.rs +++ b/quic/s2n-quic-core/src/event/metrics/aggregate/info.rs @@ -8,15 +8,15 @@ use core::{ffi::CStr, fmt, ops}; #[non_exhaustive] pub struct Info { pub id: usize, - pub name: Str<'static>, - pub units: Str<'static>, + pub name: &'static Str, + pub units: &'static Str, } #[doc(hidden)] pub struct Builder { pub id: usize, - pub name: Str<'static>, - pub units: Str<'static>, + pub name: &'static Str, + pub units: &'static Str, } impl Builder { @@ -31,66 +31,97 @@ impl Builder { } /// A str that is also a [`CStr`] -#[derive(Clone, Copy)] -pub struct Str<'a>(usize, &'a CStr); +#[repr(transparent)] +pub struct Str(str); + +impl Str { + /// Creates a new `Str` value + /// + /// # Panics + /// + /// The provided slice **must** be nul-terminated and not contain any interior + /// nul bytes. + pub const fn new(value: &str) -> &Self { + { + let value = value.as_bytes(); + + if value.is_empty() { + panic!("provided string is empty"); + } + + let last_idx = value.len() - 1; + + if value[last_idx] != 0 { + panic!("string does not end in nul byte"); + } + + let mut idx = 0; + while idx < last_idx { + if value[idx] == 0 { + panic!("string contains nul byte"); + } + idx += 1; + } + } + + unsafe { Self::new_unchecked(value) } + } -impl<'a> Str<'a> { /// # Safety /// - /// The provided value must end in a `\0` character - pub const unsafe fn new_unchecked(value: &'a str) -> Self { + /// The provided slice **must** be nul-terminated and not contain any interior + /// nul bytes. + pub const unsafe fn new_unchecked(value: &str) -> &Self { unsafe { - Self( - value.len() - 1, - CStr::from_bytes_with_nul_unchecked(value.as_bytes()), - ) + // SAFETY: `Self` is `repr(transparent) over a `str`` + core::mem::transmute::<&str, &Self>(value) } } } -impl fmt::Debug for Str<'_> { +impl fmt::Debug for Str { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } -impl fmt::Display for Str<'_> { +impl fmt::Display for Str { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } -impl ops::Deref for Str<'_> { +impl ops::Deref for Str { type Target = str; #[inline] fn deref(&self) -> &Self::Target { - let len = self.0; - let ptr = self.1.as_ptr(); unsafe { - let bytes = core::slice::from_raw_parts(ptr as *const u8, len); - core::str::from_utf8_unchecked(bytes) + // SAFETY: string was already checked to contain at least one byte + assume!(!self.0.is_empty()); } + let len = self.0.len() - 1; + &self.0[..len] } } -impl AsRef for Str<'_> { +impl AsRef for Str { #[inline] fn as_ref(&self) -> &str { self } } -impl AsRef for Str<'_> { +impl AsRef for Str { #[inline] fn as_ref(&self) -> &CStr { - self.1 + unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes()) } } } -impl probe::Arg for Str<'_> { +impl probe::Arg for &Str { #[inline] fn into_usdt(self) -> isize { - self.1.as_ptr() as _ + self.0.as_ptr() as _ } } diff --git a/quic/s2n-quic-core/src/event/metrics/aggregate/probe/dynamic.rs b/quic/s2n-quic-core/src/event/metrics/aggregate/probe/dynamic.rs index df3b71a4a..c422cb41b 100644 --- a/quic/s2n-quic-core/src/event/metrics/aggregate/probe/dynamic.rs +++ b/quic/s2n-quic-core/src/event/metrics/aggregate/probe/dynamic.rs @@ -42,10 +42,10 @@ macro_rules! recorder { define!( extern "probe" { #[link_name = $register] - fn register(id: usize, name: Str, units: Str); + fn register(id: usize, name: &Str, units: &Str); #[link_name = $record] - fn record(id: usize, name: Str, units: Str, value: u64); + fn record(id: usize, name: &Str, units: &Str, value: u64); } ); diff --git a/quic/s2n-quic-events/src/output/metrics/aggregate.rs b/quic/s2n-quic-events/src/output/metrics/aggregate.rs index e3631aeb7..987f8ad86 100644 --- a/quic/s2n-quic-events/src/output/metrics/aggregate.rs +++ b/quic/s2n-quic-events/src/output/metrics/aggregate.rs @@ -10,7 +10,7 @@ use quote::{quote, ToTokens}; fn new_str(value: impl AsRef) -> TokenStream { let value_c = format!("{}\0", value.as_ref()); - quote!(new_str(#value_c)) + quote!(Str::new(#value_c)) } pub fn emit(output: &Output, files: &[File]) -> TokenStream { @@ -156,25 +156,29 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { let tokens = quote!( #imports - use crate::event::{metrics::aggregate::{Registry, Recorder, Info, info, AsMetric as _}, api, self}; - - const fn new_str(bytes: &'static str) -> info::Str<'static> { - unsafe { - info::Str::new_unchecked(bytes) - } - } + use crate::event::{ + metrics::aggregate::{ + Registry, + Recorder, + Info, + info::{self, Str}, + AsMetric as _ + }, + api, + self + }; static INFO: &[Info; #info_len] = &[#info]; pub struct Subscriber { #[allow(dead_code)] - counters: Box<[R::Counter]>, + counters: Box<[R::Counter; #counters_len]>, #[allow(dead_code)] - measures: Box<[R::Measure]>, + measures: Box<[R::Measure; #measures_len]>, #[allow(dead_code)] - gauges: Box<[R::Gauge]>, + gauges: Box<[R::Gauge; #gauges_len]>, #[allow(dead_code)] - timers: Box<[R::Timer]>, + timers: Box<[R::Timer; #timers_len]>, #[allow(dead_code)] registry: R, } @@ -206,10 +210,10 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { #timers_init Self { - counters: counters.into(), - measures: measures.into(), - gauges: gauges.into(), - timers: timers.into(), + counters: counters.try_into().unwrap_or_else(|_| panic!("invalid len")), + measures: measures.try_into().unwrap_or_else(|_| panic!("invalid len")), + gauges: gauges.try_into().unwrap_or_else(|_| panic!("invalid len")), + timers: timers.try_into().unwrap_or_else(|_| panic!("invalid len")), registry, } } @@ -223,8 +227,8 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { #[allow(dead_code)] #[inline(always)] fn count(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let counter = unsafe { self.counters.get_unchecked(id) }; + let info = &INFO[info]; + let counter = &self.counters[id]; counter.record(info, value); } @@ -237,8 +241,8 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { #[allow(dead_code)] #[inline(always)] fn measure(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let measure = unsafe { self.measures.get_unchecked(id) }; + let info = &INFO[info]; + let measure = &self.measures[id]; measure.record(info, value); } @@ -251,8 +255,8 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { #[allow(dead_code)] #[inline(always)] fn gauge(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let gauge = unsafe { self.gauges.get_unchecked(id) }; + let info = &INFO[info]; + let gauge = &self.gauges[id]; gauge.record(info, value); } @@ -265,8 +269,8 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream { #[allow(dead_code)] #[inline(always)] fn time(&self, info: usize, id: usize, value: u64) { - let info = unsafe { INFO.get_unchecked(info) }; - let timer = unsafe { self.timers.get_unchecked(id) }; + let info = &INFO[info]; + let timer = &self.timers[id]; timer.record(info, value); } }