Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libdd-profiling-ffi/src/profiles/profiles_dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ pub static DDOG_PROF_STRINGID2_TRACE_ENDPOINT: StringId2 =
#[no_mangle]
pub static DDOG_PROF_STRINGID2_SPAN_ID: StringId2 = StringId2::from(StringRef::SPAN_ID);

/// A StringId that represents the string "thread id".
/// This is always available in every string set and can be used without
/// needing to insert it into a string set.
#[no_mangle]
pub static DDOG_PROF_STRINGID2_THREAD_ID: StringId2 = StringId2::from(StringRef::THREAD_ID);

/// A StringId that represents the string "thread name".
/// This is always available in every string set and can be used without
/// needing to insert it into a string set.
#[no_mangle]
pub static DDOG_PROF_STRINGID2_THREAD_NAME: StringId2 = StringId2::from(StringRef::THREAD_NAME);

const NULL_PROFILES_DICTIONARY: &CStr = c"passed a null pointer for a ProfilesDictionary";

/// Allocates a new `ProfilesDictionary` and writes a handle to it in `handle`.
Expand Down
14 changes: 14 additions & 0 deletions libdd-profiling/src/profiles/collections/parallel/string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ mod tests {
"local root span id",
"trace endpoint",
"span id",
"thread id",
"thread name",
];
for (expected, id) in strs.iter().copied().zip(WELL_KNOWN_STRING_REFS) {
let actual: &str = id.0.deref();
Expand Down Expand Up @@ -140,6 +142,12 @@ mod tests {

let str = set.get(StringRef::SPAN_ID);
assert_eq!(str, "span id");

let str = set.get(StringRef::THREAD_ID);
assert_eq!(str, "thread id");

let str = set.get(StringRef::THREAD_NAME);
assert_eq!(str, "thread name");
};

let id = set.try_insert("").unwrap();
Expand All @@ -156,6 +164,12 @@ mod tests {

let id = set.try_insert("span id").unwrap();
assert_eq!(&*id.0, &*StringRef::SPAN_ID.0);

let id = set.try_insert("thread id").unwrap();
assert_eq!(&*id.0, &*StringRef::THREAD_ID.0);

let id = set.try_insert("thread name").unwrap();
assert_eq!(&*id.0, &*StringRef::THREAD_NAME.0);
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion libdd-profiling/src/profiles/collections/string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ impl StringRef {
pub const LOCAL_ROOT_SPAN_ID: StringRef = StringRef(ThinStr::local_root_span_id());
pub const TRACE_ENDPOINT: StringRef = StringRef(ThinStr::trace_endpoint());
pub const SPAN_ID: StringRef = StringRef(ThinStr::span_id());
pub const THREAD_ID: StringRef = StringRef(ThinStr::thread_id());
pub const THREAD_NAME: StringRef = StringRef(ThinStr::thread_name());
}

pub const WELL_KNOWN_STRING_REFS: [StringRef; 5] = [
pub const WELL_KNOWN_STRING_REFS: [StringRef; 7] = [
StringRef::EMPTY,
StringRef::END_TIMESTAMP_NS,
StringRef::LOCAL_ROOT_SPAN_ID,
StringRef::TRACE_ENDPOINT,
StringRef::SPAN_ID,
StringRef::THREAD_ID,
StringRef::THREAD_NAME,
];

/// Holds unique strings and provides [`StringRef`]s to fetch them later.
Expand Down
20 changes: 20 additions & 0 deletions libdd-profiling/src/profiles/collections/thin_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ impl ThinStr<'static> {
},
}
}

pub const fn thread_id() -> ThinStr<'static> {
ThinStr {
inner: ThinSlice {
thin_ptr: THREAD_ID.as_thin_ptr(),
_marker: PhantomData,
},
}
}

pub const fn thread_name() -> ThinStr<'static> {
ThinStr {
inner: ThinSlice {
thin_ptr: THREAD_NAME.as_thin_ptr(),
_marker: PhantomData,
},
}
}
}

impl Default for ThinStr<'static> {
Expand Down Expand Up @@ -527,6 +545,8 @@ static END_TIMESTAMP_NS: ConstString<16> = ConstString::new("end_timestamp_ns");
static LOCAL_ROOT_SPAN_ID: ConstString<18> = ConstString::new("local root span id");
static TRACE_ENDPOINT: ConstString<14> = ConstString::new("trace endpoint");
static SPAN_ID: ConstString<7> = ConstString::new("span id");
static THREAD_ID: ConstString<9> = ConstString::new("thread id");
static THREAD_NAME: ConstString<11> = ConstString::new("thread name");

#[cfg(test)]
mod tests {
Expand Down
Loading