libdd_profiling/internal/
function.rs

1// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4use super::*;
5
6/// Represents a [pprof::Function] with some space-saving changes:
7///  - The id is not stored on the struct. It's stored in the container that holds the struct.
8///  - ids for linked objects use 32-bit numbers instead of 64 bit ones.
9#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
10pub struct Function {
11    pub name: StringId,
12    pub system_name: StringId,
13    pub filename: StringId,
14}
15
16impl Item for Function {
17    type Id = FunctionId;
18}
19
20#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
21#[repr(C)]
22pub struct FunctionId(NonZeroU32);
23
24impl Id for FunctionId {
25    type RawId = u64;
26
27    fn from_offset(offset: usize) -> Self {
28        #[allow(clippy::expect_used)]
29        Self(small_non_zero_pprof_id(offset).expect("FunctionId to fit into a u32"))
30    }
31
32    fn to_raw_id(&self) -> Self::RawId {
33        self.0.get().into()
34    }
35}