Skip to content

Commit 8e85201

Browse files
committed
Widen probe ID from u8 to u16
1 parent 0875a36 commit 8e85201

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/internal_telemetry/component_probes.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use std::{
99
marker::PhantomData,
10-
sync::atomic::{AtomicU8, Ordering},
10+
sync::atomic::{AtomicU16, Ordering},
1111
};
1212

1313
use tracing::{
@@ -17,19 +17,19 @@ use tracing::{
1717
};
1818
use tracing_subscriber::{Layer, layer::Context, registry::LookupSpan};
1919

20-
/// Returns a leaked `&'static AtomicU8` unique to the current thread.
20+
/// Returns a leaked `&'static AtomicU16` unique to the current thread.
2121
///
2222
/// On first access, allocates a byte via `Box::leak` and calls
2323
/// [`vector_register_thread`] so bpftrace can map this thread's TID
2424
/// to the byte's address. The leaked byte is valid for the process lifetime.
25-
fn thread_label() -> &'static AtomicU8 {
25+
fn thread_label() -> &'static AtomicU16 {
2626
thread_local! {
27-
static LABEL: &'static AtomicU8 = {
28-
let label: &'static AtomicU8 = Box::leak(Box::new(AtomicU8::new(0)));
27+
static LABEL: &'static AtomicU16 = {
28+
let label: &'static AtomicU16 = Box::leak(Box::new(AtomicU16::new(0)));
2929
#[cfg(target_os = "linux")]
3030
{
3131
let tid = nix::unistd::gettid().as_raw() as u64;
32-
vector_register_thread(tid, label as *const AtomicU8 as *const u8);
32+
vector_register_thread(tid, label as *const AtomicU16 as *const u8);
3333
}
3434
label
3535
};
@@ -52,18 +52,18 @@ pub extern "C" fn vector_register_thread(tid: u64, label_ptr: *const u8) {
5252
#[inline(never)]
5353
#[allow(clippy::missing_const_for_fn)]
5454
pub extern "C" fn vector_register_component(
55-
id: u8,
55+
id: u16,
5656
name_ptr: *const u8,
5757
name_len: usize,
5858
) {
5959
std::hint::black_box((id, name_ptr, name_len));
6060
}
6161

6262
/// Next probe group ID. 0 means idle (no component active).
63-
static NEXT_PROBE_ID: AtomicU8 = AtomicU8::new(1);
63+
static NEXT_PROBE_ID: AtomicU16 = AtomicU16::new(1);
6464

6565
/// Stored in span extensions to associate a span with a probe group ID.
66-
struct ProbeGroupId(u8);
66+
struct ProbeGroupId(u16);
6767

6868
/// Extracts the `component_id` field value from span attributes.
6969
#[derive(Default)]
@@ -86,7 +86,7 @@ impl Visit for ComponentIdVisitor {
8686
}
8787

8888
/// A tracing layer that writes the active component's group ID to a per-thread
89-
/// [`AtomicU8`] on span enter and clears it on exit.
89+
/// [`AtomicU16`] on span enter and clears it on exit.
9090
///
9191
/// Detects component spans via the `component_id` field in `on_new_span`,
9292
/// assigns a unique probe group ID, and registers the mapping with bpftrace
@@ -157,7 +157,7 @@ mod tests {
157157
#[test]
158158
fn thread_label_store_and_clear() {
159159
let label = thread_label();
160-
let group_id: u8 = 7;
160+
let group_id: u16 = 7;
161161

162162
label.store(group_id, Ordering::Relaxed);
163163
assert_eq!(label.load(Ordering::Relaxed), group_id);
@@ -180,7 +180,7 @@ mod tests {
180180
for _ in 0..4 {
181181
let tx = tx.clone();
182182
std::thread::spawn(move || {
183-
tx.send(thread_label() as *const AtomicU8 as usize)
183+
tx.send(thread_label() as *const AtomicU16 as usize)
184184
.unwrap();
185185
});
186186
}

0 commit comments

Comments
 (0)